hashicorp / packer-plugin-vsphere

Packer plugin for VMware vSphere Builder
https://www.packer.io/docs/builders/vsphere
Mozilla Public License 2.0
93 stars 91 forks source link

Crash when connecting with `insecure_connection=false` #436

Closed lindhe closed 3 weeks ago

lindhe commented 1 month ago

Community Note

Overview of the Issue

I'm working towards a vcenter server with a TLS certificate form a private CA. If I'm trying to build a VM using Packer, with insecure_connection=false, then it crashes. If I add the cert to my host, or if I use insecure_connection=true, it works as intended.

Posting this since I was greeted with this:

!!!!!!!!!!!!!!!!!!!!!!!!!!! PACKER CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Packer crashed! This is always indicative of a bug within Packer.
A crash log has been placed at "crash.log" relative to your current
working directory. It would be immensely helpful if you could please
report the crash with Packer[1] so that we can fix this.

[1]: https://github.com/hashicorp/packer/issues

!!!!!!!!!!!!!!!!!!!!!!!!!!! PACKER CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Reproduction Steps

Run packer build . with the simplified packer template shown below.

Packer version

$ packer version
Packer v1.10.3

Simplified Packer Template

packer {
  required_version = ">= 1.7.0"
  required_plugins {
    vsphere = {
      version = "~> 1.2.0"
      source  = "github.com/hashicorp/vsphere"
    }
  }
}

source "vsphere-iso" "foo" {

  insecure_connection = false  # šŸ‘ˆ If this is `false`, things crash!

  cluster              = var.vcenter_cluster
  datacenter           = var.vcenter_datacenter
  datastore            = var.vcenter_datastore
  password             = var.vcenter_password
  ssh_username         = "bar"
  storage {
    disk_size             = 32 * 1024
    disk_thin_provisioned = true
  }
  username       = var.vcenter_username
  vcenter_server = var.vcenter_server
  vm_name        = "buz"

}

build {
  sources = ["source.vsphere-iso.foo"]
}

Operating system and Environment details

Ubuntu 22.04.4 LTS as a WSL2 environment on Windows 11.

Log Fragments and crash.log files

crash.log

lbajolet-hashicorp commented 1 month ago

Hi @lindhe,

Thanks for the bug report!

While this Unexpected EOF which caused Packer to crash is coming from the SDK (likely even gob), the underlying problem is coming from a nil driver that gets coerced in the Cleanup code of the connect step for some reason.

Fixing the serialisation/stream EOF error will take some time, but this vsphere bug can be independently addressed I'd think.

tenthirtyam commented 1 month ago

Interestingly, I get the expected error:

==> vsphere-iso.linux-photon: Post "https://m01-vc01.rainpole.io/sdk":
    tls: failed to verify certificate: x509: certificate signed by unknown authority
lindhe commented 1 month ago

Oh really? That is surprising. Same packer version? And did you try with my example or a different one?

Is your vcenter_server variable set to m01-vc01.rainpole.io or https://m01-vc01.rainpole.io or something else?