Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2020-08-20 07:31:37 +0300
committerStan Hu <stanhu@gmail.com>2020-08-21 23:06:06 +0300
commit09a6677212e8b507f368f5b80e92525c577ab256 (patch)
tree058a7a0e5988e76e2a2e173356f4eb3b9c9dccce
parenta7f84c7c8ea135881fd2cc6c7f48fdc487b125fb (diff)
Fix Git hooks when GitLab relative URL path and UNIX socket in use
Previously if GitLab were configured to use a relative URL (e.g. `/gitlab`) and the Gitaly `gitlab.url` configuration used the http+unix:// scheme, the hooks would not be able to contact the API server. We add an explicit `relative_url_root` parameter to make it possible for all connections to go through Workhorse. This commit depends on changes in https://gitlab.com/gitlab-org/gitlab-shell/-/merge_requests/406. NOTE: This only fixes the Git hooks that are implemented in Go. The Ruby gitlab-shell hooks don't appear to have ever work with GitLab installations using a relative URL when a UNIX domain socket is used. Omnibus installations bypass Workhorse and talk directly to the Web server. Relates to https://gitlab.com/gitlab-org/gitlab-shell/-/issues/476
-rw-r--r--changelogs/unreleased/sh-support-gitlab-shell-relative-path.yml5
-rw-r--r--config.toml.example3
-rw-r--r--go.mod3
-rw-r--r--go.sum6
-rw-r--r--internal/config/config.go7
-rw-r--r--internal/service/hook/access.go1
6 files changed, 16 insertions, 9 deletions
diff --git a/changelogs/unreleased/sh-support-gitlab-shell-relative-path.yml b/changelogs/unreleased/sh-support-gitlab-shell-relative-path.yml
new file mode 100644
index 000000000..d8916b838
--- /dev/null
+++ b/changelogs/unreleased/sh-support-gitlab-shell-relative-path.yml
@@ -0,0 +1,5 @@
+---
+title: Fix Git hooks when GitLab relative URL path and UNIX socket in use
+merge_request: 2485
+author:
+type: fixed
diff --git a/config.toml.example b/config.toml.example
index 1332f6f9d..d0b2db3d1 100644
--- a/config.toml.example
+++ b/config.toml.example
@@ -93,6 +93,9 @@ custom_hooks_dir = "/home/git/custom_hooks"
[gitlab]
secret_file = "/home/git/gitlab-shell/.gitlab_shell_secret"
url = "http+unix://%2Fhome%2Fgit%2Fgitlab%2Ftmp%2Fsockets%2Fgitlab-workhorse.socket"
+# Only needed if a UNIX socket is used in `url` and GitLab is configured to
+# use a relative path (e.g. /gitlab).
+# relative_url_root = '/'
[gitlab.http-settings]
# read_timeout = 300
diff --git a/go.mod b/go.mod
index c9581053b..a6eaf436b 100644
--- a/go.mod
+++ b/go.mod
@@ -12,13 +12,12 @@ require (
github.com/kelseyhightower/envconfig v1.3.0
github.com/lib/pq v1.2.0
github.com/olekukonko/tablewriter v0.0.2
- github.com/otiai10/curr v1.0.0 // indirect
github.com/prometheus/client_golang v1.0.0
github.com/prometheus/procfs v0.0.3 // indirect
github.com/rubenv/sql-migrate v0.0.0-20191213152630-06338513c237
github.com/sirupsen/logrus v1.4.2
github.com/stretchr/testify v1.4.0
- gitlab.com/gitlab-org/gitlab-shell v1.9.8-0.20200506213341-716e30c55e89
+ gitlab.com/gitlab-org/gitlab-shell v0.0.0-20200821152636-82ec8144fb2a
gitlab.com/gitlab-org/labkit v0.0.0-20200507062444-0149780c759d
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
golang.org/x/sys v0.0.0-20200113162924-86b910548bc1
diff --git a/go.sum b/go.sum
index c91a01b46..4b650ad5d 100644
--- a/go.sum
+++ b/go.sum
@@ -350,10 +350,8 @@ github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZ
github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs=
github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
gitlab.com/gitlab-org/gitaly v1.68.0/go.mod h1:/pCsB918Zu5wFchZ9hLYin9WkJ2yQqdVNz0zlv5HbXg=
-gitlab.com/gitlab-org/gitlab-shell v1.9.8-0.20200506213341-716e30c55e89 h1:gZwXV5WLPmJ3NDmH+zAZkgWLVhgKvamGAjLXU5W0GiU=
-gitlab.com/gitlab-org/gitlab-shell v1.9.8-0.20200506213341-716e30c55e89 h1:gZwXV5WLPmJ3NDmH+zAZkgWLVhgKvamGAjLXU5W0GiU=
-gitlab.com/gitlab-org/gitlab-shell v1.9.8-0.20200506213341-716e30c55e89/go.mod h1:oUGdKtJHWQP4/VQ/NONJZy/8X2E5ow2eGTUDwdzvGsc=
-gitlab.com/gitlab-org/gitlab-shell v1.9.8-0.20200506213341-716e30c55e89/go.mod h1:oUGdKtJHWQP4/VQ/NONJZy/8X2E5ow2eGTUDwdzvGsc=
+gitlab.com/gitlab-org/gitlab-shell v0.0.0-20200821152636-82ec8144fb2a h1:MkoiKzWGRz2RCfDU6uFAO1vDLNZMSlyDWadL41nYjfw=
+gitlab.com/gitlab-org/gitlab-shell v0.0.0-20200821152636-82ec8144fb2a/go.mod h1:RABblvnnhHpFU/lexlwGqpKgZsLV3RGA2D/Elp5/KEA=
gitlab.com/gitlab-org/labkit v0.0.0-20190221122536-0c3fc7cdd57c/go.mod h1:rYhLgfrbEcyfinG+R3EvKu6bZSsmwQqcXzLfHWSfUKM=
gitlab.com/gitlab-org/labkit v0.0.0-20190221122536-0c3fc7cdd57c/go.mod h1:rYhLgfrbEcyfinG+R3EvKu6bZSsmwQqcXzLfHWSfUKM=
gitlab.com/gitlab-org/labkit v0.0.0-20200507062444-0149780c759d h1:Q5yZi+AelheHuvq/OK6DiaBzLU1AHrm7eWh88uE8Tsk=
diff --git a/internal/config/config.go b/internal/config/config.go
index c43d4b6a8..9837c993b 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -64,9 +64,10 @@ type GitlabShell struct {
// Gitlab contains settings required to connect to the Gitlab api
type Gitlab struct {
- URL string `toml:"url" json:"url"`
- HTTPSettings HTTPSettings `toml:"http-settings" json:"http_settings"`
- SecretFile string `toml:"secret_file" json:"secret_file"`
+ URL string `toml:"url" json:"url"`
+ RelativeURLRoot string `toml:"relative_url_root" json:"relative_url_root"`
+ HTTPSettings HTTPSettings `toml:"http-settings" json:"http_settings"`
+ SecretFile string `toml:"secret_file" json:"secret_file"`
}
// Hooks contains the settings required for hooks
diff --git a/internal/service/hook/access.go b/internal/service/hook/access.go
index 4b1793696..13d76e287 100644
--- a/internal/service/hook/access.go
+++ b/internal/service/hook/access.go
@@ -75,6 +75,7 @@ func NewGitlabAPI(gitlabCfg config.Gitlab) (GitlabAPI, error) {
httpClient := client.NewHTTPClient(
url,
+ gitlabCfg.RelativeURLRoot,
gitlabCfg.HTTPSettings.CAFile,
gitlabCfg.HTTPSettings.CAPath,
gitlabCfg.HTTPSettings.SelfSigned,