Problem
Several templates inline the agent init script via:
sudo -u '${linux_user}' sh -c '${init_script}'
This pattern is fragile: if the upstream bootstrap script (provisionersdk/scripts/bootstrap_linux.sh in coder/coder) ever contains a single quote (apostrophe), the shell quoting breaks silently. The agent fails to start with no clear error.
This just happened — see coder/coder#22062. A comment containing exec'ing was added to the bootstrap script, breaking all templates using this pattern.
Affected templates
coder/templates/aws-linux — cloud-init/userdata.sh.tftpl
coder/templates/gcp-linux — main.tf (metadata_startup_script)
mossylion/templates/scaleway-instance — cloud-init/userdata.sh.tftpl
ericpaulsen/templates/k8s-username — main.tf
Templates already using safe patterns
These templates write the init script as file content via cloud-config write_files or similar, avoiding the quoting issue entirely:
coder/templates/azure-linux — cloud-init write_files + systemd
coder/templates/digitalocean-linux — cloud-init write_files
Proposed fix
Update the affected templates to use the same write_files approach as azure-linux and digitalocean-linux. Instead of inlining the script into sh -c '...', write it to a file and execute it:
write_files:
- path: /opt/coder/init
permissions: "0755"
encoding: b64
content: ${init_script}
Then execute via a systemd unit or runcmd:
runcmd:
- sudo -u ${linux_user} /opt/coder/init
This is immune to quoting issues since the script content is base64-encoded and written as a file rather than inlined into a shell command.
Related
Problem
Several templates inline the agent init script via:
This pattern is fragile: if the upstream bootstrap script (
provisionersdk/scripts/bootstrap_linux.shin coder/coder) ever contains a single quote (apostrophe), the shell quoting breaks silently. The agent fails to start with no clear error.This just happened — see coder/coder#22062. A comment containing
exec'ingwas added to the bootstrap script, breaking all templates using this pattern.Affected templates
Templates already using safe patterns
These templates write the init script as file content via cloud-config
write_filesor similar, avoiding the quoting issue entirely:Proposed fix
Update the affected templates to use the same
write_filesapproach asazure-linuxanddigitalocean-linux. Instead of inlining the script intosh -c '...', write it to a file and execute it:Then execute via a systemd unit or
runcmd:This is immune to quoting issues since the script content is base64-encoded and written as a file rather than inlined into a shell command.
Related