diff options
author | Ash McKenzie <amckenzie@gitlab.com> | 2019-08-05 05:03:16 +0000 |
---|---|---|
committer | Ash McKenzie <amckenzie@gitlab.com> | 2019-08-05 05:03:16 +0000 |
commit | c577eb9ed8bd0336870f7a83302f70821d510169 (patch) | |
tree | ed7f7281633d97933e4465a2ac0f86d62c9a216e /go/internal/command/fallback/fallback.go | |
parent | ed0460374a5ca13d9ea17c6a9c21151319b7fd53 (diff) | |
parent | 3b6f9f7583755e041e76142d7caf7716937907fa (diff) | |
download | gitlab-shell-c577eb9ed8bd0336870f7a83302f70821d510169.tar.gz |
Merge branch '181-migrate-gitlab-shell-checks-fallback' into 'master'
Support falling back to ruby version of checkers
See merge request gitlab-org/gitlab-shell!318
Diffstat (limited to 'go/internal/command/fallback/fallback.go')
-rw-r--r-- | go/internal/command/fallback/fallback.go | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/go/internal/command/fallback/fallback.go b/go/internal/command/fallback/fallback.go index f525a57..781eda1 100644 --- a/go/internal/command/fallback/fallback.go +++ b/go/internal/command/fallback/fallback.go @@ -1,30 +1,57 @@ package fallback import ( + "errors" + "fmt" "os" "path/filepath" "syscall" + + "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/commandargs" + "gitlab.com/gitlab-org/gitlab-shell/go/internal/executable" ) type Command struct { - RootDir string - Args []string + Executable *executable.Executable + RootDir string + Args commandargs.CommandArgs } var ( // execFunc is overridden in tests - execFunc = syscall.Exec -) - -const ( - RubyProgram = "gitlab-shell-ruby" + execFunc = syscall.Exec + whitelist = []string{ + executable.GitlabShell, + executable.AuthorizedKeysCheck, + executable.AuthorizedPrincipalsCheck, + } ) func (c *Command) Execute() error { - rubyCmd := filepath.Join(c.RootDir, "bin", RubyProgram) + if !c.isWhitelisted() { + return errors.New("Failed to execute unknown executable") + } + + rubyCmd := c.fallbackProgram() // Ensure rubyArgs[0] is the full path to gitlab-shell-ruby - rubyArgs := append([]string{rubyCmd}, c.Args[1:]...) + rubyArgs := append([]string{rubyCmd}, c.Args.GetArguments()...) return execFunc(rubyCmd, rubyArgs, os.Environ()) } + +func (c *Command) isWhitelisted() bool { + for _, item := range whitelist { + if c.Executable.Name == item { + return true + } + } + + return false +} + +func (c *Command) fallbackProgram() string { + fileName := fmt.Sprintf("%s-ruby", c.Executable.Name) + + return filepath.Join(c.RootDir, "bin", fileName) +} |