diff options
author | Patrick Bajao <ebajao@gitlab.com> | 2019-08-15 18:06:04 +0800 |
---|---|---|
committer | Patrick Bajao <ebajao@gitlab.com> | 2019-08-15 18:15:49 +0800 |
commit | 41f919eb86a3b1f69876f8b97572615b06521538 (patch) | |
tree | c840113cc7dc11643f5c8d7f55601322b2ee698e /go/cmd/gitlab-shell-authorized-keys-check/main.go | |
parent | f34e2cd5c4194aa8bb049e1ac8aa1b2f002395b5 (diff) | |
download | gitlab-shell-41f919eb86a3b1f69876f8b97572615b06521538.tar.gz |
Replace symlinks with actual binaries
We had `gitlab-shell-authorized-keys-check` and
`gitlab-shell-authorized-principals-check` as symlinks to
`gitlab-shell` before.
We determine the `Command` and `CommandArgs` that we build based
on the `Name` of the `Executable`. We also use that to know which
fallback ruby executable should we fallback to. We use
`os.Executable()` to do that.
`os.Executable()` behaves differently depending on OS. It may
return the symlink or the target's name. That can result to a
buggy behavior.
The fix is to create binaries for each instead of using a symlink.
That way we don't need to rely on `os.Executable()` to get the name.
We pass the `Name` of the executable instead.
Diffstat (limited to 'go/cmd/gitlab-shell-authorized-keys-check/main.go')
-rw-r--r-- | go/cmd/gitlab-shell-authorized-keys-check/main.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/go/cmd/gitlab-shell-authorized-keys-check/main.go b/go/cmd/gitlab-shell-authorized-keys-check/main.go new file mode 100644 index 0000000..2bde63d --- /dev/null +++ b/go/cmd/gitlab-shell-authorized-keys-check/main.go @@ -0,0 +1,46 @@ +package main + +import ( + "fmt" + "os" + + "gitlab.com/gitlab-org/gitlab-shell/go/internal/command" + "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/readwriter" + "gitlab.com/gitlab-org/gitlab-shell/go/internal/config" + "gitlab.com/gitlab-org/gitlab-shell/go/internal/executable" +) + +func main() { + readWriter := &readwriter.ReadWriter{ + Out: os.Stdout, + In: os.Stdin, + ErrOut: os.Stderr, + } + + executable, err := executable.New(executable.AuthorizedKeysCheck) + if err != nil { + fmt.Fprintln(readWriter.ErrOut, "Failed to determine executable, exiting") + os.Exit(1) + } + + config, err := config.NewFromDir(executable.RootDir) + if err != nil { + fmt.Fprintln(readWriter.ErrOut, "Failed to read config, exiting") + os.Exit(1) + } + + cmd, err := command.New(executable, os.Args[1:], config, readWriter) + if err != nil { + // For now this could happen if `SSH_CONNECTION` is not set on + // the environment + fmt.Fprintf(readWriter.ErrOut, "%v\n", err) + os.Exit(1) + } + + // The command will write to STDOUT on execution or replace the current + // process in case of the `fallback.Command` + if err = cmd.Execute(); err != nil { + fmt.Fprintf(readWriter.ErrOut, "%v\n", err) + os.Exit(1) + } +} |