hashicorp / packer-plugin-docker

Packer plugin for Docker Builder
https://www.packer.io/docs/builders/docker
Mozilla Public License 2.0
31 stars 25 forks source link

/bin/sh: 1: /home/ubuntu/packer/script_2501.sh: Permission denied #118

Open hc-github-team-packer opened 1 year ago

hc-github-team-packer commented 1 year ago

This issue was originally opened by @fredleger in https://github.com/hashicorp/packer/issues/11968 and has been migrated to this repository. The original issue description is below.


Community Note

Overview of the Issue

As stated in #5307 packer even at latest version upload temporary script files with wrong owner if the container is nut run as root

Reproduction Steps

source "docker" "container" {
  commit = true
  image  = "ubuntu:jammy"
  run_command = [
    "-d", "-i", "-t", "--user", "1000", "--entrypoint=/bin/sh", "--", "{{.Image}}"
  ]
}

Packer version

v1.8.3

Simplified Packer Template

see above

Operating system and Environment details

macosx ruuning rancher desktop for docker (so at the end linux)

Log Fragments and crash.log files

==> docker.container: Starting docker container...
    docker.container: Run command: docker run -v /Users/frederic/.packer.d/tmp2545466742:/packer-files -d -i -t --user 1000 --entrypoint=/bin/sh -- ubuntu:jammy
    docker.container: Container ID: eee892b4cf201e56176d93c5cd131b2ed6c76f4e4d342b8eed7c7479833718cc
==> docker.container: Pausing after run of step 'StepRun'. Press enter to continue. 
==> docker.container: Using docker communicator to connect: 172.17.0.2
==> docker.container: Pausing after run of step 'StepConnect'. Press enter to continue. 
==> docker.container: Pausing before the next provisioner . Press enter to continue. 
==> docker.container: Provisioning with shell script: /var/folders/n_/jtqch7ls28534bbt4hl905mr0000gn/T/packer-shell1344318242
==> docker.container: chmod: changing permissions of '/home/ubuntu/packer/script_2501.sh': Operation not permitted
==> docker.container: /bin/sh: 1: /home/ubuntu/packer/script_2501.sh: Permission denied
==> docker.container: Script exited with non-zero exit status: 126. Allowed exit codes are: [0]
==> docker.container: Step "StepProvision" failed

In the container:

buntu@3c5cc3a18ffc:~/packer$ ls -l
total 4
-rw------- 1 501 dialout 66 Sep  1 15:02 script_4966.sh

The owner id is 501 (which is my host user id) and not 1000 as it should be