@@ -178,7 +178,7 @@ func New(instName string, stdout io.Writer, signalCh chan os.Signal, opts ...Opt
178
178
instName : instName ,
179
179
instSSHAddress : inst .SSHAddress ,
180
180
sshConfig : sshConfig ,
181
- portForwarder : newPortForwarder (sshConfig , sshLocalPort , rules , inst .VMType ),
181
+ portForwarder : newPortForwarder (sshConfig , inst . SSHAddress , sshLocalPort , rules , inst .VMType ),
182
182
driver : limaDriver ,
183
183
signalCh : signalCh ,
184
184
eventEnc : json .NewEncoder (stdout ),
@@ -567,7 +567,7 @@ func (a *HostAgent) watchGuestAgentEvents(ctx context.Context) {
567
567
for _ , rule := range a .y .PortForwards {
568
568
if rule .GuestSocket != "" {
569
569
local := hostAddress (rule , guestagentapi.IPPort {})
570
- _ = forwardSSH (ctx , a .sshConfig , a .sshLocalPort , local , rule .GuestSocket , verbForward , rule .Reverse )
570
+ _ = forwardSSH (ctx , a .sshConfig , a .instSSHAddress , a . sshLocalPort , local , rule .GuestSocket , verbForward , rule .Reverse )
571
571
}
572
572
}
573
573
}
@@ -582,13 +582,13 @@ func (a *HostAgent) watchGuestAgentEvents(ctx context.Context) {
582
582
if rule .GuestSocket != "" {
583
583
local := hostAddress (rule , guestagentapi.IPPort {})
584
584
// using ctx.Background() because ctx has already been cancelled
585
- if err := forwardSSH (context .Background (), a .sshConfig , a .sshLocalPort , local , rule .GuestSocket , verbCancel , rule .Reverse ); err != nil {
585
+ if err := forwardSSH (context .Background (), a .sshConfig , a .instSSHAddress , a . sshLocalPort , local , rule .GuestSocket , verbCancel , rule .Reverse ); err != nil {
586
586
errs = append (errs , err )
587
587
}
588
588
}
589
589
}
590
590
if a .driver .ForwardGuestAgent () {
591
- if err := forwardSSH (context .Background (), a .sshConfig , a .sshLocalPort , localUnix , remoteUnix , verbCancel , false ); err != nil {
591
+ if err := forwardSSH (context .Background (), a .sshConfig , a .instSSHAddress , a . sshLocalPort , localUnix , remoteUnix , verbCancel , false ); err != nil {
592
592
errs = append (errs , err )
593
593
}
594
594
}
@@ -597,7 +597,7 @@ func (a *HostAgent) watchGuestAgentEvents(ctx context.Context) {
597
597
for {
598
598
if a .client == nil || ! isGuestAgentSocketAccessible (ctx , a .client ) {
599
599
if a .driver .ForwardGuestAgent () {
600
- _ = forwardSSH (ctx , a .sshConfig , a .sshLocalPort , localUnix , remoteUnix , verbForward , false )
600
+ _ = forwardSSH (ctx , a .sshConfig , a .instSSHAddress , a . sshLocalPort , localUnix , remoteUnix , verbForward , false )
601
601
}
602
602
}
603
603
client , err := a .getOrCreateClient (ctx )
@@ -684,11 +684,11 @@ const (
684
684
verbCancel = "cancel"
685
685
)
686
686
687
- func executeSSH (ctx context.Context , sshConfig * ssh.SSHConfig , port int , command ... string ) error {
687
+ func executeSSH (ctx context.Context , sshConfig * ssh.SSHConfig , addr string , port int , command ... string ) error {
688
688
args := sshConfig .Args ()
689
689
args = append (args ,
690
690
"-p" , strconv .Itoa (port ),
691
- "127.0.0.1" ,
691
+ addr ,
692
692
"--" ,
693
693
)
694
694
args = append (args , command ... )
@@ -699,7 +699,7 @@ func executeSSH(ctx context.Context, sshConfig *ssh.SSHConfig, port int, command
699
699
return nil
700
700
}
701
701
702
- func forwardSSH (ctx context.Context , sshConfig * ssh.SSHConfig , port int , local , remote , verb string , reverse bool ) error {
702
+ func forwardSSH (ctx context.Context , sshConfig * ssh.SSHConfig , addr string , port int , local , remote , verb string , reverse bool ) error {
703
703
args := sshConfig .Args ()
704
704
args = append (args ,
705
705
"-T" ,
@@ -718,15 +718,15 @@ func forwardSSH(ctx context.Context, sshConfig *ssh.SSHConfig, port int, local,
718
718
"-N" ,
719
719
"-f" ,
720
720
"-p" , strconv .Itoa (port ),
721
- "127.0.0.1" ,
721
+ addr ,
722
722
"--" ,
723
723
)
724
724
if strings .HasPrefix (local , "/" ) {
725
725
switch verb {
726
726
case verbForward :
727
727
if reverse {
728
728
logrus .Infof ("Forwarding %q (host) to %q (guest)" , local , remote )
729
- if err := executeSSH (ctx , sshConfig , port , "rm" , "-f" , remote ); err != nil {
729
+ if err := executeSSH (ctx , sshConfig , addr , port , "rm" , "-f" , remote ); err != nil {
730
730
logrus .WithError (err ).Warnf ("Failed to clean up %q (guest) before setting up forwarding" , remote )
731
731
}
732
732
} else {
@@ -741,7 +741,7 @@ func forwardSSH(ctx context.Context, sshConfig *ssh.SSHConfig, port int, local,
741
741
case verbCancel :
742
742
if reverse {
743
743
logrus .Infof ("Stopping forwarding %q (host) to %q (guest)" , local , remote )
744
- if err := executeSSH (ctx , sshConfig , port , "rm" , "-f" , remote ); err != nil {
744
+ if err := executeSSH (ctx , sshConfig , addr , port , "rm" , "-f" , remote ); err != nil {
745
745
logrus .WithError (err ).Warnf ("Failed to clean up %q (guest) after stopping forwarding" , remote )
746
746
}
747
747
} else {
@@ -761,7 +761,7 @@ func forwardSSH(ctx context.Context, sshConfig *ssh.SSHConfig, port int, local,
761
761
if verb == verbForward && strings .HasPrefix (local , "/" ) {
762
762
if reverse {
763
763
logrus .WithError (err ).Warnf ("Failed to set up forward from %q (host) to %q (guest)" , local , remote )
764
- if err := executeSSH (ctx , sshConfig , port , "rm" , "-f" , remote ); err != nil {
764
+ if err := executeSSH (ctx , sshConfig , addr , port , "rm" , "-f" , remote ); err != nil {
765
765
logrus .WithError (err ).Warnf ("Failed to clean up %q (guest) after forwarding failed" , remote )
766
766
}
767
767
} else {
0 commit comments