Repository navigation
190 lines (182 loc) · 8.63 KB
/
Copy pathsecurity.yml
File metadata and controls
190 lines (182 loc) · 8.63 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
name: Security
# Advisories are published on someone else's schedule, so this runs on one of
# its own as well as on every change. A dependency that was clean on Monday is
# not necessarily clean on Friday, and nothing about this repository has to
# change for that to happen.
# No push trigger for `dev` — same reasoning as ci.yml: dev travels through
# pull requests, and a push twin under required checks poisons the gate.
on:
pull_request:
schedule:
- cron: "17 6 * * 1"
workflow_dispatch:
# A push during a run makes the older run's answer obsolete.
concurrency:
group: security-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
policy:
name: the security policy names the current line
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
# The stale-table drift this org has already lived through once:
# SECURITY.md said 0.0.x while the workspace shipped 0.7. The table's
# top row must name the line that is actually published.
- run: |
version=$(grep -m1 '^version = ' dynamic-config-python/Cargo.toml | cut -d'"' -f2)
line="${version%.*}.x"
if ! grep -qF "| ${line}" SECURITY.md; then
echo "::error file=SECURITY.md::the supported-versions table does not name ${line} (workspace is ${version})"
exit 1
fi
echo "SECURITY.md names ${line} — current"
deny:
name: advisories, licences, sources
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: EmbarkStudios/cargo-deny-action@3c6349835b2b7b196a839186cb8b78e02f7b5f25 # v2
with:
# The full `check` — advisories, licences, sources *and* bans — so a
# duplicate-dependency policy in deny.toml is enforced somewhere
# rather than assumed to be enforced somewhere else.
command: check
# An exception that no longer matches anything is a decision about
# a dependency that left, still being carried as though it were
# current — and the reason beside it is then documentation of
# something untrue. This is the only way that drift is visible
# without somebody going and looking, so it fails the job.
arguments: --all-features
# After the subcommand, not before it: the action puts
# `arguments` ahead of `check`, where a lint level is not a
# flag cargo-deny takes — it exits on the usage message
# rather than on anything it found.
command-arguments: -D advisory-not-detected
unsafe:
name: no unsafe code
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: dtolnay/rust-toolchain@6c977a6ca4077a0ceb28ffbe03f59d46e9ac8772 # master
with:
toolchain: stable
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
# Every crate here declares `#![forbid(unsafe_code)]`, which the compiler
# enforces. This proves the declaration is still there rather than
# trusting that nobody removed it in a hurry.
- run: |
# Neither crate can say `#![forbid(unsafe_code)]`: PyO3's
# `#[pyclass]` and `#[pymethods]` expand to `unsafe impl`, which
# is the binding machinery rather than this repository's code.
# What *is* checkable is that the hand-written half has none, and
# that is what this looks at.
if grep -rn 'unsafe' dynamic-config-python/src/ dynamic-config-python-remote/src/; then
echo "::error::hand-written unsafe in a Python extension"
exit 1
fi
osv:
name: advisories, every ecosystem
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
with:
python-version: "3.13"
# One scanner over every ecosystem rather than one per ecosystem, and
# deliberately *not* a second copy of cargo-deny: OSV aggregates RustSec,
# PyPA and GitHub advisories, so it carries entries RustSec does not and
# the two disagreeing is information rather than noise.
#
# What it closes is a real gap: the wheels ship Pydantic,
# pydantic-settings and msgspec as runtime dependencies of a published
# artefact, and cargo-deny has never heard of any of them.
#
# The binary, pinned and checksummed like every other download here.
# An action would be one more third party in a job about third parties.
- name: install osv-scanner
run: |
curl -sSL -o osv-scanner \
https://github.com/google/osv-scanner/releases/download/v2.5.0/osv-scanner_linux_amd64
echo "edcfc41d257db36148f065055655fe3fcfc434b0b423ea67468a84c207524e0c osv-scanner" \
| sha256sum -c -
chmod +x osv-scanner
# Neither wheel commits a lockfile, and neither should — a library that
# pinned its dependencies would pin its users'. What is auditable is
# what somebody installing today actually resolves, so it is resolved
# here and the frozen result is what gets scanned.
- name: resolve what the wheels install
run: python scripts/resolve-python-audit.py /tmp/audit-venv /tmp/python-requirements.txt
# `osv-scanner.toml` at the root carries the exemptions, each with the
# reason and what would expire it. It is a second list beside
# deny.toml's on purpose: cargo-deny refuses an ignore that matches
# nothing it raises, so an advisory only OSV reports cannot be answered
# there.
# `|| true`, and the classification is the next step's: the scanner
# exits non-zero for *any* finding, and an unmaintained crate with no
# published fix is not something a pull request here can answer.
# Failing on those is how a gate becomes one people learn to ignore.
- name: scan
run: |
./osv-scanner scan source \
--lockfile Cargo.lock \
--lockfile "requirements.txt:/tmp/python-requirements.txt" \
--format json --output osv.json || true
# Fails on anything with a fix available, warns on anything without
# one, and writes both halves into the job summary either way.
- name: report
run: python scripts/audit-report.py osv.json "$GITHUB_STEP_SUMMARY"
supply-chain:
name: dependency review
runs-on: ubuntu-latest
timeout-minutes: 10
if: github.event_name == 'pull_request'
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
# Flags a pull request that adds a dependency with a known advisory or a
# licence outside the allow-list, at the point where changing course is
# still cheap.
- uses: actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294 # v5
with:
fail-on-severity: low
comment-summary-in-pr: on-failure
# The one advisory this repository has already answered, and the
# answer is in `osv-scanner.toml` at length: `lru 0.12.5` reaches
# the graph through `aws-sdk-s3`'s identity cache, which pins
# `^0.12.2` — the fix is 0.16.3 and no version of this workspace
# can reach it until the SDK moves. Neither vulnerable path
# occurs in the SDK's usage: it caches credentials by key and
# never iterates mutably.
#
# This action reads no configuration file of its own, so the
# decision is repeated here rather than left to disagree with the
# scanner's.
allow-ghsas: GHSA-rhfx-m35p-ff5j
# The one status branch protection requires from this workflow — same
# reasoning as CI's gate. `supply-chain` IS in the needs even though it only
# exists on pull requests: the gate's own check tolerates `skipped`, so a
# plain push passes, while a PR with a failing dependency review is blocked
# — which is the whole point of running it.
security-ok:
name: Security is green
needs: [policy, deny, unsafe, osv, supply-chain]
if: always()
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: every job this gate needs has succeeded
run: |
results='${{ toJSON(needs.*.result) }}'
echo "$results"
case "$results" in
*failure*|*cancelled*) exit 1 ;;
esac