From f9d24ccda0bcfff561a9971b39221a67900a3519 Mon Sep 17 00:00:00 2001 From: Stephen Fox Date: Tue, 5 Feb 2019 11:59:13 -0500 Subject: [PATCH] Allow user to get public key straight up, or URL encoded. --- builder/virtualbox/common/step_ssh_key_pair.go | 2 ++ .../common/step_type_boot_command.go | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/builder/virtualbox/common/step_ssh_key_pair.go b/builder/virtualbox/common/step_ssh_key_pair.go index 2e157940f..40c728e2f 100644 --- a/builder/virtualbox/common/step_ssh_key_pair.go +++ b/builder/virtualbox/common/step_ssh_key_pair.go @@ -66,6 +66,8 @@ func (s *StepSshKeyPair) Run(_ context.Context, state multistep.StateBag) multis // If we're in debug mode, output the private key to the working // directory. + // TODO: It would be better if the file was 'chmod' before writing + // the key to the disk - or if umask was set before creating the file. if s.Debug { ui.Message(fmt.Sprintf("Saving communicator private key for debug purposes: %s", s.DebugKeyPath)) f, err := os.Create(s.DebugKeyPath) diff --git a/builder/virtualbox/common/step_type_boot_command.go b/builder/virtualbox/common/step_type_boot_command.go index 0cb433903..6095505af 100644 --- a/builder/virtualbox/common/step_type_boot_command.go +++ b/builder/virtualbox/common/step_type_boot_command.go @@ -27,8 +27,13 @@ type bootCommandTemplateData struct { // Name is the VM's name. Name string - // SSHPublicKey is the URL encoded public key in - // authorized_keys format. + // EncodedSSHPublicKey is the URL encoded SSH public key in + // OpenSSH authorized_keys format. This is safe for usage + // on the the kernel command line, or other places that split + // on whitespace. + EncodedSSHPublicKey string + + // SSHPublicKey is the SSH public key in OpenSSH authorized_keys format. SSHPublicKey string } @@ -67,10 +72,11 @@ func (s *StepTypeBootCommand) Run(ctx context.Context, state multistep.StateBag) hostIP := "10.0.2.2" common.SetHTTPIP(hostIP) s.Ctx.Data = &bootCommandTemplateData{ - HTTPIP: hostIP, - HTTPPort: httpPort, - Name: s.VMName, - SSHPublicKey: s.Comm.SSHPublicKeyUrlEncoded(), + HTTPIP: hostIP, + HTTPPort: httpPort, + Name: s.VMName, + EncodedSSHPublicKey: s.Comm.SSHPublicKeyUrlEncoded(), + SSHPublicKey: string(s.Comm.SSHPublicKey), } sendCodes := func(codes []string) error {