Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 171 additions & 7 deletions .github/workflows/security-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
#
# SPDX-License-Identifier: Apache-2.0
#
# CI security scanning via the NVIDIA/security-workflows suite: Pulse secret scan + CodeQL SAST.
# CI security scanning via the NVIDIA/security-workflows suite: Pulse secret scan,
# Pulse OSS vulnerability scan (SCA), Pulse malware scan, and CodeQL SAST.
# Pulse runs on Linux nv-gha-runners (Docker image + OIDC/Vault) — Linux-only by design.
# The local secret-scan-trufflehog pre-commit hook is cross-platform (Linux/macOS/Windows).
# Pinned to a reviewed commit SHA.
# Pinned by commit SHA to the security-workflows v0.6.0 release.

name: Security Suite (Pulse + CodeQL)
name: Security Suite (Secret, Vulnerability, Malware, SAST)

on:
push:
Expand All @@ -29,16 +30,162 @@ permissions:
actions: read

jobs:
# On main the vulnerability scan inspects installed wheels: Detect cannot resolve
# cuda_core's CUDA-dependent build or cuda_python's dynamic setup.py from source.
# Wheel mode is refused on pull-request/* mirrors. Python 3.12 matches the scanner image.
# The same path-based detection as ci.yml decides what to build: a push that changes no
# package skips the wheel scan, and unchanged packages reuse wheels from the latest main CI run.
wheel-plan:
name: Plan wheels for the vulnerability scan
if: >-
github.ref == 'refs/heads/main' &&
(github.repository == 'NVIDIA/cuda-python' ||
vars.CI_CUSTOMIZATIONS_SECURITY_SUITE_ENABLED == 'true')
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
outputs:
scan: ${{ steps.plan.outputs.scan }}
workplan: ${{ steps.plan.outputs.workplan }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
filter: blob:none
- uses: ./.github/actions/setup-hardened-python
with:
python-version: "3.11"
- name: Install CI tools
run: python3 -m pip install -e ./ci
- name: Resolve the previous commit and reusable wheels
id: baseline
env:
BEFORE: ${{ github.event_name == 'push' && github.event.before || '' }}
GH_TOKEN: ${{ github.token }}
run: |
set -uo pipefail
# A manual run, a new branch or a rewritten history has no previous commit to diff.
if [[ "$BEFORE" =~ ^[0-9a-f]{40}$ && ! "$BEFORE" =~ ^0+$ ]] \
&& git merge-base --is-ancestor "$BEFORE" HEAD 2>/dev/null; then
echo "previous=${BEFORE}" >> "$GITHUB_OUTPUT"
fi
# main CI runs are often cancelled by newer pushes, so reuse the latest successful one
# this commit descends from, with the complete artifact set ci.yml itself requires.
runs=$(gh run list --repo "$GITHUB_REPOSITORY" --branch main --event push --workflow ci.yml \
--status success --limit 10 --json databaseId,headSha --jq '.[] | "\(.databaseId) \(.headSha)"') || exit 0
while read -r run_id sha; do
[[ -n "$run_id" ]] && git merge-base --is-ancestor "$sha" HEAD 2>/dev/null || continue
names=$(gh api "repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}/artifacts?per_page=100" \
--paginate --jq '.artifacts[] | select(.expired == false) | .name') || continue
expected=$(python3 -m ci.tools.ci_artifacts --baseline-sha "$sha") || continue
complete=true
while IFS= read -r name; do
grep -Fxq "$name" <<< "$names" || { complete=false; break; }
done <<< "$expected"
if [[ "$complete" == true ]]; then
printf 'baseline_sha=%s\nrun_id=%s\n' "$sha" "$run_id" >> "$GITHUB_OUTPUT"
break
fi
done <<< "$runs"
- name: Compute the linux-64 Python 3.12 workplan
id: plan
env:
PREVIOUS: ${{ steps.baseline.outputs.previous }}
BASELINE_SHA: ${{ steps.baseline.outputs.baseline_sha }}
BASELINE_RUN: ${{ steps.baseline.outputs.run_id }}
run: |
set -euo pipefail
plan() {
local output
output="$(mktemp)"
GITHUB_OUTPUT="$output" MERGE_BASE="$1" BASELINE_RUN_ID="$2" RELEASE_TAG= \
python3 -m ci.tools.compute_ci_plan >/dev/null
sed -n 's/^workplan=//p' "$output"
}
# Without a baseline the planner builds everything, so ask what changed separately.
changed='{}'
if [[ -n "$PREVIOUS" ]]; then
changed="$(plan "$PREVIOUS" path-detection)"
fi
# Build what changed since the reusable wheels; with none, build everything.
workplan="$(plan "$BASELINE_SHA" "$BASELINE_RUN")"
CHANGED="$changed" WORKPLAN="$workplan" python3 - <<'PY'
import json
import os

changed = json.loads(os.environ["CHANGED"])
plan = json.loads(os.environ["WORKPLAN"])
# A push that changes no package has no new dependencies to scan.
scan = not changed or any(module["needs_build"] for module in changed["modules"].values())
plan["jobs"]["wheel_python_versions"] = {"linux-64": ["3.12"]}
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as output:
output.write(f"scan={'true' if scan else 'false'}\n")
output.write(f"workplan={json.dumps(plan, separators=(',', ':'))}\n")
PY

build-wheels:
name: Build wheels for the vulnerability scan
needs: wheel-plan
if: needs.wheel-plan.outputs.scan == 'true'
permissions:
actions: read
contents: read
secrets: inherit
uses: ./.github/workflows/build-wheel.yml
with:
host-platform: linux-64
workplan: ${{ needs.wheel-plan.outputs.workplan }}
single-cuda-major: true
Comment on lines +127 to +139

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems more complex than necessary. What is the reason to build a wheel here, instead of just adding a job in ci.yml that waits for a wheel build to finish and then download it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The said job can invoke this workflow, and everything you do below can be used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same suggestion, and I did try it — ci.yml calling this workflow after
build-linux-64, keeping everything below line 88. The wiring is fine; the
wheels aren't.

ci.yml's matrix is sharded, so no single run has a complete set for one
interpreter. A recent main run had bindings for 3.12/cu12.9.1 and for
3.14t + 3.15t/cu13.5.0, and core for 3.15 — so 3.12 has bindings but no core,
3.15 the reverse. cuda-* also matches 38 artifacts there, including win-64
and aarch64, so pip download fails on the first incompatible wheel.

Pulse installs offline and needs one coherent set: one interpreter, one CUDA
major, all runtime deps. Reusing ci.yml's wheels would mean forcing it to
always build a complete 3.12 set — the same work, moved onto everyone's
critical path.

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.

Having to rebuild all of our wheels in every PR doesn't feel like the right approach. We have path based detections to determine if something changed that warrants a rebuild where the security scans should be able to reuse that same logic and only scan what is built since it was the only thing changed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed — updated to reuse ci.yml's logic.
To clarify, the wheel build never ran on PRs (it is main-only), but it did rebuild everything on every main push. Now wheel-plan runs compute_ci_plan against the previous push: if no package changed, the wheel build and the main vulnerability scan are skipped; otherwise only the changed packages are built and the rest are reused from the latest successful main CI run with a complete artifact set (checked with ci.tools.ci_artifacts), falling back to a full build like ci.yml does. Secret, malware and CodeQL still run on every push.


# The scan installs offline, so the artifact carries every runtime dependency wheel too.
python-wheels:
name: Collect runtime wheels for the vulnerability scan
needs: build-wheels
runs-on: linux-amd64-cpu8
permissions:
contents: read
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: cuda-*
path: built
merge-multiple: true
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: "3.12"
- name: Add runtime dependency wheels
run: |
set -euo pipefail
mkdir wheelhouse
cp built/*.whl wheelhouse/
python -m pip download --only-binary=:all: --dest wheelhouse wheelhouse/*.whl
Comment thread
gmanal marked this conversation as resolved.
Resolved
ls wheelhouse
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: python-wheels
path: wheelhouse/*.whl
if-no-files-found: error

security-suite:
name: Security Suite
# Repository-specific workflow opt-ins use CI_CUSTOMIZATIONS_* Actions variables;
# see ci/README.md. Enable this only after the security-suite prerequisites exist.
needs: python-wheels
# Repository-specific workflow opt-ins use CI_CUSTOMIZATIONS_* Actions variables.
# Enable this only after the security-suite prerequisites exist.
# Runs whether or not wheels were built, so secret, malware and SAST cover every push.
if: >-
github.repository == 'NVIDIA/cuda-python' ||
vars.CI_CUSTOMIZATIONS_SECURITY_SUITE_ENABLED == 'true'
!cancelled() &&
(github.repository == 'NVIDIA/cuda-python' ||
vars.CI_CUSTOMIZATIONS_SECURITY_SUITE_ENABLED == 'true')
uses: NVIDIA/security-workflows/.github/workflows/security-suite.yml@d8189f3176942de7ffe2c48bcd7bb5fbdee2dd15 # v0.6.0
with:
enable-secret-scan: true
# The vulnerability and malware scans use a Charon tenant that authorizes only these refs.
# On main the vulnerability scan runs only when this push built wheels to inspect.
enable-vuln-scan: >-
${{ startsWith(github.ref, 'refs/heads/pull-request/') ||
(github.ref == 'refs/heads/main' && needs.python-wheels.result == 'success') }}
enable-malware-scan: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/pull-request/') }}
enable-sast-scan: true
secret-runs-on: linux-amd64-cpu4
# Set failure_policy explicitly so enforcement can't drift with upstream defaults.
Expand All @@ -48,3 +195,20 @@ jobs:
secret-failure-policy: unverified
# Same analysis the retired codeql.yml performed: python, build-mode none, security-extended.
sast-languages: '["python"]'
# NSPECT_ID must be an Actions *variable*: a reusable workflow's inputs cannot read secrets.
# Empty fails the suite preflight rather than reporting to the wrong nSpect program.
nspect-id: ${{ vars.NSPECT_ID }}
vuln-runs-on: linux-amd64-cpu4
vuln-python-wheels-artifact: ${{ needs.python-wheels.result == 'success' && 'python-wheels' || '' }}
vuln-python-project: ${{ needs.python-wheels.result == 'success' && 'cuda-python' || '' }}
# Mirrors have no wheels, and Detect cannot resolve these two packages from source, so
# it skips them there. Their dependencies are covered by the wheel scan on main.
vuln-detect-properties: >-
${{ github.ref == 'refs/heads/main' && '{}' ||
'{"detect.excluded.directories": "cuda_core,cuda_python"}' }}
# report-only (default) — findings warn; fail-on-vulnerability — any finding fails. Errors always fail.
vuln-failure-policy: report-only
vuln-upload-report: true
malware-runs-on: linux-amd64-cpu4
# strict (default) — SUSPICIOUS fails too; malicious-only — it only warns. MALICIOUS always fails.
malware-failure-policy: strict
6 changes: 4 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ci:
autoupdate_branch: ''
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
autoupdate_schedule: quarterly
skip: [lychee, check-precommit-installed, secret-scan-trufflehog]
skip: [lychee, check-precommit-installed, secret-scan-trufflehog, guardwords-scan-code-scanning]
submodules: false

# Please update the rev: SHAs below with this command:
Expand All @@ -18,10 +18,12 @@ repos:
# Runs first so a leaked credential blocks the commit before any formatter runs.
# Self-installing: the hook downloads a pinned, checksum-verified trufflehog on
# first use (no manual install). Skipped on pre-commit.ci; Pulse CI enforces server-side.
# GuardWords needs NVIDIA's internal client and network; it skips with a notice elsewhere.
- repo: https://github.com/NVIDIA/security-workflows
rev: c736f0454dc99764a66af6b906adfcdfbf621985 # frozen: v0.4.0
rev: d8189f3176942de7ffe2c48bcd7bb5fbdee2dd15 # frozen: v0.6.0
hooks:
- id: secret-scan-trufflehog
- id: guardwords-scan-code-scanning

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 25bcf95026b96e2dd3c0aec3090c3d6ef6ca2e6c # frozen: v0.17.3
Expand Down
Loading