hashicorp / packer-plugin-sdk

Packer Plugin SDK enables building Packer plugins (builders, provisioners, or post-processors) to manage any service providers or custom in-house solutions
Mozilla Public License 2.0
34 stars 48 forks source link

SCP in SSH proxy adapter does not handle spaces in filenames correctly #260

Open Jackenmen opened 4 months ago

Jackenmen commented 4 months ago

Overview of the Issue

It appears that SDK's SSH proxy adapter (used, for example, by the Ansible plugin) does not handle spaces in filenames correctly resulting in exit code 1 from scp during the transfer. The build runs fine if the proxy is disabled.

Reproduction Steps

  1. Create a directory with build.sh with following contents:
    
    #!/bin/bash

cleanup previous run output

rm -f \ example_file_with_no_spaces \ 'example file with spaces' \ ssh_key \ ssh_key.pub \ meta-data \ user-data \ cidata.iso \ playbook.yaml \ repro.pkr.hcl rm -rf output

create files for the build

touch example_file_with_no_spaces touch 'example file with spaces' ssh-keygen -t rsa -q -f ssh_key -N '' -C 'packer' echo '{}' > meta-data echo "#cloud-config users:

source "qemu" "ubuntu" { format = "qcow2" disk_image = true disk_size = "10G" headless = true iso_checksum = "file:https://cloud-images.ubuntu.com/jammy/current/SHA256SUMS" iso_url = "https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img" qemuargs = [["-cdrom", "cidata.iso"]] ssh_username = "packer" ssh_private_key_file = "ssh_key" vm_name = "build.qcow2" output_directory = "output" }

build { sources = ["source.qemu.ubuntu"]

provisioner "ansible" { playbook_file = "playbook.yaml" ansible_env_vars = ["ANSIBLE_VERBOSITY=5", "ANSIBLE_DISPLAY_ARGS_TO_STDOUT=True"] } } ' > repro.pkr.hcl

run Packer

packer init repro.pkr.hcl packer build repro.pkr.hcl

2. Run the following commands:

chmod +x build.sh ./build.sh


3. See the failure.

Note that as described, adding `use_proxy = false` to the Ansible provisioner results in a successful build.

### Packer Plugin SDK version

0.5.1 (the version that the Packer Ansible plugin uses)

### Operating system and Environment details

Packer ran from OS: Ubuntu Desktop 22.04.4 LTS x86_64
OS ran in Packer: Ubuntu Server 22.04.4 LTS x86_64

### Log Fragments and crash.log files

https://gist.github.com/Jackenmen/bb97795a3e69709a1d7dda6cab75e07f