hashicorp / packer

Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.
http://www.packer.io
Other
14.99k stars 3.32k forks source link

Getting "permission denied" when packer is creating temporary file for CD #10219

Open ruzickap opened 3 years ago

ruzickap commented 3 years ago

Overview of the Issue

When using packer with cd_files I can not use files/directories which are read only. That is usually the case when working with "CD".

Reproduction Steps

$ curl -L https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/latest-virtio/virtio-win.iso --output virtio-win.iso
$ xorriso -osirrox on -indev virtio-win.iso -extract / /tmp/test2

# The directories+files are read only !
$ find /tmp/test2 -type d -ls
  7270426      0 dr-xr-xr-x  25 petr_ruzicka wheel         800 Aug 10 09:51 /tmp/test2
  7270427      0 dr-xr-xr-x  14 petr_ruzicka wheel         448 Aug 10 08:10 /tmp/test2/Balloon
...

$ cat > test-ubuntu.json << EOF
{
  "builders": [
    {
      "iso_checksum": "file:http://archive.ubuntu.com/ubuntu/dists/xenial-updates/main/installer-amd64/current/images/SHA256SUMS",
      "iso_urls": [
        "http://archive.ubuntu.com/ubuntu/dists/xenial-updates/main/installer-amd64/current/images/netboot/mini.iso"
      ],
      "type": "qemu",
      "ssh_username": "root",
      "cd_files": [
        "/tmp/test2"
      ]
    }
  ]
}
EOF

$ PACKER_LOG=1 packer build ./test-ubuntu.json
...
==> qemu: Deleting output directory...
2020/11/05 06:21:42 [INFO] (telemetry) ending qemu
==> Wait completed after 171 milliseconds 264 microseconds
2020/11/05 06:21:42 machine readable: error-count []string{"1"}
==> Some builds didn't complete successfully and had errors:
2020/11/05 06:21:42 machine readable: qemu,error []string{"Error creating temporary file for CD: error creating new directory /var/folders/3n/72wkgzv175957c4cmybxd_4r0000gn/T/packer_to_cdrom148067970/test2/Balloon: mkdir /var/folders/3n/72wkgzv175957c4cmybxd_4r0000gn/T/packer_to_cdrom148067970/test2/Balloon: permission denied"}

Packer version

$ packer version
Packer v1.6.5

Simplified Packer Buildfile

See reproduction steps above.

Operating system and Environment details

MacOS Catalina

Log Fragments and crash.log files

See reproduction steps above - contains error logs

nywilken commented 3 years ago

Thanks for reaching out. We’ll take a look when we get a chance.

roblabla commented 2 years ago

I'm having the same issue on a Linux host (NixOS). Anything I can do to help debug this?

Packer version: 1.7.8

roblabla commented 2 years ago

Did some investigation. The error arrives here: https://github.com/hashicorp/packer-plugin-sdk/blob/f98795fcc30b7de77ce79bef3997699291e7bc20/multistep/commonsteps/step_create_cdrom.go#L293-L297

The issue seem to be related to the Mode argument passed to os.MkdirAll. If I chmod 777 -R test before running packer, then I get no error.