1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
155
156
157
158
159
160
161
162
163
164
165
166
167
# Security scanning for zakuro-ai/zc.
#
# Closes #44. Hardened per #99.
#
# Tiered for the runner budget (zakuro-ai CI policy 2026-10-06):
# T0 (PR into master/release): cargo-audit (required, fast) + gitleaks on
# the PR diff only.
# T2 (nightly, release/** via Build's security-full job, PRs based on
# release/**, PRs labelled ci:full, manual): everything below, incl.
# cargo-deny, gitleaks full history and trivy fs.
# No run on master push: Build gates deploy; the nightly covers the rest.
#
# Three lanes:
# - cargo-audit + cargo-deny — Rust advisory DB + licence/source policy.
# cargo-audit is a REQUIRED check: a new CVE
# in the dependency tree blocks merge. The
# cargo-deny sub-steps remain advisory.
# - gitleaks — secrets in history / working tree (advisory).
# - trivy fs — filesystem-level CVEs (catches Dockerfile
# base-image issues + lockfile vulns; advisory).
#
# To finish the rollout: add the `cargo-audit` job to branch-protection
# required checks (see the PR for the gh api command), then drop the
# remaining `continue-on-error` blocks lane-by-lane as each baseline is
# confirmed.
name: security
on:
pull_request:
types:
paths-ignore:
- "**.md"
- "docs/**"
- ".github/ISSUE_TEMPLATE/**"
schedule:
# Nightly 18:00 UTC full scan against the latest advisory DBs.
- cron: "0 18 * * *"
workflow_dispatch:
# Called by build.yml on release/** pushes so the release gate runs T2.
workflow_call:
concurrency:
group: security-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
env:
# T2 scope: anything that is not a plain PR into the default branch.
FULL_SCAN: ${{ github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'ci:full') || startsWith(github.base_ref, 'release/') }}
jobs:
runner:
uses: zakuro-ai/zakuro-infra/.github/workflows/pick-runner.yml@main
permissions:
secrets: inherit
if: >-
github.event_name != 'pull_request' || (
github.event.pull_request.draft == false &&
(github.event.action != 'edited' || github.event.changes.base != null) &&
(github.base_ref == github.event.repository.default_branch || startsWith(github.base_ref, 'release/')))
cargo-audit:
needs: runner
runs-on: ${{ needs.runner.outputs.runner }}
timeout-minutes: 10
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable
with:
toolchain: "stable"
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2
# Pull prebuilt cargo-audit / cargo-deny binaries instead of
# `cargo install --locked` (which compiled both from source and was
# ~8 min of this job's runtime). taiki-e/install-action fetches
# pinned release binaries in seconds.
- name: Install cargo-audit + cargo-deny
uses: taiki-e/install-action@9e1e5806d4a4822de933115878265be9aaa786d9 # v2
with:
tool: cargo-audit,cargo-deny
- name: cargo audit
run: cargo audit --ignore RUSTSEC-0000-0000
- name: cargo deny check advisories
if: env.FULL_SCAN == 'true'
run: cargo deny check advisories
continue-on-error: true
- name: cargo deny check bans + licenses + sources
if: env.FULL_SCAN == 'true'
run: cargo deny check bans licenses sources
continue-on-error: true
# Last step on purpose: a red cargo-audit cancels the rest of the run
# (in Build on release/**, the build job) instead of letting it finish on
# a commit that is already red. Not on the nightly, where the advisory
# gitleaks / trivy scans are independent findings worth keeping. Needs
# actions: write (the default token here; build.yml grants it when it
# calls this suite). The advisory jobs below never cancel anything.
- name: Cancel the rest of the run
if: failure() && github.event_name != 'schedule'
uses: ./.github/actions/cancel-run-on-failure
gitleaks:
needs: runner
runs-on: ${{ needs.runner.outputs.runner }}
timeout-minutes: 10
continue-on-error: true
permissions:
contents: read
security-events: write
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0
- name: gitleaks
uses: gitleaks/gitleaks-action@e0c47f4f8be36e29cdc102c57e68cb5cbf0e8d1e # v3
with:
# PR: only the commits the PR adds. T2: full history.
args: >-
detect --source . --report-format sarif --report-path gitleaks.sarif
${{ github.event_name == 'pull_request' && format('--log-opts={0}..{1}', github.event.pull_request.base.sha, github.event.pull_request.head.sha) || '' }}
continue-on-error: true
- name: Upload gitleaks SARIF
if: always()
uses: github/codeql-action/upload-sarif@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4
with:
sarif_file: gitleaks.sarif
category: gitleaks
continue-on-error: true
trivy-fs:
needs: runner
# T2 only (nightly / release / ci:full).
if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'ci:full') || startsWith(github.base_ref, 'release/')
runs-on: ${{ needs.runner.outputs.runner }}
timeout-minutes: 10
continue-on-error: true
permissions:
contents: read
security-events: write
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Trivy filesystem scan
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
with:
scan-type: fs
scan-ref: .
format: sarif
output: trivy.sarif
severity: CRITICAL,HIGH
ignore-unfixed: true
- name: Upload Trivy SARIF
if: always()
uses: github/codeql-action/upload-sarif@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4
with:
sarif_file: trivy.sarif
category: trivy-fs
continue-on-error: true