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