Skip to content

Commit 8ff5cb8

Browse files
committed
ci: isolate tirith SARIF upload in a least-privilege job
Address CodeRabbit's security review: keep the elevated `security-events: write` scope out of any job that executes PR-controlled code. - `tirith-scan` now holds only `contents: read`. It still runs the local action, the PR flake and the installed tirith (it must, to scan the PR), but with no write scope a neutered scan cannot abuse any privilege — the same trust model as the existing `test`/`build` jobs that run the PR's `nix flake check`. - The SARIF is handed off as an artifact and published by a new `tirith-sarif-upload` job that never executes PR code: it only checks out files for path mapping and runs trusted, pinned actions (download-artifact + codeql upload-sarif). This is the only job with `security-events: write`. - The upload runs `always()` so findings reach the Security tab even when the gate blocks the PR, and is skipped for fork PRs (read-only token cannot upload).
1 parent 5b09c71 commit 8ff5cb8

1 file changed

Lines changed: 43 additions & 9 deletions

File tree

‎.github/workflows/ci.yaml‎

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ jobs:
3131
name: tirith security scan
3232
runs-on: blacksmith-32vcpu-ubuntu-2404
3333
timeout-minutes: 15
34+
# Read-only: this job executes PR-controlled code (the local action, the PR
35+
# flake, the installed tirith), so it must hold no write scopes. The SARIF
36+
# is published from the separate `tirith-sarif-upload` job, which never runs
37+
# PR code, keeping the elevated `security-events: write` away from the scan.
3438
permissions:
3539
contents: read
36-
# Publish SARIF to the Security tab. Only effective for same-repo PRs and
37-
# pushes to main; fork PRs get a read-only token, so the upload is gated
38-
# to non-fork events below (the scan and gate still run for forks).
39-
security-events: write
4040
steps:
4141
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
4242
with:
@@ -70,12 +70,16 @@ jobs:
7070
echo "tirith reported ${count} finding(s)" | tee -a "$GITHUB_STEP_SUMMARY"
7171
jq -r '.runs[].results[]? | "- [\(.level // "warning")] \(.ruleId): \(.locations[0].physicalLocation.artifactLocation.uri)"' \
7272
results.sarif 2>/dev/null | tee -a "$GITHUB_STEP_SUMMARY" || true
73-
- name: Upload SARIF to the Security tab
74-
if: ${{ always() && !github.event.pull_request.head.repo.fork }}
75-
uses: github/codeql-action/upload-sarif@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4.36.2
73+
# Hand the SARIF to the privileged upload job as an artifact. Uploaded
74+
# before the gate step so findings reach the Security tab even when the
75+
# gate then blocks the PR.
76+
- name: Upload SARIF artifact
77+
if: always()
78+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
7679
with:
77-
sarif_file: results.sarif
78-
category: tirith
80+
name: tirith-sarif
81+
path: results.sarif
82+
if-no-files-found: error
7983
- name: Gate CI on tirith findings
8084
if: always()
8185
env:
@@ -95,6 +99,35 @@ jobs:
9599
;;
96100
esac
97101
102+
# Publish the tirith SARIF to the Security tab. Split from the scan so the
103+
# `security-events: write` scope lives in a job that never executes
104+
# PR-controlled code: it only downloads the artifact and runs trusted, pinned
105+
# actions. `always()` so findings are published even when the gate blocked the
106+
# PR; skipped for fork PRs, whose token is read-only and cannot upload.
107+
tirith-sarif-upload:
108+
name: tirith SARIF upload
109+
needs: tirith-scan
110+
if: ${{ always() && !github.event.pull_request.head.repo.fork }}
111+
runs-on: ubuntu-slim
112+
timeout-minutes: 10
113+
permissions:
114+
contents: read
115+
security-events: write
116+
steps:
117+
# Checkout only places files for path mapping; no PR code is executed in
118+
# this privileged job.
119+
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
120+
with:
121+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
122+
persist-credentials: false
123+
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
124+
with:
125+
name: tirith-sarif
126+
- uses: github/codeql-action/upload-sarif@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4.36.2
127+
with:
128+
sarif_file: results.sarif
129+
category: tirith
130+
98131
# Fast, unconditional fail-fast gate for the cheap-but-high-signal checks:
99132
# secret detection (gitleaks) and workflow/format lint (the treefmt check,
100133
# which runs actionlint + zizmor with the repo's exact ignore config). Runs in
@@ -493,6 +526,7 @@ jobs:
493526
needs:
494527
- changes
495528
- tirith-scan
529+
- tirith-sarif-upload
496530
- preflight
497531
- test
498532
- build-native-packages

0 commit comments

Comments
 (0)