From 18b4a45c22aa066f6ad6d7e1a44499f14200614b Mon Sep 17 00:00:00 2001 From: Prekshi Vyas Date: Mon, 19 Oct 2026 09:22:26 -0700 Subject: [PATCH 1/3] fix(e2e): admit approved OpenShell templates in GPU controller --- .github/workflows/e2e.yaml | 17 +- test/e2e/README.md | 20 +- ...d-image-protected-runtime-workflow.test.ts | 35 +-- .../protected-openshell-workspace.test.ts | 242 ++++++++++-------- test/support/protected-openshell-workspace.ts | 152 +++++++++++ ...ge-protected-runtime-workflow-boundary.mts | 32 ++- tools/e2e/protected-openshell-projection.mts | 6 +- tools/e2e/protected-openshell-workspace.mts | 100 +++++++- 8 files changed, 452 insertions(+), 152 deletions(-) create mode 100644 test/support/protected-openshell-workspace.ts diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index d4486e3a3e7..d975045d284 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -5213,6 +5213,7 @@ jobs: timeout-minutes: 75 permissions: contents: read + pull-requests: read env: CHECKOUT_SHA: ${{ inputs.checkout_sha || github.sha }} E2E_ARTIFACT_DIR: ${{ github.workspace }}/e2e-artifacts/live/managed-image-protected-runtime @@ -5361,6 +5362,9 @@ jobs: - id: openshell-projection name: Bind reviewed candidate OpenShell runtime shell: bash + env: + GITHUB_TOKEN: ${{ github.token }} + UPGRADE_PR_NUMBER: ${{ inputs.pr_number }} run: | set -euo pipefail node tools/e2e/protected-openshell-workspace.mts prepare > "$E2E_ARTIFACT_DIR/openshell-projection.json" @@ -5500,6 +5504,15 @@ jobs: shell: bash run: env -u DOCKER_CONFIG -u DOCKERHUB_USERNAME -u DOCKERHUB_TOKEN -u NVIDIA_API_KEY -u NVIDIA_INFERENCE_API_KEY -u GITHUB_TOKEN bash scripts/install-openshell.sh + - name: Verify reviewed candidate OpenShell runtime + shell: bash + env: + GITHUB_TOKEN: ${{ github.token }} + UPGRADE_PR_NUMBER: ${{ inputs.pr_number }} + run: | + set -euo pipefail + node tools/e2e/protected-openshell-workspace.mts verify > "$E2E_ARTIFACT_DIR/openshell-projection-verified.json" + - name: Run all-agent GPU, local inference, rollback, and cleanup qualification env: NVIDIA_API_KEY: ${{ github.repository == 'NVIDIA/NemoClaw' && (github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/main')) && (inputs.checkout_sha == '' || needs.generate-matrix.outputs.e2e_credentials_allowed == 'true') && secrets.NVIDIA_API_KEY || '' }} @@ -5510,7 +5523,6 @@ jobs: echo "::error::Protected NIM qualification must execute trusted workflow code" >&2 exit 1 } - node tools/e2e/protected-openshell-workspace.mts verify > "$E2E_ARTIFACT_DIR/openshell-projection-verified.json" export PATH="$HOME/.local/bin:$HOME/.npm-global/bin:$PATH" OPENSHELL_BIN="$(command -v openshell)" export OPENSHELL_BIN @@ -5546,6 +5558,9 @@ jobs: - name: Restore trusted OpenShell sources if: ${{ always() && steps.openshell-projection.outcome == 'success' }} shell: bash + env: + GITHUB_TOKEN: ${{ github.token }} + UPGRADE_PR_NUMBER: ${{ inputs.pr_number }} run: | set -euo pipefail node tools/e2e/protected-openshell-workspace.mts restore > "$E2E_ARTIFACT_DIR/openshell-projection-restored.json" diff --git a/test/e2e/README.md b/test/e2e/README.md index 2a7907ef04e..60ef280335f 100644 --- a/test/e2e/README.md +++ b/test/e2e/README.md @@ -350,11 +350,10 @@ The API credential is limited to trusted preparation and removed before npm runs If CI starts before the approved artifact exists, wait for the admission workflow's SDK job, then rerun CI. Changed or revoked approval cannot reuse the older artifact. -This does not yet extend the protected runtime's source projection, permit a new -SDK graph on protected E2E hosts, qualify Pi, or pass candidate catalogs to the Jetson operator. A data-admission -comment is not permission to execute arbitrary candidate code on a protected -host. Those boundaries require their own supported implementation and validation; -passing the hash check is not full E2E qualification. +The protected runtime controller uses candidate approval for source projection as described under [Push and Manual PR E2E](#push-and-manual-pr-e2e). +Approval does not permit a new SDK dependency graph on protected E2E hosts, qualify Pi, or pass candidate catalogs to the Jetson operator. +Those boundaries require their own supported implementation and validation. +Passing the hash check is not full E2E qualification. Unchanged runs pass the selected base revision and complete cohort receipt to every stock-onboarding consumer. Changed-input runs pass the authenticated candidate catalog separately to those consumers. @@ -2274,9 +2273,20 @@ Leave `targets` empty. Keep `include_staging_brev_launchable=false`. The candidate must contain `ci/protected-managed-image-multiarch-activation-v1.json` and `ci/protected-managed-image-runtime-activation-v1.json`. The GPU job reads OpenShell sources from the candidate commit as data, then validates their pins and operational templates. +When the candidate needs trust absent from the controller's registry, each prepare, verify, and restore operation rechecks the [candidate approval](#candidate-openshell-release-admission). +The approval must match the open PR, candidate commit, and base commit. +The approved registry and installer sources must match the candidate's committed files. +Candidates covered by the controller's registry need no additional approval. +The job exposes its GitHub token as `GITHUB_TOKEN` only to the three trusted source-projection steps, with `contents: read` and `pull-requests: read` permissions. +The token exists in those step environments and is absent from the live qualification environment. It projects only the reviewed installer, supervisor and feature-check modules, plus version literals, into the trusted controller checkout. It builds that controller after projection and verifies the projected sources before qualification. The job restores the trusted sources after qualification and retains source-digest records with its artifacts. +An admission rejection changes no files. +A failed verification blocks qualification. +A failed restoration fails the job. +If admission fails after preparation, the projected checkout remains for diagnosis. +Inspect the job log and projection artifacts before recovering the runner or dispatching another run. Those records identify tested inputs; they do not prove live E2E success. The job also selects the candidate OpenShell SDK from the controller's reviewed current or replacement archives. It projects the SDK identity into the trusted manifest and lockfile, then installs the verified archive before building the CLI. diff --git a/test/e2e/support/managed-image-protected-runtime-workflow.test.ts b/test/e2e/support/managed-image-protected-runtime-workflow.test.ts index b46f0ffcec7..569dcbab88f 100644 --- a/test/e2e/support/managed-image-protected-runtime-workflow.test.ts +++ b/test/e2e/support/managed-image-protected-runtime-workflow.test.ts @@ -118,27 +118,28 @@ describe("protected managed-image runtime workflow", () => { expect(validateManagedImageProtectedRuntimeWorkflow(value)).not.toEqual([]); }); - it("rejects missing source verification", () => { - const value = workflow(); - const step = namedStep( - value, + it.each([ + ["Verify reviewed candidate OpenShell runtime", "run", "echo bypass"], + ["Verify reviewed candidate OpenShell runtime", "if", "false"], + ["Verify reviewed candidate OpenShell runtime", "continue-on-error", true], + ["Verify reviewed candidate OpenShell runtime", "env", {}], + [ "Run all-agent GPU, local inference, rollback, and cleanup qualification", - ); - const command = - 'node tools/e2e/protected-openshell-workspace.mts verify > "$E2E_ARTIFACT_DIR/openshell-projection-verified.json"'; - step.run = String(step.run).replace(command, ""); + "env", + { GITHUB_TOKEN: "${{ github.token }}" }, + ], + ])("rejects admission step %s with altered %s", (name, field, replacement) => { + const value = workflow(); + namedStep(value, String(name))[String(field)] = replacement; expect(validateManagedImageProtectedRuntimeWorkflow(value)).not.toEqual([]); }); it("rejects source verification after qualification", () => { const value = workflow(); - const step = namedStep( - value, - "Run all-agent GPU, local inference, rollback, and cleanup qualification", - ); - const command = - 'node tools/e2e/protected-openshell-workspace.mts verify > "$E2E_ARTIFACT_DIR/openshell-projection-verified.json"'; - step.run = `${String(step.run).replace(command, "")}\n${command}\n`; + const job = runtimeJob(value); + const steps = job.steps as Array>; + const verify = namedStep(value, "Verify reviewed candidate OpenShell runtime"); + job.steps = [...steps.filter((step) => step !== verify), verify]; expect(validateManagedImageProtectedRuntimeWorkflow(value)).not.toEqual([]); }); @@ -793,12 +794,12 @@ describe("protected managed-image runtime workflow", () => { ); }); - it("rejects protected runtime permissions beyond same-run artifact access", () => { + it("rejects protected runtime permissions beyond source and approval reads", () => { const value = workflow(); runtimeJob(value).permissions = { actions: "read", contents: "read" }; expect(validateManagedImageProtectedRuntimeWorkflow(value)).toContain( - "managed-image-protected-runtime permissions must be exactly contents: read", + "managed-image-protected-runtime permissions must be exactly contents: read and pull-requests: read", ); }); diff --git a/test/e2e/support/protected-openshell-workspace.test.ts b/test/e2e/support/protected-openshell-workspace.test.ts index 47fe8de860f..74d49d36367 100644 --- a/test/e2e/support/protected-openshell-workspace.test.ts +++ b/test/e2e/support/protected-openshell-workspace.test.ts @@ -4,10 +4,15 @@ import { execFileSync } from "node:child_process"; import { createHash } from "node:crypto"; import * as fs from "node:fs"; -import { tmpdir } from "node:os"; -import { dirname, join } from "node:path"; +import { join } from "node:path"; import { fileURLToPath } from "node:url"; import { afterEach, describe, expect, it, vi } from "vitest"; +import { identity } from "../../helpers/candidate-openshell-trust"; +import { + CANDIDATE_OPENSHELL_SOURCES, + CANDIDATE_OPENSHELL_TRUST_PATH, +} from "../../../tools/e2e/candidate-openshell-trust.mts"; +import { fixture, approvedFixture, git, roots } from "../../support/protected-openshell-workspace"; import { manageProtectedOpenShellWorkspace } from "../../../tools/e2e/protected-openshell-workspace.mts"; vi.mock("node:fs", async (importOriginal) => { @@ -20,81 +25,103 @@ vi.mock("node:fs", async (importOriginal) => { }; }); -const sources = [ - "nemoclaw-blueprint/blueprint.yaml", - "scripts/install-openshell.sh", - "scripts/brev-launchable-ci-cpu.sh", - "src/lib/onboard/docker-driver-gateway-runtime.ts", - "src/lib/onboard/openshell-feature-gate.ts", - "src/lib/onboard/openshell-version.ts", - "package.json", - "package-lock.json", - "ci/reviewed-npm-audit.json", -]; -const roots: string[] = []; afterEach(() => { vi.restoreAllMocks(); vi.mocked(fs.openSync).mockReset(); for (const root of roots.splice(0)) fs.rmSync(root, { recursive: true, force: true }); }); -function git(root: string, ...args: string[]) { - return execFileSync( - "git", +describe("protected OpenShell workspace", () => { + it("projects independently approved installer and feature gate templates and rechecks each phase", async () => { + const { input, request } = approvedFixture(); + await expect(manageProtectedOpenShellWorkspace("prepare", input)).resolves.toMatchObject({ + operation: "prepare", + }); + expect( + request.mock.calls.filter(([path]) => path === "/repos/NVIDIA/NemoClaw/pulls/123"), + ).toHaveLength(2); + request.mockClear(); + await expect(manageProtectedOpenShellWorkspace("verify", input)).resolves.toMatchObject({ + operation: "verify", + }); + expect( + request.mock.calls.filter(([path]) => path === "/repos/NVIDIA/NemoClaw/pulls/123"), + ).toHaveLength(2); + request.mockClear(); + await expect(manageProtectedOpenShellWorkspace("restore", input)).resolves.toMatchObject({ + operation: "restore", + }); + expect( + request.mock.calls.filter(([path]) => path === "/repos/NVIDIA/NemoClaw/pulls/123"), + ).toHaveLength(2); + expect(git(input.trustedRoot, "status", "--porcelain")).toBe(""); + }); + + it.each<[string, (value: ReturnType) => void, RegExp]>([ [ - "-c", - "core.hooksPath=/dev/null", - "-c", - "commit.gpgsign=false", - "-c", - "user.name=Fixture", - "-c", - "user.email=fixture@example.invalid", - "-C", - root, - ...args, + "missing", + ({ approval }) => { + approval.approvals.splice(0); + }, + /approval|decision/i, ], - { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }, - ).trim(); -} -function fixture() { - const root = fs.mkdtempSync(join(tmpdir(), "protected-openshell-workspace-")); - roots.push(root); - const trustedRoot = join(root, "trusted"); - const candidateRoot = join(root, "candidate"); - for (const target of [trustedRoot, candidateRoot]) { - fs.mkdirSync(target); - git(target, "init", "--quiet"); - for (const path of sources) { - const file = join(target, path); - fs.mkdirSync(dirname(file), { recursive: true }); - fs.copyFileSync(new URL(`../../../${path}`, import.meta.url), file); - fs.chmodSync(file, path.endsWith(".sh") ? 0o755 : 0o644); - } - fs.writeFileSync(join(target, "controller.txt"), "trusted fixture\n"); - } - fs.writeFileSync( - join(trustedRoot, "nemoclaw-blueprint/blueprint.yaml"), - 'name: fixture\nmin_openshell_version: "0.0.1"\nmax_openshell_version: "0.0.1"\n', - ); - fs.writeFileSync( - join(trustedRoot, "src/lib/onboard/openshell-version.ts"), - 'export const SUPPORTED_OPENSHELL_FALLBACK_VERSION = "0.0.1";\n', - ); - git(trustedRoot, "add", "."); - git(trustedRoot, "commit", "--quiet", "-m", "fixture"); - git(candidateRoot, "add", "."); - git(candidateRoot, "commit", "--quiet", "-m", "fixture"); - return { - trustedRoot, - candidateRoot, - workflowSha: git(trustedRoot, "rev-parse", "HEAD"), - candidateSha: git(candidateRoot, "rev-parse", "HEAD"), - }; -} + [ + "stale", + ({ approval }) => { + approval.approvals[0]!.body = `NemoClaw-Upgrade-E2E: approve ${identity.candidateSha} ${identity.baseSha}`; + }, + /approval|decision/i, + ], + [ + "registry", + ({ approval }) => { + approval.files[CANDIDATE_OPENSHELL_TRUST_PATH] += "\n"; + }, + /Committed candidate registry differs/, + ], + [ + "source", + ({ approval }) => { + approval.files[CANDIDATE_OPENSHELL_SOURCES.blueprintSource] += "\n"; + }, + /Committed candidate source differs/, + ], + ])("rejects %s candidate approval before mutation", async (_scenario, mutate, expected) => { + const value = approvedFixture(); + mutate(value); + await expect(manageProtectedOpenShellWorkspace("prepare", value.input)).rejects.toThrow( + expected, + ); + expect(git(value.input.trustedRoot, "status", "--porcelain")).toBe(""); + }); -describe("protected OpenShell workspace", () => { - it("binds the workflow CLI to dispatch commits and emits records for each phase", () => { + it("rejects an unapproved feature gate template before mutation", async () => { + const { input, approval } = approvedFixture(); + fs.appendFileSync( + join(input.candidateRoot, "src/lib/onboard/openshell-feature-gate.ts"), + "\nunreviewed_operation();\n", + ); + git(input.candidateRoot, "add", "."); + git(input.candidateRoot, "commit", "--quiet", "-m", "unapproved feature"); + input.candidateSha = git(input.candidateRoot, "rev-parse", "HEAD"); + approval.approvals[0]!.body = `NemoClaw-Upgrade-E2E: approve ${input.candidateSha} ${identity.baseSha}`; + await expect(manageProtectedOpenShellWorkspace("prepare", input)).rejects.toThrow( + /feature gate operational template/, + ); + expect(git(input.trustedRoot, "status", "--porcelain")).toBe(""); + }); + + it("rejects revoked approval before verification and leaves projected files untouched", async () => { + const { input, approval } = approvedFixture(); + await manageProtectedOpenShellWorkspace("prepare", input); + const before = git(input.trustedRoot, "diff", "--no-ext-diff"); + approval.approvals[0]!.body = `NemoClaw-Upgrade-E2E: revoke ${input.candidateSha} ${identity.baseSha}`; + await expect(manageProtectedOpenShellWorkspace("verify", input)).rejects.toThrow(); + await expect(manageProtectedOpenShellWorkspace("restore", input)).rejects.toThrow(); + expect(git(input.trustedRoot, "diff", "--no-ext-diff")).toBe(before); + }); + + it("binds the workflow CLI to dispatch commits and emits records for each phase", async () => { const input = fixture(); const command = fileURLToPath( new URL("../../../tools/e2e/protected-openshell-workspace.mts", import.meta.url), @@ -122,16 +149,16 @@ describe("protected OpenShell workspace", () => { expect(git(input.trustedRoot, "status", "--porcelain")).toBe(""); }); - it("prepares candidate pins, verifies their bytes, and restores the trusted checkout", () => { + it("prepares candidate pins, verifies their bytes, and restores the trusted checkout", async () => { const input = fixture(); - const prepared = manageProtectedOpenShellWorkspace("prepare", input); + const prepared = await manageProtectedOpenShellWorkspace("prepare", input); expect(prepared).toMatchObject({ workflowSha: input.workflowSha, candidateSha: input.candidateSha, operation: "prepare", }); expect(prepared.files).toHaveLength(7); - expect(manageProtectedOpenShellWorkspace("verify", input)).toEqual({ + expect(await manageProtectedOpenShellWorkspace("verify", input)).toEqual({ ...prepared, operation: "verify", }); @@ -142,33 +169,35 @@ describe("protected OpenShell workspace", () => { .digest("hex"), })); expect(actualDigests).toEqual(prepared.files); - manageProtectedOpenShellWorkspace("restore", input); + await manageProtectedOpenShellWorkspace("restore", input); expect(git(input.trustedRoot, "status", "--porcelain")).toBe(""); - expect(() => manageProtectedOpenShellWorkspace("restore", input)).not.toThrow(); + await expect(manageProtectedOpenShellWorkspace("restore", input)).resolves.toBeDefined(); }); it.each(["workflowSha", "candidateSha"] as const)( "rejects a mismatched %s before changing files", - (key) => { + async (key) => { const input = fixture(); input[key] = "a".repeat(40); - expect(() => manageProtectedOpenShellWorkspace("prepare", input)).toThrow(/dispatch commit/); + await expect(manageProtectedOpenShellWorkspace("prepare", input)).rejects.toThrow( + /dispatch commit/, + ); expect(git(input.trustedRoot, "status", "--porcelain")).toBe(""); }, ); - it("uses committed candidate blobs instead of mutable worktree content", () => { + it("uses committed candidate blobs instead of mutable worktree content", async () => { const input = fixture(); fs.appendFileSync( join(input.candidateRoot, "scripts/install-openshell.sh"), "\nunreviewed_operation\n", ); - const result = manageProtectedOpenShellWorkspace("prepare", input); + const result = await manageProtectedOpenShellWorkspace("prepare", input); expect(result.releaseVersion).toMatch(/^\d+\.\d+\.\d+$/); - expect(() => manageProtectedOpenShellWorkspace("verify", input)).not.toThrow(); + await expect(manageProtectedOpenShellWorkspace("verify", input)).resolves.toBeDefined(); }); - it("rejects committed unreviewed candidate operations", () => { + it("rejects committed unreviewed candidate operations", async () => { const input = fixture(); fs.appendFileSync( join(input.candidateRoot, "scripts/install-openshell.sh"), @@ -177,41 +206,50 @@ describe("protected OpenShell workspace", () => { git(input.candidateRoot, "add", "."); git(input.candidateRoot, "commit", "--quiet", "-m", "unreviewed"); input.candidateSha = git(input.candidateRoot, "rev-parse", "HEAD"); - expect(() => manageProtectedOpenShellWorkspace("prepare", input)).toThrow(/template/); + await expect(manageProtectedOpenShellWorkspace("prepare", input)).rejects.toThrow(/template/); expect(git(input.trustedRoot, "status", "--porcelain")).toBe(""); }); it.each(["prepare", "verify", "restore"] as const)( "rejects unrelated controller edits during %s", - (operation) => { + async (operation) => { const input = fixture(); fs.writeFileSync(join(input.trustedRoot, "controller.txt"), "modified"); - expect(() => manageProtectedOpenShellWorkspace(operation, input)).toThrow(/Unrelated/); + await expect(manageProtectedOpenShellWorkspace(operation, input)).rejects.toThrow( + /Unrelated/, + ); expect(fs.readFileSync(join(input.trustedRoot, "controller.txt"), "utf8")).toBe("modified"); }, ); - it.each(["file", "parent"])("rejects a symlinked destination %s without following it", (kind) => { - const input = fixture(); - const path = join( - input.trustedRoot, - kind === "file" ? "scripts/install-openshell.sh" : "scripts", - ); - const moved = `${path}.retained`; - fs.renameSync(path, moved); - fs.symlinkSync(moved, path); - expect(() => manageProtectedOpenShellWorkspace("prepare", input)).toThrow(/Unsafe/); - expect(fs.readlinkSync(path)).toBe(moved); - }); + it.each(["file", "parent"])( + "rejects a symlinked destination %s without following it", + async (kind) => { + const input = fixture(); + const path = join( + input.trustedRoot, + kind === "file" ? "scripts/install-openshell.sh" : "scripts", + ); + const moved = `${path}.retained`; + fs.renameSync(path, moved); + fs.symlinkSync(moved, path); + await expect(manageProtectedOpenShellWorkspace("prepare", input)).rejects.toThrow(/Unsafe/); + expect(fs.readlinkSync(path)).toBe(moved); + }, + ); - it("rejects tampering before verification or restoration", () => { + it("rejects tampering before verification or restoration", async () => { const input = fixture(); - manageProtectedOpenShellWorkspace("prepare", input); + await manageProtectedOpenShellWorkspace("prepare", input); const path = join(input.trustedRoot, "src/lib/onboard/openshell-version.ts"); fs.appendFileSync(path, "\nunreviewed_operation();\n"); const before = git(input.trustedRoot, "diff", "--no-ext-diff"); - expect(() => manageProtectedOpenShellWorkspace("verify", input)).toThrow(/Unexpected verify/); - expect(() => manageProtectedOpenShellWorkspace("restore", input)).toThrow(/Unexpected restore/); + await expect(manageProtectedOpenShellWorkspace("verify", input)).rejects.toThrow( + /Unexpected verify/, + ); + await expect(manageProtectedOpenShellWorkspace("restore", input)).rejects.toThrow( + /Unexpected restore/, + ); expect(git(input.trustedRoot, "diff", "--no-ext-diff")).toBe(before); }); @@ -227,7 +265,7 @@ describe("protected OpenShell workspace", () => { fs.symlinkSync(retained, path); return original(file, flags, mode); }); - expect(() => manageProtectedOpenShellWorkspace("prepare", input)).toThrow(/Unsafe/); + await expect(manageProtectedOpenShellWorkspace("prepare", input)).rejects.toThrow(/Unsafe/); expect(fs.readlinkSync(path)).toBe(retained); expect(fs.statSync(retained)).toMatchObject({ ino: before.ino, @@ -236,13 +274,13 @@ describe("protected OpenShell workspace", () => { }); }); - it("rejects a hard-linked destination and closes its opened descriptor", () => { + it("rejects a hard-linked destination and closes its opened descriptor", async () => { const input = fixture(); const path = join(input.trustedRoot, "scripts/install-openshell.sh"); fs.linkSync(path, `${path}.retained`); vi.mocked(fs.openSync).mockClear(); vi.mocked(fs.closeSync).mockClear(); - expect(() => manageProtectedOpenShellWorkspace("prepare", input)).toThrow(/Unsafe/); + await expect(manageProtectedOpenShellWorkspace("prepare", input)).rejects.toThrow(/Unsafe/); const opened = vi.mocked(fs.openSync).mock.results.map((result) => result.value); expect(opened.length).toBeGreaterThan(0); expect(vi.mocked(fs.closeSync).mock.calls.map(([fd]) => fd)).toEqual(opened); @@ -257,7 +295,7 @@ describe("protected OpenShell workspace", () => { .mockImplementationOnce(() => { throw new Error("fixture replacement failure"); }); - expect(() => manageProtectedOpenShellWorkspace("prepare", input)).toThrow( + await expect(manageProtectedOpenShellWorkspace("prepare", input)).rejects.toThrow( /fixture replacement failure/, ); expect(git(input.trustedRoot, "status", "--porcelain")).toBe(""); diff --git a/test/support/protected-openshell-workspace.ts b/test/support/protected-openshell-workspace.ts new file mode 100644 index 00000000000..6d3d3d09bd2 --- /dev/null +++ b/test/support/protected-openshell-workspace.ts @@ -0,0 +1,152 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { execFileSync } from "node:child_process"; +import * as fs from "node:fs"; +import { tmpdir } from "node:os"; +import { dirname, join } from "node:path"; +import { vi } from "vitest"; +import { fixture as approvalFixture, identity } from "../helpers/candidate-openshell-trust"; +import { + CANDIDATE_OPENSHELL_SOURCES, + CANDIDATE_OPENSHELL_TRUST_PATH, +} from "../../tools/e2e/candidate-openshell-trust.mts"; +import { + readOpenShellTrustRegistry, + validateInstallerSources, + validateOpenShellFeatureGateSource, +} from "../../scripts/checks/extract-installer-pins.mts"; + +const sources = [ + "nemoclaw-blueprint/blueprint.yaml", + "scripts/install-openshell.sh", + "scripts/brev-launchable-ci-cpu.sh", + "src/lib/onboard/docker-driver-gateway-runtime.ts", + "src/lib/onboard/openshell-feature-gate.ts", + "src/lib/onboard/openshell-version.ts", + "package.json", + "package-lock.json", + "ci/reviewed-npm-audit.json", +]; +export const roots: string[] = []; + +export function git(root: string, ...args: string[]) { + return execFileSync( + "git", + [ + "-c", + "core.hooksPath=/dev/null", + "-c", + "commit.gpgsign=false", + "-c", + "user.name=Fixture", + "-c", + "user.email=fixture@example.invalid", + "-C", + root, + ...args, + ], + { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }, + ).trim(); +} +export function fixture() { + const root = fs.mkdtempSync(join(tmpdir(), "protected-openshell-workspace-")); + roots.push(root); + const trustedRoot = join(root, "trusted"); + const candidateRoot = join(root, "candidate"); + for (const target of [trustedRoot, candidateRoot]) { + fs.mkdirSync(target); + git(target, "init", "--quiet"); + for (const path of sources) { + const file = join(target, path); + fs.mkdirSync(dirname(file), { recursive: true }); + fs.copyFileSync(new URL(`../../${path}`, import.meta.url), file); + fs.chmodSync(file, path.endsWith(".sh") ? 0o755 : 0o644); + } + fs.writeFileSync(join(target, "controller.txt"), "trusted fixture\n"); + } + fs.writeFileSync( + join(trustedRoot, "nemoclaw-blueprint/blueprint.yaml"), + 'name: fixture\nmin_openshell_version: "0.0.1"\nmax_openshell_version: "0.0.1"\n', + ); + fs.writeFileSync( + join(trustedRoot, "src/lib/onboard/openshell-version.ts"), + 'export const SUPPORTED_OPENSHELL_FALLBACK_VERSION = "0.0.1";\n', + ); + git(trustedRoot, "add", "."); + git(trustedRoot, "commit", "--quiet", "-m", "fixture"); + git(candidateRoot, "add", "."); + git(candidateRoot, "commit", "--quiet", "-m", "fixture"); + return { + trustedRoot, + candidateRoot, + workflowSha: git(trustedRoot, "rev-parse", "HEAD"), + candidateSha: git(candidateRoot, "rev-parse", "HEAD"), + }; +} + +function templateDigest(check: () => unknown): string { + try { + check(); + } catch (error) { + const digest = /actual_sha256=([a-f0-9]{64})/.exec(String(error))?.[1]; + if (digest) return digest; + throw error; + } + throw new Error("Fixture must introduce an untrusted template"); +} + +export function approvedFixture() { + const input = fixture(); + const approval = approvalFixture(); + const candidate = Object.fromEntries( + Object.entries(CANDIDATE_OPENSHELL_SOURCES).map(([key, path]) => [ + key, + fs.readFileSync(join(input.candidateRoot, path), "utf8"), + ]), + ) as Record; + const selected = validateInstallerSources(candidate); + const release = structuredClone(selected.installerReleases[0]!); + candidate.installerSource += "\n# Reviewed installer fixture change.\n"; + release.installerTemplateSha256 = [ + ...release.installerTemplateSha256, + templateDigest(() => validateInstallerSources(candidate)), + ]; + const featurePath = "src/lib/onboard/openshell-feature-gate.ts"; + const featureSource = + fs.readFileSync(join(input.candidateRoot, featurePath), "utf8") + + "\n// Reviewed feature gate fixture change.\n"; + release.featureGateTemplateSha256 = [ + ...(release.featureGateTemplateSha256 ?? []), + templateDigest(() => validateOpenShellFeatureGateSource(featureSource, release.version)), + ]; + for (const [key, path] of Object.entries(CANDIDATE_OPENSHELL_SOURCES)) + approval.files[path] = candidate[key as keyof typeof candidate]; + const registry = readOpenShellTrustRegistry(); + approval.files[CANDIDATE_OPENSHELL_TRUST_PATH] = JSON.stringify({ + ...registry, + releases: [...registry.releases.filter((prior) => prior.version !== release.version), release], + }); + for (const [path, source] of Object.entries(approval.files)) + fs.writeFileSync(join(input.candidateRoot, path), source); + fs.writeFileSync(join(input.candidateRoot, featurePath), featureSource); + git(input.candidateRoot, "add", "."); + git(input.candidateRoot, "commit", "--quiet", "-m", "approved fixture"); + input.candidateSha = git(input.candidateRoot, "rev-parse", "HEAD"); + approval.approvals[0]!.body = `NemoClaw-Upgrade-E2E: approve ${input.candidateSha} ${identity.baseSha}`; + const request = vi.fn(async (path: string) => { + const result = await approval.request(path); + if (path === "/repos/NVIDIA/NemoClaw/pulls/123") { + const pr = result as { head: { sha: string } }; + return { ...pr, head: { ...pr.head, sha: input.candidateSha } }; + } + return result; + }); + return { + input: Object.assign(input, { + admission: { prNumber: identity.prNumber, baseSha: identity.baseSha, request }, + }), + approval, + request, + }; +} diff --git a/tools/e2e/managed-image-protected-runtime-workflow-boundary.mts b/tools/e2e/managed-image-protected-runtime-workflow-boundary.mts index 99e7dd88ba4..53e46da94f2 100644 --- a/tools/e2e/managed-image-protected-runtime-workflow-boundary.mts +++ b/tools/e2e/managed-image-protected-runtime-workflow-boundary.mts @@ -112,8 +112,8 @@ export function validateManagedImageProtectedRuntimeWorkflow(workflow: WorkflowR errors.push(`${JOB_ID} must run on the protected amd64 GPU runner`); } if (job["timeout-minutes"] !== 75) errors.push(`${JOB_ID} must keep the 75 minute timeout`); - if (!isDeepStrictEqual(job.permissions, { contents: "read" })) { - errors.push(`${JOB_ID} permissions must be exactly contents: read`); + if (!isDeepStrictEqual(job.permissions, { contents: "read", "pull-requests": "read" })) { + errors.push(`${JOB_ID} permissions must be exactly contents: read and pull-requests: read`); } if (job["continue-on-error"] !== undefined) { errors.push(`${JOB_ID} must not weaken failures with continue-on-error`); @@ -265,19 +265,36 @@ export function validateManagedImageProtectedRuntimeWorkflow(workflow: WorkflowR ); if (projection?.id !== "openshell-projection") errors.push(`${JOB_ID} must identify the OpenShell projection`); + const verify = requireStep(errors, workflowSteps, "Verify reviewed candidate OpenShell runtime"); const restore = requireStep(errors, workflowSteps, "Restore trusted OpenShell sources"); + const admissionEnv = { + GITHUB_TOKEN: "${{ github.token }}", + UPGRADE_PR_NUMBER: "${{ inputs.pr_number }}", + }; + if ( + jobEnv.GITHUB_TOKEN !== undefined || + jobEnv.GH_TOKEN !== undefined || + workflowSteps.some( + (step) => + ![projection, verify, restore].includes(step) && + (record(step.env).GITHUB_TOKEN !== undefined || record(step.env).GH_TOKEN !== undefined), + ) + ) + errors.push(`${JOB_ID} must expose GitHub credentials only to candidate admission operations`); + if (verify?.if !== undefined) errors.push(`${JOB_ID} must not skip OpenShell verification`); if (restore?.if !== "${{ always() && steps.openshell-projection.outcome == 'success' }}") { errors.push(`${JOB_ID} must restore sources after a successful OpenShell projection`); } for (const [step, operation, output] of [ [projection, "prepare", "openshell-projection.json"], + [verify, "verify", "openshell-projection-verified.json"], [restore, "restore", "openshell-projection-restored.json"], ] as const) { const expected = `set -euo pipefail\nnode tools/e2e/protected-openshell-workspace.mts ${operation} > "$E2E_ARTIFACT_DIR/${output}"\n`; if ( step?.run !== expected || step?.shell !== "bash" || - step?.env !== undefined || + !isDeepStrictEqual(step?.env, admissionEnv) || step?.["continue-on-error"] !== undefined ) { errors.push(`${JOB_ID} must use the reviewed OpenShell ${operation} operation`); @@ -476,19 +493,11 @@ export function validateManagedImageProtectedRuntimeWorkflow(workflow: WorkflowR errors.push(`${JOB_ID} must expose NVIDIA_API_KEY only to trusted qualification code`); } requireFragments(errors, qualification, [ - 'node tools/e2e/protected-openshell-workspace.mts verify > "$E2E_ARTIFACT_DIR/openshell-projection-verified.json"', '[[ "$(git rev-parse --verify HEAD)" == "$NEMOCLAW_PROTECTED_MANAGED_IMAGE_WORKFLOW_SHA" ]]', 'OPENSHELL_BIN="$(command -v openshell)"\nexport OPENSHELL_BIN', "tools/e2e/live-vitest-invocation.mts run", `--test-path ${LIVE_TEST_PATH}`, ]); - const qualificationRun = text(qualification?.run); - const verifyPosition = qualificationRun.indexOf( - "node tools/e2e/protected-openshell-workspace.mts verify", - ); - if (verifyPosition < 0 || verifyPosition > qualificationRun.indexOf("OPENSHELL_BIN=")) { - errors.push(`${JOB_ID} must verify projected sources before runtime qualification`); - } if (text(qualification?.run).includes(".candidate-runtime")) { errors.push(`${JOB_ID} trusted qualification must not execute candidate checkout paths`); } @@ -530,6 +539,7 @@ export function validateManagedImageProtectedRuntimeWorkflow(workflow: WorkflowR "Start isolated protected runtime registry", "Build exact all-agent protected runtime images", "Install OpenShell CLI", + "Verify reviewed candidate OpenShell runtime", "Run all-agent GPU, local inference, rollback, and cleanup qualification", "Remove isolated protected runtime registry", "Restore trusted OpenShell sources", diff --git a/tools/e2e/protected-openshell-projection.mts b/tools/e2e/protected-openshell-projection.mts index 0b6531983c2..cce2ae4f841 100644 --- a/tools/e2e/protected-openshell-projection.mts +++ b/tools/e2e/protected-openshell-projection.mts @@ -4,6 +4,7 @@ import { validateInstallerSources, validateOpenShellFeatureGateSource, + type OpenShellReleaseTrust, } from "../../scripts/checks/extract-installer-pins.mts"; import { isDeepStrictEqual } from "node:util"; import { parseAuditConfig } from "../../scripts/audit-reviewed-npm-graph.mts"; @@ -28,9 +29,10 @@ function replaceOne(source: string, pattern: RegExp, replacement: string, label: export function projectProtectedOpenShellSources( candidate: ProtectedOpenShellCandidateSources, trusted: { blueprintSource: string; versionSource: string }, + releases?: readonly OpenShellReleaseTrust[], ): { releaseVersion: string; files: Record } { - const { releaseVersion } = validateInstallerSources(candidate); - validateOpenShellFeatureGateSource(candidate.featureGateSource, releaseVersion); + const { releaseVersion } = validateInstallerSources(candidate, releases); + validateOpenShellFeatureGateSource(candidate.featureGateSource, releaseVersion, releases); const qualified = [ ...candidate.supervisorRuntimeSource.matchAll( /^const QUALIFIED_STABLE_OPENSHELL_VERSION = "([0-9]+\.[0-9]+\.[0-9]+)";$/gm, diff --git a/tools/e2e/protected-openshell-workspace.mts b/tools/e2e/protected-openshell-workspace.mts index 39d222b4982..2adfd126429 100644 --- a/tools/e2e/protected-openshell-workspace.mts +++ b/tools/e2e/protected-openshell-workspace.mts @@ -21,11 +21,22 @@ import { projectProtectedOpenShellSdk, } from "./protected-openshell-projection.mts"; +import { + readOpenShellTrustRegistry, + resolveOpenShellTrustRegistry, +} from "../../scripts/checks/extract-installer-pins.mts"; +import { parseOpenShellTrustRegistry } from "../../scripts/checks/openshell-trust-data.mts"; +import { + CANDIDATE_OPENSHELL_SOURCES, + CANDIDATE_OPENSHELL_TRUST_PATH, + registryCoveredByTrusted, + reviewedCandidateOpenShellTrust, +} from "./candidate-openshell-trust.mts"; +import { type UpgradeRequest } from "./candidate-upgrade-admission.mts"; +import { githubRequest } from "./base-image-publication.mts"; + const SOURCE_PATHS = { - blueprintSource: "nemoclaw-blueprint/blueprint.yaml", - installerSource: "scripts/install-openshell.sh", - brevInstallerSource: "scripts/brev-launchable-ci-cpu.sh", - supervisorRuntimeSource: "src/lib/onboard/docker-driver-gateway-runtime.ts", + ...CANDIDATE_OPENSHELL_SOURCES, featureGateSource: "src/lib/onboard/openshell-feature-gate.ts", packageSource: "package.json", lockSource: "package-lock.json", @@ -38,6 +49,7 @@ export interface ProtectedOpenShellWorkspace { candidateRoot: string; workflowSha: string; candidateSha: string; + admission?: { prNumber: number; baseSha: string; request: UpgradeRequest }; } function git(root: string, args: string[]): string { @@ -119,8 +131,53 @@ function replaceSource(path: string, source: string, mode: number): void { } } +/** Recheck approval for each phase; local receipts cannot authorize new executable templates. */ +async function candidateReleases( + input: ProtectedOpenShellWorkspace, + candidate: Record, +) { + const registryPath = CANDIDATE_OPENSHELL_TRUST_PATH; + const present = git(input.candidateRoot, [ + "ls-tree", + "-z", + input.candidateSha, + "--", + registryPath, + ]); + const registrySource = present + ? committedSource(input.candidateRoot, input.candidateSha, registryPath) + : undefined; + const registry = + registrySource === undefined + ? { schemaVersion: 1 as const, releases: [], revokedTemplateSha256: [] } + : parseOpenShellTrustRegistry(registrySource); + const trusted = readOpenShellTrustRegistry(); + if (registryCoveredByTrusted(registry, trusted)) return resolveOpenShellTrustRegistry(trusted); + if (!input.admission) + throw new Error("Candidate OpenShell trust requires live upgrade admission"); + const approved = await reviewedCandidateOpenShellTrust( + { + prNumber: input.admission.prNumber, + baseSha: input.admission.baseSha, + candidateSha: input.candidateSha, + }, + input.admission.request, + ); + if (registrySource !== approved.registrySource) + throw new Error("Committed candidate registry differs from the approved commit"); + for (const key of Object.keys( + CANDIDATE_OPENSHELL_SOURCES, + ) as (keyof typeof CANDIDATE_OPENSHELL_SOURCES)[]) { + if (candidate[key] !== approved.sources[key]) + throw new Error( + `Committed candidate source differs from the approved commit: ${CANDIDATE_OPENSHELL_SOURCES[key]}`, + ); + } + return approved.releases; +} + /** Apply only reviewed modules and release literals to an isolated trusted workflow checkout. */ -export function manageProtectedOpenShellWorkspace( +export async function manageProtectedOpenShellWorkspace( operation: "prepare" | "verify" | "restore", input: ProtectedOpenShellWorkspace, ) { @@ -134,14 +191,19 @@ export function manageProtectedOpenShellWorkspace( committedSource(input.candidateRoot, input.candidateSha, path), ]), ) as Record; - const projected = projectProtectedOpenShellSources(candidate, { - blueprintSource: committedSource( - input.trustedRoot, - input.workflowSha, - SOURCE_PATHS.blueprintSource, - ), - versionSource: committedSource(input.trustedRoot, input.workflowSha, VERSION_PATH), - }); + const releases = await candidateReleases(input, candidate); + const projected = projectProtectedOpenShellSources( + candidate, + { + blueprintSource: committedSource( + input.trustedRoot, + input.workflowSha, + SOURCE_PATHS.blueprintSource, + ), + versionSource: committedSource(input.trustedRoot, input.workflowSha, VERSION_PATH), + }, + releases, + ); const sdk = projectProtectedOpenShellSdk( candidate, { @@ -231,11 +293,21 @@ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) } console.log( JSON.stringify( - manageProtectedOpenShellWorkspace(operation as "prepare" | "verify" | "restore", { + await manageProtectedOpenShellWorkspace(operation as "prepare" | "verify" | "restore", { trustedRoot: process.env.GITHUB_WORKSPACE!, candidateRoot: process.env.NEMOCLAW_E2E_TESTED_ROOT!, workflowSha: process.env.NEMOCLAW_PROTECTED_MANAGED_IMAGE_WORKFLOW_SHA!, candidateSha: process.env.CHECKOUT_SHA!, + admission: { + prNumber: Number(process.env.UPGRADE_PR_NUMBER), + baseSha: process.env.NEMOCLAW_PROTECTED_MANAGED_IMAGE_BASE_SHA ?? "", + request: (url) => { + const token = process.env.GITHUB_TOKEN; + if (!token) + throw new Error("Candidate upgrade admission requires authenticated GitHub access"); + return githubRequest(url, token); + }, + }, }), null, 2, From 6bb89cfe67537bb49118a5448c3f670c77294784 Mon Sep 17 00:00:00 2001 From: Prekshi Vyas Date: Mon, 19 Oct 2026 09:42:45 -0700 Subject: [PATCH 2/3] test(e2e): require the revoked approval error Signed-off-by: Prekshi Vyas --- test/e2e/support/protected-openshell-workspace.test.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/e2e/support/protected-openshell-workspace.test.ts b/test/e2e/support/protected-openshell-workspace.test.ts index 74d49d36367..fb28df81816 100644 --- a/test/e2e/support/protected-openshell-workspace.test.ts +++ b/test/e2e/support/protected-openshell-workspace.test.ts @@ -116,8 +116,12 @@ describe("protected OpenShell workspace", () => { await manageProtectedOpenShellWorkspace("prepare", input); const before = git(input.trustedRoot, "diff", "--no-ext-diff"); approval.approvals[0]!.body = `NemoClaw-Upgrade-E2E: revoke ${input.candidateSha} ${identity.baseSha}`; - await expect(manageProtectedOpenShellWorkspace("verify", input)).rejects.toThrow(); - await expect(manageProtectedOpenShellWorkspace("restore", input)).rejects.toThrow(); + await expect(manageProtectedOpenShellWorkspace("verify", input)).rejects.toThrow( + "Candidate upgrade needs an independent maintainer's current commit-bound E2E approval", + ); + await expect(manageProtectedOpenShellWorkspace("restore", input)).rejects.toThrow( + "Candidate upgrade needs an independent maintainer's current commit-bound E2E approval", + ); expect(git(input.trustedRoot, "diff", "--no-ext-diff")).toBe(before); }); From 95cad4745bec8bf5d0d1b0d6a69d37d77858aaaa Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Mon, 19 Oct 2026 10:42:44 -0700 Subject: [PATCH 3/3] fix(e2e): verify OpenShell approval before runtime use Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- .github/workflows/e2e.yaml | 9 +++++++++ test/e2e/README.md | 6 +++--- ...d-image-protected-runtime-workflow.test.ts | 19 +++++++++++++++++++ ...ge-protected-runtime-workflow-boundary.mts | 12 ++++++++++-- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index d975045d284..36de4ae9d62 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -5369,6 +5369,15 @@ jobs: set -euo pipefail node tools/e2e/protected-openshell-workspace.mts prepare > "$E2E_ARTIFACT_DIR/openshell-projection.json" + - name: Verify reviewed candidate OpenShell runtime before consumption + shell: bash + env: + GITHUB_TOKEN: ${{ github.token }} + UPGRADE_PR_NUMBER: ${{ inputs.pr_number }} + run: | + set -euo pipefail + node tools/e2e/protected-openshell-workspace.mts verify > "$E2E_ARTIFACT_DIR/openshell-projection-initially-verified.json" + - name: Download reviewed OpenShell SDK archive uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: diff --git a/test/e2e/README.md b/test/e2e/README.md index 60ef280335f..66396c53683 100644 --- a/test/e2e/README.md +++ b/test/e2e/README.md @@ -2273,14 +2273,14 @@ Leave `targets` empty. Keep `include_staging_brev_launchable=false`. The candidate must contain `ci/protected-managed-image-multiarch-activation-v1.json` and `ci/protected-managed-image-runtime-activation-v1.json`. The GPU job reads OpenShell sources from the candidate commit as data, then validates their pins and operational templates. -When the candidate needs trust absent from the controller's registry, each prepare, verify, and restore operation rechecks the [candidate approval](#candidate-openshell-release-admission). +When the candidate needs trust absent from the controller's registry, preparation, both verifications, and restoration recheck the [candidate approval](#candidate-openshell-release-admission). The approval must match the open PR, candidate commit, and base commit. The approved registry and installer sources must match the candidate's committed files. Candidates covered by the controller's registry need no additional approval. -The job exposes its GitHub token as `GITHUB_TOKEN` only to the three trusted source-projection steps, with `contents: read` and `pull-requests: read` permissions. +The job exposes its GitHub token as `GITHUB_TOKEN` only to the four trusted source-projection steps, with `contents: read` and `pull-requests: read` permissions. The token exists in those step environments and is absent from the live qualification environment. It projects only the reviewed installer, supervisor and feature-check modules, plus version literals, into the trusted controller checkout. -It builds that controller after projection and verifies the projected sources before qualification. +It verifies the projected sources before installing the SDK or building the controller, then rechecks them before qualification. The job restores the trusted sources after qualification and retains source-digest records with its artifacts. An admission rejection changes no files. A failed verification blocks qualification. diff --git a/test/e2e/support/managed-image-protected-runtime-workflow.test.ts b/test/e2e/support/managed-image-protected-runtime-workflow.test.ts index 569dcbab88f..6e4335392d3 100644 --- a/test/e2e/support/managed-image-protected-runtime-workflow.test.ts +++ b/test/e2e/support/managed-image-protected-runtime-workflow.test.ts @@ -119,6 +119,10 @@ describe("protected managed-image runtime workflow", () => { }); it.each([ + ["Verify reviewed candidate OpenShell runtime before consumption", "run", "echo bypass"], + ["Verify reviewed candidate OpenShell runtime before consumption", "if", "false"], + ["Verify reviewed candidate OpenShell runtime before consumption", "continue-on-error", true], + ["Verify reviewed candidate OpenShell runtime before consumption", "env", {}], ["Verify reviewed candidate OpenShell runtime", "run", "echo bypass"], ["Verify reviewed candidate OpenShell runtime", "if", "false"], ["Verify reviewed candidate OpenShell runtime", "continue-on-error", true], @@ -134,6 +138,21 @@ describe("protected managed-image runtime workflow", () => { expect(validateManagedImageProtectedRuntimeWorkflow(value)).not.toEqual([]); }); + it("rejects consuming projected sources before verifying approval", () => { + const value = workflow(); + const job = runtimeJob(value); + const steps = job.steps as Array>; + const verify = namedStep( + value, + "Verify reviewed candidate OpenShell runtime before consumption", + ); + const install = namedStep(value, "Install reviewed OpenShell SDK from trusted controller"); + const withoutVerify = steps.filter((step) => step !== verify); + const index = withoutVerify.indexOf(install); + job.steps = [...withoutVerify.slice(0, index + 1), verify, ...withoutVerify.slice(index + 1)]; + expect(validateManagedImageProtectedRuntimeWorkflow(value)).not.toEqual([]); + }); + it("rejects source verification after qualification", () => { const value = workflow(); const job = runtimeJob(value); diff --git a/tools/e2e/managed-image-protected-runtime-workflow-boundary.mts b/tools/e2e/managed-image-protected-runtime-workflow-boundary.mts index 53e46da94f2..ce5321963dd 100644 --- a/tools/e2e/managed-image-protected-runtime-workflow-boundary.mts +++ b/tools/e2e/managed-image-protected-runtime-workflow-boundary.mts @@ -265,6 +265,11 @@ export function validateManagedImageProtectedRuntimeWorkflow(workflow: WorkflowR ); if (projection?.id !== "openshell-projection") errors.push(`${JOB_ID} must identify the OpenShell projection`); + const verifyBeforeUse = requireStep( + errors, + workflowSteps, + "Verify reviewed candidate OpenShell runtime before consumption", + ); const verify = requireStep(errors, workflowSteps, "Verify reviewed candidate OpenShell runtime"); const restore = requireStep(errors, workflowSteps, "Restore trusted OpenShell sources"); const admissionEnv = { @@ -276,17 +281,19 @@ export function validateManagedImageProtectedRuntimeWorkflow(workflow: WorkflowR jobEnv.GH_TOKEN !== undefined || workflowSteps.some( (step) => - ![projection, verify, restore].includes(step) && + ![projection, verifyBeforeUse, verify, restore].includes(step) && (record(step.env).GITHUB_TOKEN !== undefined || record(step.env).GH_TOKEN !== undefined), ) ) errors.push(`${JOB_ID} must expose GitHub credentials only to candidate admission operations`); - if (verify?.if !== undefined) errors.push(`${JOB_ID} must not skip OpenShell verification`); + if (verifyBeforeUse?.if !== undefined || verify?.if !== undefined) + errors.push(`${JOB_ID} must not skip OpenShell verification`); if (restore?.if !== "${{ always() && steps.openshell-projection.outcome == 'success' }}") { errors.push(`${JOB_ID} must restore sources after a successful OpenShell projection`); } for (const [step, operation, output] of [ [projection, "prepare", "openshell-projection.json"], + [verifyBeforeUse, "verify", "openshell-projection-initially-verified.json"], [verify, "verify", "openshell-projection-verified.json"], [restore, "restore", "openshell-projection-restored.json"], ] as const) { @@ -531,6 +538,7 @@ export function validateManagedImageProtectedRuntimeWorkflow(workflow: WorkflowR "Prepare E2E workspace", "Validate protected runtime activation contract", "Bind reviewed candidate OpenShell runtime", + "Verify reviewed candidate OpenShell runtime before consumption", "Download reviewed OpenShell SDK archive", "Install reviewed OpenShell SDK from trusted controller", "Build trusted CLI with reviewed OpenShell runtime",