From dad34e71103e1fab26f3c405172ab9772532db46 Mon Sep 17 00:00:00 2001 From: Gopal Lal Date: Wed, 3 Jun 2026 09:26:11 +0530 Subject: [PATCH 1/4] ci(security): add OSV-Scanner gate for source-repo CVE detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .github/workflows/securityScan.yml | 236 +++++++++++++++++++++++++++++ osv-scanner.toml | 18 +++ 2 files changed, 254 insertions(+) create mode 100644 .github/workflows/securityScan.yml create mode 100644 osv-scanner.toml diff --git a/.github/workflows/securityScan.yml b/.github/workflows/securityScan.yml new file mode 100644 index 00000000..214cef67 --- /dev/null +++ b/.github/workflows/securityScan.yml @@ -0,0 +1,236 @@ +name: Security Scan + +# Source-repo CVE gate. Lives in `databricks/databricks-sql-kernel`'s +# `.github/workflows/`. Ported from databricks-jdbc/securityScan.yml. +# +# Three modes with different thresholds: +# +# - pull_request to main: fail the job on any unsuppressed CVSS >= 7 +# finding. MEDIUM/LOW findings show in the step summary but don't +# block merges. +# +# - cron (weekly): report ALL findings regardless of severity. Sends +# an email with the full sorted list and fails the job on any +# finding. The weekly is read by humans, not enforced by code. +# +# - 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 three workspaces (root + napi + pyo3) so +# it sees the actually-resolved dep tree. +# +# Why OSV in addition to cargo-deny (which we already run in +# license-check.yml): OSV's GHSA-Rust source includes advisories that +# aren't yet mirrored to RustSec (the source cargo-deny uses). +# +# Suppressions live in `osv-scanner.toml` at repo root as +# [[IgnoredVulns]] entries. Each entry needs a justification comment. + +on: + pull_request: + branches: [main] + schedule: + - cron: '0 0 * * 0' # Every Sunday at midnight UTC + workflow_dispatch: + +permissions: + id-token: write + contents: read + +defaults: + run: + shell: bash + +jobs: + security-scan: + name: Security Scan + runs-on: + group: databricks-protected-runner-group + labels: linux-ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + + # JFrog OIDC + cargo proxy: skipped on fork PRs (no OIDC token). + # Fork PRs still work because cargo can reach crates.io directly; + # JFrog is just a faster mirror. + - name: Set up JFrog + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository + uses: ./.github/actions/setup-jfrog + with: + cargo: "true" + + - uses: actions-rust-lang/setup-rust-toolchain@46268bd060767258de96ed93c1251119784f2ab6 # v1.16.1 + + # cargo-cyclonedx produces a CycloneDX SBOM from Cargo.lock for + # each workspace. The kernel has three: the root (publishes the + # crate), pyo3/ (PyPI wheel), and napi/ (npm package). + - name: Install cargo-cyclonedx + run: cargo install cargo-cyclonedx --version 0.5.7 --locked + + - name: Generate SBOMs (root + napi + pyo3) + run: | + set -euo pipefail + mkdir -p /tmp/sboms + + cargo cyclonedx --format json --override-filename root-bom + mv root-bom.cdx.json /tmp/sboms/root.json + + ( cd napi && cargo cyclonedx --format json --override-filename napi-bom ) + mv napi/napi-bom.cdx.json /tmp/sboms/napi.json + + ( cd pyo3 && cargo cyclonedx --format json --override-filename pyo3-bom ) + mv pyo3/pyo3-bom.cdx.json /tmp/sboms/pyo3.json + + ls -lh /tmp/sboms/ + + - 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 + + - name: Run OSV-Scanner + # Drop -e: osv-scanner exits 1 on ANY finding regardless of + # severity. The severity gate below is what actually blocks PRs; + # we tolerate osv-scanner's non-zero exit via `|| true`. + run: | + set -uo pipefail + /tmp/osv-scanner scan source \ + --recursive=false \ + --config=osv-scanner.toml \ + --format=json \ + --output-file=/tmp/osv-out.json \ + /tmp/sboms/root.json /tmp/sboms/napi.json /tmp/sboms/pyo3.json || true + + if [ ! -s /tmp/osv-out.json ]; then + echo "::error::OSV-Scanner did not produce an output file." + exit 1 + fi + + - name: Collect findings + id: findings + run: | + set -uo pipefail + + # All findings sorted by severity desc. Anything missing a + # CVSS score sorts to 0 -- still visible. + ALL_FINDINGS=$(jq -c '[ + .results[].packages[]? | + .package as $pkg | + .groups[]? | + {pkg: ($pkg.name + "@" + $pkg.version), ids: .ids, severity: (.max_severity // "0")} + ] | sort_by(- (.severity | tonumber? // 0))' /tmp/osv-out.json) + TOTAL_FINDINGS=$(echo "$ALL_FINDINGS" | jq 'length') + + HIGH_FINDINGS=$(echo "$ALL_FINDINGS" | jq -c '[.[] | select((.severity | tonumber? // 0) >= 7)]') + HIGH_COUNT=$(echo "$HIGH_FINDINGS" | jq 'length') + + # Persist findings to a file -- GitHub Actions outputs are + # capped at 1 MB and the email body can exceed that. + echo "$ALL_FINDINGS" > /tmp/all-findings.json + + echo "total_findings=$TOTAL_FINDINGS" >> "$GITHUB_OUTPUT" + echo "high_count=$HIGH_COUNT" >> "$GITHUB_OUTPUT" + + { + echo "## OSV-Scanner Findings" + echo "" + echo "- Total findings (any severity): \`$TOTAL_FINDINGS\`" + echo "- High findings (CVSS >= 7, PR-blocking): \`$HIGH_COUNT\`" + if [ "$TOTAL_FINDINGS" -gt 0 ]; then + echo "" + echo "All findings (sorted by severity desc):" + echo "" + echo "| Severity | Package | IDs |" + echo "|---|---|---|" + echo "$ALL_FINDINGS" | jq -r '.[] | "| \(.severity) | \(.pkg) | \(.ids | join(",")) |"' + fi + } >> "$GITHUB_STEP_SUMMARY" + + echo "OSV: $TOTAL_FINDINGS total findings, $HIGH_COUNT at CVSS>=7" + if [ "$TOTAL_FINDINGS" -gt 0 ]; then + echo "" + echo "All findings (sorted by severity desc):" + echo "$ALL_FINDINGS" | jq -r '.[] | " [\(.severity)] \(.pkg) \(.ids | join(\", \"))"' + fi + + - name: Fail on findings (PR) + if: github.event_name == 'pull_request' && steps.findings.outputs.high_count != '0' + run: | + set -uo pipefail + HIGH_FINDINGS=$(jq -c '[.[] | select((.severity | tonumber? // 0) >= 7)]' /tmp/all-findings.json) + echo "::error::${{ steps.findings.outputs.high_count }} unsuppressed CVSS>=7 finding(s):" + echo "" + echo "$HIGH_FINDINGS" | jq -r '.[] | " [\(.severity)] \(.pkg) \(.ids | join(\", \"))"' + 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 + + - name: Compose email body + if: (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && steps.findings.outputs.total_findings != '0' + run: | + set -uo pipefail + { + echo "Kernel Security Scan Results" + echo "" + echo "

