Skip to content

Commit 22a24db

Browse files
committed
Move set of env vars to createCommand
1 parent 3823d23 commit 22a24db

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

agent/agent.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,15 @@ func (a *agent) createCommand(ctx context.Context, rawCommand string, env []stri
404404
unixExecutablePath := strings.ReplaceAll(executablePath, "\\", "/")
405405
cmd.Env = append(cmd.Env, fmt.Sprintf(`GIT_SSH_COMMAND=%s gitssh --`, unixExecutablePath))
406406

407+
// Set SSH connection environment variables (these are also set by OpenSSH
408+
// and thus expected to be present by SSH clients). Since the agent does
409+
// networking in-memory, trying to provide accurate values here would be
410+
// nonsensical. For now, we hard code these values so that they're present.
411+
srcAddr, srcPort := "0.0.0.0", "0"
412+
dstAddr, dstPort := "0.0.0.0", "0"
413+
cmd.Env = append(cmd.Env, fmt.Sprintf("SSH_CLIENT=%s %s %s", srcAddr, srcPort, dstPort))
414+
cmd.Env = append(cmd.Env, fmt.Sprintf("SSH_CONNECTION=%s %s %s %s", srcAddr, srcPort, dstAddr, dstPort))
415+
407416
// Load environment variables passed via the agent.
408417
// These should override all variables we manually specify.
409418
for envKey, value := range metadata.EnvironmentVariables {
@@ -427,15 +436,6 @@ func (a *agent) handleSSHSession(session ssh.Session) (retErr error) {
427436
if err != nil {
428437
return err
429438
}
430-
// Set SSH connection environment variables, from the clients perspective.
431-
// Set SSH connection environment variables (these are also set by OpenSSH
432-
// and thus expected to be present by SSH clients). Since the agent does
433-
// networking in-memory, trying to provide accurate values here would be
434-
// nonsensical. For now, we hard code these values so that they're present.
435-
srcAddr, srcPort := "0.0.0.0", "0"
436-
dstAddr, dstPort := "0.0.0.0", "0"
437-
cmd.Env = append(cmd.Env, fmt.Sprintf("SSH_CLIENT=%s %s %s", srcAddr, srcPort, dstPort))
438-
cmd.Env = append(cmd.Env, fmt.Sprintf("SSH_CONNECTION=%s %s %s %s", srcAddr, srcPort, dstAddr, dstPort))
439439

440440
if ssh.AgentRequested(session) {
441441
l, err := ssh.NewAgentListener()

0 commit comments

Comments
 (0)