정리 4단계의 R2 검사는 등록부를 쓰는 7곳만 봤다. 그 밖에 루트 이름을 담은 목록이 코드 15파일에 19개 따로 있어, 루트 항목 하나를 옮기면 여전히 여러 곳을 같이 고쳐야 했다. - 등록부에 집합 12개를 더했다. 사본 복사에서 건너뛰는 항목 셋 (checkout·provider·공급망 fixture), fixture 코드 범위, pnpm 매니페스트, Playwright 설정, visual 증거, 문서 입력, 에이전트 하네스, tsconfig 묶음 셋. 각 집합 설명에 읽는 파일을 적었다. - 사본이 건너뛰는 node_modules·dist·.tmp 같은 추적 안 하는 항목은 종류 untracked(optional)로 적는다. 추적 파일이 있으면 시험이 실패한다. - 19개 목록이 모두 집합을 고른다. 집합의 원소는 전과 같아 동작은 바뀌지 않는다. - R2 시험이 추적되는 코드 파일 전체를 본다. 루트 항목(이나 그 안 경로)만 담은 문자열 배열에 추적되는 루트 이름이 둘 이상이면 실패. 인자 목록은 `--` 뒤만 본다. main의 옛 목록 18개를 이 검사가 잡는 것을 확인했다. - 집합마다 selectRepositoryPaths·selectRepositoryEntries로 고르는 코드가 있는지 본다. 문서를 복사하지 않는 제거 drill(FE-GATE-020)은 문서 시험(REMOVAL_FIXTURE_DOCUMENT_TESTS)을 지우는데, 집합 셋 (agent-harness·documentation-inputs·feature-typecheck)은 그 시험만 읽는다. 시험이 이 셋을 적어 두고, 문서 시험이 지워진 사본에서만 셋이 비는 것을 허용한다. 셋이 바뀌면 전체 checkout에서 실패한다. - 파서가 kinds·sets 설명과 코드의 목록이 같은지 본다. - .gitignore 주석이 a11y 기록을 아직 artifacts/ 아래라고 적던 것을 고쳤다(정리 3단계에서 docs/로 옮김). 검증(desktop): test:unit, check:types, check:ci, lint, verify:documentation. repository-layout 시험을 문서 없는 제거 사본과 feature-scaffold 사본에서도 돌렸고, 집합 하나의 읽는 곳을 지우면 두 곳 모두 실패한다.
420 lines
15 KiB
TypeScript
420 lines
15 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
|
import {
|
|
createHash,
|
|
generateKeyPairSync,
|
|
sign,
|
|
type KeyObject,
|
|
} from "node:crypto";
|
|
import {
|
|
cp,
|
|
mkdir,
|
|
mkdtemp,
|
|
readFile,
|
|
readdir,
|
|
rm,
|
|
writeFile,
|
|
} from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
|
|
import {
|
|
localEvidenceAssessmentArtifactSchema,
|
|
supplyChainProviderFixturesArtifactSchema,
|
|
} from "./contracts/release-artifacts.ts";
|
|
import { PROMOTED_FILE_NAMES } from "./contracts/promotion-artifacts.ts";
|
|
import {
|
|
captureCiCandidateArchive,
|
|
} from "./lib/ci-candidate-archive.ts";
|
|
import {
|
|
cleanupFinalizedPromotion,
|
|
finalizeVerifiedPromotion,
|
|
} from "./lib/promotion-stager.ts";
|
|
import { verifyExactPromotionBundle } from "./lib/exact-promotion-bundle.ts";
|
|
import {
|
|
providerEvidenceSignaturePayload,
|
|
providerPublicKeyFingerprint,
|
|
} from "./lib/provider-evidence.ts";
|
|
import {
|
|
LOCAL_EVIDENCE_ASSESSMENT_PATH,
|
|
RELEASE_CANDIDATE_EVIDENCE_PATHS,
|
|
RELEASE_CANDIDATE_MANIFEST_PATH,
|
|
releaseCandidateManifestSchema,
|
|
} from "./lib/release-candidate.ts";
|
|
import { writeValidatedJsonArtifact } from "./lib/validated-json-artifact.ts";
|
|
import {
|
|
FIXTURE_PNPM_ENVIRONMENT,
|
|
linkFixtureNodeModules,
|
|
} from "./lib/fixture-node-modules.ts";
|
|
import { selectRepositoryPaths } from "./lib/repository-layout.ts";
|
|
|
|
const repositoryRoot = process.cwd();
|
|
const UNCOPIED_ROOTS = selectRepositoryPaths("supply-chain-fixture-skip");
|
|
const fixtureRoot = await mkdtemp(path.join(tmpdir(), "provider-exact-five-fixture-"));
|
|
try {
|
|
await cp(repositoryRoot, fixtureRoot, {
|
|
recursive: true,
|
|
filter: (source) => {
|
|
const relative = path.relative(repositoryRoot, source);
|
|
if (!relative) return true;
|
|
const first = relative.split(path.sep)[0];
|
|
return !UNCOPIED_ROOTS.includes(first ?? "");
|
|
},
|
|
});
|
|
await cp(path.join(repositoryRoot, "artifacts"), path.join(fixtureRoot, "artifacts"), {
|
|
recursive: true,
|
|
});
|
|
await rm(path.join(fixtureRoot, "artifacts/release"), { recursive: true, force: true });
|
|
await linkFixtureNodeModules(fixtureRoot, repositoryRoot);
|
|
const git = spawnSync("git", ["show", "-s", "--format=%H%n%ct", "HEAD"], {
|
|
cwd: repositoryRoot,
|
|
encoding: "utf8",
|
|
});
|
|
if (git.status !== 0) throw new Error(`provider fixture git identity failed: ${git.stderr}`);
|
|
const [revision, sourceDateEpoch] = git.stdout.trim().split(/\r?\n/u);
|
|
if (!revision || !sourceDateEpoch) throw new Error("provider fixture git identity is incomplete");
|
|
const build = spawnSync("corepack", ["pnpm", "build:release-candidate"], {
|
|
cwd: fixtureRoot,
|
|
encoding: "utf8",
|
|
timeout: 120_000,
|
|
maxBuffer: 32 * 1024 * 1024,
|
|
env: {
|
|
...process.env,
|
|
...FIXTURE_PNPM_ENVIRONMENT,
|
|
CI: "true",
|
|
VITE_BUILD_ID: "provider-exact-five-fixture",
|
|
VITE_COMMIT_SHA: revision,
|
|
RELEASE_ID: "provider-exact-five-fixture",
|
|
SOURCE_DATE_EPOCH: sourceDateEpoch,
|
|
CI_RUNNER_IMAGE: `fixture@sha256:${"a".repeat(64)}`,
|
|
},
|
|
});
|
|
if (build.status !== 0) throw new Error(`${build.stdout}\n${build.stderr}`);
|
|
const manifest = releaseCandidateManifestSchema.parse(
|
|
JSON.parse(
|
|
await readFile(path.join(fixtureRoot, RELEASE_CANDIDATE_MANIFEST_PATH), "utf8"),
|
|
) as unknown,
|
|
);
|
|
const assessment = localEvidenceAssessmentArtifactSchema.parse(
|
|
JSON.parse(
|
|
await readFile(path.join(fixtureRoot, LOCAL_EVIDENCE_ASSESSMENT_PATH), "utf8"),
|
|
) as unknown,
|
|
);
|
|
const archivePath = path.join(fixtureRoot, "candidate.tar.gz");
|
|
const tar = spawnSync(
|
|
"/usr/bin/tar",
|
|
[
|
|
"--sort=name",
|
|
"--mtime=@0",
|
|
"--owner=0",
|
|
"--group=0",
|
|
"--numeric-owner",
|
|
"-czf",
|
|
archivePath,
|
|
"dist",
|
|
...RELEASE_CANDIDATE_EVIDENCE_PATHS,
|
|
RELEASE_CANDIDATE_MANIFEST_PATH,
|
|
],
|
|
{ cwd: fixtureRoot, encoding: "utf8" },
|
|
);
|
|
if (tar.status !== 0) throw new Error(`provider fixture real tar failed: ${tar.stderr}`);
|
|
const archiveBytes = await readFile(archivePath);
|
|
const archiveSha256 = sha256(archiveBytes);
|
|
const now = Date.parse("2026-08-02T01:00:00.000Z");
|
|
const vulnerabilityKeys = generateKeyPairSync("ed25519");
|
|
const provenanceKeys = generateKeyPairSync("ed25519");
|
|
const vulnerabilityKeyId = "fixture-vulnerability-key";
|
|
const provenanceKeyId = "fixture-provenance-key";
|
|
const vulnerabilityNonce = "1".repeat(64);
|
|
const provenanceNonce = "2".repeat(64);
|
|
const context = {
|
|
run: { id: "fixture-run", attempt: 1 },
|
|
source: {
|
|
revision: assessment.source.revision,
|
|
sourceSetSha256: assessment.source.sourceSetSha256,
|
|
},
|
|
candidate: {
|
|
archiveSha256,
|
|
bundleSha256: manifest.bundleSha256,
|
|
distSha256: manifest.distSha256,
|
|
lockfileSha256: manifest.lockfileSha256,
|
|
},
|
|
} as const;
|
|
const vulnerability = signedEvidence(
|
|
{
|
|
schemaVersion: 2,
|
|
evidenceType: "vulnerability-report",
|
|
provider: "fixture-vulnerability-provider",
|
|
issuedAt: new Date(now).toISOString(),
|
|
expiresAt: new Date(now + 60 * 60 * 1_000).toISOString(),
|
|
run: { ...context.run, invocationNonce: vulnerabilityNonce },
|
|
source: context.source,
|
|
candidate: context.candidate,
|
|
secretScanAttestation: {
|
|
status: "PASS",
|
|
localEvidenceAssessmentSha256: sha256(
|
|
await readFile(path.join(fixtureRoot, LOCAL_EVIDENCE_ASSESSMENT_PATH)),
|
|
),
|
|
sourceSetSha256: assessment.source.sourceSetSha256,
|
|
policySha256: assessment.secretScan.policySha256,
|
|
sarifSha256: assessment.secretScan.sarifSha256,
|
|
scanInputSha256: assessment.secretScan.scanInputSha256,
|
|
},
|
|
findings: [],
|
|
},
|
|
vulnerabilityKeyId,
|
|
vulnerabilityKeys.publicKey,
|
|
vulnerabilityKeys.privateKey,
|
|
);
|
|
const provenance = signedEvidence(
|
|
{
|
|
schemaVersion: 2,
|
|
evidenceType: "provenance-attestation",
|
|
provider: "fixture-provenance-provider",
|
|
signer: "fixture-workload-identity",
|
|
issuedAt: new Date(now).toISOString(),
|
|
expiresAt: new Date(now + 60 * 60 * 1_000).toISOString(),
|
|
run: { ...context.run, invocationNonce: provenanceNonce },
|
|
source: context.source,
|
|
candidate: context.candidate,
|
|
subject: { name: "dist", digest: { sha256: manifest.distSha256 } },
|
|
},
|
|
provenanceKeyId,
|
|
provenanceKeys.publicKey,
|
|
provenanceKeys.privateKey,
|
|
);
|
|
await Promise.all([
|
|
write(fixtureRoot, "provider/vulnerability.json", `${JSON.stringify(vulnerability)}\n`),
|
|
write(fixtureRoot, "provider/provenance.json", `${JSON.stringify(provenance)}\n`),
|
|
write(
|
|
fixtureRoot,
|
|
"provider/vulnerability.pem",
|
|
vulnerabilityKeys.publicKey.export({ type: "spki", format: "pem" }),
|
|
),
|
|
write(
|
|
fixtureRoot,
|
|
"provider/provenance.pem",
|
|
provenanceKeys.publicKey.export({ type: "spki", format: "pem" }),
|
|
),
|
|
]);
|
|
const runnerTempRoot = path.join(fixtureRoot, "runner-temp");
|
|
await mkdir(runnerTempRoot, { mode: 0o700 });
|
|
const finalized = await finalizeVerifiedPromotion(
|
|
{
|
|
repositoryRoot: fixtureRoot,
|
|
archivePath,
|
|
expectedArchiveSha256: archiveSha256,
|
|
vulnerabilityReportPath: "provider/vulnerability.json",
|
|
provenanceAttestationPath: "provider/provenance.json",
|
|
vulnerabilityPublicKeyPath: "provider/vulnerability.pem",
|
|
vulnerabilityKeyId,
|
|
provenancePublicKeyPath: "provider/provenance.pem",
|
|
provenanceKeyId,
|
|
expectedRun: { id: context.run.id, attempt: 1, sourceRevision: revision },
|
|
vulnerabilityInvocationNonce: vulnerabilityNonce,
|
|
provenanceInvocationNonce: provenanceNonce,
|
|
runnerTempRoot,
|
|
},
|
|
{
|
|
nowEpochMs: () => now,
|
|
randomBytes: (bytes) => Buffer.alloc(bytes, 0x4a),
|
|
afterCapture: async () => {
|
|
await writeFile(path.join(fixtureRoot, "dist/index.html"), "contradictory external tree\n");
|
|
},
|
|
},
|
|
);
|
|
const validImmutable =
|
|
finalized.files.length === 5 &&
|
|
(await readdir(finalized.stagingRoot)).length === 5;
|
|
const exactFiles = Object.fromEntries(
|
|
await Promise.all(
|
|
PROMOTED_FILE_NAMES.map(async (name) => [
|
|
name,
|
|
await readFile(path.join(finalized.stagingRoot, name)),
|
|
] as const),
|
|
),
|
|
);
|
|
const bundleTrust = {
|
|
vulnerabilityTrust: {
|
|
keyId: vulnerabilityKeyId,
|
|
publicKey: vulnerabilityKeys.publicKey,
|
|
publicKeyFingerprint: providerPublicKeyFingerprint(vulnerabilityKeys.publicKey),
|
|
},
|
|
provenanceTrust: {
|
|
keyId: provenanceKeyId,
|
|
publicKey: provenanceKeys.publicKey,
|
|
publicKeyFingerprint: providerPublicKeyFingerprint(provenanceKeys.publicKey),
|
|
},
|
|
expected: {
|
|
run: context.run,
|
|
sourceRevision: context.source.revision,
|
|
sourceSetSha256: context.source.sourceSetSha256,
|
|
archiveSha256: context.candidate.archiveSha256,
|
|
bundleSha256: context.candidate.bundleSha256,
|
|
distSha256: context.candidate.distSha256,
|
|
lockfileSha256: context.candidate.lockfileSha256,
|
|
},
|
|
nowEpochMs: () => now,
|
|
} as const;
|
|
// 13-04: the same bundle three hours later. Current freshness refuses the
|
|
// expired provider evidence; archived freshness accepts it at the recorded
|
|
// promotion time, and still refuses a tampered archive.
|
|
const threeHoursLater = now + 3 * 60 * 60 * 1_000;
|
|
const archivedAfterWindow = await captureRejection(async () => {
|
|
await verifyExactPromotionBundle(exactFiles, {
|
|
...bundleTrust,
|
|
nowEpochMs: () => threeHoursLater,
|
|
freshness: "archived",
|
|
});
|
|
});
|
|
const currentAfterWindow = await captureRejection(async () => {
|
|
await verifyExactPromotionBundle(exactFiles, {
|
|
...bundleTrust,
|
|
nowEpochMs: () => threeHoursLater,
|
|
});
|
|
});
|
|
const tamperedArchive = Buffer.from(exactFiles["release-candidate.tar.gz"]);
|
|
tamperedArchive[tamperedArchive.length - 1] ^= 0xff;
|
|
const archivedTampered = await captureRejection(async () => {
|
|
await verifyExactPromotionBundle(
|
|
{ ...exactFiles, "release-candidate.tar.gz": tamperedArchive },
|
|
{ ...bundleTrust, nowEpochMs: () => threeHoursLater, freshness: "archived" },
|
|
);
|
|
});
|
|
const absentFiles = { ...exactFiles } as Partial<typeof exactFiles>;
|
|
delete absentFiles["provider-verification.json"];
|
|
const absent = await captureRejection(async () => {
|
|
await verifyExactPromotionBundle(absentFiles, bundleTrust);
|
|
});
|
|
|
|
const invalidPath = path.join(fixtureRoot, "invalid.tar.gz");
|
|
const invalidBytes = Buffer.from("arbitrary non-tar bytes\n");
|
|
await writeFile(invalidPath, invalidBytes);
|
|
const invalidTar = await captureRejection(async () => {
|
|
await finalizeVerifiedPromotion(
|
|
{
|
|
repositoryRoot: fixtureRoot,
|
|
archivePath: invalidPath,
|
|
expectedArchiveSha256: sha256(invalidBytes),
|
|
vulnerabilityReportPath: "provider/vulnerability.json",
|
|
provenanceAttestationPath: "provider/provenance.json",
|
|
vulnerabilityPublicKeyPath: "provider/vulnerability.pem",
|
|
vulnerabilityKeyId,
|
|
provenancePublicKeyPath: "provider/provenance.pem",
|
|
provenanceKeyId,
|
|
expectedRun: { id: context.run.id, attempt: 1, sourceRevision: revision },
|
|
vulnerabilityInvocationNonce: vulnerabilityNonce,
|
|
provenanceInvocationNonce: provenanceNonce,
|
|
runnerTempRoot,
|
|
},
|
|
{ nowEpochMs: () => now },
|
|
);
|
|
});
|
|
const wrongDigest = await captureRejection(async () => {
|
|
await captureCiCandidateArchive({ archivePath, expectedSha256: "0".repeat(64) });
|
|
});
|
|
const passed =
|
|
validImmutable && absent.rejected && invalidTar.rejected && wrongDigest.rejected &&
|
|
!archivedAfterWindow.rejected && currentAfterWindow.rejected && archivedTampered.rejected;
|
|
await cleanupFinalizedPromotion({
|
|
runnerTempRoot,
|
|
stagingRoot: finalized.stagingRoot,
|
|
cleanupToken: finalized.cleanupToken,
|
|
runnerTempIdentity: finalized.runnerTempIdentity,
|
|
stagingIdentity: finalized.stagingIdentity,
|
|
});
|
|
await mkdir(path.join(repositoryRoot, "artifacts/security"), { recursive: true });
|
|
await writeValidatedJsonArtifact({
|
|
path: path.join(repositoryRoot, "artifacts/security/supply-chain-provider-fixtures.json"),
|
|
schema: supplyChainProviderFixturesArtifactSchema,
|
|
value: {
|
|
schemaVersion: 1,
|
|
actualDefaultVerifier: {
|
|
status: validImmutable ? "PASS" : "FAIL_UNVERIFIED",
|
|
failures: validImmutable ? [] : ["canonical exact-five finalizer failed"],
|
|
},
|
|
fixtures: {
|
|
absent: {
|
|
status: absent.rejected ? "FAIL_UNVERIFIED" : "PASS",
|
|
failures: [absent.failure],
|
|
},
|
|
validImmutable: { status: validImmutable ? "PASS" : "FAIL_UNVERIFIED", failures: [] },
|
|
wrongDigest: {
|
|
status: wrongDigest.rejected ? "FAIL_UNVERIFIED" : "PASS",
|
|
failures: [wrongDigest.failure],
|
|
},
|
|
invalidTar: {
|
|
status: invalidTar.rejected ? "FAIL_UNVERIFIED" : "PASS",
|
|
failures: [invalidTar.failure],
|
|
},
|
|
archivedAfterWindow: {
|
|
status: archivedAfterWindow.rejected ? "FAIL_UNVERIFIED" : "PASS",
|
|
failures: archivedAfterWindow.rejected ? [archivedAfterWindow.failure] : [],
|
|
},
|
|
currentAfterWindow: {
|
|
status: currentAfterWindow.rejected ? "FAIL_UNVERIFIED" : "PASS",
|
|
failures: [currentAfterWindow.failure],
|
|
},
|
|
archivedTampered: {
|
|
status: archivedTampered.rejected ? "FAIL_UNVERIFIED" : "PASS",
|
|
failures: [archivedTampered.failure],
|
|
},
|
|
},
|
|
externalTreeCanary: {
|
|
status: validImmutable ? "PASS" : "FAIL_UNVERIFIED",
|
|
failures: validImmutable ? [] : ["external tree canary influenced captured archive"],
|
|
},
|
|
passingFixtureCount: (validImmutable ? 1 : 0) + (archivedAfterWindow.rejected ? 0 : 1),
|
|
status: passed ? "PASS" : "FAIL",
|
|
},
|
|
});
|
|
if (!passed) throw new Error("canonical exact-five provider fixtures failed closed incorrectly");
|
|
process.stdout.write("Supply-chain provider real-tar signed exact-five fixtures: PASS\n");
|
|
} finally {
|
|
await rm(fixtureRoot, { recursive: true, force: true });
|
|
}
|
|
|
|
function signedEvidence(
|
|
value: Record<string, unknown>,
|
|
keyId: string,
|
|
publicKey: KeyObject,
|
|
privateKey: KeyObject,
|
|
) {
|
|
return {
|
|
...value,
|
|
signature: {
|
|
algorithm: "Ed25519",
|
|
keyId,
|
|
publicKeyFingerprint: providerPublicKeyFingerprint(publicKey),
|
|
value: sign(
|
|
null,
|
|
providerEvidenceSignaturePayload(value),
|
|
privateKey,
|
|
).toString("base64"),
|
|
},
|
|
};
|
|
}
|
|
|
|
async function write(root: string, relative: string, value: string | Buffer): Promise<void> {
|
|
const absolute = path.join(root, relative);
|
|
await mkdir(path.dirname(absolute), { recursive: true });
|
|
await writeFile(absolute, value);
|
|
}
|
|
|
|
async function captureRejection(
|
|
operation: () => Promise<void>,
|
|
): Promise<Readonly<{ rejected: boolean; failure: string }>> {
|
|
try {
|
|
await operation();
|
|
return Object.freeze({ rejected: false, failure: "fixture unexpectedly passed" });
|
|
} catch (error) {
|
|
return Object.freeze({
|
|
rejected: true,
|
|
failure: error instanceof Error ? error.message : String(error),
|
|
});
|
|
}
|
|
}
|
|
|
|
function sha256(bytes: Buffer): string {
|
|
return createHash("sha256").update(bytes).digest("hex");
|
|
}
|