Security Vulnerabilities Found

" + echo "

${{ steps.findings.outputs.total_findings }} total finding(s) on main; ${{ steps.findings.outputs.high_count }} at CVSS >= 7 (PR-blocking).

" + echo "

Full reports: View Artifacts

" + echo "" + jq -r '.[] | + (if (.severity | tonumber? // 0) >= 7 then "high" + elif (.severity | tonumber? // 0) >= 4 then "medium" + else "" end) as $cls | + "" + ' /tmp/all-findings.json + echo "
SeverityPackageIDs
\(.severity)\(.pkg)\(.ids | join(", "))
" + echo "" + } > security-scan-report.html + + - name: Send Email + if: (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && steps.findings.outputs.total_findings != '0' + uses: dawidd6/action-send-mail@4226df7daafa6fc901a43789c49bf7ab309066e7 # v3 + with: + server_address: smtp.gmail.com + server_port: 465 + username: ${{ secrets.SMTP_USERNAME }} + password: ${{ secrets.SMTP_PASSWORD }} + subject: Databricks SQL Kernel Security Scan - Vulnerabilities Found + html_body: file://security-scan-report.html + to: ${{ secrets.EMAIL_RECIPIENTS }} + from: Kernel Security Scanner + content_type: text/html + + - 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 }} OSV finding(s) on main (${{ steps.findings.outputs.high_count }} at CVSS>=7). Email sent." + exit 1 + + - name: Upload reports + if: always() + uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 + with: + name: security-scan-reports + path: | + /tmp/osv-out.json + /tmp/sboms/ + security-scan-report.html + if-no-files-found: ignore diff --git a/osv-scanner.toml b/osv-scanner.toml new file mode 100644 index 00000000..afd9c78e --- /dev/null +++ b/osv-scanner.toml @@ -0,0 +1,18 @@ +# OSV-Scanner suppression config for databricks-sql-kernel. +# +# Each [[IgnoredVulns]] entry suppresses a CVE/GHSA ID GLOBALLY across +# all packages (osv-scanner v2.3.8 doesn't support per-package CVE +# scoping). Every entry MUST carry a justification comment explaining +# why the vulnerability doesn't apply to our usage, and a TODO or +# expiry note if the suppression is provisional. +# +# Example: +# +# [[IgnoredVulns]] +# id = "CVE-2024-XXXXX" +# # Justification: +# # Expiry: 2026-12-31 (if provisional) + +# (intentionally empty — add entries here as needed) From 5ab839cdd78bf1bc3ab8f8f7bca243e399d374ec Mon Sep 17 00:00:00 2001 From: Gopal Lal Date: Wed, 3 Jun 2026 10:15:31 +0530 Subject: [PATCH 2/4] ci(security): close textual-severity bypass + fix SBOM collisions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .github/workflows/securityScan.yml | 202 +++++++++++++++++++---------- 1 file changed, 136 insertions(+), 66 deletions(-) diff --git a/.github/workflows/securityScan.yml b/.github/workflows/securityScan.yml index 214cef67..30bd079c 100644 --- a/.github/workflows/securityScan.yml +++ b/.github/workflows/securityScan.yml @@ -1,31 +1,49 @@ name: Security Scan # Source-repo CVE gate. Lives in `databricks/databricks-sql-kernel`'s -# `.github/workflows/`. Ported from databricks-jdbc/securityScan.yml. +# `.github/workflows/`. Ported from databricks-jdbc/securityScan.yml, +# then hardened in response to PR #118 review. # -# Three modes with different thresholds: +# 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 CVSS >= 7 -# finding. MEDIUM/LOW findings show in the step summary but don't -# block merges. +# - 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): report ALL findings regardless of severity. Sends -# an email with the full sorted list and fails the job on any -# finding. The weekly is read by humans, not enforced by code. +# - 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 three workspaces (root + napi + pyo3) so -# it sees the actually-resolved dep tree. +# 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 kernel's two workspaces: # -# Why OSV in addition to cargo-deny (which we already run in -# license-check.yml): OSV's GHSA-Rust source includes advisories that -# aren't yet mirrored to RustSec (the source cargo-deny uses). +# 1. Root workspace `[".", "pyo3"]` — emits two SBOMs (one per +# member: databricks-sql-kernel + databricks-sql-kernel-pyo3). +# 2. napi/ standalone workspace — emits its own SBOM. # -# Suppressions live in `osv-scanner.toml` at repo root as -# [[IgnoredVulns]] entries. Each entry needs a justification comment. +# We deliberately do NOT pass --override-filename, because that +# causes a same-name collision when a workspace has multiple members +# (one SBOM per member is written to the same path, last-writer +# wins). Letting cyclonedx pick per-package names + globbing keeps +# every workspace member in scope. +# +# 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-PR coverage gap: this job runs on the protected runner group, +# which (per org policy) does not pick up fork PRs. Fork PRs DO get +# a check-run entry — it stays pending and the required-status-check +# rule blocks merge until a maintainer pushes the same SHA to a +# branch in this repo. Documented; revisit if external contributors +# become common. on: pull_request: @@ -45,6 +63,10 @@ defaults: 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 @@ -54,8 +76,8 @@ jobs: uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 # JFrog OIDC + cargo proxy: skipped on fork PRs (no OIDC token). - # Fork PRs still work because cargo can reach crates.io directly; - # JFrog is just a faster mirror. + # Fork PRs still resolve crates.io directly; JFrog is a faster + # mirror, not a source of any otherwise-unavailable artifact. - name: Set up JFrog if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository uses: ./.github/actions/setup-jfrog @@ -64,27 +86,48 @@ jobs: - uses: actions-rust-lang/setup-rust-toolchain@46268bd060767258de96ed93c1251119784f2ab6 # v1.16.1 - # cargo-cyclonedx produces a CycloneDX SBOM from Cargo.lock for - # each workspace. The kernel has three: the root (publishes the - # crate), pyo3/ (PyPI wheel), and napi/ (npm package). - name: Install cargo-cyclonedx run: cargo install cargo-cyclonedx --version 0.5.7 --locked - - name: Generate SBOMs (root + napi + pyo3) + # Two cyclonedx invocations cover all three published artifacts: + # + # - From repo root: writes one SBOM per root-workspace member. + # Members are [".", "pyo3"], so we get + # databricks-sql-kernel.cdx.json AND + # 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 - cargo cyclonedx --format json --override-filename root-bom - mv root-bom.cdx.json /tmp/sboms/root.json - - ( cd napi && cargo cyclonedx --format json --override-filename napi-bom ) - mv napi/napi-bom.cdx.json /tmp/sboms/napi.json + cargo cyclonedx --format json + # Root workspace places per-member SBOMs alongside each + # member's Cargo.toml. Glob them all in. + shopt -s globstar nullglob + for f in **/*.cdx.json; do + cp "$f" "/tmp/sboms/$(basename "$f")" + done - ( cd pyo3 && cargo cyclonedx --format json --override-filename pyo3-bom ) - mv pyo3/pyo3-bom.cdx.json /tmp/sboms/pyo3.json + ( 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 3 || { + echo "::error::expected >=3 SBOMs (root crate + pyo3 + napi), got $(ls /tmp/sboms/*.cdx.json 2>/dev/null | wc -l)" + exit 1 + } - name: Install osv-scanner run: | @@ -94,19 +137,33 @@ jobs: 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 - # Drop -e: osv-scanner exits 1 on ANY finding regardless of - # severity. The severity gate below is what actually blocks PRs; - # we tolerate osv-scanner's non-zero exit via `|| true`. run: | + # GHA's default shell is `bash --noprofile --norc -eo pipefail + # {0}`; add `-u`. set -uo pipefail + RC=0 /tmp/osv-scanner scan source \ - --recursive=false \ --config=osv-scanner.toml \ --format=json \ --output-file=/tmp/osv-out.json \ - /tmp/sboms/root.json /tmp/sboms/napi.json /tmp/sboms/pyo3.json || true - + --sbom=/tmp/sboms/databricks-sql-kernel.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 @@ -117,56 +174,61 @@ jobs: run: | set -uo pipefail - # All findings sorted by severity desc. Anything missing a - # CVSS score sorts to 0 -- still visible. + # 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 go to UNSCORED_FINDINGS and STILL + # block PRs under the fail-on-any policy. The numeric + # value (or "unscored") is what we display. ALL_FINDINGS=$(jq -c '[ .results[].packages[]? | .package as $pkg | .groups[]? | - {pkg: ($pkg.name + "@" + $pkg.version), ids: .ids, severity: (.max_severity // "0")} - ] | sort_by(- (.severity | tonumber? // 0))' /tmp/osv-out.json) + ( .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') - HIGH_FINDINGS=$(echo "$ALL_FINDINGS" | jq -c '[.[] | select((.severity | tonumber? // 0) >= 7)]') - HIGH_COUNT=$(echo "$HIGH_FINDINGS" | jq 'length') - - # Persist findings to a file -- GitHub Actions outputs are - # capped at 1 MB and the email body can exceed that. echo "$ALL_FINDINGS" > /tmp/all-findings.json - echo "total_findings=$TOTAL_FINDINGS" >> "$GITHUB_OUTPUT" - echo "high_count=$HIGH_COUNT" >> "$GITHUB_OUTPUT" { echo "## OSV-Scanner Findings" echo "" - echo "- Total findings (any severity): \`$TOTAL_FINDINGS\`" - echo "- High findings (CVSS >= 7, PR-blocking): \`$HIGH_COUNT\`" + 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 "All findings (sorted by severity desc):" echo "" echo "| Severity | Package | IDs |" echo "|---|---|---|" - echo "$ALL_FINDINGS" | jq -r '.[] | "| \(.severity) | \(.pkg) | \(.ids | join(",")) |"' + echo "$ALL_FINDINGS" | jq -r '.[] | "| \(.display) | \(.pkg) | \(.ids | join(",")) |"' fi } >> "$GITHUB_STEP_SUMMARY" - echo "OSV: $TOTAL_FINDINGS total findings, $HIGH_COUNT at CVSS>=7" + echo "OSV: $TOTAL_FINDINGS unsuppressed finding(s)" if [ "$TOTAL_FINDINGS" -gt 0 ]; then - echo "" - echo "All findings (sorted by severity desc):" - echo "$ALL_FINDINGS" | jq -r '.[] | " [\(.severity)] \(.pkg) \(.ids | join(\", \"))"' + echo "$ALL_FINDINGS" | jq -r '.[] | " [\(.display)] \(.pkg) \(.ids | join(\", \"))"' fi - name: Fail on findings (PR) - if: github.event_name == 'pull_request' && steps.findings.outputs.high_count != '0' + if: github.event_name == 'pull_request' && steps.findings.outputs.total_findings != '0' run: | set -uo pipefail - HIGH_FINDINGS=$(jq -c '[.[] | select((.severity | tonumber? // 0) >= 7)]' /tmp/all-findings.json) - echo "::error::${{ steps.findings.outputs.high_count }} unsuppressed CVSS>=7 finding(s):" + echo "::error::${{ steps.findings.outputs.total_findings }} unsuppressed OSV finding(s):" echo "" - echo "$HIGH_FINDINGS" | jq -r '.[] | " [\(.severity)] \(.pkg) \(.ids | join(\", \"))"' + 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" @@ -191,22 +253,27 @@ jobs: echo " tr.medium { background: #fff5e5; }" echo "" echo "

