Skip to content

Commit 74309c7

Browse files
committed
Add a workflow to check that all workflows don't persist credentials.
`publish.yaml` is excluded just because testing it is more cumbersome, and it's nothing that untrusted parties can easily run.
1 parent 05a52a7 commit 74309c7

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

.github/workflows/push.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,32 @@ jobs:
212212
shared-key: windows-rust-testing
213213
- name: 'cargo check'
214214
run: cargo check --workspace --all-targets --features windows
215+
216+
# Check that all `actions/checkout` in CI jobs have `persist-credentials: false`.
217+
check-no-persist-credentials:
218+
runs-on: ubuntu-latest
219+
220+
env:
221+
GLOB: .github/workflows/*.@(yaml|yml)
222+
223+
steps:
224+
- uses: actions/checkout@v5
225+
with:
226+
persist-credentials: false
227+
sparse-checkout: '.github/workflows'
228+
- name: Generate workflows list to scan
229+
run: |
230+
shopt -s extglob
231+
printf '%s\n' ${{ env.GLOB }} | grep -v .github/workflows/publish.yaml >workflows.list
232+
cat workflows.list
233+
echo "Note that publish.yaml is excluded until it's ensured to not need this feature"
234+
- name: Scan workflows
235+
run: |
236+
shopt -s extglob
237+
yq '.jobs.*.steps[]
238+
| select(.uses == "actions/checkout@*" and .with.["persist-credentials"]? != false)
239+
| {"file": filename, "line": line, "name": (.name // .uses)}
240+
| .file + ":" + (.line | tostring) + ": " + .name
241+
' -- $(cat workflows.list) >query-output.txt
242+
cat query-output.txt
243+
test -z "$(<query-output.txt)" # Report failure if we found anything.

0 commit comments

Comments
 (0)