Skip to content
Draft
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
103 changes: 103 additions & 0 deletions .github/scripts/managed-image-scan-results.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";

type RecordValue = Record<string, unknown>;
function record(value: unknown): RecordValue {
if (!value || typeof value !== "object" || Array.isArray(value)) {
throw new Error("Invalid scan evidence.");
}
return value as RecordValue;
}

// Never include scanner-controlled text in an error or public summary.
export function scanPassed(kind: string, exitCode: number, source: string): boolean {
if (kind === "secrets") {
if (![0, 185, 189].includes(exitCode)) return false;
const results = source.split(/\r?\n/u).filter((line) => line.trim());
const verified = results.map((line) => {
const result = record(JSON.parse(line));
if (typeof result.Verified !== "boolean") throw new Error("Invalid scan evidence.");
return result.Verified;
});
// 189 means all findings were allowlisted by the repository's reviewed allowlist.
return exitCode === 189 || !verified.some(Boolean);
}
if (exitCode !== 0) return false;
const report = record(JSON.parse(source));
if (kind === "vulnerabilities") {
if (!Array.isArray(report.matches)) throw new Error("Invalid scan evidence.");
return report.matches.every((match) => {
const severity = record(record(match).vulnerability).severity;
if (typeof severity !== "string") throw new Error("Invalid scan evidence.");
return severity.toLowerCase() !== "critical";
});
}
if (kind === "malware") {
const data = record(report.data);
if (!Array.isArray(data.report)) throw new Error("Invalid scan evidence.");
return data.status === "CLEAN";
}
throw new Error("Unknown scan category.");
}

export function candidateReference(value: unknown, env: NodeJS.ProcessEnv): string {
const candidate = record(value);
const source = record(candidate.source);
const run = record(candidate.run);
const evidence = record(candidate.publicationEvidence);
const workload = record(evidence.workloadDescriptor);
const platform = record(workload.platform);
const digest = /^sha256:[0-9a-f]{64}$/u;
if (
candidate.contractVersion !== 2 ||
candidate.phase !== "candidate" ||
candidate.agent !== env.AGENT ||
candidate.platform !== env.PLATFORM ||
candidate.image !== env.IMAGE ||
typeof candidate.digest !== "string" ||
!digest.test(candidate.digest) ||
candidate.reference !== `${candidate.image}@${candidate.digest}` ||
source.repository !== "NVIDIA/NemoClaw" ||
source.repository !== env.GITHUB_REPOSITORY ||
source.revision !== env.GITHUB_SHA ||
source.ref !== "refs/heads/main" ||
env.GITHUB_REF !== "refs/heads/main" ||
env.GITHUB_EVENT_NAME !== "workflow_dispatch" ||
run.id !== Number(env.GITHUB_RUN_ID) ||
!Number.isSafeInteger(run.attempt) ||
Number(run.attempt) < 1 ||
Number(run.attempt) > Number(env.GITHUB_RUN_ATTEMPT) ||
typeof workload.digest !== "string" ||
!digest.test(workload.digest) ||
workload.mediaType !== "application/vnd.oci.image.manifest.v1+json" ||
`${platform.os}/${platform.architecture}` !== env.PLATFORM
) {
throw new Error("Candidate does not belong to this publication.");
}
// Scan the platform workload, not the OCI index containing its attestations.
return `${candidate.image}@${workload.digest}`;
}

if (process.argv[1] === fileURLToPath(import.meta.url)) {
try {
const [mode, ...args] = process.argv.slice(2);
if (mode === "candidate" && args.length === 1) {
process.stdout.write(
candidateReference(JSON.parse(readFileSync(args[0]!, "utf8")), process.env),
);
} else if (mode === "result" && args.length === 3) {
const code = Number(args[1]);
if (!Number.isSafeInteger(code) || code < 0 || code > 255)
throw new Error("Invalid exit code.");
process.exitCode = scanPassed(args[0]!, code, readFileSync(args[2]!, "utf8")) ? 0 : 1;
} else {
throw new Error("Invalid arguments.");
}
} catch {
console.error("Scan evidence is missing, invalid, or blocking.");
process.exitCode = 1;
}
}
80 changes: 80 additions & 0 deletions .github/scripts/scan-managed-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env bash
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

set -euo pipefail
umask 077

scan_root="${SCAN_ROOT:?Missing SCAN_ROOT}"
helper="$GITHUB_WORKSPACE/.github/scripts/managed-image-scan-results.mts"
prefix="managed-scan-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}-${AGENT}-${ARCH}"
failed=0

