@@ -400,6 +400,15 @@ func (a *agent) createCommand(ctx context.Context, rawCommand string, env []stri
400
400
unixExecutablePath := strings .ReplaceAll (executablePath ,"\\ " ,"/" )
401
401
cmd .Env = append (cmd .Env ,fmt .Sprintf (`GIT_SSH_COMMAND=%s gitssh --` ,unixExecutablePath ))
402
402
403
+ // Set SSH connection environment variables (these are also set by OpenSSH
404
+ // and thus expected to be present by SSH clients). Since the agent does
405
+ // networking in-memory, trying to provide accurate values here would be
406
+ // nonsensical. For now, we hard code these values so that they're present.
407
+ srcAddr ,srcPort := "0.0.0.0" ,"0"
408
+ dstAddr ,dstPort := "0.0.0.0" ,"0"
409
+ cmd .Env = append (cmd .Env ,fmt .Sprintf ("SSH_CLIENT=%s %s %s" ,srcAddr ,srcPort ,dstPort ))
410
+ cmd .Env = append (cmd .Env ,fmt .Sprintf ("SSH_CONNECTION=%s %s %s %s" ,srcAddr ,srcPort ,dstAddr ,dstPort ))
411
+
403
412
// Load environment variables passed via the agent.
404
413
// These should override all variables we manually specify.
405
414
for envKey ,value := range metadata .EnvironmentVariables {
@@ -423,15 +432,6 @@ func (a *agent) handleSSHSession(session ssh.Session) (retErr error) {
423
432
if err != nil {
424
433
return err
425
434
}
426
- // Set SSH connection environment variables, from the clients perspective.
427
- // Set SSH connection environment variables (these are also set by OpenSSH
428
- // and thus expected to be present by SSH clients). Since the agent does
429
- // networking in-memory, trying to provide accurate values here would be
430
- // nonsensical. For now, we hard code these values so that they're present.
431
- srcAddr ,srcPort := "0.0.0.0" ,"0"
432
- dstAddr ,dstPort := "0.0.0.0" ,"0"
433
- cmd .Env = append (cmd .Env ,fmt .Sprintf ("SSH_CLIENT=%s %s %s" ,srcAddr ,srcPort ,dstPort ))
434
- cmd .Env = append (cmd .Env ,fmt .Sprintf ("SSH_CONNECTION=%s %s %s %s" ,srcAddr ,srcPort ,dstAddr ,dstPort ))
435
435
436
436
if ssh .AgentRequested (session ) {
437
437
l ,err := ssh .NewAgentListener ()