executor: quote env vars if passed as args & contain whitespace
Created by: mrnugget
This fixes auto-indexing on executors that use ignite/firecracker under the hood.
It was broken since #30023 (and due to #29885 for a different reason), because in #30023 we added an env var to the auto-index jobs whose value contains whitespace.
We didn't detect that this is a problem when testing locally, because on
macOS we don't use ignite and all the commands are executed on the host.
In that case the env vars are set as env vars on Go's exec.Cmd
structure and that takes care of the whitespace for us.
But when the jobs are run via ignite in firecracker VMs the env vars are
passed to the VM as args of the ignite
command.
That lead to a command like this being executed:
ignite exec $VM-NAME -- \
SRC_HEADER_AUTHORIZATION=token-executor SECRET-TOKEN src lsif upload [...]
(details omitted)
That failed with:
bash: SECRET-TOKEN: command not found
Because we didn't put the env var value in quotes.
Now we come to this PR.
This quotes env vars, but only under two circumstances:
- if the env vars are passed as part of the command line
- if they contain whitespace
The important bit is (1), because we need to make sure that when we set
a cmd.Env
field we don't quote the env vars, because Go will then
use the quotes as part of the value.