diff --git a/.github/actions/ci-wechat-runtime-audit/audit.sh b/.github/actions/ci-wechat-runtime-audit/audit.sh index 783e316184a..44e4782f61c 100755 --- a/.github/actions/ci-wechat-runtime-audit/audit.sh +++ b/.github/actions/ci-wechat-runtime-audit/audit.sh @@ -249,11 +249,54 @@ fs.writeFileSync(process.env.PROVENANCE_PATH, `${JSON.stringify(provenance, null if (failure !== undefined) process.exitCode = 1; NODE +run_signature_audit() { + local attempt + local attempt_report + local command_status + local signature_attempt_limit=3 + local signature_report="$report_dir/npm-audit-signatures.txt" + local signature_debug_dir="$report_dir/npm-audit-signature-debug" + + : >"$signature_report" + for ((attempt = 1; attempt <= signature_attempt_limit; attempt += 1)); do + attempt_report="$report_dir/npm-audit-signatures-attempt-${attempt}.txt" + command_status=0 + npm --prefix "$runtime_dir" audit signatures \ + --userconfig "$trusted_npmrc" \ + --registry "$npm_registry" \ + --cache "$trusted_cache" \ + >"$attempt_report" 2>&1 || command_status=$? + { + printf 'attempt=%d status=%d\n' "$attempt" "$command_status" + cat "$attempt_report" + } >>"$signature_report" + + if ((command_status == 0)); then + return 0 + fi + + if [[ -d "$trusted_cache/_logs" ]]; then + mkdir -p "$signature_debug_dir" + cp -a "$trusted_cache/_logs/." "$signature_debug_dir/" + fi + + # Retry only when failed npm output contains the registry download marker. + # A failure without this marker stops further signature audit attempts. + if ! grep -Fq "npm error Failed to download" "$attempt_report"; then + return "$command_status" + fi + if ((attempt < signature_attempt_limit)); then + printf 'retrying transient signature download after attempt %d\n' "$attempt" \ + >>"$signature_report" + sleep 2 + fi + done + + return "$command_status" +} + signature_status=0 -npm --prefix "$runtime_dir" audit signatures \ - --userconfig "$trusted_npmrc" \ - --registry "$npm_registry" \ - >"$report_dir/npm-audit-signatures.txt" 2>&1 || signature_status=$? +run_signature_audit || signature_status=$? # Reproduce the sandbox-user npm-pack boundary with the exact reviewed archive. # The trusted source cache is read-only; only its short-lived copy is writable. diff --git a/agents/openclaw/dependency-review.md b/agents/openclaw/dependency-review.md index 2a41254e82f..364099cda06 100644 --- a/agents/openclaw/dependency-review.md +++ b/agents/openclaw/dependency-review.md @@ -31,10 +31,26 @@ The reviewed audit wrapper reports lower-severity production findings and blocks - Locked graph: `agents/openclaw/wechat-runtime/package-lock.json` (npm lockfile version 3). - Lock regeneration: `npm install --package-lock-only --legacy-peer-deps --ignore-scripts --omit=dev --prefix agents/openclaw/wechat-runtime`. - Installation boundary: the image materializes the reviewed lock into a root-owned dedicated npm cache and adds the exact package metadata needed by npm's offline resolver. Before that cache becomes immutable, the shared `scripts/lib/reviewed-npm-archive.mts` implementation re-packs every locked archive offline from the final cache and rejects registry-origin drift, metadata or packed-byte SRI drift, unsafe filenames, missing archives, and symlinks. The sandbox user copies that verified immutable source into a writable cache used for registry metadata lookup, archive packing, and the OpenClaw plugin install; no retrieval step falls back to `HOME/.npm`. The copy is deleted in the same image layer, and the trusted cache is never writable. The installer runs in offline, legacy-peer mode, then `verify-wechat-runtime-lock.mts` rejects integrity, version, dependency-set, or peer-range drift and refuses an image OpenClaw version below the plugin's locked peer minimum. -- Default CI gate: `wechat-runtime-audit` in `.github/workflows/pr.yaml` and `.github/workflows/main.yaml` invokes the reviewed `.github/actions/ci-wechat-runtime-audit` implementation. Pull requests resolve it from the base SHA. Because PR #6739's base predates the action, that PR alone may bootstrap the action from signed immutable commit `HOYALIM/NemoClaw@0d2256d71d5bbba3bcaaaa4d01714fa56f22d1e2`; every other PR fails closed if its base lacks the action. Main uses the merged action. The action uses Node `22.19.0` and npm `10.9.4`, materializes the committed graph with scripts disabled, fails on any low-or-higher production advisory, verifies registry signatures, uploads the JSON/text reports, and exercises the exact reviewed archive through a copied writable cache while the trusted source remains read-only. Removal condition: delete the PR #6739 bootstrap checkout, its paired conditional audit step, and the bootstrap-specific test assertions in the first follow-up after this PR merges, before the next release tag; all later PRs must use the normal base-SHA action path. +- Default CI gate: `wechat-runtime-audit` in `.github/workflows/pr.yaml` and `.github/workflows/main.yaml` invokes the reviewed `.github/actions/ci-wechat-runtime-audit` implementation. + The pull request workflow resolves the action from the PR base SHA. + Because PR #6739's base SHA predates the action, only that PR can use the pinned bootstrap action from signed immutable commit `HOYALIM/NemoClaw@0d2256d71d5bbba3bcaaaa4d01714fa56f22d1e2`. + Other PRs fail closed if their base lacks the action. + The `main.yaml` workflow uses the merged action. + The action uses Node `22.19.0` and npm `10.9.4`. + It materializes the committed graph with scripts disabled. + The action rejects any low-or-higher production advisory and verifies registry signatures. + The PR and main workflows upload the resulting reports. + It also exercises the reviewed archive through a copied writable cache while the trusted source remains read-only. + The action makes at most three `npm audit signatures` attempts. + It retries a failed attempt only when the output contains `npm error Failed to download`. + A failed attempt without this marker stops further attempts. + Any final nonzero status fails the action. + The report directory stores each attempt in `npm-audit-signatures-attempt-.txt`. + After a failed attempt, the action copies available npm debug logs to `npm-audit-signature-debug/`. + Removal condition: delete the PR #6739 bootstrap checkout, its paired conditional audit step, and the bootstrap-specific test assertions in the first follow-up after this PR merges, before the next release tag; all later PRs must use the normal base-SHA action path. - Advisory command: `npm ci --ignore-scripts --omit=dev --legacy-peer-deps --prefix agents/openclaw/wechat-runtime && npm audit --omit=dev --audit-level=low --json --prefix agents/openclaw/wechat-runtime && npm audit signatures --prefix agents/openclaw/wechat-runtime`. - Advisory review: `2026-07-12`; result: `0` known vulnerabilities across the resolved production graph. -- Regression tests: `test/wechat-locked-install.test.ts` keeps the manifest runtime-lock paths and installer verification dispatch synchronized; `test/verify-wechat-runtime-lock.test.ts` proves the installed graph and OpenClaw peer-range compatibility fail closed; `test/wechat-runtime-audit-workflow.test.ts` keeps the Docker cache lifecycle, base-trusted required CI gate, evidence upload, audit threshold, signature verification, and real npm-pack boundary synchronized. +- Regression tests: `test/wechat-locked-install.test.ts` keeps the manifest runtime-lock paths and installer verification dispatch synchronized; `test/verify-wechat-runtime-lock.test.ts` proves the installed graph and OpenClaw peer-range compatibility fail closed; `test/wechat-runtime-audit-workflow.test.ts` keeps the Docker cache lifecycle, base-trusted required CI gate, evidence upload, audit threshold, bounded download-only signature retry, invalid-signature denial, and real npm-pack boundary synchronized. The dedicated graph intentionally omits the plugin's `openclaw` peer dependency. The image already installs and integrity-verifies the reviewed OpenClaw runtime separately; auto-installing another OpenClaw copy would create a second unreviewed runtime graph. Disabling scripts also prevents transitive packages from executing lifecycle code during the trusted image build. diff --git a/test/wechat-runtime-audit-workflow.test.ts b/test/wechat-runtime-audit-workflow.test.ts index 0db36cb7ee8..5dd025950db 100644 --- a/test/wechat-runtime-audit-workflow.test.ts +++ b/test/wechat-runtime-audit-workflow.test.ts @@ -68,11 +68,24 @@ function runAuditValidation( "wechat-runtime-audit", "npm-audit.provenance.json", ); + const reportDir = path.join(targetRoot, "artifacts", "wechat-runtime-audit"); + const signatureReportPath = path.join(reportDir, "npm-audit-signatures.txt"); + const signatureCounterPath = path.join(targetRoot, "signature-attempt-count"); + const signatureDebugDir = path.join(reportDir, "npm-audit-signature-debug"); return { ...result, provenance: fs.existsSync(provenancePath) ? (JSON.parse(fs.readFileSync(provenancePath, "utf8")) as Record) : undefined, + signatureAttemptCount: fs.existsSync(signatureCounterPath) + ? Number(fs.readFileSync(signatureCounterPath, "utf8")) + : 0, + signatureDebugFiles: fs.existsSync(signatureDebugDir) + ? fs.readdirSync(signatureDebugDir).sort() + : [], + signatureReport: fs.existsSync(signatureReportPath) + ? fs.readFileSync(signatureReportPath, "utf8") + : "", }; } finally { fs.rmSync(targetRoot, { force: true, recursive: true }); @@ -83,27 +96,64 @@ function installFakeAuditNpm( targetRoot: string, auditOutput: Record | string, auditStatus: number, + signatureAttempts: readonly { readonly output: string; readonly status: number }[] = [ + { output: "verified signatures", status: 0 }, + ], ): void { const binDir = path.join(targetRoot, "bin"); fs.mkdirSync(binDir, { recursive: true }); const npm = path.join(binDir, "npm"); + const packageLock = JSON.parse( + fs.readFileSync( + path.join(targetRoot, "agents", "openclaw", "wechat-runtime", "package-lock.json"), + "utf8", + ), + ); + const expectedIntegrity = + packageLock.packages["node_modules/@tencent-weixin/openclaw-weixin"].integrity; fs.writeFileSync( npm, [ "#!/usr/bin/env node", + 'const fs = require("node:fs");', + 'const path = require("node:path");', `const auditReport = ${JSON.stringify( typeof auditOutput === "string" ? auditOutput : JSON.stringify(auditOutput), )};`, `const auditStatus = ${auditStatus};`, + `const expectedIntegrity = ${JSON.stringify(expectedIntegrity)};`, + `const signatureAttempts = ${JSON.stringify(signatureAttempts)};`, + `const signatureCounterPath = ${JSON.stringify(path.join(targetRoot, "signature-attempt-count"))};`, "const args = process.argv.slice(2);", 'if (args[0] === "--version") {', ' console.log("10.9.4");', " process.exit(0);", "}", + 'if (args.includes("audit") && args.includes("signatures")) {', + ' const attempt = fs.existsSync(signatureCounterPath) ? Number(fs.readFileSync(signatureCounterPath, "utf8")) + 1 : 1;', + " fs.writeFileSync(signatureCounterPath, String(attempt));", + " const selected = signatureAttempts[Math.min(attempt - 1, signatureAttempts.length - 1)];", + ' const cacheIndex = args.indexOf("--cache");', + " if (cacheIndex >= 0) {", + ' const logDir = path.join(args[cacheIndex + 1], "_logs");', + " fs.mkdirSync(logDir, { recursive: true });", + ' fs.writeFileSync(path.join(logDir, \"signature-attempt-\" + attempt + \".log\"), selected.output + \"\\\\n\");', + " }", + " console.error(selected.output);", + " process.exit(selected.status);", + "}", 'if (args.includes("audit")) {', " console.log(auditReport);", " process.exit(auditStatus);", "}", + 'if (args[0] === "pack") {', + ' const destination = args[args.indexOf("--pack-destination") + 1];', + ' const filename = "wechat-runtime-test.tgz";', + " fs.mkdirSync(destination, { recursive: true });", + ' fs.writeFileSync(path.join(destination, filename), "test archive");', + " console.log(JSON.stringify([{ filename, integrity: expectedIntegrity }]));", + " process.exit(0);", + "}", "process.exit(0);", "", ].join("\n"), @@ -279,12 +329,65 @@ describe("WeChat runtime audit and install-cache gates (#5896)", () => { }); expect(result.status).not.toBe(0); - expect(result.provenance).toMatchObject({ + expect(result.provenance, result.stderr).toMatchObject({ failure: expect.stringMatching(expectedFailure), rawReportPath: "npm-audit.json", }); }); + it("retries signature download failures and succeeds on the third attempt", () => { + const result = runAuditValidation(({ targetRoot }) => { + installFakeAuditNpm( + targetRoot, + { + vulnerabilities: {}, + metadata: { + vulnerabilities: { info: 0, low: 0, moderate: 0, high: 0, critical: 0 }, + }, + }, + 0, + [ + { output: "npm error Failed to download", status: 1 }, + { output: "npm error Failed to download", status: 1 }, + { output: "verified signatures", status: 0 }, + ], + ); + }); + + expect(result.status, result.stderr).toBe(0); + expect(result.signatureAttemptCount, result.stderr).toBe(3); + expect(result.signatureDebugFiles).toEqual([ + "signature-attempt-1.log", + "signature-attempt-2.log", + ]); + expect(result.signatureReport).toContain("retrying transient signature download"); + expect(result.signatureReport).toContain("attempt=3 status=0"); + }); + + it("does not retry an invalid signature result", () => { + const result = runAuditValidation(({ targetRoot }) => { + installFakeAuditNpm( + targetRoot, + { + vulnerabilities: {}, + metadata: { + vulnerabilities: { info: 0, low: 0, moderate: 0, high: 0, critical: 0 }, + }, + }, + 0, + [ + { output: "npm error Invalid registry signature", status: 1 }, + { output: "verified signatures", status: 0 }, + ], + ); + }); + + expect(result.status).not.toBe(0); + expect(result.signatureAttemptCount, result.stderr).toBe(1); + expect(result.signatureDebugFiles).toEqual(["signature-attempt-1.log"]); + expect(result.signatureReport).not.toContain("retrying transient signature download"); + }); + it("keeps the image cache trusted and deletes the sandbox-writable copy", () => { const dockerfile = fs.readFileSync(path.join(repoRoot, "Dockerfile"), "utf8"); for (const fragment of [ diff --git a/tools/e2e/cli-artifact-workflow-boundary.mts b/tools/e2e/cli-artifact-workflow-boundary.mts index 6f84612892b..f2e1aa07a11 100644 --- a/tools/e2e/cli-artifact-workflow-boundary.mts +++ b/tools/e2e/cli-artifact-workflow-boundary.mts @@ -40,7 +40,7 @@ const CLI_ARTIFACT_PROVENANCE_STEP = "Record CLI artifact provenance"; const CANDIDATE_CHECKOUT_STEP_CONTENT_SHA256 = "3578a053cede863f7aa4814d8399b4ca21ea0b77cee712e6d549c684818f11dd"; const CLI_ARTIFACT_WORKFLOW_CONTRACT_SHA256 = - "a6e5816e8033eed53f43a384474f84e51057af131c90c369a1fccc066828419a"; + "14fb4de8dffd0cfd3f0dd3177f03e806c8912247bac4f5919a570c0f6b4c0ca2"; const CLI_ARTIFACT_CONSUMER_JOB_NAMES = [ "agent-turn-latency", "bedrock-runtime-compatible-anthropic",