Move all environment inspection away from `os.Getenv` and into the `sshenv` package
There's a lot of code in gitlab-shell/internal/... that looks at environment variables, with the assumption that it is being called from bin/gitlab-shell
. However, with the introduction of bin/gitlab-sshd
, this is no longer a safe assumption.
Some specific culprits:
SSH_ORIGINAL_COMMAND
SSH_CONNECTION
GIT_PROTOCOL
However, it looks like labkit's opentracking code also pays attention to environment variables, and there may be other examples too.
For bin/gitlab-shell
, envvars are per-connection state, but for bin/gitlab-sshd
, they are global state. We should introduce a presumption against using them in internal/
as much as possible, and refactor away existing users, such as determining a client's IP, which command to execute, or which git protocol version to pay attention to.