Skip to content

Commit 67c050b

Browse files
committed
ci: use env vars to avoid template expansion in code contexts
Template expansions are not aware of shell script syntax, and therefore can potentially result in code injection vulnerabilities when used in code contexts: https://docs.zizmor.sh/audits/#template-injection To avoid this, instead use environment variables to safely store the values of the template expansions. Also (in the process of doing the above) added double-quotes around a some instances of variable expansions in shell scripts, which is necessary to avoid unintended shell splitting and globbing. (I didn't see any instances where this was actually likely to result in erroneous behavior, but it's good practice and makes shell scripts more robust.) Signed-off-by: Daniel Hast <hast.daniel@protonmail.com>
1 parent 3f4af37 commit 67c050b

File tree

8 files changed

+246
-150
lines changed

8 files changed

+246
-150
lines changed

.github/workflows/dev-bump.yml

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ jobs:
2222
- name: Bump
2323
id: bump
2424
run: |
25-
ref=${{ github.ref_name }}
26-
version=${ref#v}
25+
version=${GITHUB_REF_NAME#v}
2726
if [[ $version == *-rc* ]]; then
2827
devbump="${version%-*}-dev"
2928
echo "::notice:: is a rc - bumping z down to $devbump"
@@ -38,49 +37,52 @@ jobs:
3837
3938
echo "devbump=$devbump" >> $GITHUB_OUTPUT
4039
- name: Push
40+
env:
41+
DEVBUMP: ${{ steps.bump.outputs.devbump }}
4142
run: |
4243
# Make committer the user who triggered the action, either through cutting a release or manual trigger
4344
# GitHub gives everyone a noreply email associated with their account, use that email for the sign-off
44-
git config --local user.name ${{ github.actor }}
45-
git config --local user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com"
46-
bumpbranch="bump-${{ steps.bump.outputs.devbump }}"
45+
git config --local user.name "${GITHUB_ACTOR}"
46+
git config --local user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com"
47+
bumpbranch="bump-${DEVBUMP}"
4748
git checkout -b $bumpbranch
4849
git add version/rawversion/version.go
49-
git commit --signoff -m "Bump Podman to v${{ steps.bump.outputs.devbump }}"
50+
git commit --signoff -m "Bump Podman to v${DEVBUMP}"
5051
git remote add podmanbot https://github.com/podmanbot/podman
5152
git push -f podmanbot "$bumpbranch"
5253
- name: Check open PRs
5354
id: checkpr
5455
env:
56+
DEVBUMP: ${{ steps.bump.outputs.devbump }}
5557
GH_TOKEN: ${{ secrets.PODMANBOT_TOKEN }}
5658
run: |
5759
prs=$(gh pr list \
58-
--repo ${{ github.repository }} \
59-
--head bump-${{ steps.bump.outputs.devbump }} \
60+
--repo "${GITHUB_REPOSITORY}" \
61+
--head "bump-${DEVBUMP}" \
6062
--state open \
6163
--json title \
6264
--jq 'length')
6365
if ((prs > 0)); then
64-
echo "SKIPPING: PR already exists to update from ${{ github.ref_name }}."
66+
echo "SKIPPING: PR already exists to update from ${GITHUB_REF_NAME}."
6567
else
6668
echo "prexists=false" >> "$GITHUB_OUTPUT"
6769
fi
6870
- name: Open PR
6971
if: steps.checkpr.outputs.prexists == 'false'
7072
id: pr
73+
env:
74+
DEVBUMP: ${{ steps.bump.outputs.devbump }}
75+
GH_TOKEN: ${{ secrets.PODMANBOT_TOKEN }}
7176
run: |
72-
bumpbranch="bump-${{ steps.bump.outputs.devbump }}"
73-
ref=${{ github.ref_name }}
74-
base=${ref%.*}
77+
bumpbranch="bump-${DEVBUMP}"
78+
base=${GITHUB_REF_NAME%.*}
7579
body=$(printf '```release-note\nNone\n```\n')
7680
gh pr create \
77-
--title "Bump Podman to v${{ steps.bump.outputs.devbump }}" \
81+
--title "Bump Podman to v${DEVBUMP}" \
7882
--body "$body" \
7983
--head "podmanbot:$bumpbranch" \
8084
--base "$base" \
81-
--repo ${{ github.repository }}
82-
env:
83-
GH_TOKEN: ${{ secrets.PODMANBOT_TOKEN }}
85+
--repo "${GITHUB_REPOSITORY}"
8486
mainbump:
8587
name: Bump on main
8688
runs-on: ubuntu-latest
@@ -99,8 +101,7 @@ jobs:
99101
id: check
100102
run: |
101103
mainvers=`grep -P '(?<=const RawVersion = ")(\d.\d)' -o version/rawversion/version.go`
102-
ref=${{ github.ref_name }}
103-
releasevers=${ref#v}
104+
releasevers=${GITHUB_REF_NAME#v}
104105
if echo "${mainvers},${releasevers}" | tr ',' '\n' | sort -V -C
105106
then
106107
echo "bump=true" >> $GITHUB_OUTPUT
@@ -112,8 +113,7 @@ jobs:
112113
id: bump
113114
if: steps.check.outputs.bump == 'true'
114115
run: |
115-
ref=${{ github.ref_name }}
116-
releasevers=${ref#v}
116+
releasevers=${GITHUB_REF_NAME#v}
117117
118118
arr=($(echo "$releasevers" | tr . '\n'))
119119
arr[1]=$((${arr[1]}+1))
@@ -126,44 +126,48 @@ jobs:
126126
echo "devbump=$devbump" >> $GITHUB_OUTPUT
127127
- name: Push
128128
if: steps.check.outputs.bump == 'true'
129+
env:
130+
DEVBUMP: ${{ steps.bump.outputs.devbump }}
129131
run: |
130132
# Make committer the user who triggered the action, either through cutting a release or manual trigger
131-
# GitHub gisves everyone a noreply email associated with their account, use that email for the sign-off
132-
git config --local user.name ${{ github.actor }}
133-
git config --local user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com"
134-
bumpbranch="bump-main-${{ steps.bump.outputs.devbump }}"
133+
# GitHub gives everyone a noreply email associated with their account, use that email for the sign-off
134+
git config --local user.name "${GITHUB_ACTOR}"
135+
git config --local user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com"
136+
bumpbranch="bump-main-${DEVBUMP}"
135137
git checkout -b $bumpbranch
136138
git add version/rawversion/version.go
137-
git commit --signoff -m "Bump main to v${{ steps.bump.outputs.devbump }}"
139+
git commit --signoff -m "Bump main to v${DEVBUMP}"
138140
git remote add podmanbot https://github.com/podmanbot/podman
139141
git push -f podmanbot "$bumpbranch"
140142
- name: Check open PRs
141143
id: checkpr
142144
if: steps.check.outputs.bump == 'true'
143145
env:
146+
DEVBUMP: ${{ steps.bump.outputs.devbump }}
144147
GH_TOKEN: ${{ secrets.PODMANBOT_TOKEN }}
145148
run: |
146149
prs=$(gh pr list \
147-
--repo ${{ github.repository }} \
148-
--head bump-main-${{ steps.bump.outputs.devbump }} \
150+
--repo "${GITHUB_REPOSITORY}" \
151+
--head "bump-main-${DEVBUMP}" \
149152
--state open \
150153
--json title \
151154
--jq 'length')
152155
if ((prs > 0)); then
153-
echo "SKIPPING: PR already exists to update to ${{ steps.bump.outputs.devbump }}."
156+
echo "SKIPPING: PR already exists to update to ${DEVBUMP}."
154157
else
155158
echo "prexists=false" >> "$GITHUB_OUTPUT"
156159
fi
157160
- name: Open PR
158161
if: steps.check.outputs.bump == 'true' && steps.checkpr.outputs.prexists == 'false'
162+
env:
163+
DEVBUMP: ${{ steps.bump.outputs.devbump }}
164+
GH_TOKEN: ${{ secrets.PODMANBOT_TOKEN }}
159165
run: |
160-
bumpbranch="bump-main-${{ steps.bump.outputs.devbump }}"
166+
bumpbranch="bump-main-${DEVBUMP}"
161167
body=$(printf '```release-note\nNone\n```\n')
162168
gh pr create \
163-
--title "Bump main to v${{ steps.bump.outputs.devbump }}" \
169+
--title "Bump main to v${DEVBUMP}" \
164170
--body "$body" \
165171
--head "podmanbot:$bumpbranch" \
166172
--base "main" \
167-
--repo ${{ github.repository }}
168-
env:
169-
GH_TOKEN: ${{ secrets.PODMANBOT_TOKEN }}
173+
--repo "${GITHUB_REPOSITORY}"

.github/workflows/first_contrib_cert_generator.yml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ jobs:
6565
# Step 3: Update the HTML file locally
6666
- name: Update HTML file
6767
if: ${{ github.event_name == 'workflow_dispatch' || steps.check_first_pr.outputs.is_first_pr == 'true' }}
68+
env:
69+
CONTRIBUTOR_NAME: ${{ github.event.inputs.contributor_username || github.event.pull_request.user.login }}
70+
PR_NUMBER: ${{ github.event.inputs.pr_number || github.event.pull_request.number }}
6871
run: |
6972
HTML_FILE="automation-repo/certificate-generator/certificate_generator.html"
70-
CONTRIBUTOR_NAME="${{ github.event.inputs.contributor_username || github.event.pull_request.user.login }}"
71-
PR_NUMBER="${{ github.event.inputs.pr_number || github.event.pull_request.number }}"
7273
MERGE_DATE=$(date -u +"%B %d, %Y")
7374
7475
sed --sandbox -i -e "/id=\"contributorName\"/s/value=\"[^\"]*\"/value=\"${CONTRIBUTOR_NAME}\"/" ${HTML_FILE} || { echo "ERROR: Failed to update contributor name."; exit 1; }
@@ -120,6 +121,10 @@ jobs:
120121
- name: Upload certificate to separate repository
121122
if: ${{ github.event_name == 'workflow_dispatch' || steps.check_first_pr.outputs.is_first_pr == 'true' }}
122123
uses: actions/github-script@v8
124+
env:
125+
CONTRIBUTOR_USERNAME: ${{ github.event.inputs.contributor_username }}
126+
USER_LOGIN: ${{ github.event.pull_request.user.login }}
127+
PR_NUMBER: ${{ github.event.inputs.pr_number }}
123128
with:
124129
github-token: ${{ secrets.CERTIFICATES_REPO_TOKEN }}
125130
script: |
@@ -157,10 +162,10 @@ jobs:
157162
// Create a unique filename with timestamp
158163
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
159164
const contributorName = context.eventName === 'workflow_dispatch'
160-
? '${{ github.event.inputs.contributor_username }}'
161-
: '${{ github.event.pull_request.user.login }}';
165+
? process.env.CONTRIBUTOR_USERNAME
166+
: process.env.USER_LOGIN;
162167
const prNumber = context.eventName === 'workflow_dispatch'
163-
? '${{ github.event.inputs.pr_number }}'
168+
? process.env.PR_NUMBER
164169
: context.issue.number;
165170
166171
const filename = `certificates/${contributorName}-${prNumber}-${timestamp}.png`;
@@ -219,6 +224,10 @@ jobs:
219224
- name: Comment with embedded certificate image
220225
if: ${{ github.event_name == 'workflow_dispatch' || steps.check_first_pr.outputs.is_first_pr == 'true' }}
221226
uses: actions/github-script@v8
227+
env:
228+
CONTRIBUTOR_USERNAME: ${{ github.event.inputs.contributor_username }}
229+
USER_LOGIN: ${{ github.event.pull_request.user.login }}
230+
PR_NUMBER: ${{ github.event.inputs.pr_number }}
222231
with:
223232
script: |
224233
try {
@@ -240,17 +249,17 @@ jobs:
240249
241250
if (context.eventName === 'workflow_dispatch') {
242251
// Manual trigger case
243-
const contributorName = '${{ github.event.inputs.contributor_username }}';
244-
const prNumber = '${{ github.event.inputs.pr_number }}';
252+
const contributorName = process.env.CONTRIBUTOR_USERNAME;
253+
const prNumber = process.env.PR_NUMBER;
245254
body = `📜 Certificate preview generated for @${contributorName} (PR #${prNumber}):\n\n${body}`;
246255
} else {
247256
// Auto trigger case for first-time contributors
248-
const username = '${{ github.event.pull_request.user.login }}';
257+
const username = process.env.USER_LOGIN;
249258
body = `🎉 Congratulations on your first merged pull request, @${username}! Thank you for your contribution.\n\nHere's a preview of your certificate:\n\n${body}`;
250259
}
251260
252261
const issueNumber = context.eventName === 'workflow_dispatch' ?
253-
parseInt('${{ github.event.inputs.pr_number }}') :
262+
parseInt(process.env.PR_NUMBER) :
254263
context.issue.number;
255264
256265
await github.rest.issues.createComment({

.github/workflows/mac-pkg.yml

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,33 +37,42 @@ jobs:
3737
steps:
3838
- name: Consolidate dryrun setting to always be true or false
3939
id: actual_dryrun
40+
env:
41+
INPUT_DRYRUN: ${{ inputs.dryrun }}
4042
run: |
4143
# The 'release' trigger will not have a 'dryrun' input set. Handle
4244
# this case in a readable/maintainable way.
43-
if [[ -z "${{ inputs.dryrun }}" ]]
45+
if [[ -z "${INPUT_DRYRUN}" ]]
4446
then
4547
echo "dryrun=false" >> $GITHUB_OUTPUT
4648
else
47-
echo "dryrun=${{ inputs.dryrun }}" >> $GITHUB_OUTPUT
49+
echo "dryrun=${INPUT_DRYRUN}" >> $GITHUB_OUTPUT
4850
fi
4951
- name: Dry Run Status
52+
env:
53+
DRYRUN: ${{ steps.actual_dryrun.outputs.dryrun }}
5054
run: |
51-
echo "::notice::This workflow execution will be a dry-run: ${{ steps.actual_dryrun.outputs.dryrun }}"
55+
echo "::notice::This workflow execution will be a dry-run: ${DRYRUN}"
5256
- name: Determine Version
5357
id: getversion
58+
env:
59+
INPUT_VERSION: ${{ inputs.version }}
60+
TAG_NAME: ${{ github.event.release.tag_name }}
5461
run: |
55-
if [[ -z "${{ inputs.version }}" ]]
62+
if [[ -z "${INPUT_VERSION}" ]]
5663
then
57-
VERSION=${{ github.event.release.tag_name }}
64+
VERSION=${TAG_NAME}
5865
else
59-
VERSION=${{ inputs.version }}
66+
VERSION=${INPUT_VERSION}
6067
fi
6168
echo
6269
echo "version=$VERSION" >> $GITHUB_OUTPUT
6370
- name: Check uploads
6471
id: check
72+
env:
73+
VERSION: ${{ steps.getversion.outputs.version }}
6574
run: |
66-
URI="https://github.com/containers/podman/releases/download/${{steps.getversion.outputs.version}}"
75+
URI="https://github.com/containers/podman/releases/download/${VERSION}"
6776
ARM_FILE="podman-installer-macos-arm64.pkg"
6877
AMD_FILE="podman-installer-macos-amd64.pkg"
6978
UNIVERSAL_FILE="podman-installer-macos-universal.pkg"
@@ -168,8 +177,9 @@ jobs:
168177
steps.check.outputs.builduniversal == 'true' )
169178
env:
170179
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
180+
VERSION: ${{ steps.getversion.outputs.version }}
171181
run: |
172-
(gh release download ${{steps.getversion.outputs.version}} -p "shasums" || exit 0)
182+
(gh release download "${VERSION}" -p "shasums" || exit 0)
173183
cat contrib/pkginstaller/out/shasums >> shasums
174-
gh release upload ${{steps.getversion.outputs.version}} contrib/pkginstaller/out/podman-installer-macos-*.pkg
175-
gh release upload ${{steps.getversion.outputs.version}} --clobber shasums
184+
gh release upload "${VERSION}" contrib/pkginstaller/out/podman-installer-macos-*.pkg
185+
gh release upload "${VERSION}" --clobber shasums

0 commit comments

Comments
 (0)