# Called by the EXIT trap, including scanner failures.
# shellcheck disable=SC2329
cleanup() {
local cleanup_failed=0 name
for name in grype secrets malware; do
docker rm --force "$prefix-$name" >/dev/null 2>&1 || true
if ! remaining="$(docker ps -aq --filter "name=^/$prefix-$name$")" || [ -n "$remaining" ]; then
cleanup_failed=1
fi
done
rm -rf "$scan_root"
if [ "$cleanup_failed" -ne 0 ]; then
echo "ERROR: Could not remove a scan container." >&2
exit 1
fi
}
trap cleanup EXIT

# Pull by workload digest. No candidate image is executed or given credentials.
reference="$(node "$helper" candidate "$CONTRACT")"
docker pull --platform "$PLATFORM" "$reference" >"$scan_root/pull.log" 2>&1
image_id="$(docker image inspect --format '{{.Id}}' "$reference")"
[[ "$image_id" =~ ^sha256:[0-9a-f]{64}$ ]]
docker save "$image_id" >"$scan_root/image.tar"

record_result() {
local category="$1" code="$2" path="$3" result=FAIL
if node "$helper" result "$category" "$code" "$path" >/dev/null 2>&1; then
result=PASS
else
failed=1
fi
# Only fixed category names and pass/fail reach the public job summary.
printf '| %s | %s |\n' "$category" "$result" >>"$GITHUB_STEP_SUMMARY"
}
printf '### Managed image security scans\n\n| Scan | Result |\n| --- | --- |\n' >>"$GITHUB_STEP_SUMMARY"

code=0
docker run --rm --name "$prefix-grype" --cap-drop=ALL --security-opt=no-new-privileges \
--volume "$scan_root/image.tar:/scan/image.tar:ro" \
"$GRYPE_IMAGE" docker-archive:/scan/image.tar --fail-on critical --output json \
>"$scan_root/vulnerabilities.json" 2>"$scan_root/grype.log" || code=$?
record_result vulnerabilities "$code" "$scan_root/vulnerabilities.json"

code=0
docker run --rm --name "$prefix-secrets" --cap-drop=ALL --security-opt=no-new-privileges \
--volume "$scan_root/image.tar:/scan/image.tar:ro" \
--volume "$GITHUB_WORKSPACE/.nspect-allowlist.toml:/allowlist.toml:ro" \
"$PULSE_SECRET_IMAGE" docker --image file:///scan/image.tar \
--allowlist=/allowlist.toml --json --results=verified,unknown --fail --fail-on-scan-errors \
>"$scan_root/secrets.jsonl" 2>"$scan_root/secrets.log" || code=$?
record_result secrets "$code" "$scan_root/secrets.jsonl"

# The approved scanner alone receives short-lived OIDC request credentials.
# Charon authorizes image submission and report retrieval for this repository/ref.
code=0
docker create --name "$prefix-malware" --network host \
--cap-drop=ALL --security-opt=no-new-privileges --workdir /tmp \
--env ACTIONS_ID_TOKEN_REQUEST_URL --env ACTIONS_ID_TOKEN_REQUEST_TOKEN \
--env CI=true --env GITHUB_ACTIONS=true \
"$PULSE_MALWARE_IMAGE" pulse-malware-scanner-cli \
--nspect "$NSPECT_ID" --tenant github-first --base-url http://127.0.0.1:8888 \
--output-dir=. --wait=true --wait-retries=50 --backoff-sec=2 --max-poll-wait-sec=60 \
image-scan --image-ref "$reference" --platform "$PLATFORM" >/dev/null
docker start --attach "$prefix-malware" >"$scan_root/malware.log" 2>&1 || code=$?
docker cp "$prefix-malware:/tmp/malware_report_1.json" "$scan_root/malware.json" >/dev/null 2>&1 || code=1
record_result malware "$code" "$scan_root/malware.json"
exit "$failed"
7 changes: 7 additions & 0 deletions .github/workflows/base-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ on:
- "scripts/lib/sandbox-rlimits.sh"
workflow_dispatch:
inputs:
run_security_scans:
description: "Scan managed images before promotion (requires Pulse onboarding)"
required: false
type: boolean
default: false
openclaw_version:
description: "OpenClaw version to install (leave blank to use the default in Dockerfile.base)"
required: false
Expand Down Expand Up @@ -448,8 +453,10 @@ jobs:
permissions:
contents: read
packages: write
id-token: write
uses: ./.github/workflows/managed-images.yaml
with:
run_security_scans: ${{ inputs.run_security_scans || false }}
dcode-base-contract-base64: ${{ needs.build-and-push-dcode.outputs.contract-base64 }}
hermes-base-contract-base64: ${{ needs.build-and-push-hermes.outputs.contract-base64 }}
openclaw-base-contract-base64: ${{ needs.build-and-push-openclaw.outputs.contract-base64 }}
Loading
Loading