Skip to content

test(sweep): execute the param-env loop instead of reading it - #703

Merged
scttfrdmn merged 1 commit into
mainfrom
test/531-execute-param-env
Oct 5, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
test/531-execute-param-env

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #531 as already fixed — with the verification it never had.

The fix was in; nothing had run it

The generated bootstrap already single-quotes spawn:param:* tag values into /etc/profile.d/spawn-params.sh, using the close/escape/reopen idiom, and the code comment cites this issue. So the reported bug — a value of $HOME/out being expanded by every login shell, and a value containing " breaking the generated line outright — is fixed.

But it had only ever been verified by reading, and #680 just demonstrated why that is not enough: its nested-quote rendering (echo "export EFS_MOUNT="/efs"") was syntactically valid, passed review, and silently produced the wrong value for any path with a space. Reading shell you have written is the weakest possible check on it.

So this adds the test that runs it.

What the test does

It extracts the real export loop from the generated bootstrap and rewrites only its output path — rather than restating the loop in the test, which would verify the copy and not the shipped script. Then it feeds a tag stream through the actual aws ec2 describe-tags --output text shape (key<TAB>value, one per line):

value what used to happen
$HOME/out expanded to the instance's real home
run "A" broke the generated line's quoting
it's the one character single-quoting must escape
$(id -u) executed in every login shell
`id` executed
a'b"c$d​e​`` all of the above at once
/a b/c a space, which is legal and ordinary

and then checks three things: the generated file parses (bash -n), sourcing it returns every value byte for byte, and $HOME — set to /SHOULD-NOT-APPEAR — never expands.

Confirmed to fail when I restore the double-quoted form: the file stops parsing and the shape gate names the cause.

The parse check matters independently. A quoting bug corrupts the rest of the file, not just the one variable — so a single bad value takes out every parameter after it, which is why #531 described it as corrupting the environment for the whole instance.

Param names: checked, no change needed

I went looking for the adjacent hole, since the name is interpolated unquoted too:

export PARAM_${param_name}='${escaped_value}'

A name like x;id would end the statement and leave id='v' as a second command in a file every login shell sources. I demonstrated that in a scratch shell before checking whether it was reachable — and it is not. resolveParamName validates against shellIdentifier = ^[A-Za-z_][A-Za-z0-9_]*$, so these are all rejected before launch with a message explaining that parameters become PARAM_<key> variables:

learning-rate → not a valid shell identifier (letters, digits and underscores only, not starting with a digit)
x;id          → rejected
a b           → rejected
x$(id)        → rejected
2lr           → rejected

learning-rate is the realistic one — a hyphen is natural in a config key — and rejecting it up front with that message is better than the alternative, which would have been export: not a valid identifier on every login and a workload seeing no parameter at all.

Values containing a newline are rejected too, since they cannot survive an EC2 tag.

Gates

gofmt -l empty, go vet ./..., go test -short ./... (whole module), changelog gate, semgrep → 0 findings. Also ran make changelog-fix — this and #702 each added an ### Added group.

#531's fix — single-quoting spawn:param:* tag values into
/etc/profile.d/spawn-params.sh — was already in place and verified only
by reading. #680 showed why that is insufficient: its nested-quote
rendering was syntactically valid and silently wrong.

The test extracts the real loop from the generated bootstrap (not a
restatement, which would verify the copy), runs it against values
including $HOME/out, run "A", it's, $(id -u) and a path with a space,
then bash -n's the output and sources it. Every value must round-trip
byte for byte, with HOME set to a sentinel that would show expansion.
Confirmed to fail when double-quoting is restored.

Also verified with no change needed: param names cannot inject, because
shellIdentifier rejects learning-rate, x;id, spaces and $(...) before
launch.
@scttfrdmn
scttfrdmn force-pushed the test/531-execute-param-env branch from eebb6b1 to 3239807 Compare October 5, 2026 01:33
@scttfrdmn
scttfrdmn merged commit 52de95f into main Oct 5, 2026
6 checks passed
@scttfrdmn
scttfrdmn deleted the test/531-execute-param-env branch October 5, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sweep parameter values are interpolated unquoted into /etc/profile.d — a value containing a quote or $ corrupts the sweep environment

1 participant