@@ -404,6 +404,15 @@ func (a *agent) createCommand(ctx context.Context, rawCommand string, env []stri
404
404
unixExecutablePath := strings .ReplaceAll (executablePath ,"\\ " ,"/" )
405
405
cmd .Env = append (cmd .Env ,fmt .Sprintf (`GIT_SSH_COMMAND=%s gitssh --` ,unixExecutablePath ))
406
406
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
+
407
416
// Load environment variables passed via the agent.
408
417
// These should override all variables we manually specify.
409
418
for envKey ,value := range metadata .EnvironmentVariables {
@@ -427,15 +436,6 @@ func (a *agent) handleSSHSession(session ssh.Session) (retErr error) {
427
436
if err != nil {
428
437
return err
429
438
}
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 ))
439
439
440
440
if ssh .AgentRequested (session ) {
441
441
l ,err := ssh .NewAgentListener ()