As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • idrozdov/gitlab-shell
  • mmj/gitlab-shell
2 results
Show changes
Commits on Source (190)
Showing
with 200 additions and 83 deletions
Loading
@@ -7,11 +7,7 @@
Loading
@@ -7,11 +7,7 @@
.gitlab_shell_secret .gitlab_shell_secret
.idea .idea
/*.log* /*.log*
/bin/check /bin/*
/bin/gitlab-shell
/bin/gitlab-shell-authorized-keys-check
/bin/gitlab-shell-authorized-principals-check
/bin/gitlab-sshd
/gl-code-quality-report.json /gl-code-quality-report.json
/go_build /go_build
/support/bin/golangci-* /support/bin/golangci-*
Loading
Loading
Loading
@@ -3,27 +3,29 @@ include:
Loading
@@ -3,27 +3,29 @@ include:
- template: Security/SAST.gitlab-ci.yml - template: Security/SAST.gitlab-ci.yml
- template: Security/Dependency-Scanning.gitlab-ci.yml - template: Security/Dependency-Scanning.gitlab-ci.yml
- template: Security/Secret-Detection.gitlab-ci.yml - template: Security/Secret-Detection.gitlab-ci.yml
- component: ${CI_SERVER_FQDN}/gitlab-org/components/danger-review/danger-review@1.4.1
stages: stages:
- prepare - prepare
- lint
- test - test
- post-test
variables: variables:
FF_USE_FASTZIP: 'true' FF_USE_FASTZIP: 'true'
TRANSFER_METER_FREQUENCY: "1s" TRANSFER_METER_FREQUENCY: "1s"
DOCKER_VERSION: "20.10.15" DOCKER_VERSION: "20.10.15"
BUNDLE_FROZEN: "true" BUNDLE_FROZEN: "true"
GO_VERSION: "golang-1.22" GO_VERSION: "1.23"
GOPATH: $CI_PROJECT_DIR/.GOPATH GOPATH: $CI_PROJECT_DIR/.GOPATH
DEBIAN_VERSION: "bookworm" DEBIAN_VERSION: "bookworm"
RUBY_VERSION: "3.2.4" RUBY_VERSION: "3.2.5"
BUNDLE_PATH: vendor/ruby BUNDLE_PATH: vendor/ruby
POLICY: pull POLICY: pull
CI_DEBUG_SERVICES: 'true' CI_DEBUG_SERVICES: 'true'
RUST_VERSION: "rust-1.73" RUST_VERSION: "1.73"
UBI_VERSION: "8.6" UBI_VERSION: "8.6"
IMAGE_TAG: "rubygems-3.4-git-2.36-exiftool-12.60" IMAGE_TAG: "rubygems-3.5-git-2.45-exiftool-12.60"
GITLAB_ADVANCED_SAST_ENABLED: 'true'
workflow: workflow:
rules: &workflow_rules rules: &workflow_rules
Loading
@@ -34,8 +36,15 @@ workflow:
Loading
@@ -34,8 +36,15 @@ workflow:
# For tags, create a pipeline. # For tags, create a pipeline.
- if: '$CI_COMMIT_TAG' - if: '$CI_COMMIT_TAG'
.rules:go-changes:
rules:
- changes:
- 'go.mod'
- 'go.sum'
- '**/*.go'
default: default:
image: registry.gitlab.com/gitlab-org/gitlab-build-images/debian-${DEBIAN_VERSION}-ruby-${RUBY_VERSION}-${GO_VERSION}-${RUST_VERSION}:${IMAGE_TAG} image: registry.gitlab.com/gitlab-org/gitlab-build-images/debian-${DEBIAN_VERSION}-ruby-${RUBY_VERSION}-golang-${GO_VERSION}-rust-${RUST_VERSION}:${IMAGE_TAG}
tags: tags:
- gitlab-org - gitlab-org
Loading
@@ -49,7 +58,7 @@ default:
Loading
@@ -49,7 +58,7 @@ default:
.cached-go: &cached_go .cached-go: &cached_go
- key: - key:
prefix: $GO_VERSION-cache prefix: "golang-${GO_VERSION}-cache"
files: files:
- go.mod - go.mod
- go.sum - go.sum
Loading
@@ -84,7 +93,7 @@ default:
Loading
@@ -84,7 +93,7 @@ default:
.go-matrix-job: .go-matrix-job:
parallel: parallel:
matrix: matrix:
- GO_VERSION: ["golang-1.21", "golang-1.22"] - GO_VERSION: ["1.22", "1.23"]
################################################################################ ################################################################################
# Prepare jobs # Prepare jobs
Loading
@@ -114,6 +123,7 @@ modules:download:
Loading
@@ -114,6 +123,7 @@ modules:download:
.test-job: .test-job:
needs: ['bundle:install', 'modules:download'] needs: ['bundle:install', 'modules:download']
rules: !reference [".rules:go-changes", rules]
variables: variables:
GITALY_CONNECTION_INFO: '{"address":"tcp://gitaly:8075", "storage":"default"}' GITALY_CONNECTION_INFO: '{"address":"tcp://gitaly:8075", "storage":"default"}'
before_script: before_script:
Loading
@@ -156,7 +166,7 @@ tests_without_cgo:
Loading
@@ -156,7 +166,7 @@ tests_without_cgo:
- make verify test_fancy - make verify test_fancy
tests:fips: tests:fips:
image: registry.gitlab.com/gitlab-org/gitlab-build-images/ubi-${UBI_VERSION}-ruby-${RUBY_VERSION}-${GO_VERSION}-${RUST_VERSION}:${IMAGE_TAG} image: registry.gitlab.com/gitlab-org/gitlab-build-images/ubi-${UBI_VERSION}-ruby-${RUBY_VERSION}-golang-${GO_VERSION}-rust-${RUST_VERSION}:${IMAGE_TAG}
extends: extends:
- .cached-job - .cached-job
- .test-job - .test-job
Loading
@@ -174,10 +184,12 @@ race:
Loading
@@ -174,10 +184,12 @@ race:
- make test_golang_race - make test_golang_race
code_quality: code_quality:
stage: lint
extends: .use-docker-in-docker extends: .use-docker-in-docker
rules: *workflow_rules rules: *workflow_rules
code_navigation: code_navigation:
stage: post-test
image: sourcegraph/lsif-go:v1.9 image: sourcegraph/lsif-go:v1.9
allow_failure: true allow_failure: true
script: script:
Loading
@@ -188,17 +200,25 @@ code_navigation:
Loading
@@ -188,17 +200,25 @@ code_navigation:
# SAST # SAST
semgrep-sast: semgrep-sast:
stage: lint
rules: *workflow_rules
gitlab-advanced-sast:
stage: lint
rules: *workflow_rules rules: *workflow_rules
# Dependency Scanning # Dependency Scanning
gemnasium-dependency_scanning: gemnasium-dependency_scanning:
stage: lint
rules: *workflow_rules rules: *workflow_rules
# Secret Detection # Secret Detection
secret_detection: secret_detection:
stage: lint
rules: *workflow_rules rules: *workflow_rules
build-package-and-qa: build-package-and-qa:
stage: post-test
trigger: trigger:
project: 'gitlab-org/build/omnibus-gitlab-mirror' project: 'gitlab-org/build/omnibus-gitlab-mirror'
branch: 'master' branch: 'master'
Loading
@@ -230,13 +250,14 @@ build-package-and-qa:
Loading
@@ -230,13 +250,14 @@ build-package-and-qa:
needs: [] needs: []
modules:tidy: modules:tidy:
stage: lint
needs: ['modules:download'] needs: ['modules:download']
script: script:
- go mod tidy - go mod tidy
- git diff --exit-code go.mod go.sum - git diff --exit-code go.mod go.sum
lint: lint:
stage: test stage: lint
script: script:
# Write the code coverage report to gl-code-quality-report.json # Write the code coverage report to gl-code-quality-report.json
# and print linting issues to stdout in the format: path/to/file:line description # and print linting issues to stdout in the format: path/to/file:line description
Loading
@@ -252,7 +273,8 @@ lint:
Loading
@@ -252,7 +273,8 @@ lint:
- gl-code-quality-report.json - gl-code-quality-report.json
nilaway: nilaway:
stage: test stage: lint
rules: !reference [".rules:go-changes", rules]
before_script: before_script:
- go install go.uber.org/nilaway/cmd/nilaway@latest - go install go.uber.org/nilaway/cmd/nilaway@latest
script: script:
Loading
Loading
# https://gitlab.com/groups/gitlab-org/maintainers/gitlab-shell/-/group_members?with_inherited_permissions=exclude # https://gitlab.com/groups/gitlab-org/maintainers/gitlab-shell/-/group_members?with_inherited_permissions=exclude
* @gitlab-org/maintainers/gitlab-shell * @gitlab-org/maintainers/gitlab-shell
[Documentation] [Documentation] @gl-docsteam
*.md @aqualls *.md
/doc/
Loading
@@ -61,6 +61,8 @@ output:
Loading
@@ -61,6 +61,8 @@ output:
# print linter name in the end of issue text, default is true # print linter name in the end of issue text, default is true
print-linter-name: true print-linter-name: true
sort-results: true
# all available settings of specific linters # all available settings of specific linters
linters-settings: linters-settings:
errcheck: errcheck:
Loading
@@ -262,11 +264,11 @@ linters:
Loading
@@ -262,11 +264,11 @@ linters:
disable-all: true disable-all: true
enable: enable:
- bodyclose - bodyclose
- copyloopvar
- depguard - depguard
- dogsled - dogsled
- dupl - dupl
- errcheck - errcheck
- exportloopref
- funlen - funlen
- gocognit - gocognit
- goconst - goconst
Loading
Loading
3.2.3 3.3.4
ruby 3.2.3 ruby 3.3.5
golang 1.22.4 golang 1.23.2
v14.39.0
- Revise CODEOWNERS to use entire TW team !1125
- Rename bin/check to bin/gitlab-shell-check to to avoid name clash !801
- Update golangci to 1.60.1 !1122
- Move bin/install to support/make_necessary_dirs !799
- Update dependency golang to v1.23.0 !1121
- Use go build so we can use -o !1117
- Add 'make make_necessary_dirs' alias !1119
- Add GitLab Advanced SAST to CI/CD config !1120
- Update github.com/charmbracelet/git-lfs-transfer digest to 2cab0ea !1118
- Update module golang.org/x/crypto to v0.26.0 !1115
- Update dependency golang to v1.22.6 !1116
- Update github.com/charmbracelet/git-lfs-transfer digest to c3aa24b !1113
- Update module gitlab.com/gitlab-org/gitaly/v16 to v16.11.8 !1114
- Update module golang.org/x/sync to v0.8.0 !1112
v14.38.0
- Update module gitlab.com/gitlab-org/gitaly/v16 to v16.11.7 !1110
- Add basic LFS connections metric for SSH !1107
- Update module google.golang.org/grpc to v1.65.0 !1098
- Add basic LFS connections metric for HTTP !1108
- Remove migration section as no longer supported !1106
- Update module gitlab.com/gitlab-org/gitaly/v16 to v16.11.6 !1104
- Update dependency ruby to v3.3.4 !1102
- Update Ruby to 3.3.4 !1105
- Update module golang.org/x/crypto to v0.25.0 !1100
- Update github.com/charmbracelet/git-lfs-transfer digest to bacbfdb !1101
- Restructure CI jobs !1097
- Update dependency golang to v1.22.5 !1099
v14.37.0 v14.37.0
- Update dependency danger-review to v1.4.1 !1095 - Update dependency danger-review to v1.4.1 !1095
Loading
Loading
Loading
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
Loading
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
group :development, :test do group :development, :test do
gem 'rspec', '~> 3.13.0' gem 'rspec', '~> 3.13.0'
gem 'webrick', '~> 1.8', '>= 1.8.1' gem 'webrick', '~> 1.8', '>= 1.8.2'
end end
group :development, :danger do group :development, :danger do
Loading
Loading
Loading
@@ -91,7 +91,7 @@ GEM
Loading
@@ -91,7 +91,7 @@ GEM
unicode-display_width (>= 1.1.1, < 3) unicode-display_width (>= 1.1.1, < 3)
unicode-display_width (2.5.0) unicode-display_width (2.5.0)
uri (0.13.0) uri (0.13.0)
webrick (1.8.1) webrick (1.8.2)
PLATFORMS PLATFORMS
ruby ruby
Loading
@@ -99,7 +99,7 @@ PLATFORMS
Loading
@@ -99,7 +99,7 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
gitlab-dangerfiles (~> 4.8.0) gitlab-dangerfiles (~> 4.8.0)
rspec (~> 3.13.0) rspec (~> 3.13.0)
webrick (~> 1.8, >= 1.8.1) webrick (~> 1.8, >= 1.8.2)
BUNDLED WITH BUNDLED WITH
2.5.11 2.5.11
.PHONY: validate verify verify_ruby verify_golang test test_ruby test_golang test_fancy test_golang_fancy coverage coverage_golang setup _script_install build compile check clean install lint .PHONY: validate verify verify_ruby verify_golang test test_ruby test_golang test_fancy test_golang_fancy coverage coverage_golang setup _script_install make_necessary_dirs build compile check clean install lint
FIPS_MODE ?= 0 FIPS_MODE ?= 0
OS := $(shell uname | tr A-Z a-z) OS := $(shell uname | tr A-Z a-z)
Loading
@@ -9,10 +9,10 @@ GO_TAGS := tracer_static tracer_static_jaeger continuous_profiler_stackdriver
Loading
@@ -9,10 +9,10 @@ GO_TAGS := tracer_static tracer_static_jaeger continuous_profiler_stackdriver
ARCH ?= $(shell uname -m | sed -e 's/x86_64/amd64/' | sed -e 's/aarch64/arm64/') ARCH ?= $(shell uname -m | sed -e 's/x86_64/amd64/' | sed -e 's/aarch64/arm64/')
GOTESTSUM_VERSION := 1.11.0 GOTESTSUM_VERSION := 1.12.0
GOTESTSUM_FILE := support/bin/gotestsum-${GOTESTSUM_VERSION} GOTESTSUM_FILE := support/bin/gotestsum-${GOTESTSUM_VERSION}
GOLANGCI_LINT_VERSION := 1.59.1 GOLANGCI_LINT_VERSION := 1.60.3
GOLANGCI_LINT_FILE := support/bin/golangci-lint-${GOLANGCI_LINT_VERSION} GOLANGCI_LINT_FILE := support/bin/golangci-lint-${GOLANGCI_LINT_VERSION}
export GOFLAGS := -mod=readonly export GOFLAGS := -mod=readonly
Loading
@@ -86,36 +86,42 @@ coverage: coverage_golang
Loading
@@ -86,36 +86,42 @@ coverage: coverage_golang
coverage_golang: coverage_golang:
[ -f cover.out ] && go tool cover -func cover.out [ -f cover.out ] && go tool cover -func cover.out
lint: ${GOLANGCI_LINT_FILE} lint:
${GOLANGCI_LINT_FILE} --version @support/lint.sh ./...
${GOLANGCI_LINT_FILE} run --issues-exit-code 0 --print-issued-lines=false ${GOLANGCI_LINT_ARGS}
golangci: ${GOLANGCI_LINT_FILE}
@${GOLANGCI_LINT_FILE} run --issues-exit-code 0 --print-issued-lines=false ${GOLANGCI_LINT_ARGS}
${GOLANGCI_LINT_FILE}: ${GOLANGCI_LINT_FILE}:
mkdir -p $(shell dirname ${GOLANGCI_LINT_FILE}) @mkdir -p $(shell dirname ${GOLANGCI_LINT_FILE})
curl -L https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_LINT_VERSION}/golangci-lint-${GOLANGCI_LINT_VERSION}-${OS}-${ARCH}.tar.gz | tar --strip-components 1 -zOxf - golangci-lint-${GOLANGCI_LINT_VERSION}-${OS}-${ARCH}/golangci-lint > ${GOLANGCI_LINT_FILE} && chmod +x ${GOLANGCI_LINT_FILE} @curl -L https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_LINT_VERSION}/golangci-lint-${GOLANGCI_LINT_VERSION}-${OS}-${ARCH}.tar.gz | tar --strip-components 1 -zOxf - golangci-lint-${GOLANGCI_LINT_VERSION}-${OS}-${ARCH}/golangci-lint > ${GOLANGCI_LINT_FILE} && chmod +x ${GOLANGCI_LINT_FILE}
setup: _script_install bin/gitlab-shell setup: make_necessary_dirs bin/gitlab-shell
_script_install: make_necessary_dirs:
bin/install support/make_necessary_dirs
compile: bin/gitlab-shell bin/gitlab-sshd compile: bin/gitlab-shell bin/gitlab-sshd
bin/gitlab-shell: $(GO_SOURCES)
GOBIN="$(CURDIR)/bin" go install $(GOBUILD_FLAGS) ./cmd/...
bin/gitlab-sshd: $(GO_SOURCES) bin:
GOBIN="$(CURDIR)/bin" go install $(GOBUILD_FLAGS) ./cmd/gitlab-sshd mkdir -p bin
bin/gitlab-shell: bin $(GO_SOURCES)
go build $(GOBUILD_FLAGS) -o $(CURDIR)/bin ./cmd/...
bin/gitlab-sshd: bin $(GO_SOURCES)
go build $(GOBUILD_FLAGS) -o $(CURDIR)/bin/gitlab-sshd ./cmd/gitlab-sshd
check: check:
bin/check bin/gitlab-shell-check
clean: clean:
rm -f bin/check bin/gitlab-shell bin/gitlab-shell-authorized-keys-check bin/gitlab-shell-authorized-principals-check bin/gitlab-sshd rm -f bin/*
install: compile install: compile
mkdir -p $(DESTDIR)$(PREFIX)/bin/ mkdir -p $(DESTDIR)$(PREFIX)/bin/
install -m755 bin/check $(DESTDIR)$(PREFIX)/bin/check install -m755 bin/gitlab-shell-check $(DESTDIR)$(PREFIX)/bin/
install -m755 bin/gitlab-shell $(DESTDIR)$(PREFIX)/bin/gitlab-shell install -m755 bin/gitlab-shell $(DESTDIR)$(PREFIX)/bin/
install -m755 bin/gitlab-shell-authorized-keys-check $(DESTDIR)$(PREFIX)/bin/gitlab-shell-authorized-keys-check install -m755 bin/gitlab-shell-authorized-keys-check $(DESTDIR)$(PREFIX)/bin/
install -m755 bin/gitlab-shell-authorized-principals-check $(DESTDIR)$(PREFIX)/bin/gitlab-shell-authorized-principals-check install -m755 bin/gitlab-shell-authorized-principals-check $(DESTDIR)$(PREFIX)/bin/
install -m755 bin/gitlab-sshd $(DESTDIR)$(PREFIX)/bin/gitlab-sshd install -m755 bin/gitlab-sshd $(DESTDIR)$(PREFIX)/bin/
Loading
@@ -4,10 +4,48 @@ group: Source Code
Loading
@@ -4,10 +4,48 @@ group: Source Code
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
--- ---
# GitLab Shell documentation has moved
[![pipeline status](https://gitlab.com/gitlab-org/gitlab-shell/badges/main/pipeline.svg)](https://gitlab.com/gitlab-org/gitlab-shell/-/pipelines?ref=main) [![pipeline status](https://gitlab.com/gitlab-org/gitlab-shell/badges/main/pipeline.svg)](https://gitlab.com/gitlab-org/gitlab-shell/-/pipelines?ref=main)
[![coverage report](https://gitlab.com/gitlab-org/gitlab-shell/badges/main/coverage.svg)](https://gitlab.com/gitlab-org/gitlab-shell/-/pipelines?ref=main) [![coverage report](https://gitlab.com/gitlab-org/gitlab-shell/badges/main/coverage.svg)](https://gitlab.com/gitlab-org/gitlab-shell/-/pipelines?ref=main)
[![Code Climate](https://codeclimate.com/github/gitlabhq/gitlab-shell.svg)](https://codeclimate.com/github/gitlabhq/gitlab-shell) [![Code Climate](https://codeclimate.com/github/gitlabhq/gitlab-shell.svg)](https://codeclimate.com/github/gitlabhq/gitlab-shell)
The documentation for GitLab Shell [has moved into the `gitlab` repository](https://docs.gitlab.com/ee/development/gitlab_shell/). # GitLab Shell
GitLab Shell handles Git SSH sessions for GitLab and modifies the list of
authorized keys. GitLab Shell is not a Unix shell nor a replacement for Bash or Zsh.
GitLab supports Git LFS authentication through SSH.
## Development Documentation
Development documentation for GitLab Shell [has moved into the `gitlab` repository](https://docs.gitlab.com/ee/development/gitlab_shell/).
## Project structure
| Directory | Description |
|-----------|-------------|
| `cmd/` | 'Commands' that will ultimately be compiled into binaries. |
| `internal/` | Internal Go source code that is not intended to be used outside of the project/module. |
| `client/` | HTTP and GitLab client logic that is used internally and by other modules, e.g. Gitaly. |
| `bin/` | Compiled binaries are created here. |
| `support/` | Scripts and tools that assist in development and/or testing. |
| `spec/` | Ruby based integration tests. |
## Building
Run `make` or `make build`.
## Testing
Run `make test`.
## Release Process
1. Create a `gitlab-org/gitlab-shell` MR to update [`VERSION`](https://gitlab.com/gitlab-org/gitlab-shell/-/blob/main/VERSION) and [`CHANGELOG`](https://gitlab.com/gitlab-org/gitlab-shell/-/blob/main/CHANGELOG) files, e.g. [Release v14.39.0](https://gitlab.com/gitlab-org/gitlab-shell/-/merge_requests/1123).
2. Once `gitlab-org/gitlab-shell` MR is merged, create the corresponding git tag, e.g. https://gitlab.com/gitlab-org/gitlab-shell/-/tags/v14.39.0.
3. Create a `gitlab-org/gitlab` MR to update [`GITLAB_SHELL_VERSION`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/GITLAB_SHELL_VERSION) to the proposed tag, e.g. [Bump GitLab Shell to 14.39.0](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/162661).
4. Announce in `#gitlab-shell` a new version has been created.
## Licensing
See the `LICENSE` file for licensing information as it pertains to files in
this repository.
14.37.0 14.39.0
Loading
@@ -13,6 +13,7 @@ import (
Loading
@@ -13,6 +13,7 @@ import (
"time" "time"
"github.com/golang-jwt/jwt/v5" "github.com/golang-jwt/jwt/v5"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitlab-shell/v14/client/testserver" "gitlab.com/gitlab-org/gitlab-shell/v14/client/testserver"
Loading
@@ -36,31 +37,31 @@ func TestClients(t *testing.T) {
Loading
@@ -36,31 +37,31 @@ func TestClients(t *testing.T) {
}{ }{
{ {
desc: "Socket client", desc: "Socket client",
server: testserver.StartSocketHttpServer, server: testserver.StartSocketHTTPServer,
secret: secret, secret: secret,
}, },
{ {
desc: "Socket client with a relative URL at /", desc: "Socket client with a relative URL at /",
relativeURLRoot: "/", relativeURLRoot: "/",
server: testserver.StartSocketHttpServer, server: testserver.StartSocketHTTPServer,
secret: secret, secret: secret,
}, },
{ {
desc: "Socket client with relative URL at /gitlab", desc: "Socket client with relative URL at /gitlab",
relativeURLRoot: "/gitlab", relativeURLRoot: "/gitlab",
server: testserver.StartSocketHttpServer, server: testserver.StartSocketHTTPServer,
secret: secret, secret: secret,
}, },
{ {
desc: "Http client", desc: "Http client",
server: testserver.StartHttpServer, server: testserver.StartHTTPServer,
secret: secret, secret: secret,
}, },
{ {
desc: "Https client", desc: "Https client",
caFile: path.Join(testRoot, "certs/valid/server.crt"), caFile: path.Join(testRoot, "certs/valid/server.crt"),
server: func(t *testing.T, handlers []testserver.TestRequestHandler) string { server: func(t *testing.T, handlers []testserver.TestRequestHandler) string {
return testserver.StartHttpsServer(t, handlers, "") return testserver.StartHTTPSServer(t, handlers, "")
}, },
secret: secret, secret: secret,
}, },
Loading
@@ -68,13 +69,13 @@ func TestClients(t *testing.T) {
Loading
@@ -68,13 +69,13 @@ func TestClients(t *testing.T) {
desc: "Secret with newlines", desc: "Secret with newlines",
caFile: path.Join(testRoot, "certs/valid/server.crt"), caFile: path.Join(testRoot, "certs/valid/server.crt"),
server: func(t *testing.T, handlers []testserver.TestRequestHandler) string { server: func(t *testing.T, handlers []testserver.TestRequestHandler) string {
return testserver.StartHttpsServer(t, handlers, "") return testserver.StartHTTPSServer(t, handlers, "")
}, },
secret: "\n" + secret + "\n", secret: "\n" + secret + "\n",
}, },
{ {
desc: "Retry client", desc: "Retry client",
server: testserver.StartRetryHttpServer, server: testserver.StartRetryHTTPServer,
secret: secret, secret: secret,
}, },
} }
Loading
@@ -240,7 +241,7 @@ func buildRequests(t *testing.T, relativeURLRoot string) []testserver.TestReques
Loading
@@ -240,7 +241,7 @@ func buildRequests(t *testing.T, relativeURLRoot string) []testserver.TestReques
{ {
Path: "/api/v4/internal/hello", Path: "/api/v4/internal/hello",
Handler: func(w http.ResponseWriter, r *http.Request) { Handler: func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, http.MethodGet, r.Method) assert.Equal(t, http.MethodGet, r.Method)
fmt.Fprint(w, "Hello") fmt.Fprint(w, "Hello")
}, },
Loading
@@ -248,12 +249,12 @@ func buildRequests(t *testing.T, relativeURLRoot string) []testserver.TestReques
Loading
@@ -248,12 +249,12 @@ func buildRequests(t *testing.T, relativeURLRoot string) []testserver.TestReques
{ {
Path: "/api/v4/internal/post_endpoint", Path: "/api/v4/internal/post_endpoint",
Handler: func(w http.ResponseWriter, r *http.Request) { Handler: func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, http.MethodPost, r.Method) assert.Equal(t, http.MethodPost, r.Method)
b, err := io.ReadAll(r.Body) b, err := io.ReadAll(r.Body)
defer r.Body.Close() defer r.Body.Close()
require.NoError(t, err) assert.NoError(t, err)
fmt.Fprint(w, "Echo: "+string(b)) fmt.Fprint(w, "Echo: "+string(b))
}, },
Loading
Loading
Loading
@@ -10,6 +10,7 @@ import (
Loading
@@ -10,6 +10,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitlab-shell/v14/client/testserver" "gitlab.com/gitlab-org/gitlab-shell/v14/client/testserver"
) )
Loading
@@ -34,7 +35,7 @@ func TestBasicAuthSettings(t *testing.T) {
Loading
@@ -34,7 +35,7 @@ func TestBasicAuthSettings(t *testing.T) {
{ {
Path: "/api/v4/internal/get_endpoint", Path: "/api/v4/internal/get_endpoint",
Handler: func(w http.ResponseWriter, r *http.Request) { Handler: func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, http.MethodGet, r.Method) assert.Equal(t, http.MethodGet, r.Method)
fmt.Fprint(w, r.Header.Get("Authorization")) fmt.Fprint(w, r.Header.Get("Authorization"))
}, },
Loading
@@ -42,7 +43,7 @@ func TestBasicAuthSettings(t *testing.T) {
Loading
@@ -42,7 +43,7 @@ func TestBasicAuthSettings(t *testing.T) {
{ {
Path: "/api/v4/internal/post_endpoint", Path: "/api/v4/internal/post_endpoint",
Handler: func(w http.ResponseWriter, r *http.Request) { Handler: func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, http.MethodPost, r.Method) assert.Equal(t, http.MethodPost, r.Method)
fmt.Fprint(w, r.Header.Get("Authorization")) fmt.Fprint(w, r.Header.Get("Authorization"))
}, },
Loading
@@ -82,7 +83,7 @@ func TestEmptyBasicAuthSettings(t *testing.T) {
Loading
@@ -82,7 +83,7 @@ func TestEmptyBasicAuthSettings(t *testing.T) {
{ {
Path: "/api/v4/internal/empty_basic_auth", Path: "/api/v4/internal/empty_basic_auth",
Handler: func(_ http.ResponseWriter, r *http.Request) { Handler: func(_ http.ResponseWriter, r *http.Request) {
require.Equal(t, "", r.Header.Get("Authorization")) assert.Equal(t, "", r.Header.Get("Authorization"))
}, },
}, },
} }
Loading
@@ -100,13 +101,13 @@ func TestRequestWithUserAgent(t *testing.T) {
Loading
@@ -100,13 +101,13 @@ func TestRequestWithUserAgent(t *testing.T) {
{ {
Path: "/api/v4/internal/default_user_agent", Path: "/api/v4/internal/default_user_agent",
Handler: func(_ http.ResponseWriter, r *http.Request) { Handler: func(_ http.ResponseWriter, r *http.Request) {
require.Equal(t, defaultUserAgent, r.UserAgent()) assert.Equal(t, defaultUserAgent, r.UserAgent())
}, },
}, },
{ {
Path: "/api/v4/internal/override_user_agent", Path: "/api/v4/internal/override_user_agent",
Handler: func(_ http.ResponseWriter, r *http.Request) { Handler: func(_ http.ResponseWriter, r *http.Request) {
require.Equal(t, gitalyUserAgent, r.UserAgent()) assert.Equal(t, gitalyUserAgent, r.UserAgent())
}, },
}, },
} }
Loading
@@ -125,7 +126,7 @@ func TestRequestWithUserAgent(t *testing.T) {
Loading
@@ -125,7 +126,7 @@ func TestRequestWithUserAgent(t *testing.T) {
} }
func setup(t *testing.T, username, password string, requests []testserver.TestRequestHandler) *GitlabNetClient { func setup(t *testing.T, username, password string, requests []testserver.TestRequestHandler) *GitlabNetClient {
url := testserver.StartHttpServer(t, requests) url := testserver.StartHTTPServer(t, requests)
httpClient, err := NewHTTPClientWithOpts(url, "", "", "", 1, nil) httpClient, err := NewHTTPClientWithOpts(url, "", "", "", 1, nil)
require.NoError(t, err) require.NoError(t, err)
Loading
Loading
Loading
@@ -8,6 +8,7 @@ import (
Loading
@@ -8,6 +8,7 @@ import (
"path" "path"
"testing" "testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitlab-shell/v14/client/testserver" "gitlab.com/gitlab-org/gitlab-shell/v14/client/testserver"
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/testhelper" "gitlab.com/gitlab-org/gitlab-shell/v14/internal/testhelper"
Loading
@@ -116,14 +117,14 @@ func setupWithRequests(t *testing.T, caFile, caPath, clientCAPath, clientCertPat
Loading
@@ -116,14 +117,14 @@ func setupWithRequests(t *testing.T, caFile, caPath, clientCAPath, clientCertPat
{ {
Path: "/api/v4/internal/hello", Path: "/api/v4/internal/hello",
Handler: func(w http.ResponseWriter, r *http.Request) { Handler: func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, http.MethodGet, r.Method) assert.Equal(t, http.MethodGet, r.Method)
fmt.Fprint(w, "Hello") fmt.Fprint(w, "Hello")
}, },
}, },
} }
url := testserver.StartHttpsServer(t, requests, clientCAPath) url := testserver.StartHTTPSServer(t, requests, clientCAPath)
opts := defaultHttpOpts opts := defaultHttpOpts
if clientCertPath != "" && clientKeyPath != "" { if clientCertPath != "" && clientKeyPath != "" {
Loading
Loading
Loading
@@ -22,7 +22,8 @@ type TestRequestHandler struct {
Loading
@@ -22,7 +22,8 @@ type TestRequestHandler struct {
Handler func(w http.ResponseWriter, r *http.Request) Handler func(w http.ResponseWriter, r *http.Request)
} }
func StartSocketHttpServer(t *testing.T, handlers []TestRequestHandler) string { // StartSocketHTTPServer starts a socket based HTTP server
func StartSocketHTTPServer(t *testing.T, handlers []TestRequestHandler) string {
t.Helper() t.Helper()
// We can't use t.TempDir() here because it will create a directory that // We can't use t.TempDir() here because it will create a directory that
Loading
@@ -55,7 +56,8 @@ func StartSocketHttpServer(t *testing.T, handlers []TestRequestHandler) string {
Loading
@@ -55,7 +56,8 @@ func StartSocketHttpServer(t *testing.T, handlers []TestRequestHandler) string {
return url return url
} }
func StartHttpServer(t *testing.T, handlers []TestRequestHandler) string { // StartHTTPServer starts a TCP based HTTP server
func StartHTTPServer(t *testing.T, handlers []TestRequestHandler) string {
t.Helper() t.Helper()
server := httptest.NewServer(buildHandler(handlers)) server := httptest.NewServer(buildHandler(handlers))
Loading
@@ -64,7 +66,8 @@ func StartHttpServer(t *testing.T, handlers []TestRequestHandler) string {
Loading
@@ -64,7 +66,8 @@ func StartHttpServer(t *testing.T, handlers []TestRequestHandler) string {
return server.URL return server.URL
} }
func StartRetryHttpServer(t *testing.T, handlers []TestRequestHandler) string { // StartRetryHTTPServer starts a TCP based HTTP server with retry capabilities
func StartRetryHTTPServer(t *testing.T, handlers []TestRequestHandler) string {
attempts := map[string]int{} attempts := map[string]int{}
retryMiddileware := func(next func(w http.ResponseWriter, r *http.Request)) http.Handler { retryMiddileware := func(next func(w http.ResponseWriter, r *http.Request)) http.Handler {
Loading
@@ -92,7 +95,8 @@ func StartRetryHttpServer(t *testing.T, handlers []TestRequestHandler) string {
Loading
@@ -92,7 +95,8 @@ func StartRetryHttpServer(t *testing.T, handlers []TestRequestHandler) string {
return server.URL return server.URL
} }
func StartHttpsServer(t *testing.T, handlers []TestRequestHandler, clientCAPath string) string { // StartHTTPSServer starts a TCP based HTTPS capable server
func StartHTTPSServer(t *testing.T, handlers []TestRequestHandler, clientCAPath string) string {
t.Helper() t.Helper()
testRoot := testhelper.PrepareTestRootDir(t) testRoot := testhelper.PrepareTestRootDir(t)
Loading
Loading
// Package client provides an HTTP client with enhanced logging, tracing, and correlation handling.
package client package client
import ( import (
Loading
@@ -13,6 +14,7 @@ type transport struct {
Loading
@@ -13,6 +14,7 @@ type transport struct {
next http.RoundTripper next http.RoundTripper
} }
// RoundTrip executes a single HTTP transaction, adding logging and tracing capabilities.
func (rt *transport) RoundTrip(request *http.Request) (*http.Response, error) { func (rt *transport) RoundTrip(request *http.Request) (*http.Response, error) {
ctx := request.Context() ctx := request.Context()
Loading
@@ -55,10 +57,12 @@ func (rt *transport) RoundTrip(request *http.Request) (*http.Response, error) {
Loading
@@ -55,10 +57,12 @@ func (rt *transport) RoundTrip(request *http.Request) (*http.Response, error) {
return response, nil return response, nil
} }
// DefaultTransport returns a clone of the default HTTP transport.
func DefaultTransport() http.RoundTripper { func DefaultTransport() http.RoundTripper {
return http.DefaultTransport.(*http.Transport).Clone() return http.DefaultTransport.(*http.Transport).Clone()
} }
// NewTransport creates a new transport with logging, tracing, and correlation handling.
func NewTransport(next http.RoundTripper) http.RoundTripper { func NewTransport(next http.RoundTripper) http.RoundTripper {
t := &transport{next: next} t := &transport{next: next}
return correlation.NewInstrumentedRoundTripper(tracing.NewRoundTripper(t)) return correlation.NewInstrumentedRoundTripper(tracing.NewRoundTripper(t))
Loading
Loading
// Package command handles command creation and initialization in GitLab Shell.
package command package command
import ( import (
Loading
@@ -9,6 +10,7 @@ import (
Loading
@@ -9,6 +10,7 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/config" "gitlab.com/gitlab-org/gitlab-shell/v14/internal/config"
) )
// New creates a new command based on provided arguments, config, and I/O.
func New(arguments []string, config *config.Config, readWriter *readwriter.ReadWriter) (command.Command, error) { func New(arguments []string, config *config.Config, readWriter *readwriter.ReadWriter) (command.Command, error) {
args, err := Parse(arguments) args, err := Parse(arguments)
if err != nil { if err != nil {
Loading
@@ -22,6 +24,7 @@ func New(arguments []string, config *config.Config, readWriter *readwriter.ReadW
Loading
@@ -22,6 +24,7 @@ func New(arguments []string, config *config.Config, readWriter *readwriter.ReadW
return nil, disallowedcommand.Error return nil, disallowedcommand.Error
} }
// Parse parses command-line arguments into a CommandArgs structure.
func Parse(arguments []string) (*commandargs.AuthorizedPrincipals, error) { func Parse(arguments []string) (*commandargs.AuthorizedPrincipals, error) {
args := &commandargs.AuthorizedPrincipals{Arguments: arguments} args := &commandargs.AuthorizedPrincipals{Arguments: arguments}
Loading
Loading
Loading
@@ -58,7 +58,7 @@ func TestParseSuccess(t *testing.T) {
Loading
@@ -58,7 +58,7 @@ func TestParseSuccess(t *testing.T) {
desc: "It parses authorized-principals command", desc: "It parses authorized-principals command",
executable: &executable.Executable{Name: executable.AuthorizedPrincipalsCheck}, executable: &executable.Executable{Name: executable.AuthorizedPrincipalsCheck},
arguments: []string{"key", "principal-1", "principal-2"}, arguments: []string{"key", "principal-1", "principal-2"},
expectedArgs: &commandargs.AuthorizedPrincipals{Arguments: []string{"key", "principal-1", "principal-2"}, KeyId: "key", Principals: []string{"principal-1", "principal-2"}}, expectedArgs: &commandargs.AuthorizedPrincipals{Arguments: []string{"key", "principal-1", "principal-2"}, KeyID: "key", Principals: []string{"principal-1", "principal-2"}},
}, },
} }
Loading
Loading
// Package main is the entry point for the GitLab Shell authorized principals check command.
package main package main
import ( import (
Loading
@@ -21,6 +22,10 @@ var (
Loading
@@ -21,6 +22,10 @@ var (
) )
func main() { func main() {
os.Exit(run())
}
func run() int {
command.CheckForVersionFlag(os.Args, Version, BuildTime) command.CheckForVersionFlag(os.Args, Version, BuildTime)
readWriter := &readwriter.ReadWriter{ readWriter := &readwriter.ReadWriter{
Loading
@@ -31,32 +36,33 @@ func main() {
Loading
@@ -31,32 +36,33 @@ func main() {
executable, err := executable.New(executable.AuthorizedPrincipalsCheck) executable, err := executable.New(executable.AuthorizedPrincipalsCheck)
if err != nil { if err != nil {
fmt.Fprintln(readWriter.ErrOut, "Failed to determine executable, exiting") _, _ = fmt.Fprintln(readWriter.ErrOut, "Failed to determine executable, exiting")
os.Exit(1) return 1
} }
config, err := config.NewFromDirExternal(executable.RootDir) config, err := config.NewFromDirExternal(executable.RootDir)
if err != nil { if err != nil {
fmt.Fprintln(readWriter.ErrOut, "Failed to read config, exiting") _, _ = fmt.Fprintln(readWriter.ErrOut, "Failed to read config, exiting:", err)
os.Exit(1) return 1
} }
logCloser := logger.Configure(config) logCloser := logger.Configure(config)
defer logCloser.Close() defer logCloser.Close() //nolint:errcheck
cmd, err := cmd.New(os.Args[1:], config, readWriter) cmd, err := cmd.New(os.Args[1:], config, readWriter)
if err != nil { if err != nil {
// For now this could happen if `SSH_CONNECTION` is not set on // For now this could happen if `SSH_CONNECTION` is not set on
// the environment // the environment
fmt.Fprintf(readWriter.ErrOut, "%v\n", err) _, _ = fmt.Fprintf(readWriter.ErrOut, "%v\n", err)
os.Exit(1) return 1
} }
ctx, finished := command.Setup(executable.Name, config) ctx, finished := command.Setup(executable.Name, config)
defer finished() defer finished()
if ctx, err = cmd.Execute(ctx); err != nil { if _, err = cmd.Execute(ctx); err != nil {
console.DisplayWarningMessage(err.Error(), readWriter.ErrOut) console.DisplayWarningMessage(err.Error(), readWriter.ErrOut)
os.Exit(1) return 1
} }
return 0
} }