Skip to content

ci(security): add OSV-Scanner gate for source-repo CVE detection - #118

Merged
vikrantpuppala merged 4 commits into
mainfrom
ci/security-scan-osv
Jun 3, 2026
Merged

vikrantpuppala merged 4 commits into
mainfrom
ci/security-scan-osv

Conversation

@gopalldb

@gopalldb gopalldb commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a PR + weekly cron security-scan workflow to catch CVEs in
dependencies at PR time, before they land on main. Modeled on
databricks/databricks-jdbc/.github/workflows/securityScan.yml.

What this does

  • On PRs: fails the check if any unsuppressed CVSS >= 7 vulnerability
    exists in the dep graph (across root + napi/ + pyo3/ workspaces).
    MEDIUM/LOW findings show in the step summary but don't block merges.
  • Weekly cron (Sundays UTC): reports ALL findings via HTML email and
    fails the run. Read by humans, not enforced — surfaces emerging risk.
  • workflow_dispatch: same as cron.

Scanner is OSV-Scanner v2.3.8, fed CycloneDX SBOMs from cargo cyclonedx
over the three workspaces.

Why this on top of cargo-deny

We already run cargo deny check in license-check.yml, which catches
RustSec advisories. OSV federates GHSA-Rust advisories that aren't
yet mirrored to RustSec. JDBC PR #1460 motivates this concretely:
CVE-2025-66566 (lz4) and CVE-2026-5598 (bouncycastle) were GHSA-only,
invisible to NVD/OWASP, caught by OSV.

Layer relative to the release pipeline

This is the source-repo CVE gate (Layer 2). Layer 1 is the
databricks/gh-action-scan step that runs inside
databricks/secure-public-registry-releases-eng at release time — that
remains the publish gate. Defense in depth:

  • Layer 1: catches CVEs in the packaged artifact right before
    publish.
  • Layer 2 (this PR): catches the same class of CVE at PR time, so
    release day isn't a fix-or-ship decision under time pressure.

Suppressions

