Skip to content

Use intermediate env variables for bash script runners in github workflows - #13434

Merged
samuelkarp merged 1 commit into
containerd:mainfrom
lauralorenz:workflow-updates-bash-interpolation
Jun 4, 2026
Merged

samuelkarp merged 1 commit into
containerd:mainfrom
lauralorenz:workflow-updates-bash-interpolation

Conversation

@lauralorenz

Copy link
Copy Markdown
Contributor

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: Move workflow_dispatch inputs into step env: and reference them from the script.
  • .github/workflows/build-test-images.yml: Move multiple workflow_dispatch inputs into step env: and quote their usage inside CLI invocations.
  • .github/workflows/api-release.yml: Move ${{ github.ref }} into a step env: 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.

Comment thread .github/workflows/build-test-images.yml Resolved
Comment thread .github/workflows/build-test-images.yml Resolved
Comment thread .github/workflows/images.yml Resolved
Comment thread .github/workflows/api-release.yml Resolved
@lauralorenz
lauralorenz force-pushed the workflow-updates-bash-interpolation branch from 375428d to bdd1424 Compare May 27, 2026 19:45
with:
inlinescript: |
PASSWORD="$(/usr/bin/tr -dc "a-zA-Z0-9@#$%^&*()_+?><~\`;" < /dev/urandom | /usr/bin/head -c 24; echo '')"
echo "::add-mask::$PASSWORD"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 &

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
Copilot AI review requested due to automatic review settings May 27, 2026 20:53
@lauralorenz
lauralorenz force-pushed the workflow-updates-bash-interpolation branch from bdd1424 to d5b1a69 Compare May 27, 2026 20:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment on lines +61 to 63
sudo containerd -l debug > /tmp/containerd.out 2>&1 &
containerd_pid=$!
sleep 5
Comment on lines +34 to 37
releasever="$REF"
releasever="${releasever#refs/tags/}"
TAGCHECK=$(git tag -v ${releasever} 2>&1 >/dev/null) ||
echo "${TAGCHECK}" | grep -q "error" && {
@samuelkarp

Copy link
Copy Markdown
Member

Can you show a test run of the api-release.yaml and images.yaml on your fork?

@lauralorenz

lauralorenz commented May 28, 2026 •

Copy link
Copy Markdown
Contributor Author
  • There is a successful run of the API Release (api-release.yaml) workflow on this branch here. UPDATE: actually this was accidentally a Release workflow (release.yaml), see down the comment chain.
  • And a successful run of the Mirror Test Images (images.yaml) workflow for this branch here.
  • For the Build Test Volume Images (build-test-images.yaml), there is a failing workflow against this branch here as it fails early at the azure login step with which I would expect as I don't have secrets.AZURE_CREDS/azure login credentials on my fork. I'm working on getting some if we feel this needs a full run through, but as this isn't one you specifically asked for in your comment/if you feel that it's ok without it, that works for me too. cc @samuelkarp

@samuelkarp

Copy link
Copy Markdown
Member

if you feel that it's ok without it, that works for me too

I think that's fine. We can handle anything with that separately (those workflows are having some of their own issues).

@samuelkarp

Copy link
Copy Markdown
Member

There is a successful run of the API Release (api-release.yaml) workflow on this branch here.

This looks like release.yaml (which you didn't modify), not api-release.yaml.

@lauralorenz

Copy link
Copy Markdown
Contributor Author

@samuelkarp oops you're right, I tagged v0.0.0-test-workflow, not api/v0.0.0-test-workflow. There is now a successful run of the actual API Release job here.

@samuelkarp samuelkarp moved this from Needs Triage to Needs Reviewers in Pull Request Review May 29, 2026
@github-project-automation github-project-automation Bot moved this from Needs Reviewers to Review In Progress in Pull Request Review Jun 4, 2026
@samuelkarp
samuelkarp added this pull request to the merge queue Jun 4, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 4, 2026
@samuelkarp
samuelkarp added this pull request to the merge queue Jun 4, 2026
Merged via the queue into containerd:main with commit af60379 Jun 4, 2026
50 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants