diff options
author | Lucas Charles <me@lucascharles.me> | 2021-02-17 13:49:46 -0800 |
---|---|---|
committer | Lucas Charles <me@lucascharles.me> | 2021-03-15 13:47:11 -0700 |
commit | d539068dc372e46d10adee89e9b96b59156a2bb6 (patch) | |
tree | 9c37f5ade4a95622b30a7a47befcb46b185b9682 /internal/command/commandargs/shell.go | |
parent | e79f115d93a9f00f3e4f8a22ec770fdf4c3e1947 (diff) | |
download | gitlab-shell-d539068dc372e46d10adee89e9b96b59156a2bb6.tar.gz |
chore: Refactor env introspection to rely on command initialization496-move-env-introspection-to-sshenv
Refactors introspection of execution environment to rely on
per-connection state (`gitlab-shell`) or per request (`gitlab-sshd`)
Relates to https://gitlab.com/gitlab-org/gitlab-shell/-/issues/496
Diffstat (limited to 'internal/command/commandargs/shell.go')
-rw-r--r-- | internal/command/commandargs/shell.go | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/internal/command/commandargs/shell.go b/internal/command/commandargs/shell.go index 62fc8fa..9cf6720 100644 --- a/internal/command/commandargs/shell.go +++ b/internal/command/commandargs/shell.go @@ -2,11 +2,10 @@ package commandargs import ( "errors" - "net" - "os" "regexp" "github.com/mattn/go-shellwords" + "gitlab.com/gitlab-org/gitlab-shell/internal/sshenv" ) const ( @@ -18,8 +17,6 @@ const ( UploadPack CommandType = "git-upload-pack" UploadArchive CommandType = "git-upload-archive" PersonalAccessToken CommandType = "personal_access_token" - - GitProtocolEnv = "GIT_PROTOCOL" ) var ( @@ -33,10 +30,7 @@ type Shell struct { GitlabKeyId string SshArgs []string CommandType CommandType - - // Only set when running standalone - RemoteAddr *net.TCPAddr - GitProtocolVersion string + Env sshenv.Env } func (s *Shell) Parse() error { @@ -54,24 +48,19 @@ func (s *Shell) GetArguments() []string { } func (s *Shell) validate() error { - if !s.isSshConnection() { + if !s.Env.IsSSHConnection { return errors.New("Only SSH allowed") } - if !s.isValidSshCommand() { + if !s.isValidSSHCommand() { return errors.New("Invalid SSH command") } return nil } -func (s *Shell) isSshConnection() bool { - ok := os.Getenv("SSH_CONNECTION") - return ok != "" -} - -func (s *Shell) isValidSshCommand() bool { - err := s.ParseCommand(os.Getenv("SSH_ORIGINAL_COMMAND")) +func (s *Shell) isValidSSHCommand() bool { + err := s.ParseCommand(s.Env.OriginalCommand) return err == nil } |