Skip to content

Temporary SSH Key files not generated or used in proxmox-iso #301

@bl1nk1n

Description

@bl1nk1n

Overview of the Issue

I am trying to avoid having to hardcode an SSH password or SSH key that will need to be changed/removed later. In the documentation it says:

If no communicator is defined, an SSH key is generated for use, and is used in the image's Cloud-Init settings for provisioning.

When not specifying any communicator, ssh_username, ssh_password, or ssh_private_key_file, it complains about needing an ssh_username (which matches the above statement about SSH being used by default; and the fact that the variable is required by the SSH communicator).

After supplying it with ssh_username I would expect it to generate a temporary key pair to be given to cloud-init, use those credentials to provision, and then remove them from the system. However, it looks like it tries to authenticate with method "none" and inspecting the server created, the key is not in any authorized_keys files.

Reproduction Steps

In my specific instance I was creating an ubuntu-24.04.1 template from the official ISO and passing a CD with the meta-data and user-data (autoinstall) files (which should include cloud-init options). I'm running Packer in the official Packer docker container with no modifications.

I run init, validate, and build in the docker container, and it works as expected until my above issue:

  • download the image
  • create the ISO containing meta-data and user-data
  • upload both ISOs to Proxmox
  • create a VM from the Ubuntu ISO with the cidata ISO mounted
  • pass boot_command from source to instruct it to use the mounted cidata CD
  • Ubuntu autoinstalls using the mounted CD
  • VM reboots and is accessible by my host running Packer

Software Versions

Docker Version

v4.36.0

Packer Docker Image

light - f64016a1388f8d4b807978369bf09269b1823719562d4c78970a72ae10627b23

Packer Version

$ docker run --rm -e PACKER_LOG=1 hashicorp/packer:light version          
2024/11/19 02:44:15 [INFO] Packer version: 1.12.0-alpha1 [go1.21.12 linux amd64]
...
2024/11/19 02:44:15 machine readable: version []string{"1.12.0"}
2024/11/19 02:44:15 machine readable: version-prelease []string{"alpha1"}
2024/11/19 02:44:15 machine readable: version-commit []string{"9ff6fe7f"}
Packer v1.12.0-alpha1
...

proxmox Plugin Version

v1.2.1_x5.0_linux_amd64

Proxmox Version

pve-manager/8.2.8/a577cfa684c7476d

Simplified Packer Buildfile

Removed everything that didn't seem pertinent to how keys should be created/deployed. Can add more detail later if need be.

packer {
    required_version = "~> 1"
    required_plugins {
        proxmox = {
            version = "~> 1"
            source = "github.com/hashicorp/proxmox"
        }
    }
}
source "proxmox-iso" "ubuntu-template" {
    qemu_agent = true
    additional_iso_files {
        cd_files = [
            "./files/autoinstall/meta-data",
            "./files/autoinstall/user-data"
        ]
        cd_label = "cidata"
        iso_storage_pool = "local"
    }
    cloud_init = true
    cloud_init_storage_pool = "local-lvm"
    boot_wait = "5s"
    boot_command = [
        "<esc><esc><esc><esc><wait>",
        "e<wait>",
        "<down><down><down><end>",
        " autoinstall ds=\"nocloud;\"<wait>",
        "<f10><wait>"
    ]
    # communicator = "ssh"
    ssh_username = "automation"
    # temporary_key_pair_type = "ed25519"
    ssh_timeout = "10m"
}

build {
    sources = ["source.proxmox-iso.ubuntu-template"]

    # Provisioning the VM Template for Cloud-Init Integration
    provisioner "shell" {
        inline = [
            "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done",
            "sudo rm /etc/ssh/ssh_host_*",
            "sudo truncate -s 0 /etc/machine-id",
            "sudo apt -y autoremove --purge",
            "sudo apt -y clean",
            "sudo apt -y autoclean",
            "sudo cloud-init clean",
            "sudo rm -f /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg",
            "sudo sync"
        ]
    }
    provisioner "file" {
        source = "files/99-pve.cfg"
        destination = "/tmp/99-pve.cfg"
    }
    provisioner "shell" {
        inline = [ "sudo cp /tmp/99-pve.cfg /etc/cloud/cloud.cfg.d/99-pve.cfg"]
    }
}

