Repository navigation
329 lines (301 loc) · 14.1 KB
/
Copy pathsecurityScan.yml
File metadata and controls
329 lines (301 loc) · 14.1 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
name: Security Scan
# Source-repo CVE gate. Lives in `databricks/databricks-sql-kernel`'s
# `.github/workflows/`. Ported from databricks-jdbc/securityScan.yml,
# then hardened in response to PR #118 review.
#
# Two modes — fail-closed on ANY unsuppressed finding on both paths.
# Triage by adding an [[IgnoredVulns]] entry to osv-scanner.toml with
# a justification, NOT by tweaking severity thresholds here:
#
# - pull_request to main: fail the job on any unsuppressed finding.
# Justification: textual-severity findings (max_severity == ""
# or non-numeric strings — common for GHSA-Rust advisories not yet
# scored against CVSS) silently bypassed a CVSS-numeric gate and
# defeated the exact class of CVE this workflow is meant to catch.
#
# - cron (weekly): same fail-on-any policy, plus an HTML email so
# emerging findings are visible to humans, not just buried in CI.
#
# - workflow_dispatch: behaves like the cron run.
#
# Scanner: OSV-Scanner v2.3.8 (purl-based via OSV.dev; federates
# GHSA, NVD, RustSec, PyPA, Go vuln DB). Reads CycloneDX SBOMs
# produced by `cargo cyclonedx` over the repository's four standalone
# workspace views:
#
# 1. Kernel root `Cargo.toml` — emits one SBOM for `databricks-sql-kernel`.
# 2. adbc/ standalone workspace — emits one SBOM for `databricks-adbc`.
# 3. pyo3/ standalone workspace — emits one SBOM for
# `databricks-sql-kernel-pyo3` (built with `tls-rustls`).
# 4. napi/ standalone workspace — emits one SBOM for
# `databricks-sql-kernel-napi` (also `tls-rustls`).
#
# The bindings are deliberately NOT members of the kernel's root
# workspace because their kernel-dep features (`tls-rustls`) conflict
# with the kernel's default (`tls-native`); Cargo would unify the
# feature set across workspace members and trip the mutual-exclusion
# `compile_error!` in `src/lib.rs`. See the workspace comment in
# each Cargo.toml.
#
# We deliberately do NOT pass --override-filename, because that
# caused a same-name collision back when the root workspace had
# multiple members (one SBOM per member written to the same path,
# last-writer wins). Letting cyclonedx pick per-package names +
# globbing keeps every workspace in scope as the workspace shape
# evolves.
#
# Coverage caveat: the pyo3 SBOM is Rust-only — it does NOT include
# Python-side runtime deps (pyarrow, etc.) that maturin resolves at
# wheel-install time on the consumer. Layer 1 (gh-action-scan at
# release time) covers the assembled wheel.
#
# Fork PRs use the unauthenticated Databricks-filtered package proxy and receive
# no OIDC or repository secrets. Repository settings may still require a
# maintainer to approve a first-time contributor's workflow run.
on:
pull_request:
branches: [main]
schedule:
- cron: '0 0 * * 0' # Every Sunday at midnight UTC
workflow_dispatch:
concurrency:
# Coalesce only PR activity. Scheduled and manual scans remain
# distinct runs so one audit cannot cancel another.
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
defaults:
run:
shell: bash
jobs:
security-scan:
name: Security Scan
# Mitigation for the "fork deletes securityScan.yml" attack:
# protect-main must include `Security Scan` as a required status
# check (follow-up). GitHub treats a missing check as `pending`,
# not `failure`, which would silently fail-open without this gate.
runs-on:
group: databricks-protected-runner-group
labels: linux-ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
# Use the same filtered, unauthenticated proxy for internal and fork PRs.
# The job executes contributor-controlled Cargo build scripts, so it must
# not receive an OIDC mint permission.
- name: Set up public package proxy
uses: ./.github/actions/setup-public-package-proxies
with:
cargo: "true"
- uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0
- name: Install cargo-cyclonedx
run: cargo install cargo-cyclonedx --version 0.5.7 --locked
# Four cyclonedx invocations cover all four published artifacts:
#
# - From repo root: writes databricks-sql-kernel.cdx.json.
#
# - From adbc/: writes databricks-adbc.cdx.json.
#
# - From pyo3/: standalone workspace, writes one SBOM
# (databricks-sql-kernel-pyo3.cdx.json).
#
# - From napi/: standalone workspace, writes one SBOM
# (databricks-sql-kernel-napi.cdx.json).
#
# We let cyclonedx pick per-package names by NOT passing
# --override-filename — the original PR's --override-filename
# caused same-name collisions (last-writer wins) that silently
# dropped one workspace-member SBOM from scope.
- name: Generate SBOMs
run: |
set -euo pipefail
mkdir -p /tmp/sboms
# The kernel, ADBC, pyo3, and napi standalone workspaces cover all
# Rust artifacts (see the workspace comment in each Cargo.toml —
# pyo3 and napi need
# `tls-rustls` while the kernel default is `tls-native`,
# and Cargo feature unification across a shared workspace
# would trip the mutual-exclusion `compile_error!` in
# `src/lib.rs`). So `cargo cyclonedx` has to be invoked
# once per workspace.
#
# Pull SBOMs in by EXPLICIT path rather than a
# `**/*.cdx.json` globstar walk — the walk would silently
# pick up a stray .cdx.json under target/ or a test
# fixture if one ever lands.
shopt -s nullglob
cargo cyclonedx --format json
for f in ./*.cdx.json; do
cp "$f" "/tmp/sboms/$(basename "$f")"
done
( cd adbc && cargo cyclonedx --format json )
for f in adbc/*.cdx.json; do
cp "$f" "/tmp/sboms/$(basename "$f")"
done
( cd pyo3 && cargo cyclonedx --format json )
for f in pyo3/*.cdx.json; do
cp "$f" "/tmp/sboms/$(basename "$f")"
done
( cd napi && cargo cyclonedx --format json )
for f in napi/*.cdx.json; do
cp "$f" "/tmp/sboms/$(basename "$f")"
done
echo "SBOMs:"
ls -lh /tmp/sboms/
# Hard-stop if we lost coverage by accident.
test "$(ls /tmp/sboms/*.cdx.json 2>/dev/null | wc -l)" -ge 4 || {
echo "::error::expected >=4 SBOMs (kernel + ADBC + pyo3 + napi), got $(ls /tmp/sboms/*.cdx.json 2>/dev/null | wc -l)"
exit 1
}
- name: Install osv-scanner
run: |
set -euo pipefail
curl -fsSL -o /tmp/osv-scanner \
https://github.com/google/osv-scanner/releases/download/v2.3.8/osv-scanner_linux_amd64
chmod +x /tmp/osv-scanner
/tmp/osv-scanner --version
# OSV-Scanner exit codes (per its docs):
# 0 = no vulns found
# 1 = vulns found
# 2+ = real errors (no extractor matched / corrupt input / etc.)
#
# The original `|| true` swallowed everything, including the
# "no extractor matched" class that writes `{"results": []}` and
# exits non-zero. We capture RC and tolerate only 0 and 1; any
# other exit fails the step. The findings-collection step below
# is the gate on what's in the JSON.
- name: Run OSV-Scanner
run: |
# GHA's default shell is `bash --noprofile --norc -eo pipefail
# {0}`; add `-u`.
set -uo pipefail
RC=0
/tmp/osv-scanner scan source \
--config=osv-scanner.toml \
--format=json \
--output-file=/tmp/osv-out.json \
--sbom=/tmp/sboms/databricks-sql-kernel.cdx.json \
--sbom=/tmp/sboms/databricks-adbc.cdx.json \
--sbom=/tmp/sboms/databricks-sql-kernel-pyo3.cdx.json \
--sbom=/tmp/sboms/databricks-sql-kernel-napi.cdx.json || RC=$?
if [[ "$RC" -gt 1 ]]; then
echo "::error::osv-scanner exited with $RC (real error, not 'vulns found')."
exit "$RC"
fi
if [ ! -s /tmp/osv-out.json ]; then
echo "::error::OSV-Scanner did not produce an output file."
exit 1
fi
- name: Collect findings
# Intentionally NOT `set -e`: each step here ends with an
# unconditional `exit 1` (or the next step's `if:` gate on
# total_findings), and `set -e` would cause a jq-rendering
# failure here to silently abort the step *before* writing
# `total_findings=...` to GITHUB_OUTPUT — which would skip
# the downstream fail-on-findings gate and weaken the
# security posture. Do not "tighten" this to set -euo pipefail.
id: findings
run: |
set -uo pipefail
# Schema sanity check. OSV-Scanner's JSON shape is `{"results":
# [...]}`. If a future version ever changes that (or the file
# is truncated), fail loudly here rather than letting the
# classifier silently see zero findings.
if ! jq -e '.results | type == "array"' /tmp/osv-out.json >/dev/null; then
echo "::error::OSV output missing .results array — schema drift?"
head -c 4096 /tmp/osv-out.json
exit 1
fi
# Normalise severity into a single jq pipeline. OSV's
# max_severity is one of:
# - a numeric string ("7.5")
# - empty string "" (textual-only advisory)
# - missing entirely
# We classify any non-numeric / missing / 0 as
# "unscored" — these STILL block PRs under the fail-on-any
# policy (they may well be HIGH/CRITICAL with only textual
# severity). The numeric value (or "unscored") is what we
# display.
ALL_FINDINGS=$(jq -c '[
.results[].packages[]? |
.package as $pkg |
.groups[]? |
( .max_severity as $raw
| ($raw | tostring | tonumber? // null) as $num
| {
pkg: ($pkg.name + "@" + $pkg.version),
ids: .ids,
severity: ($num // 0),
display: (if $num != null then ($num | tostring) else "unscored" end)
}
)
] | sort_by(- .severity)' /tmp/osv-out.json)
TOTAL_FINDINGS=$(echo "$ALL_FINDINGS" | jq 'length')
echo "$ALL_FINDINGS" > /tmp/all-findings.json
echo "total_findings=$TOTAL_FINDINGS" >> "$GITHUB_OUTPUT"
{
echo "## OSV-Scanner Findings"
echo ""
echo "- Total unsuppressed findings: \`$TOTAL_FINDINGS\`"
echo ""
echo "Triage policy: any unsuppressed finding fails the run."
echo "Document accepted risks via \`[[IgnoredVulns]]\` entries in \`osv-scanner.toml\`."
if [ "$TOTAL_FINDINGS" -gt 0 ]; then
echo ""
echo "| Severity | Package | IDs |"
echo "|---|---|---|"
echo "$ALL_FINDINGS" | jq -r '.[] | "| \(.display) | \(.pkg) | \(.ids | join(",")) |"'
fi
} >> "$GITHUB_STEP_SUMMARY"
echo "OSV: $TOTAL_FINDINGS unsuppressed finding(s)"
if [ "$TOTAL_FINDINGS" -gt 0 ]; then
# NOTE: jq escapes inside a single-quoted bash string are
# LITERAL — `\", \"` reaches jq verbatim and jq rejects it
# as a syntax error. Use plain `", "`, same as line 216.
echo "$ALL_FINDINGS" | jq -r '.[] | " [\(.display)] \(.pkg) \(.ids | join(", "))"'
fi
- name: Fail on findings (PR)
# See "Collect findings" above for why this step intentionally
# omits `-e`. The unconditional `exit 1` below is the gate.
if: github.event_name == 'pull_request' && steps.findings.outputs.total_findings != '0'
run: |
set -uo pipefail
echo "::error::${{ steps.findings.outputs.total_findings }} unsuppressed OSV finding(s):"
echo ""
# See Collect findings note: plain `", "` is correct; the
# prior `\", \"` form was jq syntax error.
jq -r '.[] | " [\(.display)] \(.pkg) \(.ids | join(", "))"' /tmp/all-findings.json
echo ""
echo "Fix by either:"
echo " 1. Bumping the affected dependency to a patched version, or"
echo " 2. Adding a documented [[IgnoredVulns]] entry to osv-scanner.toml"
echo " with a clear justification for why the CVE doesn't apply."
echo ""
echo "Full step summary: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
exit 1
# Notification is intentionally NOT done here (no email, no HTML
# report). A separate cross-repo action collates the uploaded raw
# osv-out.json / all-findings.json artifacts across all driver repos
# and sends a single digest -- parity with the Go / Node / Python /
# JDBC gates. This job's job is to (a) fail so the scheduled run is
# red when anything is found, and (b) upload the machine-readable
# findings for the collator to consume.
- name: Fail on findings (scheduled/manual)
if: (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && steps.findings.outputs.total_findings != '0'
run: |
echo "::error::${{ steps.findings.outputs.total_findings }} unsuppressed OSV finding(s) on main. Download the security-scan-reports artifact for the raw findings."
exit 1
- name: Upload reports
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: security-scan-reports
path: |
/tmp/osv-out.json
/tmp/all-findings.json
/tmp/sboms/
if-no-files-found: ignore
# SBOMs/reports stick around long enough to triage a finding
# without being part of the 90-day default retention.
retention-days: 30