Security Vulnerabilities Found

" - echo "

${{ steps.findings.outputs.total_findings }} total finding(s) on main; ${{ steps.findings.outputs.high_count }} at CVSS >= 7 (PR-blocking).

" + echo "

${{ steps.findings.outputs.total_findings }} unsuppressed finding(s) on main.

" + echo "

All findings fail the run; document accepted risk via osv-scanner.toml.

" echo "

Full reports: View Artifacts

" echo "" jq -r '.[] | - (if (.severity | tonumber? // 0) >= 7 then "high" - elif (.severity | tonumber? // 0) >= 4 then "medium" + (if .severity >= 7 then "high" + elif .severity >= 4 then "medium" else "" end) as $cls | - "" + "" ' /tmp/all-findings.json echo "
SeverityPackageIDs
\(.severity)\(.pkg)\(.ids | join(", "))
\(.display)\(.pkg)\(.ids | join(", "))
" echo "" } > security-scan-report.html + # action-send-mail: SHA 4226df7d... resolves to v3.11.0 (the + # floating `v3` tag also points here today). Verify with + # `gh api repos/dawidd6/action-send-mail/git/refs/tags` before + # bumping. - name: Send Email if: (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && steps.findings.outputs.total_findings != '0' - uses: dawidd6/action-send-mail@4226df7daafa6fc901a43789c49bf7ab309066e7 # v3 + uses: dawidd6/action-send-mail@4226df7daafa6fc901a43789c49bf7ab309066e7 # v3.11.0 with: server_address: smtp.gmail.com server_port: 465 @@ -221,7 +288,7 @@ jobs: - 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 }} OSV finding(s) on main (${{ steps.findings.outputs.high_count }} at CVSS>=7). Email sent." + echo "::error::${{ steps.findings.outputs.total_findings }} unsuppressed OSV finding(s) on main. Email sent." exit 1 - name: Upload reports @@ -234,3 +301,6 @@ jobs: /tmp/sboms/ security-scan-report.html 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 From a635b1e50e79df1538a097b5005c4be2e3a46f97 Mon Sep 17 00:00:00 2001 From: Gopal Lal Date: Wed, 3 Jun 2026 12:29:08 +0530 Subject: [PATCH 3/4] =?UTF-8?q?ci(security):=20review=20fixes=20=E2=80=94?= =?UTF-8?q?=20jq=20inline-comment=20bug,=20schema=20check,=20ruleset=20gat?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: ` 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 --- .github/workflows/securityScan.yml | 58 ++++++++++++++++++++++++------ osv-scanner.toml | 8 +++++ 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/.github/workflows/securityScan.yml b/.github/workflows/securityScan.yml index 30bd079c..89f8cbb9 100644 --- a/.github/workflows/securityScan.yml +++ b/.github/workflows/securityScan.yml @@ -108,11 +108,15 @@ jobs: set -euo pipefail mkdir -p /tmp/sboms + # Root workspace has members [".", "pyo3"]; cargo-cyclonedx + # writes one SBOM per member alongside its Cargo.toml. Pull + # them in by EXPLICIT path (./*.cdx.json and pyo3/*.cdx.json) + # 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. cargo cyclonedx --format json - # Root workspace places per-member SBOMs alongside each - # member's Cargo.toml. Glob them all in. - shopt -s globstar nullglob - for f in **/*.cdx.json; do + shopt -s nullglob + for f in ./*.cdx.json pyo3/*.cdx.json; do cp "$f" "/tmp/sboms/$(basename "$f")" done @@ -170,19 +174,37 @@ jobs: 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 go to UNSCORED_FINDINGS and STILL - # block PRs under the fail-on-any policy. The numeric - # value (or "unscored") is what we display. + # "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 | @@ -219,16 +241,23 @@ jobs: echo "OSV: $TOTAL_FINDINGS unsuppressed finding(s)" if [ "$TOTAL_FINDINGS" -gt 0 ]; then - echo "$ALL_FINDINGS" | jq -r '.[] | " [\(.display)] \(.pkg) \(.ids | join(\", \"))"' + # 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 "" - jq -r '.[] | " [\(.display)] \(.pkg) \(.ids | join(\", \"))"' /tmp/all-findings.json + # 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" @@ -239,6 +268,8 @@ jobs: exit 1 - name: Compose email body + # See "Collect findings" above for why this step intentionally + # omits `-e`. if: (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && steps.findings.outputs.total_findings != '0' run: | set -uo pipefail @@ -251,6 +282,12 @@ jobs: echo " th { background: #f5f5f5; }" echo " tr.high { background: #ffe5e5; }" echo " tr.medium { background: #fff5e5; }" + # Unscored findings are also gate-blocking under the + # fail-on-any policy (textual-severity advisories often + # describe HIGH-impact issues with no numeric CVSS). + # Style them the same as high so recipients don't misread + # the lack of a number as "low risk". + echo " tr.unscored { background: #ffe5e5; }" echo "" echo "

Security Vulnerabilities Found

" echo "

${{ steps.findings.outputs.total_findings }} unsuppressed finding(s) on main.

" @@ -258,7 +295,8 @@ jobs: echo "

Full reports: View Artifacts

" echo "" jq -r '.[] | - (if .severity >= 7 then "high" + (if .display == "unscored" then "unscored" + elif .severity >= 7 then "high" elif .severity >= 4 then "medium" else "" end) as $cls | "" diff --git a/osv-scanner.toml b/osv-scanner.toml index afd9c78e..8fdc6643 100644 --- a/osv-scanner.toml +++ b/osv-scanner.toml @@ -14,5 +14,13 @@ # # "kernel does not parse untrusted YAML" or "kernel does not expose # # the affected entrypoint"> # # Expiry: 2026-12-31 (if provisional) +# +# TODO(securityScan): the `# Expiry:` convention above is documentation +# only — no workflow step rejects expired suppressions today. Add an +# expiry-lint step to securityScan.yml (PR + cron) that parses these +# comments, fails the run if any `Expiry: ` is in the past, and +# emits a step-summary table of upcoming-expiry entries. Tracked +# separately so this file stays empty on the initial landing; once we +# have real suppressions to enforce against, wire it up. # (intentionally empty — add entries here as needed) From f3d1df440a128b785105b748d0c2447867a9ba51 Mon Sep 17 00:00:00 2001 From: Gopal Lal Date: Wed, 3 Jun 2026 22:25:59 +0530 Subject: [PATCH 4/4] ci(security): comment out SMTP email step pending creds 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 --- .github/workflows/securityScan.yml | 39 ++++++++++++++++-------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/.github/workflows/securityScan.yml b/.github/workflows/securityScan.yml index 89f8cbb9..4046d178 100644 --- a/.github/workflows/securityScan.yml +++ b/.github/workflows/securityScan.yml @@ -305,28 +305,31 @@ jobs: echo "" } > security-scan-report.html - # action-send-mail: SHA 4226df7d... resolves to v3.11.0 (the - # floating `v3` tag also points here today). Verify with - # `gh api repos/dawidd6/action-send-mail/git/refs/tags` before - # bumping. - - name: Send Email - if: (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && steps.findings.outputs.total_findings != '0' - uses: dawidd6/action-send-mail@4226df7daafa6fc901a43789c49bf7ab309066e7 # v3.11.0 - with: - server_address: smtp.gmail.com - server_port: 465 - username: ${{ secrets.SMTP_USERNAME }} - password: ${{ secrets.SMTP_PASSWORD }} - subject: Databricks SQL Kernel Security Scan - Vulnerabilities Found - html_body: file://security-scan-report.html - to: ${{ secrets.EMAIL_RECIPIENTS }} - from: Kernel Security Scanner - content_type: text/html + # Email notification deferred — the SMTP credentials path + # (SMTP_USERNAME / SMTP_PASSWORD / EMAIL_RECIPIENTS) hasn't + # been provisioned. The HTML report is still produced and + # uploaded as a run artifact (see `Upload reports` below), so + # triagers can pull it after a scheduled-run failure without + # needing the email. Re-enable when SMTP creds are wired up. + # + # - name: Send Email + # if: (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && steps.findings.outputs.total_findings != '0' + # uses: dawidd6/action-send-mail@4226df7daafa6fc901a43789c49bf7ab309066e7 # v3.11.0 + # with: + # server_address: smtp.gmail.com + # server_port: 465 + # username: ${{ secrets.SMTP_USERNAME }} + # password: ${{ secrets.SMTP_PASSWORD }} + # subject: Databricks SQL Kernel Security Scan - Vulnerabilities Found + # html_body: file://security-scan-report.html + # to: ${{ secrets.EMAIL_RECIPIENTS }} + # from: Kernel Security Scanner + # content_type: text/html - 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. Email sent." + echo "::error::${{ steps.findings.outputs.total_findings }} unsuppressed OSV finding(s) on main. Download the security-scan-reports artifact for the HTML report." exit 1 - name: Upload reports
SeverityPackageIDs
\(.display)\(.pkg)\(.ids | join(", "))