Log Fragments and crash.log files

2024/11/19 01:50:11 [INFO] Packer version: 1.12.0-alpha1 [go1.21.12 linux amd64]
...
==> ubuntu-template.proxmox-iso.ubuntu-template: Waiting for SSH to become available...
2024/11/19 01:51:22 packer-plugin-proxmox_v1.2.1_x5.0_linux_amd64 plugin: 2024/11/19 01:51:22 [DEBUG] Unable to get address during connection step: 500 QEMU guest agent is not running   
2024/11/19 01:51:22 packer-plugin-proxmox_v1.2.1_x5.0_linux_amd64 plugin: 2024/11/19 01:51:22 [INFO] Waiting for SSH, up to timeout: 10m0s
2024/11/19 01:51:25 packer-plugin-proxmox_v1.2.1_x5.0_linux_amd64 plugin: 2024/11/19 01:51:25 [DEBUG] Error getting SSH address: 500 QEMU guest agent is not running
...
2024/11/19 01:58:14 packer-plugin-proxmox_v1.2.1_x5.0_linux_amd64 plugin: 2024/11/19 01:58:14 [DEBUG] Error getting SSH address: 500 QEMU guest agent is not running
2024/11/19 01:58:21 packer-plugin-proxmox_v1.2.1_x5.0_linux_amd64 plugin: 2024/11/19 01:58:21 [INFO] Attempting SSH connection to 192.168.209.233:22...
2024/11/19 01:58:21 packer-plugin-proxmox_v1.2.1_x5.0_linux_amd64 plugin: 2024/11/19 01:58:21 [DEBUG] reconnecting to TCP connection for SSH
2024/11/19 01:58:21 packer-plugin-proxmox_v1.2.1_x5.0_linux_amd64 plugin: 2024/11/19 01:58:21 [DEBUG] handshaking with SSH
2024/11/19 01:58:22 packer-plugin-proxmox_v1.2.1_x5.0_linux_amd64 plugin: 2024/11/19 01:58:22 [DEBUG] SSH handshake err: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none], no supported methods remain
2024/11/19 01:58:22 packer-plugin-proxmox_v1.2.1_x5.0_linux_amd64 plugin: 2024/11/19 01:58:22 [DEBUG] Detected authentication error. Increasing handshake attempts.
...
2024/11/19 02:01:15 packer-plugin-proxmox_v1.2.1_x5.0_linux_amd64 plugin: 2024/11/19 02:01:15 [INFO] Attempting SSH connection to 192.168.209.233:22...
2024/11/19 02:01:15 packer-plugin-proxmox_v1.2.1_x5.0_linux_amd64 plugin: 2024/11/19 02:01:15 [DEBUG] reconnecting to TCP connection for SSH
2024/11/19 02:01:15 packer-plugin-proxmox_v1.2.1_x5.0_linux_amd64 plugin: 2024/11/19 02:01:15 [DEBUG] handshaking with SSH
2024/11/19 02:01:15 packer-plugin-proxmox_v1.2.1_x5.0_linux_amd64 plugin: 2024/11/19 02:01:15 [DEBUG] SSH handshake err: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none], no supported methods remain
2024/11/19 02:01:15 packer-plugin-proxmox_v1.2.1_x5.0_linux_amd64 plugin: 2024/11/19 02:01:15 [DEBUG] Detected authentication error. Increasing handshake attempts.
==> ubuntu-template.proxmox-iso.ubuntu-template: Timeout waiting for SSH.
2024/11/19 02:01:22 packer-plugin-proxmox_v1.2.1_x5.0_linux_amd64 plugin: 2024/11/19 02:01:22 [DEBUG] SSH wait cancelled. Exiting loop.
...
2024/11/19 02:01:26 machine readable: error-count []string{"1"}
...
2024/11/19 02:01:26 machine readable: ubuntu-template.proxmox-iso.ubuntu-template,error []string{"Timeout waiting for SSH."}
...
Build 'ubuntu-template.proxmox-iso.ubuntu-template' errored after 11 minutes 12 seconds: Timeout waiting for SSH.
...
--> ubuntu-template.proxmox-iso.ubuntu-template: Timeout waiting for SSH.
...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions