diff --git a/.gitea/workflows/quality-gates.yml b/.gitea/workflows/quality-gates.yml index 796ff2cc..35af29d9 100644 --- a/.gitea/workflows/quality-gates.yml +++ b/.gitea/workflows/quality-gates.yml @@ -207,6 +207,20 @@ jobs: name: "release-candidate-${{ gitea.run_id }}-${{ gitea.run_attempt }}" path: ".release/release-candidate-${{ gitea.run_id }}-${{ gitea.run_attempt }}.tar.gz" if-no-files-found: error + - name: Upload immutable gate evidence + if: always() + uses: https://github.com/ChristopherHX/gitea-upload-artifact@81f940d004763f986ba3582c007fd842dd5cb0d7 + with: + name: "immutable-gate-evidence-${{ gitea.run_id }}-${{ gitea.run_attempt }}" + path: | + artifacts/quality/gates/FE-GATE-015.txt + artifacts/release/release-candidate.json + artifacts/release/verification.json + artifacts/security/supply-chain-coherence.json + artifacts/quality/gates/FE-GATE-027.txt + artifacts/release/deployment-admission.json + artifacts/security/dependency-advisories.json + if-no-files-found: error vulnerability_provider: name: external-vulnerability-provider diff --git a/config/ci/gates.json b/config/ci/gates.json index f32e169e..31175c46 100644 --- a/config/ci/gates.json +++ b/config/ci/gates.json @@ -2508,6 +2508,21 @@ "paths": [ ".release/release-candidate-${{ gitea.run_id }}-${{ gitea.run_attempt }}.tar.gz" ] + }, + { + "kind": "upload", + "transferId": "immutable-gate-evidence", + "name": "immutable-gate-evidence-${{ gitea.run_id }}-${{ gitea.run_attempt }}", + "paths": [ + "artifacts/quality/gates/FE-GATE-015.txt", + "artifacts/release/release-candidate.json", + "artifacts/release/verification.json", + "artifacts/security/supply-chain-coherence.json", + "artifacts/quality/gates/FE-GATE-027.txt", + "artifacts/release/deployment-admission.json", + "artifacts/security/dependency-advisories.json" + ], + "always": true } ] }, diff --git a/docs/operations/ci-quality-gates.md b/docs/operations/ci-quality-gates.md index 1171b76e..511689b1 100644 --- a/docs/operations/ci-quality-gates.md +++ b/docs/operations/ci-quality-gates.md @@ -163,7 +163,12 @@ Release tier의 `immutable_build`는 `dist`의 hidden `.vite` entries, raw 번 생성해 run ID/attempt로 구분된 archive로 게시한다. Raw lock bytes의 SHA-256은 dependency inventory와 candidate manifest 양쪽의 `lockfileSha256`과 같아야 한다. Producer는 게시 전에 manifest가 선언한 exact member set과 각 byte digest를 -검증하고 archive SHA-256을 job output으로 고정한다. Vulnerability/provenance +검증하고 archive SHA-256을 job output으로 고정한다. 같은 job은 마지막 단계에서 +FE-GATE-015·027의 gate log와 evidence, `scan:dependency-advisories` 기록을 후보와 +다른 이름(`immutable-gate-evidence--`)으로 성공·실패와 상관없이 +올린다(1105/13-01). `ci:gate`는 명령 출력을 gate log에만 쓰고 콘솔에는 한 줄만 +남기므로, release 단계의 실패 이유는 이 산출물에서 읽는다. 후보 archive의 member +set은 그대로다. Vulnerability/provenance provider job은 같은 archive를 각각 내려받아 output SHA-256과 exact member set을 확인한 뒤 checkout과 분리된 root에만 추출하고, `CANDIDATE_LOCKFILE_PATH`와 `CANDIDATE_DIST_SHA256`를 외부 command에 전달한다. Provider command 실행 후에는 @@ -525,6 +530,11 @@ Repository variables required by higher tiers: findings) or `UNVERIFIED` (no registry). It never fails the gate, because an advisory database that changes under unchanged code would break releases; the signed verdict of the vulnerability provider still decides promotion. + The job console shows only one PASS/FAIL line per gate, so the + immutable_build job uploads both gates' logs and evidence and this record as + the run artifact `immutable-gate-evidence--`, whether the job + passed or failed (1105/13-01). Read why FE-GATE-015 or FE-GATE-027 failed, + and the advisory status, there. `renovate.json` opens security update PRs once a Renovate runner is attached; a dependency update re-approves the dependency baseline in the same change (`update:dependency-baseline`). diff --git a/scripts/contracts/ci-gates.ts b/scripts/contracts/ci-gates.ts index 5111a329..ae02aedb 100644 --- a/scripts/contracts/ci-gates.ts +++ b/scripts/contracts/ci-gates.ts @@ -4,6 +4,7 @@ import path from "node:path"; import { z } from "zod"; +import { DEPENDENCY_ADVISORIES_RECORD_PATH } from "../lib/dependency-advisories.ts"; import { PROMOTION_FORMULA } from "../lib/promotion-readiness.ts"; import { RELEASE_CANDIDATE_EVIDENCE_PATHS, @@ -952,7 +953,7 @@ function validateContractSemantics( const expectedStepKinds: Readonly> = { merge_gate: ["checkout", "setup-node", "frozen-install", "browser-install", "run-gate", "upload"], release_gate: ["checkout", "setup-node", "frozen-install", "browser-install", "run-gate", "upload"], - immutable_build: ["checkout", "setup-node", "frozen-install", "run-gate", "archive-candidate", "upload"], + immutable_build: ["checkout", "setup-node", "frozen-install", "run-gate", "archive-candidate", "upload", "upload"], vulnerability_provider: ["checkout", "setup-node", "frozen-install", "download", "run-provider", "validate-provider-evidence", "upload"], provenance_provider: ["checkout", "setup-node", "frozen-install", "download", "run-provider", "validate-provider-evidence", "upload"], promotion: ["checkout", "setup-node", "frozen-install", "download", "download", "download", "verify-promotion", "upload", "cleanup-promotion"], @@ -1150,6 +1151,29 @@ function validateContractSemantics( validateCanonicalStepFields(contract, issue); } +const IMMUTABLE_GATE_EVIDENCE_TRANSFER_ID = "immutable-gate-evidence"; + +/** + * 1105/13-01. What immutable_build uploads besides the candidate: the log and + * evidence artifacts of each gate it runs, in gate order, then the advisory + * record of scan:dependency-advisories (FE-GATE-027), which is not a gate + * evidence artifact because it never blocks. + */ +function immutableGateEvidencePaths( + contract: Pick, "artifacts" | "gates">, + immutable: Pick, "gateIds">, +): string[] { + const paths = immutable.gateIds.flatMap((gateId) => { + const gate = contract.gates.find(({ id }) => id === gateId); + return gate + ? [gate.logArtifactId, ...gate.evidenceArtifactIds].flatMap((artifactId) => + contract.artifacts.filter(({ id }) => id === artifactId).map(({ path: artifactPath }) => artifactPath), + ) + : []; + }); + return [...new Set([...paths, DEPENDENCY_ADVISORIES_RECORD_PATH])]; +} + function validateCanonicalStepFields( contract: z.infer, issue: (message: string, path?: PropertyKey[]) => void, @@ -1168,6 +1192,26 @@ function validateCanonicalStepFields( ) { issue("immutable archive and upload fields must remain linked"); } + // 1105/13-01. ci:gate writes command output only to the gate log and prints + // one PASS/FAIL line, and this job uploaded only the candidate, on success. + // Why FE-GATE-015 or FE-GATE-027 failed, and the advisory record FE-GATE-027 + // writes, went with the runner's workspace. A separate transfer, always and + // last, carries them; the candidate archive's member set stays as it is. + const gateEvidence = immutable?.steps.find( + (step) => step.kind === "upload" && step.transferId === IMMUTABLE_GATE_EVIDENCE_TRANSFER_ID, + ); + if ( + !immutable || + gateEvidence?.kind !== "upload" || + gateEvidence.always !== true || + immutable.steps.at(-1) !== gateEvidence || + JSON.stringify(gateEvidence.paths) !== JSON.stringify(immutableGateEvidencePaths(contract, immutable)) + ) { + issue( + "immutable_build must upload its gates' logs and evidence and the dependency advisory record " + + `as ${IMMUTABLE_GATE_EVIDENCE_TRANSFER_ID}, with always, as its last step`, + ); + } const providerExpectations = { vulnerability_provider: { diff --git a/scripts/lib/dependency-advisories.ts b/scripts/lib/dependency-advisories.ts index 083540be..ffcd91ee 100644 --- a/scripts/lib/dependency-advisories.ts +++ b/scripts/lib/dependency-advisories.ts @@ -1,5 +1,11 @@ import { validateVulnerabilityReport } from "./supply-chain.ts"; +/** + * Where scan:dependency-advisories writes its record. 1105/13-01: the + * immutable_build job uploads it on every outcome (scripts/contracts/ci-gates.ts). + */ +export const DEPENDENCY_ADVISORIES_RECORD_PATH = "artifacts/security/dependency-advisories.json"; + /** * 1103/13-03. The vulnerability verdict belongs to the external provider of * the production promotion (signed, independent of the build). Without a diff --git a/scripts/scan-dependency-advisories.ts b/scripts/scan-dependency-advisories.ts index dc5a8fdf..14621e2e 100644 --- a/scripts/scan-dependency-advisories.ts +++ b/scripts/scan-dependency-advisories.ts @@ -2,7 +2,10 @@ import { spawnSync } from "node:child_process"; import { createHash } from "node:crypto"; import { mkdir, readFile, writeFile } from "node:fs/promises"; -import { summarizeDependencyAdvisories } from "./lib/dependency-advisories.ts"; +import { + DEPENDENCY_ADVISORIES_RECORD_PATH, + summarizeDependencyAdvisories, +} from "./lib/dependency-advisories.ts"; /** * 1103/13-03. Release-stage signal for known dependency advisories @@ -17,7 +20,7 @@ import { summarizeDependencyAdvisories } from "./lib/dependency-advisories.ts"; * result is UNVERIFIED, not PASS. The signed verdict of the vulnerability * provider stays the only one that decides a promotion. */ -const RECORD_PATH = "artifacts/security/dependency-advisories.json"; +const RECORD_PATH = DEPENDENCY_ADVISORIES_RECORD_PATH; const [policy, exceptions, lockfile] = await Promise.all([ readFile("config/security/vulnerability-policy.json", "utf8").then((text) => JSON.parse(text) as Record), diff --git a/tests/unit/__snapshots__/ci-workflow-generation.test.ts.snap b/tests/unit/__snapshots__/ci-workflow-generation.test.ts.snap index 6b84e76f..a64963d1 100644 --- a/tests/unit/__snapshots__/ci-workflow-generation.test.ts.snap +++ b/tests/unit/__snapshots__/ci-workflow-generation.test.ts.snap @@ -210,6 +210,20 @@ jobs: name: "release-candidate-\${{ gitea.run_id }}-\${{ gitea.run_attempt }}" path: ".release/release-candidate-\${{ gitea.run_id }}-\${{ gitea.run_attempt }}.tar.gz" if-no-files-found: error + - name: Upload immutable gate evidence + if: always() + uses: https://github.com/ChristopherHX/gitea-upload-artifact@81f940d004763f986ba3582c007fd842dd5cb0d7 + with: + name: "immutable-gate-evidence-\${{ gitea.run_id }}-\${{ gitea.run_attempt }}" + path: | + artifacts/quality/gates/FE-GATE-015.txt + artifacts/release/release-candidate.json + artifacts/release/verification.json + artifacts/security/supply-chain-coherence.json + artifacts/quality/gates/FE-GATE-027.txt + artifacts/release/deployment-admission.json + artifacts/security/dependency-advisories.json + if-no-files-found: error vulnerability_provider: name: external-vulnerability-provider diff --git a/tests/unit/ci-workflow-generation.test.ts b/tests/unit/ci-workflow-generation.test.ts index 03d8ad2d..f5ad6f8a 100644 --- a/tests/unit/ci-workflow-generation.test.ts +++ b/tests/unit/ci-workflow-generation.test.ts @@ -1654,7 +1654,7 @@ describe("CI workflow generation", () => { 'if [ -n "$PROMOTION_STAGING_ROOT" ] && [ -n "$PROMOTION_CLEANUP_TOKEN" ] && [ -n "$PROMOTION_RUNNER_TEMP_DEV" ] && [ -n "$PROMOTION_RUNNER_TEMP_INO" ] && [ -n "$PROMOTION_STAGING_DEV" ] && [ -n "$PROMOTION_STAGING_INO" ]; then', ); const actionUses = [...first.matchAll(/^\s+-?\s*uses: (.+)$/gmu)].map((match) => match[1]); - expect(actionUses).toHaveLength(33); + expect(actionUses).toHaveLength(34); expect(new Set(actionUses)).toEqual( new Set([ "https://github.com/actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5", @@ -1743,6 +1743,105 @@ describe("CI workflow generation", () => { expect(workflowGateExecutionFailures(contract, workflow)).toEqual([]); }); + // 1105/13-01. ci:gate writes each command's output only to the gate log and + // prints one PASS/FAIL line. immutable_build uploaded only the candidate, on + // success, so why FE-GATE-015 or FE-GATE-027 failed, and the advisory record + // FE-GATE-027 writes (1103/13-03), went with the runner's workspace. + const IMMUTABLE_GATE_EVIDENCE_PATHS = [ + "artifacts/quality/gates/FE-GATE-015.txt", + "artifacts/release/release-candidate.json", + "artifacts/release/verification.json", + "artifacts/security/supply-chain-coherence.json", + "artifacts/quality/gates/FE-GATE-027.txt", + "artifacts/release/deployment-admission.json", + "artifacts/security/dependency-advisories.json", + ]; + + it("uploads immutable_build's gate logs, evidence and advisory record on every outcome (1105/13-01)", async () => { + const contract = await loadCiGateContract(process.cwd()); + const index = indexCiGateContract(contract); + const gatePaths = ["FE-GATE-015", "FE-GATE-027"].flatMap((gateId) => { + const gate = index.gates.get(gateId)!; + return [gate.logArtifactId, ...gate.evidenceArtifactIds].map((artifactId) => index.artifacts.get(artifactId)!.path); + }); + expect(IMMUTABLE_GATE_EVIDENCE_PATHS).toEqual([...gatePaths, "artifacts/security/dependency-advisories.json"]); + + const workflow = renderCiWorkflow(contract); + const immutable = workflow.slice( + workflow.indexOf(" immutable_build:\n"), + workflow.indexOf(" vulnerability_provider:\n"), + ); + const candidateUpload = immutable.indexOf(" - name: Upload release candidate\n"); + const evidenceUpload = immutable.indexOf(" - name: Upload immutable gate evidence\n"); + expect(candidateUpload).toBeGreaterThan(immutable.indexOf("ci:gate -- FE-GATE-027")); + expect(evidenceUpload).toBeGreaterThan(candidateUpload); + expect(immutable.slice(evidenceUpload)).toBe( + [ + " - name: Upload immutable gate evidence", + " if: always()", + ` uses: ${resolveCiActionUses("uploadArtifact")}`, + " with:", + ' name: "immutable-gate-evidence-${{ gitea.run_id }}-${{ gitea.run_attempt }}"', + " path: |", + ...IMMUTABLE_GATE_EVIDENCE_PATHS.map((target) => ` ${target}`), + " if-no-files-found: error", + "", + "", + ].join("\n"), + ); + // The candidate still goes up only after its archive was validated, and + // the archive's member set is not widened by the evidence. + expect(immutable.slice(candidateUpload, evidenceUpload)).not.toContain("if: always()"); + const archive = contract.jobs + .find(({ id }) => id === "immutable_build") + ?.steps.find((step) => step.kind === "archive-candidate"); + expect(archive?.kind === "archive-candidate" ? archive.members : []).not.toContain( + "artifacts/quality/gates/FE-GATE-027.txt", + ); + }); + + it.each([ + [ + "is missing", + (steps: Record[]) => steps.splice(steps.findIndex((step) => step.transferId === "immutable-gate-evidence"), 1), + ], + [ + "runs only on success", + (steps: Record[]) => delete steps.find((step) => step.transferId === "immutable-gate-evidence")!.always, + ], + [ + "leaves out the advisory record", + (steps: Record[]) => { + const upload = steps.find((step) => step.transferId === "immutable-gate-evidence")!; + upload.paths = upload.paths.filter((target: string) => target !== "artifacts/security/dependency-advisories.json"); + }, + ], + [ + "leaves out the FE-GATE-027 log", + (steps: Record[]) => { + const upload = steps.find((step) => step.transferId === "immutable-gate-evidence")!; + upload.paths = upload.paths.filter((target: string) => target !== "artifacts/quality/gates/FE-GATE-027.txt"); + }, + ], + [ + "comes before the candidate upload", + (steps: Record[]) => { + const evidence = steps.splice(steps.findIndex((step) => step.transferId === "immutable-gate-evidence"), 1)[0]!; + steps.splice(steps.findIndex((step) => step.transferId === "release-candidate"), 0, evidence); + }, + ], + ])("rejects an immutable_build whose gate evidence upload %s (1105/13-01)", async (_name, mutate) => { + const contract = JSON.parse( + JSON.stringify(await loadCiGateContract(process.cwd())), + ) as Record; + const steps = contract.jobs.find((job: Record) => job.id === "immutable_build").steps; + expect(steps.filter((step: Record) => step.transferId === "immutable-gate-evidence")).toHaveLength(1); + mutate(steps); + expect(() => parseCiGateContract(contract)).toThrow( + /immutable_build must upload its gates' logs and evidence and the dependency advisory record/u, + ); + }); + it.each([ ["a non-matrix gate step", " run: corepack pnpm ci:gate -- FE-GATE-027\n", "FE-GATE-027"], ["a matrix entry", " - { gate: FE-GATE-020, name: removability, browser: false }\n", "FE-GATE-020"],