diff options
-rw-r--r-- | changelogs/unreleased/jc-deprecate-gitlab-shell-config.yml | 5 | ||||
-rw-r--r-- | cmd/gitaly-hooks/hooks.go | 7 | ||||
-rw-r--r-- | cmd/gitaly-hooks/hooks_test.go | 50 | ||||
-rw-r--r-- | config.toml.example | 11 | ||||
-rw-r--r-- | internal/config/config.go | 20 | ||||
-rw-r--r-- | internal/git/receivepack.go | 7 | ||||
-rw-r--r-- | internal/gitlabshell/env.go | 42 | ||||
-rw-r--r-- | internal/gitlabshell/env_test.go | 35 | ||||
-rw-r--r-- | internal/rubyserver/rubyserver.go | 8 | ||||
-rw-r--r-- | internal/service/hooks/post_receive.go | 7 | ||||
-rw-r--r-- | internal/service/hooks/pre_receive.go | 16 | ||||
-rw-r--r-- | internal/service/hooks/update.go | 7 | ||||
-rw-r--r-- | internal/service/smarthttp/receive_pack_test.go | 10 | ||||
-rw-r--r-- | internal/service/ssh/receive_pack_test.go | 11 | ||||
-rw-r--r-- | internal/testhelper/testserver.go | 21 | ||||
-rw-r--r-- | ruby/gitlab-shell/lib/http_helper.rb | 5 |
16 files changed, 208 insertions, 54 deletions
diff --git a/changelogs/unreleased/jc-deprecate-gitlab-shell-config.yml b/changelogs/unreleased/jc-deprecate-gitlab-shell-config.yml new file mode 100644 index 000000000..af934d0c5 --- /dev/null +++ b/changelogs/unreleased/jc-deprecate-gitlab-shell-config.yml @@ -0,0 +1,5 @@ +--- +title: Write gitlab shell config from gitaly to gitlab shell as env var +merge_request: 2066 +author: +type: added diff --git a/cmd/gitaly-hooks/hooks.go b/cmd/gitaly-hooks/hooks.go index ab88b235c..0ad1cfe93 100644 --- a/cmd/gitaly-hooks/hooks.go +++ b/cmd/gitaly-hooks/hooks.go @@ -271,7 +271,12 @@ func check(configPath string) (int, error) { cmd := exec.Command(filepath.Join(c.GitlabShell.Dir, "bin", "check")) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr - cmd.Env = append(os.Environ(), gitlabshell.EnvFromConfig(c)...) + gitlabshellEnv, err := gitlabshell.EnvFromConfig(c) + if err != nil { + return 1, err + } + + cmd.Env = append(os.Environ(), gitlabshellEnv...) if err = cmd.Run(); err != nil { if status, ok := command.ExitStatus(err); ok { diff --git a/cmd/gitaly-hooks/hooks_test.go b/cmd/gitaly-hooks/hooks_test.go index f9f247512..4807a77b2 100644 --- a/cmd/gitaly-hooks/hooks_test.go +++ b/cmd/gitaly-hooks/hooks_test.go @@ -72,14 +72,14 @@ func TestHooksPrePostReceive(t *testing.T) { ts := testhelper.NewGitlabTestServer(t, c) defer ts.Close() - gitlabShellDir := config.Config.GitlabShell.Dir - defer func() { - config.Config.GitlabShell.Dir = gitlabShellDir - }() + defer func(gitlabShell config.GitlabShell) { + config.Config.GitlabShell = gitlabShell + }(config.Config.GitlabShell) config.Config.GitlabShell.Dir = tempGitlabShellDir + config.Config.GitlabShell.GitlabURL = ts.URL + config.Config.GitlabShell.SecretFile = filepath.Join(tempGitlabShellDir, ".gitlab_shell_secret") - testhelper.WriteTemporaryGitlabShellConfigFile(t, tempGitlabShellDir, testhelper.GitlabShellConfig{GitlabURL: ts.URL}) testhelper.WriteShellSecretFile(t, tempGitlabShellDir, secretToken) gitObjectDirRegex := regexp.MustCompile(`(?m)^GIT_OBJECT_DIRECTORY=(.*)$`) @@ -254,7 +254,15 @@ func testHooksUpdate(t *testing.T, gitlabShellDir, socket, token string, glValue require.Contains(t, output, "GL_PROTOCOL="+glValues.GLProtocol) } -func TestHooksPostReceiveFailed(t *testing.T) { +func TestHooksPostReceiveFailedWithRPC(t *testing.T) { + testHooksPostReceiveFailed(t, true) +} + +func TestHooksPostReceiveFailedWithoutRPC(t *testing.T) { + testHooksPostReceiveFailed(t, false) +} + +func testHooksPostReceiveFailed(t *testing.T, callHookRPC bool) { secretToken := "secret token" glID := "key-1234" glUsername := "iamgitlab" @@ -285,15 +293,15 @@ func TestHooksPostReceiveFailed(t *testing.T) { ts := testhelper.NewGitlabTestServer(t, c) defer ts.Close() - testhelper.WriteTemporaryGitlabShellConfigFile(t, tempGitlabShellDir, testhelper.GitlabShellConfig{GitlabURL: ts.URL}) testhelper.WriteShellSecretFile(t, tempGitlabShellDir, secretToken) - gitlabShellDir := config.Config.GitlabShell.Dir - defer func() { - config.Config.GitlabShell.Dir = gitlabShellDir - }() + defer func(gitlabShell config.GitlabShell) { + config.Config.GitlabShell = gitlabShell + }(config.Config.GitlabShell) config.Config.GitlabShell.Dir = tempGitlabShellDir + config.Config.GitlabShell.GitlabURL = ts.URL + config.Config.GitlabShell.SecretFile = filepath.Join(tempGitlabShellDir, ".gitlab_shell_secret") customHookOutputPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, "post-receive") defer cleanup() @@ -313,6 +321,11 @@ func TestHooksPostReceiveFailed(t *testing.T) { GLRepo: glRepository, GLProtocol: glProtocol, }) + + if callHookRPC { + cmd.Env = append(cmd.Env, fmt.Sprintf("%s=true", featureflag.HooksRPCEnvVar)) + } + cmd.Stdout = &stdout cmd.Stderr = &stderr cmd.Stdin = bytes.NewBuffer([]byte(changes)) @@ -360,15 +373,16 @@ func TestHooksNotAllowed(t *testing.T) { testhelper.WriteTemporaryGitlabShellConfigFile(t, tempGitlabShellDir, testhelper.GitlabShellConfig{GitlabURL: ts.URL}) testhelper.WriteShellSecretFile(t, tempGitlabShellDir, "the wrong token") - gitlabShellDir := config.Config.GitlabShell.Dir - defer func() { - config.Config.GitlabShell.Dir = gitlabShellDir - }() + defer func(gitlabShell config.GitlabShell) { + config.Config.GitlabShell = gitlabShell + }(config.Config.GitlabShell) + + config.Config.GitlabShell.Dir = tempGitlabShellDir + config.Config.GitlabShell.GitlabURL = ts.URL customHookOutputPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, "post-receive") defer cleanup() - config.Config.GitlabShell.Dir = tempGitlabShellDir token := "abc123" socket, stop := runHookServiceServer(t, token) defer stop() @@ -429,7 +443,7 @@ func TestCheckOK(t *testing.T) { testhelper.WriteShellSecretFile(t, gitlabShellDir, "the secret") testhelper.WriteTemporaryGitlabShellConfigFile(t, gitlabShellDir, testhelper.GitlabShellConfig{GitlabURL: ts.URL, HTTPSettings: testhelper.HTTPSettings{User: user, Password: password}}) - configPath, cleanup := testhelper.WriteTemporaryGitalyConfigFile(t, tempDir) + configPath, cleanup := testhelper.WriteTemporaryGitalyConfigFile(t, tempDir, ts.URL, user, password) defer cleanup() cmd := exec.Command(fmt.Sprintf("%s/gitaly-hooks", config.Config.BinDir), "check", configPath) @@ -477,7 +491,7 @@ func TestCheckBadCreds(t *testing.T) { testhelper.WriteTemporaryGitlabShellConfigFile(t, gitlabShellDir, testhelper.GitlabShellConfig{GitlabURL: ts.URL, HTTPSettings: testhelper.HTTPSettings{User: user + "wrong", Password: password}}) testhelper.WriteShellSecretFile(t, gitlabShellDir, "the secret") - configPath, cleanup := testhelper.WriteTemporaryGitalyConfigFile(t, tempDir) + configPath, cleanup := testhelper.WriteTemporaryGitalyConfigFile(t, tempDir, ts.URL, "wrong", password) defer cleanup() cmd := exec.Command(fmt.Sprintf("%s/gitaly-hooks", config.Config.BinDir), "check", configPath) diff --git a/config.toml.example b/config.toml.example index 9c5db6013..7e763df42 100644 --- a/config.toml.example +++ b/config.toml.example @@ -86,6 +86,17 @@ dir = "/home/git/gitaly/ruby" [gitlab-shell] # The directory where gitlab-shell is installed dir = "/home/git/gitlab-shell" +secret_file = "/home/git/gitlab-shell/.gitlab_shell_secret" +custom_hooks_dir = "/home/git/custom_hooks" +gitlab_url = "http://localhost:3000" + +[gitlab-shell.http-settings] +read_timeout: 300 +user: someone +password: somepass +ca_file: /etc/ssl/cert.pem +ca_path: /etc/pki/tls/certs +self_signed_cert: false # # You can adjust the concurrency of each RPC endpoint # [[concurrency]] diff --git a/internal/config/config.go b/internal/config/config.go index 2779b09a9..b07945472 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -58,14 +58,26 @@ type TLS struct { // GitlabShell contains the settings required for executing `gitlab-shell` type GitlabShell struct { - Dir string `toml:"dir"` + CustomHooksDir string `toml:"custom_hooks_dir"` + Dir string `toml:"dir"` + GitlabURL string `toml:"gitlab_url"` + HTTPSettings HTTPSettings `toml:"http-settings"` + SecretFile string `toml:"secret_file"` +} + +type HTTPSettings struct { + ReadTimeout int `toml:"read_timeout" json:"read_timeout"` + User string `toml:"user" json:"user"` + Password string `toml:"password" json:"password"` + CAFile string `toml:"ca_file" json:"ca_file"` + CAPath string `toml:"ca_path" json:"ca_path"` + SelfSigned bool `toml:"self_signed_cert" json:"self_signed_cert"` } // Git contains the settings for the Git executable type Git struct { - BinPath string `toml:"bin_path"` - - CatfileCacheSize int `toml:"catfile_cache_size"` + BinPath string `toml:"bin_path"` + CatfileCacheSize int `toml:"catfile_cache_size"` } // Storage contains a single storage-shard diff --git a/internal/git/receivepack.go b/internal/git/receivepack.go index 6397497bc..662391ed6 100644 --- a/internal/git/receivepack.go +++ b/internal/git/receivepack.go @@ -33,6 +33,11 @@ func ReceivePackHookEnv(ctx context.Context, req ReceivePackRequest) ([]string, return nil, err } + gitlabshellEnv, err := gitlabshell.Env() + if err != nil { + return nil, err + } + env := append([]string{ fmt.Sprintf("GL_ID=%s", req.GetGlId()), fmt.Sprintf("GL_USERNAME=%s", req.GetGlUsername()), @@ -40,7 +45,7 @@ func ReceivePackHookEnv(ctx context.Context, req ReceivePackRequest) ([]string, fmt.Sprintf("GITALY_SOCKET=" + config.GitalyInternalSocketPath()), fmt.Sprintf("GITALY_REPO=%s", repo), fmt.Sprintf("GITALY_TOKEN=%s", config.Config.Auth.Token), - }, gitlabshell.Env()...) + }, gitlabshellEnv...) praefect, err := metadata.ExtractPraefectServer(ctx) if err == nil { diff --git a/internal/gitlabshell/env.go b/internal/gitlabshell/env.go index 4db3c4fd0..77bda2100 100644 --- a/internal/gitlabshell/env.go +++ b/internal/gitlabshell/env.go @@ -1,25 +1,53 @@ package gitlabshell import ( + "encoding/json" + "fmt" + "gitlab.com/gitlab-org/gitaly/internal/config" ) // Env is a helper that returns a slice with environment variables used by gitlab shell -func Env() []string { +func Env() ([]string, error) { cfg := config.Config return EnvFromConfig(cfg) } +type Config struct { + CustomHooksDir string `json:"custom_hooks_dir"` + GitlabURL string `json:"gitlab_url"` + HTTPSettings config.HTTPSettings `json:"http_settings"` + LogFormat string `json:"log_format"` + LogLevel string `json:"log_level"` + LogPath string `json:"log_path"` + RootPath string `json:"root_path"` + SecretFile string `json:"secret_file"` +} + // EnvFromConfig returns a set of environment variables from a config struct relevant to gitlab shell -func EnvFromConfig(cfg config.Cfg) []string { +func EnvFromConfig(cfg config.Cfg) ([]string, error) { + gitlabShellConfig := Config{ + CustomHooksDir: cfg.GitlabShell.CustomHooksDir, + GitlabURL: cfg.GitlabShell.GitlabURL, + HTTPSettings: cfg.GitlabShell.HTTPSettings, + LogFormat: cfg.Logging.Format, + LogLevel: cfg.Logging.Level, + LogPath: cfg.Logging.Dir, + RootPath: cfg.GitlabShell.Dir, //GITLAB_SHELL_DIR has been deprecated + SecretFile: cfg.GitlabShell.SecretFile, + } + + gitlabShellConfigString, err := json.Marshal(&gitlabShellConfig) + if err != nil { + return nil, err + } + return []string{ + //TODO: remove GITALY_GITLAB_SHELL_DIR: https://gitlab.com/gitlab-org/gitaly/-/issues/2679 "GITALY_GITLAB_SHELL_DIR=" + cfg.GitlabShell.Dir, - "GITALY_LOG_DIR=" + cfg.Logging.Dir, - "GITALY_LOG_FORMAT=" + cfg.Logging.Format, - "GITALY_LOG_LEVEL=" + cfg.Logging.Level, - "GITLAB_SHELL_DIR=" + cfg.GitlabShell.Dir, //GITLAB_SHELL_DIR has been deprecated "GITALY_BIN_DIR=" + cfg.BinDir, "GITALY_RUBY_DIR=" + cfg.Ruby.Dir, - } + fmt.Sprintf("GITALY_GITLAB_SHELL_CONFIG=%s", gitlabShellConfigString), + }, nil } diff --git a/internal/gitlabshell/env_test.go b/internal/gitlabshell/env_test.go index 809a436c2..240826572 100644 --- a/internal/gitlabshell/env_test.go +++ b/internal/gitlabshell/env_test.go @@ -29,15 +29,32 @@ func TestGitHooksConfig(t *testing.T) { config.Config.Logging.Dir = loggingDir config.Config.Logging.Level = "fatal" config.Config.Logging.Format = "my-custom-format" - config.Config.GitlabShell.Dir = "../../ruby/gitlab-shell" + + config.Config.GitlabShell = config.GitlabShell{ + CustomHooksDir: "/path/to/custom_hooks", + Dir: "../../ruby/gitlab-shell", + GitlabURL: "http://gitlaburl.com", + HTTPSettings: config.HTTPSettings{ + ReadTimeout: 100, + User: "user_name", + Password: "pwpw", + CAFile: "/ca_file_path", + CAPath: "/ca_path", + SelfSigned: true, + }, + SecretFile: "secret_file_path", + } dumpConfigPath := filepath.Join(config.Config.Ruby.Dir, "gitlab-shell", "bin", "dump-config") var stdout bytes.Buffer cmd := exec.Command(dumpConfigPath) - cmd.Env = append(os.Environ(), gitlabshell.Env()...) + gitlabshellEnv, err := gitlabshell.Env() + require.NoError(t, err) + cmd.Env = append(os.Environ(), gitlabshellEnv...) cmd.Stdout = &stdout + cmd.Stderr = os.Stderr require.NoError(t, cmd.Run()) @@ -46,6 +63,20 @@ func TestGitHooksConfig(t *testing.T) { require.NoError(t, json.NewDecoder(&stdout).Decode(&rubyConfigMap)) require.Equal(t, config.Config.Logging.Level, rubyConfigMap["log_level"]) require.Equal(t, config.Config.Logging.Format, rubyConfigMap["log_format"]) + require.Equal(t, config.Config.GitlabShell.SecretFile, rubyConfigMap["secret_file"]) + require.Equal(t, config.Config.GitlabShell.CustomHooksDir, rubyConfigMap["custom_hooks_dir"]) + require.Equal(t, config.Config.GitlabShell.GitlabURL, rubyConfigMap["gitlab_url"]) + require.Equal(t, config.Config.GitlabShell.SecretFile, rubyConfigMap["secret_file"]) + + // HTTP Settings + httpSettings, ok := rubyConfigMap["http_settings"].(map[string]interface{}) + require.True(t, ok) + require.Equal(t, float64(config.Config.GitlabShell.HTTPSettings.ReadTimeout), httpSettings["read_timeout"]) + require.Equal(t, config.Config.GitlabShell.HTTPSettings.User, httpSettings["user"]) + require.Equal(t, config.Config.GitlabShell.HTTPSettings.Password, httpSettings["password"]) + require.Equal(t, config.Config.GitlabShell.HTTPSettings.CAFile, httpSettings["ca_file"]) + require.Equal(t, config.Config.GitlabShell.HTTPSettings.CAPath, httpSettings["ca_path"]) + require.Equal(t, config.Config.GitlabShell.HTTPSettings.SelfSigned, httpSettings["self_signed_cert"]) dir := filepath.Dir(rubyConfigMap["log_file"].(string)) require.Equal(t, config.Config.Logging.Dir, dir) diff --git a/internal/rubyserver/rubyserver.go b/internal/rubyserver/rubyserver.go index 48c63bb84..47e7aeedf 100644 --- a/internal/rubyserver/rubyserver.go +++ b/internal/rubyserver/rubyserver.go @@ -87,6 +87,12 @@ func (s *Server) start() error { } cfg := config.Config + + gitlabshellEnv, err := gitlabshell.Env() + if err != nil { + return err + } + env := append( os.Environ(), "GITALY_RUBY_GIT_BIN_PATH="+command.GitPath(), @@ -99,7 +105,7 @@ func (s *Server) start() error { "GITALY_SOCKET="+config.GitalyInternalSocketPath(), "GITALY_TOKEN="+cfg.Auth.Token, "GITALY_RUGGED_GIT_CONFIG_SEARCH_PATH="+cfg.Ruby.RuggedGitConfigSearchPath) - env = append(env, gitlabshell.Env()...) + env = append(env, gitlabshellEnv...) env = append(env, command.GitEnv...) diff --git a/internal/service/hooks/post_receive.go b/internal/service/hooks/post_receive.go index f4e312d08..55ec0323f 100644 --- a/internal/service/hooks/post_receive.go +++ b/internal/service/hooks/post_receive.go @@ -20,7 +20,12 @@ func (s *server) PostReceiveHook(stream gitalypb.HookService_PostReceiveHookServ return helper.ErrInvalidArgument(err) } - hookEnv := append(hookRequestEnv(firstRequest), hooks.GitPushOptions(firstRequest.GetGitPushOptions())...) + hookEnv, err := hookRequestEnv(firstRequest) + if err != nil { + return helper.ErrInternal(err) + } + + hookEnv = append(hookEnv, hooks.GitPushOptions(firstRequest.GetGitPushOptions())...) stdin := streamio.NewReader(func() ([]byte, error) { req, err := stream.Recv() diff --git a/internal/service/hooks/pre_receive.go b/internal/service/hooks/pre_receive.go index 0564bb71c..a8261115f 100644 --- a/internal/service/hooks/pre_receive.go +++ b/internal/service/hooks/pre_receive.go @@ -18,8 +18,12 @@ type hookRequest interface { GetRepository() *gitalypb.Repository } -func hookRequestEnv(req hookRequest) []string { - return append(gitlabshell.Env(), req.GetEnvironmentVariables()...) +func hookRequestEnv(req hookRequest) ([]string, error) { + gitlabshellEnv, err := gitlabshell.Env() + if err != nil { + return nil, err + } + return append(gitlabshellEnv, req.GetEnvironmentVariables()...), nil } func preReceiveEnv(req hookRequest) ([]string, error) { @@ -27,7 +31,13 @@ func preReceiveEnv(req hookRequest) ([]string, error) { if err != nil { return nil, err } - return append(hookRequestEnv(req), env...), nil + + hookEnv, err := hookRequestEnv(req) + if err != nil { + return nil, err + } + + return append(hookEnv, env...), nil } func gitlabShellHook(hookName string) string { diff --git a/internal/service/hooks/update.go b/internal/service/hooks/update.go index c980dd92f..626f02ec9 100644 --- a/internal/service/hooks/update.go +++ b/internal/service/hooks/update.go @@ -25,12 +25,17 @@ func (s *server) UpdateHook(in *gitalypb.UpdateHookRequest, stream gitalypb.Hook c := exec.Command(gitlabShellHook("update"), string(in.GetRef()), in.GetOldValue(), in.GetNewValue()) c.Dir = repoPath + updateEnv, err := hookRequestEnv(in) + if err != nil { + return helper.ErrInternal(err) + } + status, err := streamCommandResponse( stream.Context(), nil, stdout, stderr, c, - hookRequestEnv(in), + updateEnv, ) if err != nil { diff --git a/internal/service/smarthttp/receive_pack_test.go b/internal/service/smarthttp/receive_pack_test.go index d8c9e0a45..e9dc039d8 100644 --- a/internal/service/smarthttp/receive_pack_test.go +++ b/internal/service/smarthttp/receive_pack_test.go @@ -367,9 +367,10 @@ func testPostReceivePackToHooks(t *testing.T, callRPC bool) { tempGitlabShellDir, cleanup := testhelper.CreateTemporaryGitlabShellDir(t) defer cleanup() - defer func(gitlabShellDir string) { - config.Config.GitlabShell.Dir = gitlabShellDir - }(config.Config.GitlabShell.Dir) + defer func(gitlabShell config.GitlabShell) { + config.Config.GitlabShell = gitlabShell + }(config.Config.GitlabShell) + config.Config.GitlabShell.Dir = tempGitlabShellDir defer func(override string) { @@ -402,6 +403,9 @@ func testPostReceivePackToHooks(t *testing.T, callRPC bool) { testhelper.WriteCustomHook(testRepoPath, "pre-receive", []byte(testhelper.CheckNewObjectExists)) + config.Config.GitlabShell.GitlabURL = ts.URL + config.Config.GitlabShell.SecretFile = filepath.Join(tempGitlabShellDir, ".gitlab_shell_secret") + defer func(override string) { hooks.Override = override }(hooks.Override) diff --git a/internal/service/ssh/receive_pack_test.go b/internal/service/ssh/receive_pack_test.go index c0201dc85..cc2dabfbe 100644 --- a/internal/service/ssh/receive_pack_test.go +++ b/internal/service/ssh/receive_pack_test.go @@ -219,10 +219,10 @@ func TestSSHReceivePackToHooks(t *testing.T) { tempGitlabShellDir, cleanup := testhelper.CreateTemporaryGitlabShellDir(t) defer cleanup() - gitlabShellDir := config.Config.GitlabShell.Dir - defer func() { - config.Config.GitlabShell.Dir = gitlabShellDir - }() + originalGitlabShellConfig := config.Config.GitlabShell + defer func(gitlabShellConfig config.GitlabShell) { + config.Config.GitlabShell = gitlabShellConfig + }(originalGitlabShellConfig) config.Config.GitlabShell.Dir = tempGitlabShellDir @@ -244,6 +244,9 @@ func TestSSHReceivePackToHooks(t *testing.T) { testhelper.WriteTemporaryGitlabShellConfigFile(t, tempGitlabShellDir, testhelper.GitlabShellConfig{GitlabURL: ts.URL}) testhelper.WriteShellSecretFile(t, tempGitlabShellDir, secretToken) + config.Config.GitlabShell.GitlabURL = ts.URL + config.Config.GitlabShell.SecretFile = filepath.Join(tempGitlabShellDir, ".gitlab_shell_secret") + testhelper.WriteCustomHook(cloneDetails.RemoteRepoPath, "pre-receive", []byte(testhelper.CheckNewObjectExists)) defer func(override string) { diff --git a/internal/testhelper/testserver.go b/internal/testhelper/testserver.go index efdf1dbe5..860b25340 100644 --- a/internal/testhelper/testserver.go +++ b/internal/testhelper/testserver.go @@ -28,6 +28,7 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/config/auth" "gitlab.com/gitlab-org/gitaly/internal/git/hooks" + "gitlab.com/gitlab-org/gitaly/internal/gitlabshell" "gitlab.com/gitlab-org/gitaly/internal/helper/fieldextractors" praefectconfig "gitlab.com/gitlab-org/gitaly/internal/praefect/config" "gitlab.com/gitlab-org/gitaly/internal/praefect/models" @@ -447,12 +448,16 @@ func WriteTemporaryGitlabShellConfigFile(t testing.TB, dir string, config Gitlab // WriteTemporaryGitalyConfigFile writes a gitaly toml file into a temporary directory. It returns the path to // the file as well as a cleanup function -func WriteTemporaryGitalyConfigFile(t testing.TB, tempDir string) (string, func()) { +func WriteTemporaryGitalyConfigFile(t testing.TB, tempDir, gitlabURL, user, password string) (string, func()) { path := filepath.Join(tempDir, "config.toml") contents := fmt.Sprintf(` [gitlab-shell] dir = "%s/gitlab-shell" -`, tempDir) + gitlab_url = "%s" + [gitlab-shell.http-settings] + user = "%s" + password = "%s" +`, tempDir, gitlabURL, user, password) require.NoError(t, ioutil.WriteFile(path, []byte(contents), 0644)) return path, func() { @@ -475,8 +480,11 @@ func EnvForHooks(t testing.TB, gitlabShellDir, gitalySocket, gitalyToken string, repoString, err := jsonpbMarshaller.MarshalToString(repo) require.NoError(t, err) - env := append(append([]string{ - fmt.Sprintf("GITALY_BIN_DIR=%s", config.Config.BinDir), + env, err := gitlabshell.EnvFromConfig(config.Config) + require.NoError(t, err) + + env = append(env, os.Environ()...) + env = append(env, []string{ fmt.Sprintf("GITALY_RUBY_DIR=%s", rubyDir), fmt.Sprintf("GL_ID=%s", glHookValues.GLID), fmt.Sprintf("GL_REPOSITORY=%s", glHookValues.GLRepo), @@ -487,9 +495,8 @@ func EnvForHooks(t testing.TB, gitlabShellDir, gitalySocket, gitalyToken string, fmt.Sprintf("GITALY_REPO=%v", repoString), fmt.Sprintf("GITALY_GITLAB_SHELL_DIR=%s", gitlabShellDir), fmt.Sprintf("GITALY_LOG_DIR=%s", gitlabShellDir), - "GITALY_LOG_LEVEL=info", - "GITALY_LOG_FORMAT=json", - }, os.Environ()...), hooks.GitPushOptions(gitPushOptions)...) + }...) + env = append(env, hooks.GitPushOptions(gitPushOptions)...) if glHookValues.GitObjectDir != "" { env = append(env, fmt.Sprintf("GIT_OBJECT_DIRECTORY=%s", glHookValues.GitObjectDir)) diff --git a/ruby/gitlab-shell/lib/http_helper.rb b/ruby/gitlab-shell/lib/http_helper.rb index c6a4bb845..5cadb6196 100644 --- a/ruby/gitlab-shell/lib/http_helper.rb +++ b/ruby/gitlab-shell/lib/http_helper.rb @@ -120,6 +120,9 @@ module HTTPHelper end def read_timeout - config.http_settings['read_timeout'] || READ_TIMEOUT + read_timeout = config.http_settings['read_timeout'] + return read_timeout unless read_timeout == 0 + + READ_TIMEOUT end end |