diff options
author | Patrick Bajao <ebajao@gitlab.com> | 2019-08-02 16:10:17 +0800 |
---|---|---|
committer | Patrick Bajao <ebajao@gitlab.com> | 2019-08-02 16:10:17 +0800 |
commit | 3b6f9f7583755e041e76142d7caf7716937907fa (patch) | |
tree | ed7f7281633d97933e4465a2ac0f86d62c9a216e /go/internal/command/fallback/fallback.go | |
parent | 592823d5e25006331b361b36cc61df7802fc1938 (diff) | |
download | gitlab-shell-3b6f9f7583755e041e76142d7caf7716937907fa.tar.gz |
Add Executable struct181-migrate-gitlab-shell-checks-fallback
This struct is responsible for determining the name and
root dir of the executable.
The `RootDir` property will be used to find the config.
The `Name` property will be used to determine what `Command`
and `CommandArgs` to be built.
Diffstat (limited to 'go/internal/command/fallback/fallback.go')
-rw-r--r-- | go/internal/command/fallback/fallback.go | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/go/internal/command/fallback/fallback.go b/go/internal/command/fallback/fallback.go index 81baaf5..781eda1 100644 --- a/go/internal/command/fallback/fallback.go +++ b/go/internal/command/fallback/fallback.go @@ -1,33 +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 commandargs.CommandArgs + Executable *executable.Executable + RootDir string + Args commandargs.CommandArgs } var ( // execFunc is overridden in tests - execFunc = syscall.Exec + execFunc = syscall.Exec + whitelist = []string{ + executable.GitlabShell, + executable.AuthorizedKeysCheck, + executable.AuthorizedPrincipalsCheck, + } ) func (c *Command) Execute() error { - rubyCmd := filepath.Join(c.RootDir, "bin", c.fallbackProgram()) + 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.Arguments()...) + 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 { - return fmt.Sprintf("%s-ruby", c.Args.Executable()) + fileName := fmt.Sprintf("%s-ruby", c.Executable.Name) + + return filepath.Join(c.RootDir, "bin", fileName) } |