From 5980d32efb3ca5341b21577c94dc665a6beefa08 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Tue, 14 Jan 2020 13:57:11 -0800 Subject: [PATCH 1/2] remove unhelpful quotes to fix bug with reading key from a path with spaces in it. --- builder/vagrant/driver_2_2.go | 8 ++++++-- builder/vagrant/step_ssh_config.go | 11 +++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/builder/vagrant/driver_2_2.go b/builder/vagrant/driver_2_2.go index f6f72e05a..0e1110517 100644 --- a/builder/vagrant/driver_2_2.go +++ b/builder/vagrant/driver_2_2.go @@ -199,7 +199,11 @@ func (d *Vagrant_2_2_Driver) vagrantCmd(args ...string) (string, string, error) cmd.Stdout = &stdout cmd.Stderr = &stderr - cmd.Start() + err := cmd.Start() + if err != nil { + return "", "", fmt.Errorf("Error starting vagrant command with args: %s", + strings.Join(args, " ")) + } stdoutString := "" stderrString := "" @@ -238,7 +242,7 @@ func (d *Vagrant_2_2_Driver) vagrantCmd(args ...string) (string, string, error) } }() - err := cmd.Wait() + err = cmd.Wait() donech <- true diff --git a/builder/vagrant/step_ssh_config.go b/builder/vagrant/step_ssh_config.go index d28f10fe4..588e20b43 100644 --- a/builder/vagrant/step_ssh_config.go +++ b/builder/vagrant/step_ssh_config.go @@ -2,7 +2,9 @@ package vagrant import ( "context" + "log" "strconv" + "strings" "github.com/hashicorp/packer/helper/multistep" ) @@ -53,6 +55,15 @@ func (s *StepSSHConfig) Run(ctx context.Context, state multistep.StateBag) multi // auth provided there. return multistep.ActionContinue } + log.Printf("identity file is %s", sshConfig.IdentityFile) + log.Printf("Removing quotes from identity file") + if strings.HasPrefix(sshConfig.IdentityFile, "\"") { + sshConfig.IdentityFile = sshConfig.IdentityFile[1:] + if strings.HasSuffix(sshConfig.IdentityFile, "\"") { + sshConfig.IdentityFile = sshConfig.IdentityFile[:len(sshConfig.IdentityFile)-1] + } + log.Printf("identity file is now %s", sshConfig.IdentityFile) + } config.Comm.SSHPrivateKeyFile = sshConfig.IdentityFile config.Comm.SSHUsername = sshConfig.User From bbd64896a0341909dcc593babb429b86d2e4f296 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Wed, 15 Jan 2020 10:23:25 -0800 Subject: [PATCH 2/2] use strconv.unquote instead of DIY --- builder/vagrant/driver_2_2.go | 2 +- builder/vagrant/step_ssh_config.go | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/builder/vagrant/driver_2_2.go b/builder/vagrant/driver_2_2.go index 0e1110517..b7a22ad2d 100644 --- a/builder/vagrant/driver_2_2.go +++ b/builder/vagrant/driver_2_2.go @@ -201,7 +201,7 @@ func (d *Vagrant_2_2_Driver) vagrantCmd(args ...string) (string, string, error) err := cmd.Start() if err != nil { - return "", "", fmt.Errorf("Error starting vagrant command with args: %s", + return "", "", fmt.Errorf("Error starting vagrant command with args: %q", strings.Join(args, " ")) } diff --git a/builder/vagrant/step_ssh_config.go b/builder/vagrant/step_ssh_config.go index 588e20b43..3cf4c1817 100644 --- a/builder/vagrant/step_ssh_config.go +++ b/builder/vagrant/step_ssh_config.go @@ -4,7 +4,6 @@ import ( "context" "log" "strconv" - "strings" "github.com/hashicorp/packer/helper/multistep" ) @@ -57,12 +56,9 @@ func (s *StepSSHConfig) Run(ctx context.Context, state multistep.StateBag) multi } log.Printf("identity file is %s", sshConfig.IdentityFile) log.Printf("Removing quotes from identity file") - if strings.HasPrefix(sshConfig.IdentityFile, "\"") { - sshConfig.IdentityFile = sshConfig.IdentityFile[1:] - if strings.HasSuffix(sshConfig.IdentityFile, "\"") { - sshConfig.IdentityFile = sshConfig.IdentityFile[:len(sshConfig.IdentityFile)-1] - } - log.Printf("identity file is now %s", sshConfig.IdentityFile) + sshConfig.IdentityFile, err = strconv.Unquote(sshConfig.IdentityFile) + if err != nil { + log.Printf("Error unquoting identity file: %s", err) } config.Comm.SSHPrivateKeyFile = sshConfig.IdentityFile config.Comm.SSHUsername = sshConfig.User