fix(ci): 배포 슬롯이 승격 후보를 받게 하고 secret을 deploy 단계에만 준다
문제: (1) 배포 슬롯 계약은 단계 종류만 제한하고 "마지막이 deploy 하나"만 강제했다. checkout → setup-node → frozen-install → deploy(script)처럼 후보 archive를 받지 않고 다시 빌드하는 슬롯도 check:ci를 통과했고, 생성된 job 이름은 그대로 deploy-promoted-release였다(리뷰 실험 E-3). (2) 생성기는 슬롯의 환경 바인딩을 job 수준 env:로 썼다. 그래서 secrets.* 배포 자격 증명이 checkout, setup-node, frozen-install과 제3자 download action에도 보였다. 고른 방법: (1) deploy 단계에 script가 있으면 promoted-release 전송 하나만 download하고, 그 경로의 release-candidate.tar.gz를 extract하고, CANDIDATE_ARCHIVE_SHA256을 immutable_build의 digest로 바인딩해야 한다. extract는 verify-ci-candidate-archive.ts가 digest로 확인한다. 빈 슬롯은 그대로 허용한다. (2) 배포 슬롯의 secrets.* 바인딩은 deploy 단계의 env:로만 렌더링한다. vars.*와 후보 digest는 job 수준에 남는다(extract가 digest를 쓴다). 버린 대안: 슬롯 단계를 템플릿이 통째로 고정하기. 다음 커밋의 제품 overlay가 채우는 모양을 고정하고, gates.json으로 채우는 길은 이 규칙으로 막는다. 위험·한계: 슬롯이 받은 파일을 deploy 스크립트가 실제로 올리는지는 계약이 볼 수 없다. 그것은 FE-GATE-019의 config.json·entry 대조(앞 커밋)가 결과로 본다. 템플릿 슬롯은 비어 있어 생성 workflow 바이트는 바뀌지 않는다. 검증: ci-workflow-generation.test.ts에 후보 없이 deploy하는 슬롯과 digest 없이 extract하는 슬롯의 거절, secret이 deploy 단계 env에만 한 번 나오는 것을 더했다(고치기 전 3건 실패). 425건 통과. check:ci PASS, CI workflow bytes PASS. Refs: docs/reviews/2026-11-03-maturity-review/13-build-release-supply-chain.md 13-01, 13-05
This commit is contained in:
@@ -348,7 +348,12 @@ generate:ci-workflow`. The contract allows the steps `checkout`, `setup-node`,
|
||||
`frozen-install`, `download` (the `promoted-release` transfer), `extract`, and
|
||||
one final `deploy` step whose `script` names a package script. Its variables
|
||||
may only be the `CANDIDATE_ARCHIVE_SHA256` digest of `immutable_build` and
|
||||
`vars.*` or `secrets.*` values. The `deploy` step writes `deployed=true` only
|
||||
`vars.*` or `secrets.*` values. A slot with a deploy script must download only
|
||||
the `promoted-release` transfer, extract its `release-candidate.tar.gz` and
|
||||
bind the digest, so the script deploys the promoted candidate rather than a
|
||||
rebuild (1103/13-01). `secrets.*` values are rendered on the `deploy` step
|
||||
alone, not on the job, so checkout, setup-node and the download action never
|
||||
see them (1103/13-05). The `deploy` step writes `deployed=true` only
|
||||
after the script succeeds. The job owns no gate, so filling it changes neither
|
||||
gate ownership nor the contract baseline. Browser boot, live API traffic, smoke after a provider
|
||||
switch, and anything the runbook marks as needing provider verification are
|
||||
|
||||
@@ -1027,6 +1027,7 @@ function validateContractSemantics(
|
||||
if (duplicate || foreign.length > 0) {
|
||||
issue(`deployment slot binding must be the candidate digest or a vars.* or secrets.* value: ${job.id}`);
|
||||
}
|
||||
for (const failure of deploymentSlotInputFailures(job)) issue(failure);
|
||||
} else if (duplicate || JSON.stringify(job.environment) !== JSON.stringify(expectedEnvironmentBindings[job.id])) {
|
||||
issue(`job environment binding drift: ${job.id}`);
|
||||
}
|
||||
@@ -1244,6 +1245,47 @@ function validateCanonicalStepFields(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 1103/13-01. A slot that runs a deploy script deploys the promoted candidate:
|
||||
* it downloads the promoted-release transfer and extracts its
|
||||
* release-candidate.tar.gz, checked against the digest immutable_build
|
||||
* recorded, before the script runs. A slot that rebuilt instead passed the
|
||||
* contract under the name deploy-promoted-release, and FE-GATE-019 could not
|
||||
* tell the rebuild from the candidate.
|
||||
*/
|
||||
function deploymentSlotInputFailures(job: z.infer<typeof jobSchema>): string[] {
|
||||
const deploy = job.steps.find((step) => step.kind === "deploy");
|
||||
if (deploy?.kind !== "deploy" || deploy.script === undefined) return [];
|
||||
const failures: string[] = [];
|
||||
const downloads = job.steps.filter((step) => step.kind === "download");
|
||||
const download = downloads[0];
|
||||
const extract = job.steps.find((step) => step.kind === "extract");
|
||||
if (
|
||||
downloads.length !== 1 ||
|
||||
download?.kind !== "download" ||
|
||||
download.transferId !== "promoted-release" ||
|
||||
extract?.kind !== "extract" ||
|
||||
extract.archivePath !== `${download.path}/release-candidate.tar.gz` ||
|
||||
job.steps.indexOf(download) > job.steps.indexOf(extract)
|
||||
) {
|
||||
failures.push(
|
||||
`deployment slot with a deploy script must download only the promoted-release transfer and extract its release-candidate.tar.gz before deploying: ${job.id}`,
|
||||
);
|
||||
}
|
||||
if (
|
||||
!job.environment.some(
|
||||
({ name, value }) =>
|
||||
name === "CANDIDATE_ARCHIVE_SHA256" &&
|
||||
value === "${{ needs.immutable_build.outputs.archive_sha256 }}",
|
||||
)
|
||||
) {
|
||||
failures.push(
|
||||
`deployment slot with a deploy script must bind CANDIDATE_ARCHIVE_SHA256 so its extract step checks the promoted archive: ${job.id}`,
|
||||
);
|
||||
}
|
||||
return failures;
|
||||
}
|
||||
|
||||
function validateJobStepKinds(
|
||||
job: z.infer<typeof jobSchema>,
|
||||
issue: (message: string, path?: PropertyKey[]) => void,
|
||||
|
||||
@@ -144,9 +144,10 @@ function renderJob(
|
||||
if (job.kind === "deployment") {
|
||||
lines.push(" outputs:", " deployed: ${{ steps.deploy.outputs.deployed }}");
|
||||
}
|
||||
if (job.environment.length > 0) {
|
||||
const jobEnvironment = job.environment.filter((binding) => !isStepScopedSecret(job, binding));
|
||||
if (jobEnvironment.length > 0) {
|
||||
lines.push(" env:");
|
||||
for (const binding of job.environment) {
|
||||
for (const binding of jobEnvironment) {
|
||||
lines.push(` ${binding.name}: ${yamlScalar(binding.value)}`);
|
||||
}
|
||||
}
|
||||
@@ -276,11 +277,15 @@ function renderStep(
|
||||
];
|
||||
// 1101/13-01. `run` fails on the first failing command, so deployed=true
|
||||
// is written only after the project's script succeeded.
|
||||
case "deploy":
|
||||
case "deploy": {
|
||||
const secrets = job.environment.filter((binding) => isStepScopedSecret(job, binding));
|
||||
return step.script
|
||||
? [
|
||||
" - name: Deploy the promoted release",
|
||||
" id: deploy",
|
||||
...(secrets.length > 0
|
||||
? [" env:", ...secrets.map((binding) => ` ${binding.name}: ${yamlScalar(binding.value)}`)]
|
||||
: []),
|
||||
" run: |",
|
||||
// The contract limits the name to [A-Za-z0-9:_-], a plain shell word.
|
||||
` corepack pnpm ${step.script}`,
|
||||
@@ -291,6 +296,7 @@ function renderStep(
|
||||
" id: deploy",
|
||||
' run: echo "deployed=false" >> "$GITHUB_OUTPUT"',
|
||||
];
|
||||
}
|
||||
case "upload": {
|
||||
const lines = [
|
||||
` - name: Upload ${humanize(step.transferId)}`,
|
||||
@@ -310,6 +316,16 @@ function renderStep(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 1103/13-05. Job env reaches every step of the job: checkout, setup-node and
|
||||
* the third-party download action as well. In the deployment slot a
|
||||
* `secrets.*` binding is rendered on the deploy step instead, the one step
|
||||
* that uses it.
|
||||
*/
|
||||
function isStepScopedSecret(job: CiWorkflowJob, binding: CiWorkflowJob["environment"][number]): boolean {
|
||||
return job.kind === "deployment" && /^\$\{\{ secrets\./u.test(binding.value);
|
||||
}
|
||||
|
||||
function requiredStepActionUses(stepKind: string): string {
|
||||
const uses = resolveCiStepActionUses(stepKind);
|
||||
if (!uses) throw new TypeError(`workflow step has no registered CI action: ${stepKind}`);
|
||||
|
||||
@@ -386,7 +386,14 @@ describe("CI gate contract", () => {
|
||||
);
|
||||
const workflow = renderCiWorkflow(contract);
|
||||
const job = workflow.slice(workflow.indexOf(" deployment:\n"), workflow.indexOf(" production_gate:\n"));
|
||||
expect(job).toContain('DEPLOY_SSH_KEY: "${{ secrets.DEPLOY_SSH_KEY }}"');
|
||||
// 1103/13-05. Job env reaches every step, checkout and the third-party
|
||||
// download action included; a credential belongs to the deploy step only.
|
||||
const jobEnvironment = job.slice(job.indexOf(" env:\n"), job.indexOf(" steps:\n"));
|
||||
const deployStep = job.slice(job.indexOf(" - name: Deploy the promoted release"));
|
||||
expect(jobEnvironment).toContain('DEPLOY_HOST: "${{ vars.DEPLOY_HOST }}"');
|
||||
expect(jobEnvironment).not.toContain("secrets.");
|
||||
expect(deployStep).toContain(' env:\n DEPLOY_SSH_KEY: "${{ secrets.DEPLOY_SSH_KEY }}"\n');
|
||||
expect(job.match(/secrets\./gu)).toHaveLength(1);
|
||||
expect(job.indexOf("--extract-to")).toBeLessThan(job.indexOf("corepack pnpm deploy:release"));
|
||||
expect(job.indexOf("corepack pnpm deploy:release")).toBeLessThan(
|
||||
job.indexOf('echo "deployed=true" >> "$GITHUB_OUTPUT"'),
|
||||
@@ -411,6 +418,18 @@ describe("CI gate contract", () => {
|
||||
(slot: Record<string, any>) => slot.steps.push({ kind: "checkout" }),
|
||||
/deploy step/u,
|
||||
],
|
||||
// 1103/13-01. A slot that rebuilt (or deployed anything but the promoted
|
||||
// archive) passed the contract under the name deploy-promoted-release.
|
||||
[
|
||||
"a slot that deploys without the promoted candidate",
|
||||
(slot: Record<string, any>) => slot.steps.splice(3, 2),
|
||||
/promoted-release/u,
|
||||
],
|
||||
[
|
||||
"a slot that extracts the candidate without its digest",
|
||||
(slot: Record<string, any>) => slot.environment.shift(),
|
||||
/CANDIDATE_ARCHIVE_SHA256/u,
|
||||
],
|
||||
])("rejects %s (1101/13-01)", async (_name, mutate, diagnostic) => {
|
||||
const contract = fillDeploymentSlot(
|
||||
JSON.parse(JSON.stringify(await loadCiGateContract(process.cwd()))),
|
||||
|
||||
Reference in New Issue
Block a user