From b92620e838b0da83393abaaf36650a065a86ad46 Mon Sep 17 00:00:00 2001 From: Piotr Mlocek Date: Fri, 11 Sep 2026 08:52:41 +0000 Subject: [PATCH 1/4] ci(rust): reject stale Cargo lockfiles (#3227) * ci(rust): reject stale Cargo lockfiles Signed-off-by: Piotr Mlocek * docs(ci): clarify lockfile validation policy Signed-off-by: Piotr Mlocek * refactor(ci): structure and test Cargo lockfile validation Signed-off-by: Piotr Mlocek * chore(ci): remove lockfile validator regression tests Signed-off-by: Piotr Mlocek * ci(rust): complete locked validation and lint examples Signed-off-by: Piotr Mlocek * ci(rust): check lockfile diffs after validation Signed-off-by: Piotr Mlocek * docs(build): shorten lockfile validation notes Signed-off-by: Piotr Mlocek * ci(rust): skip lockfile check after failures Signed-off-by: Piotr Mlocek --------- Signed-off-by: Piotr Mlocek --- .github/workflows/branch-checks.yml | 10 +++-- TESTING.md | 2 + architecture/build.md | 3 ++ tasks/ci.toml | 1 + tasks/rust.toml | 11 +++++- tasks/scripts/check-cargo-lockfiles.sh | 54 ++++++++++++++++++++++++++ tasks/test.toml | 1 + 7 files changed, 77 insertions(+), 5 deletions(-) create mode 100755 tasks/scripts/check-cargo-lockfiles.sh diff --git a/.github/workflows/branch-checks.yml b/.github/workflows/branch-checks.yml index 72f8273c1a..7b0c77c8fd 100644 --- a/.github/workflows/branch-checks.yml +++ b/.github/workflows/branch-checks.yml @@ -164,8 +164,8 @@ jobs: run: | cargo clippy --workspace --all-targets -- -D warnings cargo clippy --manifest-path e2e/rust/Cargo.toml --all-targets -- -D warnings - cargo check --manifest-path examples/governance-interceptor/Cargo.toml --all-targets - cargo check --manifest-path examples/supervisor-middleware-content-guard/Cargo.toml --all-targets + cargo clippy --manifest-path examples/governance-interceptor/Cargo.toml --all-targets -- -D warnings + cargo clippy --manifest-path examples/supervisor-middleware-content-guard/Cargo.toml --all-targets -- -D warnings - name: Test env: @@ -207,6 +207,11 @@ jobs: exit 1 fi + - name: Verify Cargo lockfiles unchanged + run: | + tasks/scripts/check-cargo-lockfiles.sh + git diff --exit-code HEAD -- ':(glob)**/Cargo.lock' + python: name: Python (${{ matrix.runner }}) needs: pr_metadata @@ -247,7 +252,6 @@ jobs: run: | bash tasks/scripts/test-gateway-pull-policy.sh bash tasks/scripts/test-gateway-config.sh - go: name: Go SDK needs: pr_metadata diff --git a/TESTING.md b/TESTING.md index 5d9674dd06..aaad71aa41 100644 --- a/TESTING.md +++ b/TESTING.md @@ -46,6 +46,8 @@ Run Rust tests only: mise run test:rust # cargo test --workspace ``` +Rust validation checks tracked Cargo lockfiles; run `mise run rust:lockfiles:check` to check them directly. If one is stale, refresh it with Cargo using its adjacent manifest, review the diff, and commit the update. + ## Python Unit Tests Python unit tests use the `*_test.py` suffix convention (not `test_*` prefix) diff --git a/architecture/build.md b/architecture/build.md index 5f3b913e1b..d6ad9914a9 100644 --- a/architecture/build.md +++ b/architecture/build.md @@ -514,6 +514,9 @@ Published docs live in `docs/`, and Fern site configuration lives in `fern/`. Se ## Validation Expectations +Rust CI rejects stale or modified Cargo lockfiles and runs Clippy for the +workspace, E2E crate, and standalone examples. + - Run `mise run pre-commit` before committing. - Run `mise run test` after code changes. - Run `mise run e2e` for sandbox, policy, driver, or deployment changes when the diff --git a/tasks/ci.toml b/tasks/ci.toml index cc4158448f..e2a388e6b1 100644 --- a/tasks/ci.toml +++ b/tasks/ci.toml @@ -54,6 +54,7 @@ description = "Run repository lint checks" depends = [ "license:check", "rust:format:check", + "rust:lockfiles:check", "rust:lint", "python:format:check", "python:lint", diff --git a/tasks/rust.toml b/tasks/rust.toml index e62e22b3cf..e8c45fd54c 100644 --- a/tasks/rust.toml +++ b/tasks/rust.toml @@ -5,17 +5,24 @@ ["rust:check"] description = "Check all Rust crates for errors" +depends = ["rust:lockfiles:check"] run = "cargo check --workspace" run_windows = "powershell -NoProfile -ExecutionPolicy Bypass -File tasks/scripts/windows-msvc.ps1 check native" hide = true +["rust:lockfiles:check"] +description = "Verify all tracked Cargo lockfiles are current" +run = "tasks/scripts/check-cargo-lockfiles.sh" +hide = true + ["rust:lint"] description = "Lint Rust code with Clippy (deny warnings)" +depends = ["rust:lockfiles:check"] run = [ "cargo clippy --workspace --all-targets -- -D warnings", "cargo clippy --manifest-path e2e/rust/Cargo.toml --all-targets -- -D warnings", - "cargo check --manifest-path examples/governance-interceptor/Cargo.toml --all-targets", - "cargo check --manifest-path examples/supervisor-middleware-content-guard/Cargo.toml --all-targets", + "cargo clippy --manifest-path examples/governance-interceptor/Cargo.toml --all-targets -- -D warnings", + "cargo clippy --manifest-path examples/supervisor-middleware-content-guard/Cargo.toml --all-targets -- -D warnings", ] run_windows = "powershell -NoProfile -ExecutionPolicy Bypass -File tasks/scripts/windows-msvc.ps1 lint native" hide = true diff --git a/tasks/scripts/check-cargo-lockfiles.sh b/tasks/scripts/check-cargo-lockfiles.sh new file mode 100755 index 0000000000..bd74d8d647 --- /dev/null +++ b/tasks/scripts/check-cargo-lockfiles.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set -euo pipefail + +check_lockfile() { + local lockfile="$1" + local manifest="${lockfile%Cargo.lock}Cargo.toml" + + if [[ ! -f "$manifest" ]]; then + printf 'error: tracked lockfile %s has no adjacent Cargo.toml\n' "$lockfile" >&2 + return 1 + fi + + printf 'Checking %s\n' "$lockfile" + if ! cargo metadata \ + --locked \ + --format-version 1 \ + --manifest-path "$manifest" \ + >/dev/null; then + printf 'error: validation failed for %s\n' "$lockfile" >&2 + return 1 + fi +} + +main() { + local lockfile + local found=0 + local failed=0 + + cd "$(git rev-parse --show-toplevel)" + + # Policy: every tracked Cargo.lock represents an intentionally reproducible + # Cargo workspace and must resolve against its adjacent Cargo.toml. Manifests + # that intentionally do not own a lockfile are outside this check. + while IFS= read -r -d '' lockfile; do + found=1 + check_lockfile "$lockfile" || failed=1 + done < <(git ls-files -z -- ':(glob)**/Cargo.lock') + + if [[ "$found" -eq 0 ]]; then + echo "error: no tracked Cargo.lock files found" >&2 + return 1 + fi + + if [[ "$failed" -ne 0 ]]; then + echo "Resolve the reported errors. If a lockfile needs updating, refresh it with Cargo and commit the result." >&2 + fi + + return "$failed" +} + +main "$@" diff --git a/tasks/test.toml b/tasks/test.toml index 0fa0bd8496..8c41e70025 100644 --- a/tasks/test.toml +++ b/tasks/test.toml @@ -78,6 +78,7 @@ run = "bash tasks/scripts/e2e-gpu-build-images.sh" ["test:rust"] description = "Run Rust tests" +depends = ["rust:lockfiles:check"] env = { OPENSHELL_TELEMETRY_ENABLED = "false" } run = [ # Run the workspace once without openshell-server so we can run that crate From 3eb81beba92f506d50f4432248a05ec9edb2af88 Mon Sep 17 00:00:00 2001 From: alangou Date: Fri, 11 Sep 2026 10:26:56 +0000 Subject: [PATCH 2/4] ci(security): orchestrate security scans with severity gating (#3255) Signed-off-by: Adrien Langou --- .github/workflows/cargo-deny.yml | 19 +++- .github/workflows/codeql.yml | 54 ++++++++-- .github/workflows/codex-security.yml | 40 ++++++- .github/workflows/security-scan.yml | 133 ++++++++++++++++++++++++ .github/workflows/trivy-scan.yml | 11 +- .github/workflows/workflow-security.yml | 51 ++++++++- CI.md | 85 ++++++++++++++- architecture/build.md | 34 ++++-- 8 files changed, 402 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/security-scan.yml diff --git a/.github/workflows/cargo-deny.yml b/.github/workflows/cargo-deny.yml index 2756215cb0..c85e9ac758 100644 --- a/.github/workflows/cargo-deny.yml +++ b/.github/workflows/cargo-deny.yml @@ -7,6 +7,16 @@ on: schedule: - cron: "23 7 * * *" workflow_dispatch: + workflow_call: + inputs: + candidate_ref: + description: Optional pre-release tag to scan instead of the triggering revision + default: "" + type: string + advisories-only: + description: Run only the dependency advisory check + default: false + type: boolean env: CARGO_TERM_COLOR: always @@ -17,7 +27,7 @@ permissions: packages: read concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: cargo-deny-${{ github.workflow }}-${{ inputs.candidate_ref || github.ref }} cancel-in-progress: true jobs: @@ -31,9 +41,16 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ inputs.candidate_ref && format('refs/tags/{0}', inputs.candidate_ref) || '' }} - name: Install tools run: mise install --locked - name: Check dependencies + if: ${{ !inputs.advisories-only }} run: mise run rust:deny + + - name: Check dependency advisories + if: inputs.advisories-only + run: cargo deny check advisories diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index bd9aef1d89..288b39b962 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -7,13 +7,23 @@ on: schedule: - cron: "29 5 * * *" workflow_dispatch: + workflow_call: + inputs: + candidate_ref: + description: Optional pre-release tag to scan instead of the triggering revision + default: "" + type: string + fail-on-findings: + description: Fail on HIGH/CRITICAL security findings (score at least 7.0) + default: false + type: boolean permissions: contents: read security-events: write concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: codeql-${{ github.workflow }}-${{ inputs.candidate_ref || github.ref }} cancel-in-progress: true jobs: @@ -38,7 +48,9 @@ jobs: build-mode: none steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + id: checkout with: + ref: ${{ inputs.candidate_ref && format('refs/tags/{0}', inputs.candidate_ref) || '' }} persist-credentials: false - name: Set up Go @@ -69,9 +81,11 @@ jobs: upload: never - name: Summarize findings + id: findings if: always() env: LANGUAGE: ${{ matrix.language }} + FAIL_ON_FINDINGS: ${{ inputs.fail-on-findings || false }} shell: bash run: | set -euo pipefail @@ -83,11 +97,23 @@ jobs: echo if [ "${#sarif_files[@]}" -eq 0 ]; then echo "No SARIF report was produced." + exit 1 else - finding_count=$(jq -s '[.[].runs[]?.results[]?] | length' "${sarif_files[@]}") + finding_count=$(jq -s '[.[].runs[].results[]] | length' "${sarif_files[@]}") + high_count=$(jq -s ' + [ .[].runs[] | . as $run | .results[] + | select(all(.suppressions[]?; .status != "accepted")) + | .ruleId as $id + | ($run.tool.driver, $run.tool.extensions[]?) | .rules[]? + | select(.id == $id) + | select((.properties["security-severity"] // "0" | tonumber) >= 7) + ] | length + ' "${sarif_files[@]}") + echo "high_count=$high_count" >> "$GITHUB_OUTPUT" echo "Findings: $finding_count" + echo "HIGH/CRITICAL: $high_count" echo - echo "Findings are informational and do not fail CI." + echo "Fail on HIGH/CRITICAL: $FAIL_ON_FINDINGS" fi } >> "$GITHUB_STEP_SUMMARY" @@ -96,6 +122,8 @@ jobs: uses: github/codeql-action/upload-sarif@ff2f1c621b7f889edc0d3c761ac2e6a3f8cdb0dd # v4.37.7 with: sarif_file: codeql-results + ref: ${{ inputs.candidate_ref && format('refs/tags/{0}', inputs.candidate_ref) || '' }} + sha: ${{ inputs.candidate_ref && steps.checkout.outputs.commit || '' }} category: /language:${{ matrix.language }} - name: Upload SARIF @@ -107,8 +135,22 @@ jobs: if-no-files-found: ignore retention-days: 14 + - name: Enforce HIGH/CRITICAL threshold + if: ${{ !cancelled() && steps.findings.outcome == 'success' }} + env: + HIGH_COUNT: ${{ steps.findings.outputs.high_count }} + FAIL_ON_FINDINGS: ${{ inputs.fail-on-findings || false }} + run: | + if [ "$HIGH_COUNT" -gt 0 ]; then + if [ "$FAIL_ON_FINDINGS" = "true" ]; then + echo "::error::CodeQL reported $HIGH_COUNT HIGH/CRITICAL findings." + exit 1 + fi + echo "::warning::CodeQL reported $HIGH_COUNT HIGH/CRITICAL findings; enforcement is disabled." + fi + result: - name: OpenShell / CodeQL (informational) + name: ${{ inputs.fail-on-findings && 'OpenShell / CodeQL' || 'OpenShell / CodeQL (informational)' }} if: always() needs: analyze runs-on: ubuntu-latest @@ -120,7 +162,7 @@ jobs: shell: bash run: | if [ "$ANALYZE_RESULT" != "success" ]; then - echo "::error::One or more CodeQL analyzers did not complete successfully." + echo "::error::CodeQL execution or the configured finding threshold failed." exit 1 fi - echo "All CodeQL analyzers completed; findings remain informational." + echo "All CodeQL analyzers completed and the configured finding threshold passed." diff --git a/.github/workflows/codex-security.yml b/.github/workflows/codex-security.yml index a008af019f..b79bc54b3a 100644 --- a/.github/workflows/codex-security.yml +++ b/.github/workflows/codex-security.yml @@ -23,6 +23,14 @@ on: required: false default: false type: boolean + fail-on-findings: + description: Fail on HIGH/CRITICAL security findings + default: false + type: boolean + upload_sarif: + description: Upload results to Code Scanning when called from a manual workflow + default: true + type: boolean outputs: base_sha: description: Previous stable commit, empty for a full bootstrap scan @@ -230,6 +238,7 @@ jobs: --output "$SARIF_FILE" - name: Summarize findings + id: findings env: BASE_TAG: ${{ steps.range.outputs.base_tag }} CANDIDATE_TAG: ${{ steps.range.outputs.candidate_tag }} @@ -237,9 +246,17 @@ jobs: SARIF_FILE: ${{ runner.temp }}/codex-security.sarif SCAN_SCOPE: ${{ steps.range.outputs.scan_scope }} TRAIN: ${{ steps.range.outputs.train }} + FAIL_ON_FINDINGS: ${{ inputs.fail-on-findings || false }} run: | set -euo pipefail - finding_count=$(jq '[.runs[]?.results[]?] | length' "$SARIF_FILE") + finding_count=$(jq '[.runs[].results[]] | length' "$SARIF_FILE") + high_count=$(jq ' + [ .runs[].results[] + | select(all(.suppressions[]?; .status != "accepted")) + | select(.properties.severity | ascii_downcase | IN("high", "critical")) + ] | length + ' "$SARIF_FILE") + echo "high_count=$high_count" >> "$GITHUB_OUTPUT" { echo "### Codex Security release qualification" echo @@ -254,8 +271,9 @@ jobs: fi echo "- Coverage: complete" echo "- Findings: $finding_count" + echo "- HIGH/CRITICAL: $high_count" echo - echo "Findings are informational during the observation phase." + echo "Fail on HIGH/CRITICAL: $FAIL_ON_FINDINGS" } >> "$GITHUB_STEP_SUMMARY" - name: Upload SARIF to Code Scanning @@ -267,8 +285,22 @@ jobs: sha: ${{ steps.range.outputs.candidate_sha }} category: ${{ steps.range.outputs.category }} + - name: Enforce HIGH/CRITICAL threshold + if: ${{ !cancelled() && steps.findings.outcome == 'success' }} + env: + HIGH_COUNT: ${{ steps.findings.outputs.high_count }} + FAIL_ON_FINDINGS: ${{ inputs.fail-on-findings || false }} + run: | + if [ "$HIGH_COUNT" -gt 0 ]; then + if [ "$FAIL_ON_FINDINGS" = "true" ]; then + echo "::error::Codex reported $HIGH_COUNT HIGH/CRITICAL findings." + exit 1 + fi + echo "::warning::Codex reported $HIGH_COUNT HIGH/CRITICAL findings; enforcement is disabled." + fi + result: - name: OpenShell / Codex Security (informational) + name: ${{ inputs.fail-on-findings && 'OpenShell / Codex Security' || 'OpenShell / Codex Security (informational)' }} if: ${{ always() }} needs: analyze runs-on: ubuntu-latest @@ -283,4 +315,4 @@ jobs: echo "::error::Codex Security release qualification did not complete successfully." exit 1 fi - echo "Codex Security completed; findings remain informational." + echo "Codex Security completed and the configured finding threshold passed." diff --git a/.github/workflows/security-scan.yml b/.github/workflows/security-scan.yml new file mode 100644 index 0000000000..2ee09d7994 --- /dev/null +++ b/.github/workflows/security-scan.yml @@ -0,0 +1,133 @@ +# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +name: Security Scan + +on: + workflow_dispatch: + inputs: + candidate_ref: + description: Pre-release tag to scan (vMAJOR.MINOR.PATCH-pre.N) + required: true + type: string + stable_ref: + description: Optional previous stable tag override for Codex + default: "" + type: string + allow_full_bootstrap: + description: Allow a full Codex scan when no previous stable tag exists + default: false + type: boolean + allow-high-critical: + description: Report HIGH/CRITICAL findings without failing; scanner errors still fail + default: false + type: boolean + images: + description: Newline-separated image references for Trivy + default: "" + type: string + charts: + description: Newline-separated packaged Helm chart OCI references for Trivy + default: "" + type: string + workflow_call: + inputs: + candidate_ref: + description: Pre-release tag to scan (vMAJOR.MINOR.PATCH-pre.N) + required: true + type: string + stable_ref: + description: Optional previous stable tag override for Codex + default: "" + type: string + allow_full_bootstrap: + description: Allow a full Codex scan when no previous stable tag exists + default: false + type: boolean + allow-high-critical: + description: Report HIGH/CRITICAL findings without failing; scanner errors still fail + default: false + type: boolean + images: + description: Newline-separated image references for Trivy + default: "" + type: string + charts: + description: Newline-separated packaged Helm chart OCI references for Trivy + default: "" + type: string + secrets: + CODEX_SECURITY_API_KEY: + required: true + CACHIX_AUTH_TOKEN: + required: false + +permissions: + contents: read + +# Only the finding threshold is overridable; execution failures remain fatal. +jobs: + codex: + name: Codex Security + uses: ./.github/workflows/codex-security.yml + permissions: + actions: read + contents: read + security-events: write + with: + candidate_ref: ${{ inputs.candidate_ref }} + stable_ref: ${{ inputs.stable_ref }} + allow_full_bootstrap: ${{ inputs.allow_full_bootstrap }} + fail-on-findings: ${{ !inputs.allow-high-critical }} + upload_sarif: true + secrets: + CODEX_SECURITY_API_KEY: ${{ secrets.CODEX_SECURITY_API_KEY }} + + codeql: + name: CodeQL + uses: ./.github/workflows/codeql.yml + permissions: + contents: read + security-events: write + with: + candidate_ref: ${{ inputs.candidate_ref }} + fail-on-findings: ${{ !inputs.allow-high-critical }} + + trivy: + name: Trivy + uses: ./.github/workflows/trivy-scan.yml + permissions: + contents: read + packages: read + security-events: write + with: + candidate_ref: ${{ inputs.candidate_ref }} + fail-on-findings: ${{ !inputs.allow-high-critical }} + severity: HIGH,CRITICAL + ignore-unfixed: false + images: ${{ inputs.images }} + charts: ${{ inputs.charts }} + secrets: + CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }} + + cargo-deny: + name: Cargo Deny + uses: ./.github/workflows/cargo-deny.yml + permissions: + contents: read + packages: read + with: + candidate_ref: ${{ inputs.candidate_ref }} + advisories-only: true + + workflow-security: + name: Actionlint and Zizmor + uses: ./.github/workflows/workflow-security.yml + permissions: + contents: read + security-events: write + with: + candidate_ref: ${{ inputs.candidate_ref }} + fail-on-findings: ${{ !inputs.allow-high-critical }} + secrets: + CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }} diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index ccfe80bd69..cad7281321 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -9,6 +9,10 @@ name: Trivy Scan on: workflow_call: inputs: + candidate_ref: + description: Optional pre-release tag to scan instead of the triggering revision + default: "" + type: string images: description: Newline-separated image references to scan type: string @@ -77,7 +81,7 @@ env: jobs: scan: - name: OpenShell / Trivy (informational) + name: ${{ inputs.fail-on-findings && 'OpenShell / Trivy' || 'OpenShell / Trivy (informational)' }} runs-on: ubuntu-latest timeout-minutes: 60 outputs: @@ -89,6 +93,7 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: + ref: ${{ inputs.candidate_ref && format('refs/tags/{0}', inputs.candidate_ref) || '' }} persist-credentials: false - uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0 @@ -203,7 +208,9 @@ jobs: batch: ${{ fromJSON(needs.scan.outputs.sarif-batches) }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + id: checkout with: + ref: ${{ inputs.candidate_ref && format('refs/tags/{0}', inputs.candidate_ref) || '' }} persist-credentials: false - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 @@ -217,3 +224,5 @@ jobs: - uses: github/codeql-action/upload-sarif@ff2f1c621b7f889edc0d3c761ac2e6a3f8cdb0dd # v4.37.7 with: sarif_file: reports/trivy/code-scanning/uploads/${{ matrix.batch }} + ref: ${{ inputs.candidate_ref && format('refs/tags/{0}', inputs.candidate_ref) || '' }} + sha: ${{ inputs.candidate_ref && steps.checkout.outputs.commit || '' }} diff --git a/.github/workflows/workflow-security.yml b/.github/workflows/workflow-security.yml index 7a87e15483..a098b2c4ab 100644 --- a/.github/workflows/workflow-security.yml +++ b/.github/workflows/workflow-security.yml @@ -12,6 +12,19 @@ on: schedule: - cron: "17 6 * * 1" workflow_dispatch: + workflow_call: + inputs: + candidate_ref: + description: Optional pre-release tag to scan instead of the triggering revision + default: "" + type: string + fail-on-findings: + description: Fail on Zizmor HIGH findings; Actionlint remains informational + default: false + type: boolean + secrets: + CACHIX_AUTH_TOKEN: + required: false permissions: contents: read @@ -21,7 +34,7 @@ defaults: shell: nix develop --command bash -euo pipefail {0} concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: workflow-security-${{ github.workflow }}-${{ inputs.candidate_ref || github.ref }} cancel-in-progress: true jobs: @@ -33,7 +46,9 @@ jobs: security-events: write steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + id: checkout with: + ref: ${{ inputs.candidate_ref && format('refs/tags/{0}', inputs.candidate_ref) || '' }} persist-credentials: false - name: Set up Nix @@ -95,6 +110,8 @@ jobs: uses: github/codeql-action/upload-sarif@ff2f1c621b7f889edc0d3c761ac2e6a3f8cdb0dd # v4.37.7 with: sarif_file: reports/actionlint.sarif + ref: ${{ inputs.candidate_ref && format('refs/tags/{0}', inputs.candidate_ref) || '' }} + sha: ${{ inputs.candidate_ref && steps.checkout.outputs.commit || '' }} category: actionlint - name: Upload Actionlint report @@ -109,14 +126,16 @@ jobs: retention-days: 14 zizmor: - name: Zizmor High report (informational) + name: ${{ inputs.fail-on-findings && 'Zizmor High report' || 'Zizmor High report (informational)' }} runs-on: ubuntu-latest permissions: contents: read security-events: write steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + id: checkout with: + ref: ${{ inputs.candidate_ref && format('refs/tags/{0}', inputs.candidate_ref) || '' }} persist-credentials: false - name: Set up Nix @@ -125,6 +144,9 @@ jobs: cachix-auth-token: ${{ github.event_name != 'pull_request' && secrets.CACHIX_AUTH_TOKEN || '' }} - name: Run Zizmor + id: findings + env: + FAIL_ON_FINDINGS: ${{ inputs.fail-on-findings || false }} run: | set -euo pipefail mkdir -p reports @@ -145,7 +167,10 @@ jobs: --format=sarif \ . > reports/zizmor-high.sarif - finding_count=$(jq 'length' reports/zizmor-high.json) + finding_count=$(jq ' + [.[] | select(.ignored != true and .determinations.severity == "High")] | length + ' reports/zizmor-high.json) + echo "high_count=$finding_count" >> "$GITHUB_OUTPUT" { echo "### Zizmor high-severity report" echo @@ -158,12 +183,12 @@ jobs: 'group_by(.ident) | .[] | "- `\(.[0].ident)`: \(length)"' \ reports/zizmor-high.json echo - echo "These findings are informational and do not fail CI." + echo "Fail on HIGH findings: $FAIL_ON_FINDINGS" fi } >> "$GITHUB_STEP_SUMMARY" if [ "$finding_count" -gt 0 ]; then - echo "::warning::Zizmor reported $finding_count high-severity findings; this check is informational." + echo "::warning::Zizmor reported $finding_count high-severity findings." fi - name: Upload Zizmor SARIF to Code Scanning @@ -171,6 +196,8 @@ jobs: uses: github/codeql-action/upload-sarif@ff2f1c621b7f889edc0d3c761ac2e6a3f8cdb0dd # v4.37.7 with: sarif_file: reports/zizmor-high.sarif + ref: ${{ inputs.candidate_ref && format('refs/tags/{0}', inputs.candidate_ref) || '' }} + sha: ${{ inputs.candidate_ref && steps.checkout.outputs.commit || '' }} category: zizmor-high - name: Upload Zizmor reports @@ -183,3 +210,17 @@ jobs: reports/zizmor-high.sarif if-no-files-found: ignore retention-days: 14 + + - name: Enforce HIGH/CRITICAL threshold + if: ${{ !cancelled() && steps.findings.outcome == 'success' }} + env: + HIGH_COUNT: ${{ steps.findings.outputs.high_count }} + FAIL_ON_FINDINGS: ${{ inputs.fail-on-findings || false }} + run: | + if [ "$HIGH_COUNT" -gt 0 ]; then + if [ "$FAIL_ON_FINDINGS" = "true" ]; then + echo "::error::Zizmor reported $HIGH_COUNT HIGH findings." + exit 1 + fi + echo "::warning::Zizmor reported $HIGH_COUNT HIGH findings; enforcement is disabled." + fi diff --git a/CI.md b/CI.md index 4838595cc5..0756e289a9 100644 --- a/CI.md +++ b/CI.md @@ -87,12 +87,93 @@ nix develop --command actionlint -shellcheck= -pyflakes= nix develop --command zizmor --offline --persona=regular --min-severity=high --no-exit-codes . ``` +## Run the security scans together + +`Security Scan` (`.github/workflows/security-scan.yml`) calls Codex Security, +CodeQL, Trivy, Cargo Deny, and Workflow Security Reports (Actionlint/Zizmor) in +parallel. Run it manually from Actions or call it from another workflow. All +children scan `candidate_ref`, which must be an existing `vX.Y.Z-pre.N` tag +because Codex qualifies pre-releases. Codex compares it with the previous stable; +the other scanners analyze the candidate snapshot. Cargo Deny uses its existing +NVIDIA self-hosted runner and CI container. + +```shell +gh workflow run security-scan.yml --ref main \ + -f candidate_ref=v0.1.1-pre.1 \ + -F allow-high-critical=true +``` + +To integrate it into a larger workflow, run it after the job that pushes the +candidate tag and publishes the artifacts. This example assumes an existing +`build` job with outputs named `candidate_tag`, `gateway_image`, `sandbox_image`, +and `chart_ref`; adapt those names to your workflow: + +```yaml +jobs: + security: + needs: build + uses: ./.github/workflows/security-scan.yml + permissions: + actions: read + contents: read + packages: read + security-events: write + with: + candidate_ref: ${{ needs.build.outputs.candidate_tag }} + stable_ref: v0.1.0 # Optional; otherwise resolved automatically. + images: | + ${{ needs.build.outputs.gateway_image }} + ${{ needs.build.outputs.sandbox_image }} + charts: ${{ needs.build.outputs.chart_ref }} + allow-high-critical: false + secrets: + CODEX_SECURITY_API_KEY: ${{ secrets.CODEX_SECURITY_API_KEY }} + CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }} +``` + +Set `needs: security` on a downstream promotion job to require successful scans. + +`CODEX_SECURITY_API_KEY` is required; `CACHIX_AUTH_TOKEN` is optional. The parent +publishes SARIF, including Codex results for manual parent runs. Codex keeps its +release-train category on `main`; CodeQL, Trivy, and workflow reports publish +against the candidate tag and commit. Existing standalone triggers stay active. + +The parent fails on HIGH/CRITICAL findings from Codex, CodeQL, Trivy, and Zizmor. +Set `allow-high-critical: true` to report those findings without failing; it +defaults to `false`. Scanner setup, execution, and report publication errors +still fail. Reports are published before the finding threshold is enforced. + +Codex uses each finding's severity; CodeQL uses the rule's security score +(at least 7.0); Trivy uses `HIGH,CRITICAL`, including vulnerabilities without an +upstream fix; Zizmor uses its High severity. Actionlint remains informational. +Existing scanner exceptions still apply. + +Cargo Deny runs only `cargo deny check advisories` in the parent. It keeps its +native failure behavior and configured exceptions, regardless of +`allow-high-critical`; it has no HIGH/CRITICAL filter. Its standalone runs still +check all dependency policies. + +Codex scans the cumulative diff from `stable_ref` to `candidate_ref`. Both inputs +are tag names, not arbitrary commit SHAs. Omit `stable_ref` to resolve the previous +stable automatically; set `allow_full_bootstrap: true` to permit a full scan when +no previous stable exists. + +Trivy accepts optional `images` and `charts`, one reference per line. Images can +use tags or digests, such as `ghcr.io/nvidia/openshell/gateway:0.1.1-pre.1` or +`ghcr.io/nvidia/openshell/gateway@sha256:`. Charts use versioned OCI +references, such as `oci://ghcr.io/nvidia/openshell/helm-chart:0.1.1-pre.1`. +Artifacts must already be published and accessible to the workflow. The caller +selects artifacts matching the candidate; the workflow does not verify that +association. Without artifact inputs, Trivy scans only the candidate's deployment +configuration. +Dependency Review and Trivy Changes keep their separate comparison workflows. + ## Artifact scanning `Trivy Scan` is a self-contained `workflow_dispatch`/`workflow_call` step. It always scans deployment configuration and optionally scans supplied OCI image -and chart references. It is not wired into a release workflow; a future analysis -orchestrator can call it directly. +and chart references. `Security Scan` calls it alongside the other independent +scanners; release workflows can also call it directly. The scan job checks static deployment files (including Dockerfiles) once, both local charts with default values, the OpenShell `HELM_PROFILES` selected in diff --git a/architecture/build.md b/architecture/build.md index d6ad9914a9..112e5e66c4 100644 --- a/architecture/build.md +++ b/architecture/build.md @@ -367,12 +367,32 @@ Triggers differ by workflow: `.github/workflows/workflow-security.yml` runs on `.github/workflows/codeql.yml` runs nightly on the default branch (`main`) via `schedule`, with `workflow_dispatch` kept for manual diagnostics; and `.github/workflows/codex-security.yml` runs on pushed `v*.*.*-pre.*` tags, and is -also callable through `workflow_call` and `workflow_dispatch`. CodeQL does -not run on `pull_request`, `merge_group`, or pushes to `main`, so it reports +also callable through `workflow_call` and `workflow_dispatch`. CodeQL has no +automatic `pull_request`, `merge_group`, or push trigger, so it reports repository-level Code Scanning state on the default branch instead of per-PR results, and its four-language matrix stays off the per-change critical path. Codex Security is release-scoped rather than change-scoped, so it never runs on -a pull request or merge group. +a pull request or merge group automatically. + +`.github/workflows/security-scan.yml` is a manual and reusable parent for Codex +Security, CodeQL, Trivy, Cargo Deny, and Actionlint/Zizmor. Each child runs +independently against the supplied pre-release tag; Codex retains its cumulative +stable-to-candidate range. The parent forwards OCI references to Trivy and +publishes SARIF, including Codex results on manual parent runs. Codex publishes +against the candidate commit on `main`; the other SARIF producers use the +candidate tag and commit. Cargo Deny retains its self-hosted runner and CI +container. Dependency Review and Trivy Changes remain separate comparison +workflows. Existing standalone triggers remain active. + +The parent enforces HIGH/CRITICAL findings for Codex, CodeQL, Trivy, and Zizmor. +Its `allow-high-critical` input disables that threshold while keeping execution +and publication failures fatal. Each scanner evaluates its existing report +after publication. Actionlint stays informational; Cargo Deny runs its native +advisory check, which is independent of the severity override. Standalone +finding policies are unchanged. Child concurrency groups distinguish the +scanner as well as the caller, so sibling workflows cannot cancel one another. +Codex retains its repository-wide release qualification group. +See [CI.md](../CI.md#run-the-security-scans-together) for invocation examples. - **Actionlint and Zizmor** analyze the workflow definitions themselves. Repository configuration lives in `.github/actionlint.yml` (self-hosted runner @@ -395,8 +415,8 @@ a pull request or merge group. integration targets the cfg override does not reach. Examples remain in scope, and E2E test code stays excluded because `e2e/` is not an analyzed path. Only Go requires a build; the other languages use build mode `none`. Analysis runs - on the nightly schedule or by manual dispatch. Results are uploaded to Code - Scanning and always retained as workflow artifacts. + on the nightly schedule, by manual dispatch, or through `workflow_call`. + Results are uploaded to Code Scanning and always retained as workflow artifacts. - **Codex Security** qualifies release candidates rather than individual changes. The job installs a pinned `@openai/codex-security` release into the runner temp directory before the repository is checked out and invokes it by @@ -462,7 +482,9 @@ a pull request or merge group. `CODEX_SECURITY_STATE_DIR`, where every shell command the agent ran is recorded. No command at all is the signal that the sandbox failed to start. -Findings never fail these checks; scanner and build failures do. A scanner that +Findings do not fail standalone informational runs; reusable callers can enable +HIGH/CRITICAL enforcement with `fail-on-findings`. Scanner and build failures +always fail. A scanner that cannot run, a CodeQL analyzer that does not complete, an unexpected Dependency Graph API error, and a Codex Security range, scan, or export failure are all errors, which keeps an informational check from silently degrading into a no-op. From 9b4b63ec693ceda9f682c699c3329616e33d46d6 Mon Sep 17 00:00:00 2001 From: alangou Date: Fri, 11 Sep 2026 10:45:29 +0000 Subject: [PATCH 3/4] fix(deps): update DOMPurify and runtime image packages (#3276) Signed-off-by: Adrien Langou --- architecture/build.md | 5 ++++- deploy/docker/Dockerfile.gateway | 2 +- deploy/docker/Dockerfile.supervisor | 4 +++- scripts/lint-mermaid/package-lock.json | 7 +++---- scripts/lint-mermaid/package.json | 2 +- skills/debug-openshell-cluster/SKILL.md | 7 +++++++ 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/architecture/build.md b/architecture/build.md index 112e5e66c4..c2798c428b 100644 --- a/architecture/build.md +++ b/architecture/build.md @@ -219,6 +219,8 @@ Runtime layout: gateway binaries must not reference `GLIBC_*` symbols newer than `GLIBC_2.28`; release workflows verify this before publishing artifacts. The gateway bundles z3, so the image does not need a distro-provided z3 runtime. + The base is pinned to a multi-architecture digest; distro security updates + require refreshing that digest and rebuilding the gateway image. - **VM driver**: host GNU-linked binary installed at `/usr/libexec/openshell/openshell-driver-vm` in Linux packages and published as a release artifact. Linux GNU VM driver binaries must not reference @@ -229,7 +231,8 @@ Runtime layout: cache action runs. An explicitly configured VM runtime bundle is required to contain every non-empty embedding input; the driver build fails before packaging when an input is absent or empty. -- **Supervisor**: Alpine base with `nftables`, static binary at +- **Supervisor**: Alpine base with `nftables`; base packages are upgraded before + installing firewall tools to pick up distro security fixes. Static binary at `/openshell-sandbox` (musl by default; see `SUPERVISOR_LIBC` above). Static linkage keeps the binary usable when the image is mounted/extracted into sandbox environments (Docker extraction, Podman image volumes, Kubernetes diff --git a/deploy/docker/Dockerfile.gateway b/deploy/docker/Dockerfile.gateway index cf68dc967a..52f2b27db3 100644 --- a/deploy/docker/Dockerfile.gateway +++ b/deploy/docker/Dockerfile.gateway @@ -8,7 +8,7 @@ # # Distroless Debian provides the glibc runtime required by the binary. -ARG GATEWAY_BASE_IMAGE=gcr.io/distroless/cc-debian13:nonroot@sha256:d97bc0a941b8d4be647dc0ee75b264ddbb772f1ac5ba690a4309c00723b23775 +ARG GATEWAY_BASE_IMAGE=gcr.io/distroless/cc-debian13:nonroot@sha256:c31ff9abcb1910f3ab25c7957bdaf0bfe12a01eb546e8df2282f1c8f682b606c FROM ${GATEWAY_BASE_IMAGE} AS gateway ARG TARGETARCH diff --git a/deploy/docker/Dockerfile.supervisor b/deploy/docker/Dockerfile.supervisor index d515fd70b1..7e7342ccb3 100644 --- a/deploy/docker/Dockerfile.supervisor +++ b/deploy/docker/Dockerfile.supervisor @@ -12,7 +12,9 @@ FROM alpine:3.22 AS supervisor ARG TARGETARCH -RUN apk add --no-cache nftables iptables iptables-legacy +# Refresh base packages too: adding firewall tools does not upgrade OpenSSL. +RUN apk upgrade --no-cache \ + && apk add --no-cache nftables iptables iptables-legacy # Keep the binary root-owned for Podman image-volume mounts and executable by # the Kubernetes network sidecar's non-root proxy UID. diff --git a/scripts/lint-mermaid/package-lock.json b/scripts/lint-mermaid/package-lock.json index 1fa73b21e6..fcb8c01d19 100644 --- a/scripts/lint-mermaid/package-lock.json +++ b/scripts/lint-mermaid/package-lock.json @@ -1114,10 +1114,9 @@ } }, "node_modules/dompurify": { - "version": "3.4.12", - "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.4.12.tgz", - "integrity": "sha512-zQvGet8Z2sWbQhCmfFz/T5QWH2oBmjnqK3qvOjaqaNLrLEF912WamU+ohnTp0TCep/MFVHpdJuCZEdFOdTnEFg==", - "license": "(MPL-2.0 OR Apache-2.0)", + "version": "3.4.15", + "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.4.15.tgz", + "integrity": "sha512-EUBjM+B+lkDE41iE82DDSCfkoPGfXx8IxFxPMjNzm/Uk4xDet77rTN9wqlxlVg71kK7XGuUMv6wUxJUwwv+Xyw==", "optionalDependencies": { "@types/trusted-types": "^2.0.7" } diff --git a/scripts/lint-mermaid/package.json b/scripts/lint-mermaid/package.json index a8c3aa2025..271bb08043 100644 --- a/scripts/lint-mermaid/package.json +++ b/scripts/lint-mermaid/package.json @@ -9,6 +9,6 @@ "mermaid": "^11.4.0" }, "overrides": { - "dompurify": "3.4.12" + "dompurify": "3.4.15" } } diff --git a/skills/debug-openshell-cluster/SKILL.md b/skills/debug-openshell-cluster/SKILL.md index 01943df044..360bf28ee4 100644 --- a/skills/debug-openshell-cluster/SKILL.md +++ b/skills/debug-openshell-cluster/SKILL.md @@ -456,6 +456,13 @@ helm -n openshell get values openshell | grep -E 'repository|tag|supervisorImage The gateway and supervisor images should use the same release tag. A stale supervisor image can make sandbox behavior lag behind gateway policy or protocol changes. +For vulnerability reports, record the running image digest and scan that exact +artifact. The gateway includes a pinned Distroless base; the supervisor includes +Alpine packages updated at image build time. A dependency or base-image fix only +reaches deployed containers after rebuilding, publishing, and redeploying the +images. Compare findings against the SBOM for that digest, not just its mutable +`latest` or `dev` tag. + For plaintext local evaluation, confirm the chart has: ```bash From d99f12a33be61a89de9d3a29a10a9c732f6cd47e Mon Sep 17 00:00:00 2001 From: alangou Date: Fri, 11 Sep 2026 10:55:52 +0000 Subject: [PATCH 4/4] fix(ci): align Trivy change detection and scan baselines (#3277) Signed-off-by: Adrien Langou --- .agents/skills/watch-github-actions/SKILL.md | 7 +++++++ .github/workflows/trivy-changes.yml | 18 +++++++++++++++++- CI.md | 13 ++++++++++--- architecture/build.md | 4 ++++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/.agents/skills/watch-github-actions/SKILL.md b/.agents/skills/watch-github-actions/SKILL.md index c9e2843311..5d926cc647 100644 --- a/.agents/skills/watch-github-actions/SKILL.md +++ b/.agents/skills/watch-github-actions/SKILL.md @@ -125,6 +125,13 @@ gh run list --json databaseId,status,headBranch,url --jq '.[] | {id: .databaseId ## View Job Logs +For `Trivy Changes`, inspect the `Resolve PR baseline` step for the base and head +SHAs. PR runs compare the tested merge commit with its +first parent; change detection and scans must use the same pair. On reruns, do +not substitute the current `main` tip or the event's older PR base SHA. Merge +groups and manual runs use their explicit baseline. Findings are reported by +`Reject new high or critical findings`; distinguish those from scanner failures. + View logs for a specific run: ```bash diff --git a/.github/workflows/trivy-changes.yml b/.github/workflows/trivy-changes.yml index 612ce891cc..15e9b7af33 100644 --- a/.github/workflows/trivy-changes.yml +++ b/.github/workflows/trivy-changes.yml @@ -34,6 +34,7 @@ jobs: pull-requests: read outputs: should_run: ${{ steps.default.outputs.should_run || steps.changed.outputs.any_modified }} + base_sha: ${{ steps.comparison.outputs.base_sha }} steps: - id: default if: github.event_name != 'pull_request' @@ -42,12 +43,27 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 if: github.event_name == 'pull_request' with: + ref: ${{ github.sha }} + # Include both parents of the exact PR merge commit, even on reruns. + fetch-depth: 2 persist-credentials: false + - name: Resolve PR baseline + id: comparison + if: github.event_name == 'pull_request' + run: | + git rev-parse --verify HEAD^2 >/dev/null + base_sha=$(git rev-parse --verify HEAD^1) + echo "base_sha=$base_sha" >> "$GITHUB_OUTPUT" + echo "Trivy comparison: $base_sha -> $(git rev-parse HEAD)" + - id: changed if: github.event_name == 'pull_request' uses: tj-actions/changed-files@aa08304bd477b800d468db44fe10f6c61f7f7b11 # v42.1.0 with: + base_sha: ${{ steps.comparison.outputs.base_sha }} + sha: ${{ github.sha }} + output_renamed_files_as_deleted_and_added: true # `any_modified` covers deletions, which `any_changed` omits, and a # failed diff has to fail the job: both otherwise report no relevant # change, and removing the scanner or a value fixture would skip the @@ -73,7 +89,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 30 env: - BASE_REF: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha || inputs.base_sha }} + BASE_REF: ${{ needs.changes.outputs.base_sha || github.event.merge_group.base_sha || inputs.base_sha }} HEAD_REF: ${{ inputs.head_sha || github.sha }} defaults: run: diff --git a/CI.md b/CI.md index 0756e289a9..692794e8ee 100644 --- a/CI.md +++ b/CI.md @@ -216,9 +216,16 @@ Use a fresh `TRIVY_REPORT_DIR` for each scan session. `prepare-sarif` creates ### Pull-request change gate -`Trivy Changes` scans the base and candidate when a pull request or merge group -changes deployment configuration or scanner inputs. It fails only for new -`HIGH` or `CRITICAL` misconfigurations and retains both report sets. +`Trivy Changes` scans the base and candidate when a pull request changes +deployment configuration or scanner inputs; merge groups and manual runs always +scan. It fails only for new `HIGH` or `CRITICAL` misconfigurations and retains +both report sets. + +For pull requests, change detection compares the exact tested merge commit with +its first parent. Both detection and scanning use that same pair. This excludes +unrelated changes on `main` even when the event carries an older base SHA or a +job is rerun. Merge groups use the event's base SHA; manual runs use the supplied +base and head. A missing revision or invalid PR merge checkout fails the gate. The candidate ignore file is validated, but the baseline policy applies to both scans so a change cannot exempt its own finding. Existing profiles are compared diff --git a/architecture/build.md b/architecture/build.md index c2798c428b..a5dcfe9241 100644 --- a/architecture/build.md +++ b/architecture/build.md @@ -519,6 +519,10 @@ references. Publication batches respect GitHub's limit of 20 SARIF runs. The PR/merge-group gate scans base and candidate with the same scanner and rejects new `HIGH` or `CRITICAL` configuration findings. Its stable `OpenShell / Trivy Changes` status succeeds when nothing relevant changed. +For PRs, the baseline is the first parent of the exact merge commit being tested, +not the event's potentially older base SHA or the current branch tip. Change +detection and both scans use that same immutable pair, including on reruns. +Merge groups and manual runs retain their explicit baseline and always scan. Image CVEs need the standalone scan. The reporting and gate invariants are: - A structurally invalid Trivy report is an error, not an empty finding set.