rancher / k3os

Purpose-built OS for Kubernetes, fully managed by Kubernetes.
https://k3os.io
Apache License 2.0
3.5k stars 404 forks source link

packer vagrant authentication error #406

Open svefors opened 4 years ago

svefors commented 4 years ago

Version (k3OS / kernel)

Architecture

Describe the bug

can't get packer to package a vagrant machine

To Reproduce

packer build vagrant.json

Expected behavior

a vagrant box

Actual behavior

it seems to run the provision steps but vagrant can't authenticate the second time

==> Builds finished but no artifacts were created.

Additional context

OS X Vagrant 2.2.7 Virtualbox 6.1.4

OUTPUT virtualbox-iso: output will be in this color.

==> virtualbox-iso: Retrieving Guest additions ==> virtualbox-iso: Trying /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso ==> virtualbox-iso: Trying /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso ==> virtualbox-iso: /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso => /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso ==> virtualbox-iso: Retrieving ISO ==> virtualbox-iso: Trying https://github.com/rancher/k3os/releases/download/v0.9.0-rc4/k3os-amd64.iso ==> virtualbox-iso: Trying https://github.com/rancher/k3os/releases/download/v0.9.0-rc4/k3os-amd64.iso?checksum=sha256%3Af790f005b7c6da19b701f1a30d5786d15eb5b5b3b49837a67872769ce0709abc k3os-amd64.iso 450.89 MiB / 450.89 MiB [==============================================================================================] 100.00% 2m20s ==> virtualbox-iso: https://github.com/rancher/k3os/releases/download/v0.9.0-rc4/k3os-amd64.iso?checksum=sha256%3Af790f005b7c6da19b701f1a30d5786d15eb5b5b3b49837a67872769ce0709abc => /Users/svefors/dev/projects/k3os/package/packer/vagrant/packer_cache/a3d15a65497858c1fd89a94cefd79ea5696d26ce.iso ==> virtualbox-iso: Starting HTTP server on port 8573 ==> virtualbox-iso: Creating virtual machine... ==> virtualbox-iso: Creating hard drive... ==> virtualbox-iso: Creating forwarded port mapping for communicator (SSH, WinRM, etc) (host port 4072) ==> virtualbox-iso: Starting the virtual machine... ==> virtualbox-iso: Waiting 6s for boot... ==> virtualbox-iso: Typing the boot command... ==> virtualbox-iso: Using ssh communicator to connect: 127.0.0.1 ==> virtualbox-iso: Waiting for SSH to become available... ==> virtualbox-iso: Error waiting for SSH: Packer experienced an authentication error when trying to connect via SSH. This can happen if your username/password are wrong. You may want to double-check your credentials as part of your debugging process. original error: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none keyboard-interactive], no supported methods remain ==> virtualbox-iso: Deregistering and deleting VM... ==> virtualbox-iso: Deleting output directory... Build 'virtualbox-iso' errored: Packer experienced an authentication error when trying to connect via SSH. This can happen if your username/password are wrong. You may want to double-check your credentials as part of your debugging process. original error: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none keyboard-interactive], no supported methods remain

==> Some builds didn't complete successfully and had errors: --> virtualbox-iso: Packer experienced an authentication error when trying to connect via SSH. This can happen if your username/password are wrong. You may want to double-check your credentials as part of your debugging process. original error: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none keyboard-interactive], no supported methods remain

==> Builds finished but no artifacts were created.

davecardwell commented 4 years ago

packer is attempting to use password authentication for ssh, but that was disabled on k3os by #321.

You can get things working again by enabling password authentication in the cloud-config.yml file:

k3os:
  password: rancher
boot_cmd:
  - sed -i -r 's/^(\s*PasswordAuthentication\s*)no(\s*)$/\1yes\2/i' /etc/ssh/sshd_config

Though when you run vagrant up it’s going to add to .ssh/authorized_keys and PasswordAuthentication won’t be needed any more, so perhaps it would be better to have packer use temporary ssh keys as well?

dweomer commented 4 years ago

packer is attempting to use password authentication for ssh, but that was disabled on k3os by #321.

You can get things working again by enabling password authentication in the cloud-config.yml file:

k3os:
  password: rancher
boot_cmd:
  - sed -i -r 's/^(\s*PasswordAuthentication\s*)no(\s*)$/\1yes\2/i' /etc/ssh/sshd_config

Though when you run vagrant up it’s going to add to .ssh/authorized_keys and PasswordAuthentication won’t be needed any more, so perhaps it would be better to have packer use temporary ssh keys as well?

sorry about this, good catch @davecardwell

stayfrostnl commented 4 years ago

Ran into the same issue with the vsphere-iso builder. Thx for the example cloud-config. I used it like this in Packer: "boot_command": [ "rancher", "<enter>", "sudo k3os install", "<enter>", "1", "<enter>", "Y", "<enter>", "http://<serverlocation>/cloud-config.yml", "<enter>", "Y", "<enter>" ] After that Packer could log in with rancher:rancher and complete the build. Don't forget to disable password auth again.

mlgim commented 4 years ago

Can't get this to work. Using @stayfrostnl Packer procedure with the following cloud-config, but PassworkAuthentication stays set to 'no' and Packer fails. Any hints would be much appreaciated :-)

k3os:
  password: topsecret
  boot_cmd:
    - sed -i -r 's/^(\s*PasswordAuthentication\s*)no(\s*)$/\1yes\2/i' /etc/ssh/sshd_config
  k3s_args:
    - server
    - "--no-deploy servicelb"
    - "--no-deploy traefik"
  token: "MyToken"
dclark commented 4 years ago

@mlgim https://github.com/cwebd/k3os-vagrant provides a packer build using virtualbox.

icanhazbeer commented 4 years ago

Ran into the same issue with the vsphere-iso builder. Thx for the example cloud-config. I used it like this in Packer: "boot_command": [ "rancher", "<enter>", "sudo k3os install", "<enter>", "1", "<enter>", "Y", "<enter>", "http://<serverlocation>/cloud-config.yml", "<enter>", "Y", "<enter>" ] After that Packer could log in with rancher:rancher and complete the build. Don't forget to disable password auth again.

Also running into issues with vsphere-iso builder. Not sure where my break is. @stayfrostnl Would you mind sharing your cloud-config.yml file? Wondering if I have a formatting issue.

dclark commented 4 years ago

@icanhazbeer cloud-config.yml is in https://github.com/cwebd/k3os-vagrant/blob/master/packer/cloud-config.yml

The packer build has been updated now so that the vagrant insecure key is inserted so that the ssh configuration does not need to be modified.

If you review: https://github.com/cwebd/k3os-vagrant/tree/master/packer

icanhazbeer commented 4 years ago

thanks, I managed to solve my issue. I had some incorrect formatting, apparently i cant type :P