Skip to content

Commit 9e254c8

Browse files
authored
Merge pull request #2187 from EliahKagan/run-ci/no-persist-credentials
Don't persist GitHub authentication token in `.git/config` on CI
2 parents f8be65f + 741cb6b commit 9e254c8

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

.github/workflows/ci.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ jobs:
3838

3939
steps:
4040
- uses: actions/checkout@v5
41+
with:
42+
persist-credentials: false
4143
- uses: extractions/setup-just@v3
4244
- name: Read the MSRV
4345
run: |
@@ -60,6 +62,8 @@ jobs:
6062

6163
steps:
6264
- uses: actions/checkout@v5
65+
with:
66+
persist-credentials: false
6367
- uses: extractions/setup-just@v3
6468
- name: Ensure we start out clean
6569
run: git diff --exit-code
@@ -75,6 +79,8 @@ jobs:
7579

7680
steps:
7781
- uses: actions/checkout@v5
82+
with:
83+
persist-credentials: false
7884
- name: Prerequisites
7985
run: |
8086
prerequisites=(
@@ -177,6 +183,8 @@ jobs:
177183

178184
steps:
179185
- uses: actions/checkout@v5
186+
with:
187+
persist-credentials: false
180188
- uses: dtolnay/rust-toolchain@stable
181189
- uses: Swatinem/rust-cache@v2
182190
- name: Setup dependencies
@@ -197,6 +205,8 @@ jobs:
197205

198206
steps:
199207
- uses: actions/checkout@v5
208+
with:
209+
persist-credentials: false
200210
- uses: dtolnay/rust-toolchain@stable
201211
- uses: Swatinem/rust-cache@v2
202212
- uses: extractions/setup-just@v3
@@ -221,6 +231,8 @@ jobs:
221231

222232
steps:
223233
- uses: actions/checkout@v5
234+
with:
235+
persist-credentials: false
224236
- uses: dtolnay/rust-toolchain@stable
225237
- uses: Swatinem/rust-cache@v2
226238
- name: cargo check default features
@@ -268,6 +280,8 @@ jobs:
268280

269281
steps:
270282
- uses: actions/checkout@v5
283+
with:
284+
persist-credentials: false
271285
- uses: dtolnay/rust-toolchain@stable
272286
- uses: Swatinem/rust-cache@v2
273287
- uses: taiki-e/install-action@v2
@@ -339,6 +353,8 @@ jobs:
339353
apt-get install --no-install-recommends -y -- "${prerequisites[@]}"
340354
shell: bash # This step needs `bash`, and the default in container jobs is `sh`.
341355
- uses: actions/checkout@v5
356+
with:
357+
persist-credentials: false
342358
- name: Install Rust via Rustup
343359
run: |
344360
# Specify toolchain to avoid possible misdetection based on the 64-bit running kernel.
@@ -365,6 +381,8 @@ jobs:
365381

366382
steps:
367383
- uses: actions/checkout@v5
384+
with:
385+
persist-credentials: false
368386
- uses: dtolnay/rust-toolchain@stable
369387
with:
370388
targets: ${{ env.TARGET }}
@@ -382,6 +400,8 @@ jobs:
382400

383401
steps:
384402
- uses: actions/checkout@v5
403+
with:
404+
persist-credentials: false
385405
- uses: dtolnay/rust-toolchain@master
386406
with:
387407
toolchain: stable
@@ -412,6 +432,8 @@ jobs:
412432

413433
steps:
414434
- uses: actions/checkout@v5
435+
with:
436+
persist-credentials: false
415437
- uses: EmbarkStudios/cargo-deny-action@v2
416438
with:
417439
command: check advisories
@@ -422,6 +444,8 @@ jobs:
422444

423445
steps:
424446
- uses: actions/checkout@v5
447+
with:
448+
persist-credentials: false
425449
- uses: EmbarkStudios/cargo-deny-action@v2
426450
with:
427451
command: check bans licenses sources
@@ -441,6 +465,8 @@ jobs:
441465

442466
steps:
443467
- uses: actions/checkout@v5
468+
with:
469+
persist-credentials: false
444470
- name: Install Rust
445471
run: |
446472
rustup update stable
@@ -520,6 +546,8 @@ jobs:
520546

521547
steps:
522548
- uses: actions/checkout@v5
549+
with:
550+
persist-credentials: false
523551
- name: Check that working tree is initially clean
524552
run: |
525553
set -x
@@ -533,6 +561,33 @@ jobs:
533561
git status
534562
git diff --exit-code
535563
564+
# Check that all `actions/checkout` in CI jobs have `persist-credentials: false`.
565+
check-no-persist-credentials:
566+
runs-on: ubuntu-latest
567+
568+
env:
569+
GLOB: .github/workflows/*.@(yaml|yml)
570+
571+
steps:
572+
- uses: actions/checkout@v5
573+
with:
574+
persist-credentials: false
575+
sparse-checkout: '.github/workflows'
576+
- name: List workflows to be scanned
577+
run: |
578+
shopt -s extglob
579+
printf '%s\n' ${{ env.GLOB }}
580+
- name: Scan workflows
581+
run: |
582+
shopt -s extglob
583+
yq '.jobs.*.steps[]
584+
| select(.uses == "actions/checkout@*" and .with.["persist-credentials"]? != false)
585+
| {"file": filename, "line": line, "name": (.name // .uses)}
586+
| .file + ":" + (.line | tostring) + ": " + .name
587+
' -- ${{ env.GLOB }} >query-output.txt
588+
cat query-output.txt
589+
test -z "$(<query-output.txt)" # Report failure if we found anything.
590+
536591
# Check that only jobs intended not to block PR auto-merge are omitted as
537592
# dependencies of the `tests-pass` job below, so that whenever a job is
538593
# added, a decision is made about whether it must pass for PRs to merge.
@@ -557,6 +612,7 @@ jobs:
557612
echo "WORKFLOW_PATH=${relative_workflow_with_ref%@*}" >> "$GITHUB_ENV"
558613
- uses: actions/checkout@v5
559614
with:
615+
persist-credentials: false
560616
sparse-checkout: ${{ env.WORKFLOW_PATH }}
561617
- name: Get all jobs
562618
run: yq '.jobs | keys.[]' -- "$WORKFLOW_PATH" | sort | tee all-jobs.txt
@@ -586,6 +642,7 @@ jobs:
586642
- lint
587643
- cargo-deny
588644
- check-packetline
645+
- check-no-persist-credentials
589646
- check-blocking
590647

591648
if: always() # Always run even if dependencies fail.

.github/workflows/cron.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jobs:
1414

1515
steps:
1616
- uses: actions/checkout@v5
17+
with:
18+
persist-credentials: false
1719
- uses: Swatinem/rust-cache@v2
1820
- name: stress
1921
run: make stress

.github/workflows/release.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ jobs:
4141
steps:
4242
- name: Checkout repository
4343
uses: actions/checkout@v5
44+
with:
45+
persist-credentials: false
4446

4547
- name: Get the release version from the tag
4648
if: env.VERSION == ''
@@ -234,6 +236,8 @@ jobs:
234236
steps:
235237
- name: Checkout repository
236238
uses: actions/checkout@v5
239+
with:
240+
persist-credentials: false
237241

238242
- name: Install packages (Ubuntu)
239243
# Because openssl doesn't work on musl by default, we resort to max-pure.
@@ -537,6 +541,8 @@ jobs:
537541

538542
steps:
539543
- uses: actions/checkout@v5
544+
with:
545+
persist-credentials: false
540546
- name: Install Rust
541547
uses: dtolnay/rust-toolchain@master
542548
with:

0 commit comments

Comments
 (0)