Repository navigation
Use intermediate env variables for bash script runners in github workflows - #13434
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates several GitHub Actions workflows to follow GitHub’s security guidance for shell steps by pre-resolving expressions (notably workflow inputs / refs) into step-level environment variables before using them in bash, reducing the risk of script-injection via expression interpolation.
Changes:
.github/workflows/images.yml: Moveworkflow_dispatchinputs into stepenv:and reference them from the script..github/workflows/build-test-images.yml: Move multipleworkflow_dispatchinputs into stepenv:and quote their usage inside CLI invocations..github/workflows/api-release.yml: Move${{ github.ref }}into a stepenv:var for the signature-check script.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| .github/workflows/images.yml | Uses step env: for input interpolation before using values in bash. |
| .github/workflows/build-test-images.yml | Uses step env: for workflow inputs before passing them into Azure CLI / make commands. |
| .github/workflows/api-release.yml | Uses step env: for github.ref in the tag signature-check script. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
375428d to
bdd1424
Compare
| with: | ||
| inlinescript: | | ||
| PASSWORD="$(/usr/bin/tr -dc "a-zA-Z0-9@#$%^&*()_+?><~\`;" < /dev/urandom | /usr/bin/head -c 24; echo '')" | ||
| echo "::add-mask::$PASSWORD" |
There was a problem hiding this comment.
Apparently this needs to be "set" once per job like this, and then all later cases of the environment variable (or string) will be masked in runner output. It's a little vague in the docs but all the examples do loo like that, and it flagged to be this way by Copilot review (comment) which I would hope knows github actions quite well
| TARGET_IMAGE: ${{ github.event.inputs.image }} | ||
| run: | | ||
| sudo containerd -l debug & > /tmp/containerd.out | ||
| sudo containerd -l debug > /tmp/containerd.out 2>&1 & |
There was a problem hiding this comment.
FYI I realize this is unrelated to the main point of this PR but was flagged by Copilot, since the output won't be redirected properly if the backgrounding with & comes before the redirect
Best practice for interpolation of input variables for bash scripts in Github workflows is to preresolve them into strings during an env step to avoid script injection; see docs at https://docs.github.com/en/actions/reference/security/secure-use#use-an-intermediate-environment-variable Signed-off-by: lauralorenz <[email protected]>
bdd1424 to
d5b1a69
Compare
| sudo containerd -l debug > /tmp/containerd.out 2>&1 & | ||
| containerd_pid=$! | ||
| sleep 5 |
| releasever="$REF" | ||
| releasever="${releasever#refs/tags/}" | ||
| TAGCHECK=$(git tag -v ${releasever} 2>&1 >/dev/null) || | ||
| echo "${TAGCHECK}" | grep -q "error" && { |
|
Can you show a test run of the api-release.yaml and images.yaml on your fork? |
|
I think that's fine. We can handle anything with that separately (those workflows are having some of their own issues). |
This looks like release.yaml (which you didn't modify), not api-release.yaml. |
|
@samuelkarp oops you're right, I tagged |
Best practice for interpolation of input variables for bash scripts in Github workflows is to preresolve them during an env step and encapsulate them inline in the bash into a string to avoid script injection. These cases could be injected from either directly in the input step for the workflow (images.yml/build-test-images.yml), or more indirectly by setting a malicious tag (api-release.yml). To be fair, to do so one would still need write access on the repository (for the tag) or the workflows directly (for the input step), but still updating it to sync with the security recommendation in the docs at https://docs.github.com/en/actions/reference/security/secure-use#use-an-intermediate-environment-variable.