Repository navigation
Commit cdda182
authored
ci: add tirith security scan and fail-fast preflight gate (#1383)
* ci: add tirith security scan and fail-fast preflight gate
Add a security gate to the CI workflow so the expensive build/test work
runs only after the cheap, high-signal security checks pass.
Two new jobs run unconditionally and in parallel at the front of the
pipeline (not gated on `changes`, so they cover docs-only PRs and fork
PRs where local git hooks never run):
- `tirith-scan`: scans the whole checkout with tirith
(https://tirith.sh/docs/ci/), uploads SARIF to the Security tab, and
gates downstream CI. Wired on `pull_request` (not
`pull_request_target`), so fork PRs only get a read-only token and
cannot leak secrets while their code is scanned; the SARIF upload is
therefore skipped for forks (the scan and gate still run). tirith is
installed from the flake's pinned nixpkgs to match the dev shell.
- `preflight`: runs the existing `gitleaks` and `treefmt` flake checks
(treefmt carries actionlint + zizmor with the repo's exact ignore
config) as an early fail-fast gate before any build/test work.
`test` and `build-native-packages` now `needs` both gates, so they are
skipped unless the gates pass.
tirith details:
- `--fail-on high` blocks on high/critical findings. tirith's `--ci`
exit code is 0 = clean, 1 = at/above threshold, 2 = findings below
threshold; the gate treats 0/2 as pass and 1 (or any other code) as a
block, and the scan exit code is passed via env to avoid template
injection.
- `*.snap` is excluded because terminal snapshot test fixtures
intentionally contain ANSI escapes that trip the `ansi_escapes` rule;
the rule stays active for real source files.
Heavy gate jobs run on blacksmith runners, consistent with the rest of
the nix-based CI jobs.
* 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 17911d6 commit cdda182
1 file changed
Lines changed: 136 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
24 | 155 | | |
25 | | - | |
| 156 | + | |
26 | 157 | | |
27 | 158 | | |
28 | 159 | | |
| |||
50 | 181 | | |
51 | 182 | | |
52 | 183 | | |
53 | | - | |
| 184 | + | |
54 | 185 | | |
55 | 186 | | |
56 | 187 | | |
| |||
394 | 525 | | |
395 | 526 | | |
396 | 527 | | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
397 | 531 | | |
398 | 532 | | |
399 | 533 | | |
| |||
0 commit comments