hashicorp / hashicorp/packer-plugin-sdk

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

Open
#260 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
42
Forks
62
Avg merge
29m
Merged PRs (30d)
2

Description

#### 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:
```bash
#!/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:
- name: packer
sudo: ALL=(ALL) NOPASSWD:ALL
shell: /bin/bash
ssh_authorized_keys:
- $(cat ssh_key.pub)
" > user-data
genisoimage -output cidata.iso -input-charset utf-8 -volid cidata -rational-rock -joliet user-data meta-data
echo '- hosts: all
tasks:
- ansible.builtin.copy:
src: example_file_with_no_spaces
dest: /tmp/example1
- ansible.builtin.copy:
src: example file with spaces
dest: /tmp/example2
' > playbook.yaml
echo 'packer {
required_plugins {
qemu = {
version = "1.1.0"
source = "github.com/hashicorp/qemu"
}
ansible = {
version = "1.1.1"
source = "github.com/hashicorp/ansible"
}
}
}

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.