Skip to content

Commit 06c7e00

Browse files
woodruffwwebknjaz
andcommitted
ci, action: address zizmor findings
Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]> Signed-off-by: William Woodruff <[email protected]>
1 parent db8f07d commit 06c7e00

File tree

5 files changed

+56
-23
lines changed

5 files changed

+56
-23
lines changed

.github/workflows/build-and-push-docker-image.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ on: # yamllint disable-line rule:truthy
1313
required: true
1414
type: string
1515

16+
permissions: {}
17+
1618
jobs:
1719
smoke-test:
1820
uses: ./.github/workflows/reusable-smoke-test.yml
@@ -34,13 +36,17 @@ jobs:
3436
jobs: ${{ toJSON(needs) }}
3537

3638
build-and-push:
39+
permissions:
40+
packages: write
3741
if: github.event_name != 'pull_request'
3842
runs-on: ubuntu-latest
3943
needs:
4044
- check
4145
timeout-minutes: 10
4246
steps:
4347
- uses: actions/checkout@v4
48+
with:
49+
persist-credentials: false
4450
- name: Build Docker image
4551
run: |
4652
DOCKER_TAG="${DOCKER_TAG/'/'/'-'}"

.github/workflows/reusable-smoke-test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ jobs:
5454
uses: actions/checkout@v4
5555
with:
5656
path: test
57+
persist-credentials: false
5758
- name: Fail-fast in unsupported environments
5859
continue-on-error: true
5960
id: fail-fast
@@ -89,6 +90,7 @@ jobs:
8990
uses: actions/checkout@v4
9091
with:
9192
path: test
93+
persist-credentials: false
9294
- name: Install the packaging-related tools
9395
run: python3 -m pip install build twine
9496
env:

.github/workflows/zizmor.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
3+
name: GitHub Actions Security Analysis with zizmor 🌈
4+
5+
on: # yamllint disable-line rule:truthy
6+
push:
7+
pull_request:
8+
9+
jobs:
10+
zizmor:
11+
name: 🌈 zizmor
12+
13+
permissions:
14+
security-events: write
15+
16+
# yamllint disable-line rule:line-length
17+
uses: zizmorcore/workflow/.github/workflows/reusable-zizmor.yml@1ae473d8672fe7613e809d86d202a35063736e16
18+
19+
...

.github/zizmor.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
rules:
3+
unpinned-uses:
4+
config:
5+
policies:
6+
actions/*: ref-pin
7+
github/*: ref-pin
8+
re-actors/*: ref-pin

action.yml

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ runs:
100100
exit 1
101101
shell: bash -eEuo pipefail {0}
102102
- name: Reset path if needed
103-
run: |
103+
run: | # zizmor: ignore[github-env] PATH is not user-controlled
104104
# Reset path if needed
105105
# https://github.com/pypa/gh-action-pypi-publish/issues/112
106106
if [[ $PATH != *"/usr/bin"* ]]; then
@@ -111,25 +111,6 @@ runs:
111111
echo "\$PATH reset. \$PATH=$PATH"
112112
fi
113113
shell: bash
114-
- name: Set repo and ref from which to run Docker container action
115-
id: set-repo-and-ref
116-
run: |
117-
# Set repo and ref from which to run Docker container action
118-
# to handle cases in which `github.action_` context is not set
119-
# https://github.com/actions/runner/issues/2473
120-
REF=${{ env.ACTION_REF || env.PR_REF || github.ref_name }}
121-
REPO=${{ env.ACTION_REPO || env.PR_REPO || github.repository }}
122-
REPO_ID=${{ env.PR_REPO_ID || github.repository_id }}
123-
echo "ref=$REF" >>"$GITHUB_OUTPUT"
124-
echo "repo=$REPO" >>"$GITHUB_OUTPUT"
125-
echo "repo-id=$REPO_ID" >>"$GITHUB_OUTPUT"
126-
shell: bash
127-
env:
128-
ACTION_REF: ${{ github.action_ref }}
129-
ACTION_REPO: ${{ github.action_repository }}
130-
PR_REF: ${{ github.event.pull_request.head.ref }}
131-
PR_REPO: ${{ github.event.pull_request.head.repo.full_name }}
132-
PR_REPO_ID: ${{ github.event.pull_request.base.repo.id }}
133114
- name: Discover pre-installed Python
134115
id: pre-installed-python
135116
run: |
@@ -151,9 +132,26 @@ runs:
151132
|| steps.pre-installed-python.outputs.python-path
152133
}} '${{ github.action_path }}/create-docker-action.py'
153134
env:
154-
REF: ${{ steps.set-repo-and-ref.outputs.ref }}
155-
REPO: ${{ steps.set-repo-and-ref.outputs.repo }}
156-
REPO_ID: ${{ steps.set-repo-and-ref.outputs.repo-id }}
135+
# Set repo and ref from which to run Docker container action
136+
# to handle cases in which `github.action_` context is not set
137+
# https://github.com/actions/runner/issues/2473
138+
REF: >-
139+
${{
140+
github.action_ref
141+
|| github.event.pull_request.head.ref
142+
|| github.ref_name
143+
}}
144+
REPO: >-
145+
${{
146+
github.action_repository
147+
|| github.event.pull_request.head.repo.full_name
148+
|| github.repository
149+
}}
150+
REPO_ID: >-
151+
${{
152+
github.event.pull_request.base.repo.id
153+
|| github.repository_id
154+
}}
157155
shell: bash
158156
- name: Run Docker container
159157
# The generated trampoline action must exist in the allowlisted

0 commit comments

Comments
 (0)