osv-scanner.toml at repo root carries [[IgnoredVulns]] entries with
required justification comments. Empty on landing; entries added when a
real CVE needs documented suppression (e.g. "kernel does not expose
the affected entrypoint").

Fork PR behaviour

Fork PRs from external contributors don't have OIDC tokens, so the JFrog
proxy step is conditionally skipped. cargo falls through to public
crates.io and the scan still runs. No secrets are exposed to fork PR
runners.

Email

SMTP credentials are optional repo secrets (SMTP_USERNAME,
SMTP_PASSWORD, EMAIL_RECIPIENTS). If unset, the email step fails
silently but the scheduled run still fails with the finding count
in the job summary.

Required check (recommendation)

Once we see one clean run, add Security Scan to the protect-main
ruleset's required-status-checks list so it becomes a merge gate.
Doing this in a follow-up so this PR can land without changing
ruleset state.

Test plan

  • Workflow runs on this PR; check shows green (no CVSS>=7 findings).
  • Manual workflow_dispatch run from main after merge succeeds.
  • Follow-up: add Security Scan to required checks in protect-main.

This pull request and its description were written by Isaac.

Adds a PR + weekly cron security-scan workflow modeled on
databricks/databricks-jdbc/.github/workflows/securityScan.yml. Uses
OSV-Scanner v2.3.8 (federates GHSA, NVD, RustSec, PyPA, Go vuln DB)
against CycloneDX SBOMs generated from the three workspaces:
root (databricks-sql-kernel crate), napi/, and pyo3/.

Why OSV in addition to cargo-deny (already in license-check.yml):
OSV's GHSA-Rust source includes advisories that aren't yet mirrored
to RustSec (cargo-deny's source). jdbc PR #1460 documents real CVEs
(CVE-2025-66566 in lz4, CVE-2026-5598 in bouncycastle) that OSV
caught and OWASP / NVD missed; the same class of gap applies here.

Trigger thresholds (mirroring jdbc):
- PR: fails on CVSS >= 7. MEDIUM/LOW findings appear in the step
  summary but don't block merges.
- Weekly cron: reports ALL findings, sends HTML email, fails the run.
- workflow_dispatch: same as cron.

Suppressions live in osv-scanner.toml at repo root. Each
[[IgnoredVulns]] entry requires a justification comment per the
template's instructions.

Fork PRs work without secrets: the JFrog OIDC step is conditionally
skipped on fork PRs, falling through to public crates.io.

Email + SMTP credentials are optional repo secrets (SMTP_USERNAME,
SMTP_PASSWORD, EMAIL_RECIPIENTS) — if unset, the email step fails
silently but the scheduled run still fails with the finding count.

Complements (does not replace) the gh-action-scan step that will run
at release time inside databricks/secure-public-registry-releases-eng.
Defense in depth: Layer 1 catches CVEs at publish time, Layer 2
(this PR) catches them at merge time before they accumulate on main.

Co-authored-by: Isaac
Signed-off-by: Gopal Lal <gopal.lal@databricks.com>
@gopalldb
gopalldb requested a review from a team as a code owner June 3, 2026 03:56
Addresses PR #118 review:

P0 fixes:

1. Textual-severity / missing-CVSS findings bypassed the CVSS>=7
   gate. `jq (.max_severity // "0")` only fires on null; "" (common
   for GHSA-Rust advisories with only textual severity) flowed
   through `tonumber? // 0` and produced 0 — the exact class of CVE
   this workflow is meant to catch silently passed.

   Switched both PR and cron policies to fail-on-any unsuppressed
   finding. Triage now happens via `[[IgnoredVulns]]` entries in
   `osv-scanner.toml` (with required justification), not via
   threshold tuning that lets unscored findings slip through.

   Display still surfaces the numeric severity when present; an
   "unscored" label appears otherwise so reviewers can see what
   they're triaging.

2. `cargo cyclonedx --override-filename` caused same-name SBOM
   collisions across workspace members. Root workspace is
   `[".", "pyo3"]` — cargo-cyclonedx writes one SBOM per member
   with the same name when `--override-filename` is set, so the
   second write clobbered the first. Any dep that lived in only
   one member silently dropped out of scope.

   Dropped `--override-filename`. Let cyclonedx pick per-package
   names (databricks-sql-kernel, databricks-sql-kernel-pyo3,
   databricks-sql-kernel-napi). Two invocations (root + napi/)
   produce three SBOMs in known paths; a hard-stop check refuses
   to proceed with < 3 SBOMs.

P1 fixes:

3. `|| true` swallowed all osv-scanner exit codes, including the
   "no extractor matched" class that writes `{"results": []}` and
   exits non-zero. Capture `RC=$?`; tolerate only 0 (no vulns) and
   1 (vulns found); fail on anything else.

4. Documented the fork-PR coverage gap — protected runners don't
   pick up fork PRs per org policy; required-status-check rule
   blocks merge until the same SHA is pushed to an internal branch.
   Revisit if external contributors become common.

5. Documented the "fork deletes the workflow file" attack and the
   mitigation (Security Scan added to `protect-main` as a required
   status check; missing-checks are `pending`, not `failure`).

6. Fixed the misleading `set -uo pipefail` comment — GHA's default
   bash already sets `-eo pipefail`, this only adds `-u`.

P2 fixes:

7. Severity normalisation moved into a single jq pipeline; emits
   both numeric `severity` (for sorting) and human `display`
   ("unscored" / "7.5").

8. Removed "PR-blocking" copy from the cron email (no PR there).

9. `dawidd6/action-send-mail@4226df7d` resolves to v3.11.0
   (not v3.0.0). Trailing comment updated.

10. Reports artifact `retention-days: 30` — SBOMs sit around long
    enough to triage without bloating the 90-day default.

11. `--recursive=false` was a no-op on file inputs. Switched to
    explicit `--sbom=/path` flags, three of them, for clarity.

12. Header docstring acknowledges the pyo3 SBOM is Rust-only —
    doesn't include maturin/uv-resolved Python deps. Layer 1
    (gh-action-scan on the assembled wheel) covers the rest.

Local verification:
- `cargo cyclonedx` from repo root produces
  `databricks-sql-kernel.cdx.json` + `pyo3/databricks-sql-kernel-pyo3.cdx.json`
- `( cd napi && cargo cyclonedx )` adds
  `napi/databricks-sql-kernel-napi.cdx.json`
- All three filenames are distinct; --sbom flag paths match.

Co-authored-by: Isaac
Signed-off-by: Gopal Lal <gopal.lal@databricks.com>
Comment thread .github/workflows/securityScan.yml Outdated

echo "OSV: $TOTAL_FINDINGS unsuppressed finding(s)"
if [ "$TOTAL_FINDINGS" -gt 0 ]; then
echo "$ALL_FINDINGS" | jq -r '.[] | " [\(.display)] \(.pkg) \(.ids | join(\", \"))"'

@vikrantpuppala vikrantpuppala Jun 3, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two jq programs sit inside single-quoted strings in plain bash run: | blocks (not GHA ${{ }} expressions), but use "-style escaping that only belongs in an Actions expression context:

  # line 222 (Collect findings) and line 231 (Fail on findings (PR))
  jq -r '.[] | "  [\(.display)] \(.pkg)  \(.ids | join(\", \"))"' ...

I reproduced it — jq rejects this as a syntax error: jq: error: syntax error, unexpected INVALID_CHARACTER (Unix shell quoting issues?) The backslashes reach jq literally. The fix is just join(", ") (no backslashes), exactly as already used correctly on line 216 and line 264.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed and fixed in a635b1e. Verified locally:

$ echo "[{\"display\":\"7.5\",\"pkg\":\"foo@1.0\",\"ids\":[\"GHSA-1\",\"CVE-2\"]}]" | jq -r '.[] | "  [\(.display)] \(.pkg)  \(.ids | join(", "))"'
  [7.5] foo@1.0  GHSA-1, CVE-2

Both occurrences (Collect findings + Fail on findings (PR)) switched to plain ", ", matching the working join(",") on line 216 / the cron HTML line 264. Without this fix, every PR run that hit a finding would have rendered as jq: compile error before the exit 1 gate — the gate still would have fired, but the user-facing output was broken.

Comment thread .github/workflows/securityScan.yml Outdated
set -uo pipefail
echo "::error::${{ steps.findings.outputs.total_findings }} unsuppressed OSV finding(s):"
echo ""
jq -r '.[] | " [\(.display)] \(.pkg) \(.ids | join(\", \"))"' /tmp/all-findings.json

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two jq programs sit inside single-quoted strings in plain bash run: | blocks (not GHA ${{ }} expressions), but use "-style escaping that only belongs in an Actions expression context:

  # line 222 (Collect findings) and line 231 (Fail on findings (PR))
  jq -r '.[] | "  [\(.display)] \(.pkg)  \(.ids | join(\", \"))"' ...

I reproduced it — jq rejects this as a syntax error: jq: error: syntax error, unexpected INVALID_CHARACTER (Unix shell quoting issues?) The backslashes reach jq literally. The fix is just join(", ") (no backslashes), exactly as already used correctly on line 216 and line 264.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed and fixed in a635b1e. Verified locally:

$ echo "[{\"display\":\"7.5\",\"pkg\":\"foo@1.0\",\"ids\":[\"GHSA-1\",\"CVE-2\"]}]" | jq -r '.[] | "  [\(.display)] \(.pkg)  \(.ids | join(", "))"'
  [7.5] foo@1.0  GHSA-1, CVE-2

Both occurrences (Collect findings + Fail on findings (PR)) switched to plain ", ", matching the working join(",") on line 216 / the cron HTML line 264. Without this fix, every PR run that hit a finding would have rendered as jq: compile error before the exit 1 gate — the gate still would have fired, but the user-facing output was broken.

…eset gate

Addresses PR #118 review:

P1:

1. Ruleset updated separately (gh api PUT) to add `Security Scan` to
   protect-main's required_status_checks. This closes the fork-PR
   coverage gap (protected runners skip fork PRs; required-status-
   checks treats `missing` as `pending` and would have let the merge
   queue through). The required-list now has three entries:
     - Unit + doc tests
     - Kernel Integration Tests
     - Security Scan

   Done via:
     gh api repos/databricks/databricks-sql-kernel/rulesets/16552595
     -> PUT with Security Scan appended.

P2:

2. SBOM glob narrowed from `**/*.cdx.json` (globstar walk of the
   whole tree) to explicit `./*.cdx.json pyo3/*.cdx.json` plus
   `napi/*.cdx.json`. A stray .cdx.json under target/ or in a test
   fixture can no longer be silently fed to the scanner.

3. Added a schema sanity check on /tmp/osv-out.json before the
   classifier: `jq -e '.results | type == "array"'`. If OSV-Scanner
   ever ships a different shape (or the file is truncated), the
   step fails loudly instead of the classifier silently seeing
   zero findings.

4. HTML email now styles unscored rows with `tr.unscored` (same red
   as `tr.high`). Unscored findings are gate-blocking under the
   fail-on-any policy precisely because textual-severity advisories
   often describe HIGH-impact issues with no numeric CVSS — without
   this, the lack of a number was rendering as a plain (unstyled)
   row that looked low-risk.

5. Inline comment added to the `Collect findings`, `Fail on findings
   (PR)`, and `Compose email body` steps explaining why `set -e` is
   intentionally absent: each step ends with an unconditional
   `exit 1` (or relies on the next step's `if:` gate), and `set -e`
   would let a jq-rendering failure silently abort the step *before*
   writing `total_findings=...` — which would skip the downstream
   fail-on-findings gate and weaken the security posture. Future
   maintainers shouldn't "tighten" this to set -euo pipefail.

6. osv-scanner.toml comments a TODO for an expiry-lint step that
   enforces the `# Expiry: <date>` convention. File is empty today
   so it's hypothetical; once we have real suppressions to enforce
   against, wire it up in securityScan.yml.

Inline review comment (Vikrant) — REAL BUG, also fixed:

  jq inside single-quoted bash strings was using `\", \"` escaping
  that only belongs in GHA `${{ }}` expressions. jq rejects this as
  a syntax error (verified: `jq: error: syntax error, unexpected
  INVALID_CHARACTER`). Both occurrences (Collect findings line 222,
  Fail on findings (PR) line 231) switched to plain `", "` matching
  the working call on line 216.

  Without this fix, every PR run that hit a finding would have
  silently failed the rendering step before reaching the gate — the
  exit 1 would still fire, but the user would see "jq: compile
  error" instead of the formatted list of findings. Now matches the
  shape that already worked in the step-summary write.

Local verification:
- `jq -r '.[] | "[\(.display)] \(.pkg)  \(.ids | join(", "))"'` -> works
- `jq -e '.results | type == "array"'` -> exits 0 on valid OSV, 1 on bad
- Workflow YAML still parses.

Co-authored-by: Isaac
Signed-off-by: Gopal Lal <gopal.lal@databricks.com>
@gopalldb
gopalldb added this pull request to the merge queue Jun 3, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Jun 3, 2026
@vikrantpuppala
vikrantpuppala added this pull request to the merge queue Jun 3, 2026
@vikrantpuppala

Copy link
Copy Markdown
Collaborator

The scan as written won't actually gate the merge queue, even after Security Scan is added to protect-main's required checks.

protect-main uses a merge queue, and GitHub re-evaluates required status checks against the merge-group ref, not the PR head. A required check whose workflow has no merge_group trigger never produces a check-run for the queue entry — so the entry either hangs until check_response_timeout_minutes expires, or (depending on queue config) the speculative merge commit lands on main without ever being scanned. Either way the actual commit that hits main isn't scanned.

This repo already documents the trap in pr-checks.yml:

GitHub re-evaluates required checks against the merge-group ref, so without this trigger the queue entry hangs until check_response_timeout_minutes expires.

That's why both pr-checks.yml and trigger-integration-tests.yml carry a merge_group trigger. securityScan.yml only triggers on pull_request / schedule / workflow_dispatch, so following the PR description's plan ("add Security Scan to required checks") would create exactly this gap.

Two changes needed before this becomes a required check:

1. Add the merge_group trigger:

on:
  pull_request:
    branches: [main]
  merge_group:
  schedule:
    - cron: '0 0 * * 0'
  workflow_dispatch:

2. Widen the Fail on findings (PR) gate — it's currently github.event_name == 'pull_request', so it would run but never block on a merge-group event:

if: (github.event_name == 'pull_request' || github.event_name == 'merge_group') && steps.findings.outputs.total_findings != '0'

Without #2, the scan runs on the queued ref but the fail step is skipped, so it fail-opens in the queue. With both, the gate actually evaluates against the commit that lands on main.

@vikrantpuppala
vikrantpuppala removed this pull request from the merge queue due to a manual request Jun 3, 2026
The Send Email step in securityScan.yml depends on SMTP_USERNAME,
SMTP_PASSWORD, and EMAIL_RECIPIENTS secrets that haven't been
provisioned. Comment out the step rather than letting it 404 on
missing secrets when a cron run lands on a finding.

The HTML report is still composed and uploaded as a run artifact
(`security-scan-reports`), so triagers can pull it after a
scheduled-run failure without the email.

Fail-on-findings step's user message updated to point at the
artifact ("Download the security-scan-reports artifact for the HTML
report") instead of the no-longer-sent email.

Re-enable when SMTP creds are wired up.

Co-authored-by: Isaac
Signed-off-by: Gopal Lal <gopal.lal@databricks.com>
@vikrantpuppala
vikrantpuppala enabled auto-merge June 3, 2026 17:01
@vikrantpuppala
vikrantpuppala added this pull request to the merge queue Jun 3, 2026
Merged via the queue into main with commit 101aa46 Jun 3, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants