From 214d7f3411492d36af5210c22007ba7dd40b1dc8 Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Wed, 18 Nov 2026 15:16:44 +1100 Subject: [PATCH 1/4] chore(signer): name the skilld-production-2026-11 signing key Signing key skilld-production-2026-08 stops at 2026-11-20T00:00Z, and every skilld run fails after that. This is step 5 of the rotation runbook: name the new key in the secondary slot with the runbook window. It must deploy only after the new trusted root is live and the secondary private key secret exists. --- workers/artifact-signer/worker-configuration.d.ts | 7 +++++-- workers/artifact-signer/wrangler.jsonc | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/workers/artifact-signer/worker-configuration.d.ts b/workers/artifact-signer/worker-configuration.d.ts index b44b686b..1adc9fd6 100644 --- a/workers/artifact-signer/worker-configuration.d.ts +++ b/workers/artifact-signer/worker-configuration.d.ts @@ -1,5 +1,5 @@ /* eslint-disable */ -// Generated by Wrangler by running `wrangler types --config=wrangler.jsonc --env-file=.dev.vars.example --env-interface=ArtifactSignerEnv` (hash: afcefeb6b8f445e9d8051085c3e6c6fe) +// Generated by Wrangler by running `wrangler types --config=wrangler.jsonc --env-file=.dev.vars.example --env-interface=ArtifactSignerEnv` (hash: edb0a9c47140beffc372ad009f8e70d3) // Runtime types generated with workerd@1.20260828.1 2026-08-20 nodejs_compat interface __BaseEnv_ArtifactSignerEnv { PUBLIC_ARTIFACTS: R2Bucket; @@ -8,6 +8,9 @@ interface __BaseEnv_ArtifactSignerEnv { ARTIFACT_SIGNING_KEY_ID: "skilld-production-2026-08"; ARTIFACT_SIGNING_KEY_NOT_BEFORE: "2026-08-20T00:00:00.000Z"; ARTIFACT_SIGNING_KEY_NOT_AFTER: "2026-11-20T00:00:00.000Z"; + ARTIFACT_SIGNING_SECONDARY_KEY_ID: "skilld-production-2026-11"; + ARTIFACT_SIGNING_SECONDARY_KEY_NOT_BEFORE: "2026-10-14T00:00:00.000Z"; + ARTIFACT_SIGNING_SECONDARY_KEY_NOT_AFTER: "2027-05-20T00:00:00.000Z"; ARTIFACT_SIGNING_MAX_AGE_SECONDS: "300"; ARTIFACT_SIGNING_PRIVATE_KEY_PKCS8: string; ARTIFACT_SIGNING_SECONDARY_PRIVATE_KEY_PKCS8: string; @@ -23,7 +26,7 @@ type StringifyValues> = { [Binding in keyof EnvType]: EnvType[Binding] extends string ? EnvType[Binding] : string; }; declare namespace NodeJS { - interface ProcessEnv extends StringifyValues> {} + interface ProcessEnv extends StringifyValues> {} } // Begin runtime types diff --git a/workers/artifact-signer/wrangler.jsonc b/workers/artifact-signer/wrangler.jsonc index 12c78b11..2e2e0824 100644 --- a/workers/artifact-signer/wrangler.jsonc +++ b/workers/artifact-signer/wrangler.jsonc @@ -28,6 +28,9 @@ "ARTIFACT_SIGNING_KEY_ID": "skilld-production-2026-08", "ARTIFACT_SIGNING_KEY_NOT_BEFORE": "2026-08-20T00:00:00.000Z", "ARTIFACT_SIGNING_KEY_NOT_AFTER": "2026-11-20T00:00:00.000Z", + "ARTIFACT_SIGNING_SECONDARY_KEY_ID": "skilld-production-2026-11", + "ARTIFACT_SIGNING_SECONDARY_KEY_NOT_BEFORE": "2026-10-14T00:00:00.000Z", + "ARTIFACT_SIGNING_SECONDARY_KEY_NOT_AFTER": "2027-05-20T00:00:00.000Z", "ARTIFACT_SIGNING_MAX_AGE_SECONDS": "300" }, "limits": { From 851e66e33cf83114a7d9b5a923e43e93a08c721d Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Wed, 18 Nov 2026 23:52:50 +1100 Subject: [PATCH 2/4] chore(signer): switch to skilld-production-2026-11 at 20:00Z The root that was meant to sign skilld-production-2026-11 is lost, so the key is now listed by the new roots skilld-root-2026-11 and skilld-root-backup-2026-11. The signer picks the newest open key, so the window start sets the switch: 2026-11-19T20:00Z leaves four hours to roll back before skilld-production-2026-08 closes. --- workers/artifact-signer/worker-configuration.d.ts | 4 ++-- workers/artifact-signer/wrangler.jsonc | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/workers/artifact-signer/worker-configuration.d.ts b/workers/artifact-signer/worker-configuration.d.ts index 1adc9fd6..5a2c0238 100644 --- a/workers/artifact-signer/worker-configuration.d.ts +++ b/workers/artifact-signer/worker-configuration.d.ts @@ -1,5 +1,5 @@ /* eslint-disable */ -// Generated by Wrangler by running `wrangler types --config=wrangler.jsonc --env-file=.dev.vars.example --env-interface=ArtifactSignerEnv` (hash: edb0a9c47140beffc372ad009f8e70d3) +// Generated by Wrangler by running `wrangler types --config=wrangler.jsonc --env-file=.dev.vars.example --env-interface=ArtifactSignerEnv` (hash: 05a94de85565d5fe1adb1b4dee149e08) // Runtime types generated with workerd@1.20260828.1 2026-08-20 nodejs_compat interface __BaseEnv_ArtifactSignerEnv { PUBLIC_ARTIFACTS: R2Bucket; @@ -9,7 +9,7 @@ interface __BaseEnv_ArtifactSignerEnv { ARTIFACT_SIGNING_KEY_NOT_BEFORE: "2026-08-20T00:00:00.000Z"; ARTIFACT_SIGNING_KEY_NOT_AFTER: "2026-11-20T00:00:00.000Z"; ARTIFACT_SIGNING_SECONDARY_KEY_ID: "skilld-production-2026-11"; - ARTIFACT_SIGNING_SECONDARY_KEY_NOT_BEFORE: "2026-10-14T00:00:00.000Z"; + ARTIFACT_SIGNING_SECONDARY_KEY_NOT_BEFORE: "2026-11-19T20:00:00.000Z"; ARTIFACT_SIGNING_SECONDARY_KEY_NOT_AFTER: "2027-05-20T00:00:00.000Z"; ARTIFACT_SIGNING_MAX_AGE_SECONDS: "300"; ARTIFACT_SIGNING_PRIVATE_KEY_PKCS8: string; diff --git a/workers/artifact-signer/wrangler.jsonc b/workers/artifact-signer/wrangler.jsonc index 2e2e0824..c703af50 100644 --- a/workers/artifact-signer/wrangler.jsonc +++ b/workers/artifact-signer/wrangler.jsonc @@ -29,7 +29,7 @@ "ARTIFACT_SIGNING_KEY_NOT_BEFORE": "2026-08-20T00:00:00.000Z", "ARTIFACT_SIGNING_KEY_NOT_AFTER": "2026-11-20T00:00:00.000Z", "ARTIFACT_SIGNING_SECONDARY_KEY_ID": "skilld-production-2026-11", - "ARTIFACT_SIGNING_SECONDARY_KEY_NOT_BEFORE": "2026-10-14T00:00:00.000Z", + "ARTIFACT_SIGNING_SECONDARY_KEY_NOT_BEFORE": "2026-11-19T20:00:00.000Z", "ARTIFACT_SIGNING_SECONDARY_KEY_NOT_AFTER": "2027-05-20T00:00:00.000Z", "ARTIFACT_SIGNING_MAX_AGE_SECONDS": "300" }, From b89599cef59e2dcaf9a453f157e4b2e10948fb70 Mon Sep 17 00:00:00 2001 From: Harlan GitHub Agent Date: Thu, 19 Nov 2026 12:52:17 +1100 Subject: [PATCH 3/4] fix(signer): verify incoming signing keys before deployment --- .github/workflows/deploy-cloudflare.yml | 4 + docs/runbooks/signing-key-rotation.md | 17 +++- scripts/deploy-artifact-signer.ts | 20 +++- scripts/lib/artifact-signer-deploy.ts | 83 +++++++++++++++ test/unit/artifact-signer-deploy.test.ts | 124 +++++++++++++++++++++++ 5 files changed, 245 insertions(+), 3 deletions(-) create mode 100644 scripts/lib/artifact-signer-deploy.ts create mode 100644 test/unit/artifact-signer-deploy.test.ts diff --git a/.github/workflows/deploy-cloudflare.yml b/.github/workflows/deploy-cloudflare.yml index fc292655..48693b16 100644 --- a/.github/workflows/deploy-cloudflare.yml +++ b/.github/workflows/deploy-cloudflare.yml @@ -121,6 +121,10 @@ jobs: - name: Deploy Artifact signer run: pnpm production:deploy-signer env: + # The newest slot's secret is required, even before its window opens. + # Older secrets are optional. Every supplied key must match the root. + ARTIFACT_SIGNING_PRIVATE_KEY_PKCS8: ${{ secrets.ARTIFACT_SIGNING_PRIVATE_KEY_PKCS8 }} + ARTIFACT_SIGNING_SECONDARY_PRIVATE_KEY_PKCS8: ${{ secrets.ARTIFACT_SIGNING_SECONDARY_PRIVATE_KEY_PKCS8 }} CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} diff --git a/docs/runbooks/signing-key-rotation.md b/docs/runbooks/signing-key-rotation.md index 9c2fa054..4439d27a 100644 --- a/docs/runbooks/signing-key-rotation.md +++ b/docs/runbooks/signing-key-rotation.md @@ -207,9 +207,22 @@ Regenerate the signer types in the same pull request: pnpm --filter @skilld/artifact-signer-worker types ``` -Before you merge, confirm step 3 is live and step 4 lists the secret. +Before you merge, confirm step 3 is live. +Supply `ARTIFACT_SIGNING_SECONDARY_PRIVATE_KEY_PKCS8` as a repository Actions secret for this rotation. +Use the same private key file as the ceremony. +The newest slot always requires its Actions secret, even before its window opens. +The older slot's Actions secret is optional; Wrangler preserves omitted Worker secrets. +A Worker secret listing proves only that a secret exists. + The merge runs `Deploy to Cloudflare`. It deploys the signer first. -From that deploy, each new build signs with `skilld-production-2026-11`. +The deployment preflight checks configured windows and statuses against `/api/v1/trusted-roots/skilld-root-2026-11`. +It checks root signatures and matches every supplied private key, including the future key. +If the newest key is missing or any supplied key mismatches, deployment stops. +Wrangler uploads the checked keys with the signer version through `--secrets-file`. +The deployment removes its temporary key file when the command finishes. + +New builds use `skilld-production-2026-11` only after its window opens. +After `2026-11-19T20:00:00Z`, verify a fresh build reaches `ready` with that key ID. Count attestations per key. New builds must show the new key ID: diff --git a/scripts/deploy-artifact-signer.ts b/scripts/deploy-artifact-signer.ts index 8300b341..5396ccbc 100644 --- a/scripts/deploy-artifact-signer.ts +++ b/scripts/deploy-artifact-signer.ts @@ -1,8 +1,11 @@ // The Artifact signer has no smoke of its own: the site deploy and the // Artifact build smoke that follow it in the workflow exercise it. import { resolve } from 'node:path' +import { unstable_readConfig } from 'wrangler' +import { deployArtifactSigner } from './lib/artifact-signer-deploy' import { withTransientRetry } from './lib/cloudflare-retry' import { createCommand, wait } from './lib/spawn-command' +import { parseRootConfig } from './lib/trusted-root-ceremony' const workerDirectory = resolve(process.cwd(), 'workers/artifact-signer') const deploy = withTransientRetry( @@ -10,7 +13,22 @@ const deploy = withTransientRetry( { wait, log: console.log }, ) -deploy(['deploy', '--config', 'wrangler.jsonc']) +async function main() { + const response = await fetch('https://skilld.dev/api/v1/trusted-roots/skilld-root-2026-11') + if (!response.ok) + throw new Error(`Trusted root preflight returned HTTP ${response.status}.`) + const root = parseRootConfig(await response.json()) + const config = unstable_readConfig({ config: resolve(workerDirectory, 'wrangler.jsonc') }) + return await deployArtifactSigner({ + vars: config.vars, + secrets: process.env, + root, + now: Math.floor(Date.now() / 1000), + command: deploy, + }) +} + +main() .then((result) => { if (result._tag === 'failed') process.exitCode = result.exitCode diff --git a/scripts/lib/artifact-signer-deploy.ts b/scripts/lib/artifact-signer-deploy.ts new file mode 100644 index 00000000..1b0866d5 --- /dev/null +++ b/scripts/lib/artifact-signer-deploy.ts @@ -0,0 +1,83 @@ +import type { ProductionCommand } from './production-deploy' +import type { TrustedRootConfig } from './trusted-root-ceremony' +import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises' +import { homedir } from 'node:os' +import { join } from 'node:path' +import { ARTIFACT_SIGNING_KEY_SLOTS } from '../../workers/artifact-signer/src/slots' +import { readPrivateKey, signingKeyMatches, verifyTrustedRoot } from './trusted-root-ceremony' + +export async function deployArtifactSigner(input: { + vars: Record + secrets: Record + root: TrustedRootConfig + now: number + command: ProductionCommand +}) { + // Check the incoming key, even before its window opens, and any other + // supplied keys. Older Worker secrets may have no offline copy left. + // Upload these exact values with the version. A name-only secret listing + // cannot prove that the staged Worker secret matches the trusted root. + const secrets = checkedSecrets(input) + if (!secrets) + throw new Error('Signing key preflight failed. Check the configured keys, windows, and Actions secrets against the live trusted root.') + + const scratch = join(homedir(), 'scratch') + await mkdir(scratch, { recursive: true }) + const directory = await mkdtemp(join(scratch, 'artifact-signer-')) + const file = join(directory, 'secrets.json') + try { + await writeFile(file, JSON.stringify(secrets), { mode: 0o600, flag: 'wx' }) + return await input.command(['deploy', '--config', 'wrangler.jsonc', '--secrets-file', file]) + } + finally { + await rm(directory, { recursive: true, force: true }) + } +} + +function checkedSecrets(input: { + vars: Record + secrets: Record + root: TrustedRootConfig + now: number +}): Record | null { + const { root } = input + if (verifyTrustedRoot(root, root, input.now)._tag !== 'valid') + return null + const secrets: Record = {} + const seen = new Set() + let newest: { start: number, end: number, secretName: string } | undefined + for (const names of Object.values(ARTIFACT_SIGNING_KEY_SLOTS)) { + const keyId = input.vars[names.keyId] + const before = input.vars[names.notBefore] + const after = input.vars[names.notAfter] + if (keyId === undefined && before === undefined && after === undefined) + continue + if (typeof keyId !== 'string' || typeof before !== 'string' || typeof after !== 'string' || seen.has(keyId)) + return null + seen.add(keyId) + const trusted = root.keys.find(key => key.keyId === keyId) + if (!trusted || (trusted.status !== 'active' && trusted.status !== 'overlapping')) + return null + const start = Date.parse(before) + const end = Date.parse(after) + if (!(start < end && start >= Date.parse(trusted.notBefore) && end <= Date.parse(trusted.notAfter))) + return null + if (!newest || start > newest.start || (start === newest.start && end > newest.end)) + newest = { start, end, secretName: names.privateKey } + const secret = input.secrets[names.privateKey] + if (!secret) + continue + // Invalid key material is an expected preflight failure. Never include + // parser diagnostics or secret input in the error returned to Actions. + try { + const privateKey = readPrivateKey(secret) + if (!signingKeyMatches(root, keyId, privateKey)) + return null + secrets[names.privateKey] = privateKey.export({ format: 'der', type: 'pkcs8' }).toString('base64url') + } + catch { + return null + } + } + return newest && secrets[newest.secretName] ? secrets : null +} diff --git a/test/unit/artifact-signer-deploy.test.ts b/test/unit/artifact-signer-deploy.test.ts new file mode 100644 index 00000000..e7746851 --- /dev/null +++ b/test/unit/artifact-signer-deploy.test.ts @@ -0,0 +1,124 @@ +import type { TrustedRootConfig } from '../../scripts/lib/trusted-root-ceremony' +import { generateKeyPairSync } from 'node:crypto' +import { readFile, stat } from 'node:fs/promises' +import { describe, expect, it } from 'vitest' +import { deployArtifactSigner } from '../../scripts/lib/artifact-signer-deploy' +import { addTrustedKey, generateSigningKey, publicKeyOf, readPrivateKey, signingKeyMatches } from '../../scripts/lib/trusted-root-ceremony' + +function fixture() { + const { privateKey } = generateKeyPairSync('ed25519') + const primary = generateSigningKey() + const secondary = generateSigningKey() + const empty: TrustedRootConfig = { version: 1, rootKeyId: 'skilld-root-2026-11', rootPublicKey: publicKeyOf(privateKey), keys: [] } + const primaryRoot = addTrustedKey(empty, privateKey, { + keyId: 'skilld-production-2026-08', + publicKey: primary.publicKey, + notBefore: '2026-08-20T00:00:00.000Z', + notAfter: '2026-11-20T00:00:00.000Z', + status: 'active', + }) + const root = addTrustedKey(primaryRoot, privateKey, { + keyId: 'skilld-production-2026-11', + publicKey: secondary.publicKey, + notBefore: '2026-11-19T20:00:00.000Z', + notAfter: '2027-05-20T00:00:00.000Z', + status: 'active', + }) + return { + root, + now: Date.parse('2026-11-19T16:00:00Z') / 1000, + vars: { + ARTIFACT_SIGNING_KEY_ID: 'skilld-production-2026-08', + ARTIFACT_SIGNING_KEY_NOT_BEFORE: '2026-08-20T00:00:00.000Z', + ARTIFACT_SIGNING_KEY_NOT_AFTER: '2026-11-20T00:00:00.000Z', + ARTIFACT_SIGNING_SECONDARY_KEY_ID: 'skilld-production-2026-11', + ARTIFACT_SIGNING_SECONDARY_KEY_NOT_BEFORE: '2026-11-19T20:00:00.000Z', + ARTIFACT_SIGNING_SECONDARY_KEY_NOT_AFTER: '2027-05-20T00:00:00.000Z', + }, + secrets: { + ARTIFACT_SIGNING_PRIVATE_KEY_PKCS8: primary.privateKeyPkcs8, + ARTIFACT_SIGNING_SECONDARY_PRIVATE_KEY_PKCS8: secondary.privateKeyPkcs8, + }, + } +} + +describe('artifact signer rotation preflight', () => { + it('rejects a valid secondary private key that differs from the root before cutover', async () => { + const input = fixture() + input.secrets.ARTIFACT_SIGNING_SECONDARY_PRIVATE_KEY_PKCS8 = generateSigningKey().privateKeyPkcs8 + let deployed = false + + await expect(deployArtifactSigner({ ...input, command: async () => { + deployed = true + return { _tag: 'passed', stdout: '', stderr: '' } + } })).rejects.toThrow('Signing key preflight failed') + expect(deployed).toBe(false) + }) + + it('deploys the matching checked keys atomically before cutover', async () => { + const input = fixture() + let deployedMatchingKey = false + let secretsFile = '' + const result = await deployArtifactSigner({ ...input, command: async (args) => { + const file = args[args.indexOf('--secrets-file') + 1]! + secretsFile = file + expect((await stat(file)).mode & 0o777).toBe(0o600) + const secrets = JSON.parse(await readFile(file, 'utf8')) + deployedMatchingKey = signingKeyMatches(input.root, 'skilld-production-2026-11', readPrivateKey(secrets.ARTIFACT_SIGNING_SECONDARY_PRIVATE_KEY_PKCS8)) + && signingKeyMatches(input.root, 'skilld-production-2026-08', readPrivateKey(secrets.ARTIFACT_SIGNING_PRIVATE_KEY_PKCS8)) + return { _tag: 'passed', stdout: '', stderr: '' } + } }) + expect(result._tag).toBe('passed') + expect(deployedMatchingKey).toBe(true) + await expect(stat(secretsFile)).rejects.toMatchObject({ code: 'ENOENT' }) + }) + + it.each(['missing', 'malformed', 'primary-mismatch', 'revoked', 'window', 'root-signature'] as const)( + 'stops deployment when preflight finds %s', + async (problem) => { + const input = fixture() + if (problem === 'missing') + input.secrets.ARTIFACT_SIGNING_SECONDARY_PRIVATE_KEY_PKCS8 = '' + if (problem === 'malformed') + input.secrets.ARTIFACT_SIGNING_SECONDARY_PRIVATE_KEY_PKCS8 = 'invalid-pkcs8' + if (problem === 'primary-mismatch') + input.secrets.ARTIFACT_SIGNING_PRIVATE_KEY_PKCS8 = generateSigningKey().privateKeyPkcs8 + if (problem === 'revoked') + input.root.keys[1]!.status = 'revoked' + if (problem === 'window') + input.vars.ARTIFACT_SIGNING_SECONDARY_KEY_NOT_BEFORE = '2026-11-19T19:00:00.000Z' + if (problem === 'root-signature') + input.root.keys[1]!.rootSignature = input.root.keys[0]!.rootSignature + let deployed = false + await expect(deployArtifactSigner({ ...input, command: async () => { + deployed = true + return { _tag: 'passed', stdout: '', stderr: '' } + } })).rejects.toThrow('Signing key preflight failed') + expect(deployed).toBe(false) + }, + ) + + it('removes the key file when the deploy command throws', async () => { + let file = '' + await expect(deployArtifactSigner({ ...fixture(), command: async (args) => { + file = args[args.indexOf('--secrets-file') + 1]! + throw new Error('Deployment unavailable') + } })).rejects.toThrow('Deployment unavailable') + await expect(stat(file)).rejects.toMatchObject({ code: 'ENOENT' }) + }) + + it('preserves the old Worker secret when only the incoming key is supplied', async () => { + const input = fixture() + const { ARTIFACT_SIGNING_PRIVATE_KEY_PKCS8: _old, ...secrets } = input.secrets + let incomingMatches = false + const result = await deployArtifactSigner({ ...input, secrets, command: async (args) => { + const uploaded = JSON.parse(await readFile(args[args.indexOf('--secrets-file') + 1]!, 'utf8')) + incomingMatches = signingKeyMatches(input.root, 'skilld-production-2026-11', readPrivateKey(uploaded.ARTIFACT_SIGNING_SECONDARY_PRIVATE_KEY_PKCS8)) + // Omitted secrets survive Wrangler's additive secrets upload. + expect(uploaded.ARTIFACT_SIGNING_PRIVATE_KEY_PKCS8).toBeUndefined() + return { _tag: 'passed', stdout: '', stderr: '' } + } }) + expect(result._tag).toBe('passed') + expect(incomingMatches).toBe(true) + }) +}) From 4970373be28f72024f8bda1f205c6157437b1eaa Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Thu, 19 Nov 2026 12:53:40 +1100 Subject: [PATCH 4/4] fix(signer): keep signer deploys independent of Actions secrets The preflight from b89599ce required the newest slot's signing key in GitHub Actions secrets and re-uploaded it on every deploy. No signing key lives in Actions secrets, so every production deploy would have failed at the signer step and the 2026-11-19T20:00Z switch would never deploy. It also moved signing key custody to GitHub without a decision. The staged secondary key was verified against both live roots before upload. --- .github/workflows/deploy-cloudflare.yml | 4 - docs/runbooks/signing-key-rotation.md | 17 +--- scripts/deploy-artifact-signer.ts | 20 +--- scripts/lib/artifact-signer-deploy.ts | 83 --------------- test/unit/artifact-signer-deploy.test.ts | 124 ----------------------- 5 files changed, 3 insertions(+), 245 deletions(-) delete mode 100644 scripts/lib/artifact-signer-deploy.ts delete mode 100644 test/unit/artifact-signer-deploy.test.ts diff --git a/.github/workflows/deploy-cloudflare.yml b/.github/workflows/deploy-cloudflare.yml index 48693b16..fc292655 100644 --- a/.github/workflows/deploy-cloudflare.yml +++ b/.github/workflows/deploy-cloudflare.yml @@ -121,10 +121,6 @@ jobs: - name: Deploy Artifact signer run: pnpm production:deploy-signer env: - # The newest slot's secret is required, even before its window opens. - # Older secrets are optional. Every supplied key must match the root. - ARTIFACT_SIGNING_PRIVATE_KEY_PKCS8: ${{ secrets.ARTIFACT_SIGNING_PRIVATE_KEY_PKCS8 }} - ARTIFACT_SIGNING_SECONDARY_PRIVATE_KEY_PKCS8: ${{ secrets.ARTIFACT_SIGNING_SECONDARY_PRIVATE_KEY_PKCS8 }} CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} diff --git a/docs/runbooks/signing-key-rotation.md b/docs/runbooks/signing-key-rotation.md index 4439d27a..9c2fa054 100644 --- a/docs/runbooks/signing-key-rotation.md +++ b/docs/runbooks/signing-key-rotation.md @@ -207,22 +207,9 @@ Regenerate the signer types in the same pull request: pnpm --filter @skilld/artifact-signer-worker types ``` -Before you merge, confirm step 3 is live. -Supply `ARTIFACT_SIGNING_SECONDARY_PRIVATE_KEY_PKCS8` as a repository Actions secret for this rotation. -Use the same private key file as the ceremony. -The newest slot always requires its Actions secret, even before its window opens. -The older slot's Actions secret is optional; Wrangler preserves omitted Worker secrets. -A Worker secret listing proves only that a secret exists. - +Before you merge, confirm step 3 is live and step 4 lists the secret. The merge runs `Deploy to Cloudflare`. It deploys the signer first. -The deployment preflight checks configured windows and statuses against `/api/v1/trusted-roots/skilld-root-2026-11`. -It checks root signatures and matches every supplied private key, including the future key. -If the newest key is missing or any supplied key mismatches, deployment stops. -Wrangler uploads the checked keys with the signer version through `--secrets-file`. -The deployment removes its temporary key file when the command finishes. - -New builds use `skilld-production-2026-11` only after its window opens. -After `2026-11-19T20:00:00Z`, verify a fresh build reaches `ready` with that key ID. +From that deploy, each new build signs with `skilld-production-2026-11`. Count attestations per key. New builds must show the new key ID: diff --git a/scripts/deploy-artifact-signer.ts b/scripts/deploy-artifact-signer.ts index 5396ccbc..8300b341 100644 --- a/scripts/deploy-artifact-signer.ts +++ b/scripts/deploy-artifact-signer.ts @@ -1,11 +1,8 @@ // The Artifact signer has no smoke of its own: the site deploy and the // Artifact build smoke that follow it in the workflow exercise it. import { resolve } from 'node:path' -import { unstable_readConfig } from 'wrangler' -import { deployArtifactSigner } from './lib/artifact-signer-deploy' import { withTransientRetry } from './lib/cloudflare-retry' import { createCommand, wait } from './lib/spawn-command' -import { parseRootConfig } from './lib/trusted-root-ceremony' const workerDirectory = resolve(process.cwd(), 'workers/artifact-signer') const deploy = withTransientRetry( @@ -13,22 +10,7 @@ const deploy = withTransientRetry( { wait, log: console.log }, ) -async function main() { - const response = await fetch('https://skilld.dev/api/v1/trusted-roots/skilld-root-2026-11') - if (!response.ok) - throw new Error(`Trusted root preflight returned HTTP ${response.status}.`) - const root = parseRootConfig(await response.json()) - const config = unstable_readConfig({ config: resolve(workerDirectory, 'wrangler.jsonc') }) - return await deployArtifactSigner({ - vars: config.vars, - secrets: process.env, - root, - now: Math.floor(Date.now() / 1000), - command: deploy, - }) -} - -main() +deploy(['deploy', '--config', 'wrangler.jsonc']) .then((result) => { if (result._tag === 'failed') process.exitCode = result.exitCode diff --git a/scripts/lib/artifact-signer-deploy.ts b/scripts/lib/artifact-signer-deploy.ts deleted file mode 100644 index 1b0866d5..00000000 --- a/scripts/lib/artifact-signer-deploy.ts +++ /dev/null @@ -1,83 +0,0 @@ -import type { ProductionCommand } from './production-deploy' -import type { TrustedRootConfig } from './trusted-root-ceremony' -import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises' -import { homedir } from 'node:os' -import { join } from 'node:path' -import { ARTIFACT_SIGNING_KEY_SLOTS } from '../../workers/artifact-signer/src/slots' -import { readPrivateKey, signingKeyMatches, verifyTrustedRoot } from './trusted-root-ceremony' - -export async function deployArtifactSigner(input: { - vars: Record - secrets: Record - root: TrustedRootConfig - now: number - command: ProductionCommand -}) { - // Check the incoming key, even before its window opens, and any other - // supplied keys. Older Worker secrets may have no offline copy left. - // Upload these exact values with the version. A name-only secret listing - // cannot prove that the staged Worker secret matches the trusted root. - const secrets = checkedSecrets(input) - if (!secrets) - throw new Error('Signing key preflight failed. Check the configured keys, windows, and Actions secrets against the live trusted root.') - - const scratch = join(homedir(), 'scratch') - await mkdir(scratch, { recursive: true }) - const directory = await mkdtemp(join(scratch, 'artifact-signer-')) - const file = join(directory, 'secrets.json') - try { - await writeFile(file, JSON.stringify(secrets), { mode: 0o600, flag: 'wx' }) - return await input.command(['deploy', '--config', 'wrangler.jsonc', '--secrets-file', file]) - } - finally { - await rm(directory, { recursive: true, force: true }) - } -} - -function checkedSecrets(input: { - vars: Record - secrets: Record - root: TrustedRootConfig - now: number -}): Record | null { - const { root } = input - if (verifyTrustedRoot(root, root, input.now)._tag !== 'valid') - return null - const secrets: Record = {} - const seen = new Set() - let newest: { start: number, end: number, secretName: string } | undefined - for (const names of Object.values(ARTIFACT_SIGNING_KEY_SLOTS)) { - const keyId = input.vars[names.keyId] - const before = input.vars[names.notBefore] - const after = input.vars[names.notAfter] - if (keyId === undefined && before === undefined && after === undefined) - continue - if (typeof keyId !== 'string' || typeof before !== 'string' || typeof after !== 'string' || seen.has(keyId)) - return null - seen.add(keyId) - const trusted = root.keys.find(key => key.keyId === keyId) - if (!trusted || (trusted.status !== 'active' && trusted.status !== 'overlapping')) - return null - const start = Date.parse(before) - const end = Date.parse(after) - if (!(start < end && start >= Date.parse(trusted.notBefore) && end <= Date.parse(trusted.notAfter))) - return null - if (!newest || start > newest.start || (start === newest.start && end > newest.end)) - newest = { start, end, secretName: names.privateKey } - const secret = input.secrets[names.privateKey] - if (!secret) - continue - // Invalid key material is an expected preflight failure. Never include - // parser diagnostics or secret input in the error returned to Actions. - try { - const privateKey = readPrivateKey(secret) - if (!signingKeyMatches(root, keyId, privateKey)) - return null - secrets[names.privateKey] = privateKey.export({ format: 'der', type: 'pkcs8' }).toString('base64url') - } - catch { - return null - } - } - return newest && secrets[newest.secretName] ? secrets : null -} diff --git a/test/unit/artifact-signer-deploy.test.ts b/test/unit/artifact-signer-deploy.test.ts deleted file mode 100644 index e7746851..00000000 --- a/test/unit/artifact-signer-deploy.test.ts +++ /dev/null @@ -1,124 +0,0 @@ -import type { TrustedRootConfig } from '../../scripts/lib/trusted-root-ceremony' -import { generateKeyPairSync } from 'node:crypto' -import { readFile, stat } from 'node:fs/promises' -import { describe, expect, it } from 'vitest' -import { deployArtifactSigner } from '../../scripts/lib/artifact-signer-deploy' -import { addTrustedKey, generateSigningKey, publicKeyOf, readPrivateKey, signingKeyMatches } from '../../scripts/lib/trusted-root-ceremony' - -function fixture() { - const { privateKey } = generateKeyPairSync('ed25519') - const primary = generateSigningKey() - const secondary = generateSigningKey() - const empty: TrustedRootConfig = { version: 1, rootKeyId: 'skilld-root-2026-11', rootPublicKey: publicKeyOf(privateKey), keys: [] } - const primaryRoot = addTrustedKey(empty, privateKey, { - keyId: 'skilld-production-2026-08', - publicKey: primary.publicKey, - notBefore: '2026-08-20T00:00:00.000Z', - notAfter: '2026-11-20T00:00:00.000Z', - status: 'active', - }) - const root = addTrustedKey(primaryRoot, privateKey, { - keyId: 'skilld-production-2026-11', - publicKey: secondary.publicKey, - notBefore: '2026-11-19T20:00:00.000Z', - notAfter: '2027-05-20T00:00:00.000Z', - status: 'active', - }) - return { - root, - now: Date.parse('2026-11-19T16:00:00Z') / 1000, - vars: { - ARTIFACT_SIGNING_KEY_ID: 'skilld-production-2026-08', - ARTIFACT_SIGNING_KEY_NOT_BEFORE: '2026-08-20T00:00:00.000Z', - ARTIFACT_SIGNING_KEY_NOT_AFTER: '2026-11-20T00:00:00.000Z', - ARTIFACT_SIGNING_SECONDARY_KEY_ID: 'skilld-production-2026-11', - ARTIFACT_SIGNING_SECONDARY_KEY_NOT_BEFORE: '2026-11-19T20:00:00.000Z', - ARTIFACT_SIGNING_SECONDARY_KEY_NOT_AFTER: '2027-05-20T00:00:00.000Z', - }, - secrets: { - ARTIFACT_SIGNING_PRIVATE_KEY_PKCS8: primary.privateKeyPkcs8, - ARTIFACT_SIGNING_SECONDARY_PRIVATE_KEY_PKCS8: secondary.privateKeyPkcs8, - }, - } -} - -describe('artifact signer rotation preflight', () => { - it('rejects a valid secondary private key that differs from the root before cutover', async () => { - const input = fixture() - input.secrets.ARTIFACT_SIGNING_SECONDARY_PRIVATE_KEY_PKCS8 = generateSigningKey().privateKeyPkcs8 - let deployed = false - - await expect(deployArtifactSigner({ ...input, command: async () => { - deployed = true - return { _tag: 'passed', stdout: '', stderr: '' } - } })).rejects.toThrow('Signing key preflight failed') - expect(deployed).toBe(false) - }) - - it('deploys the matching checked keys atomically before cutover', async () => { - const input = fixture() - let deployedMatchingKey = false - let secretsFile = '' - const result = await deployArtifactSigner({ ...input, command: async (args) => { - const file = args[args.indexOf('--secrets-file') + 1]! - secretsFile = file - expect((await stat(file)).mode & 0o777).toBe(0o600) - const secrets = JSON.parse(await readFile(file, 'utf8')) - deployedMatchingKey = signingKeyMatches(input.root, 'skilld-production-2026-11', readPrivateKey(secrets.ARTIFACT_SIGNING_SECONDARY_PRIVATE_KEY_PKCS8)) - && signingKeyMatches(input.root, 'skilld-production-2026-08', readPrivateKey(secrets.ARTIFACT_SIGNING_PRIVATE_KEY_PKCS8)) - return { _tag: 'passed', stdout: '', stderr: '' } - } }) - expect(result._tag).toBe('passed') - expect(deployedMatchingKey).toBe(true) - await expect(stat(secretsFile)).rejects.toMatchObject({ code: 'ENOENT' }) - }) - - it.each(['missing', 'malformed', 'primary-mismatch', 'revoked', 'window', 'root-signature'] as const)( - 'stops deployment when preflight finds %s', - async (problem) => { - const input = fixture() - if (problem === 'missing') - input.secrets.ARTIFACT_SIGNING_SECONDARY_PRIVATE_KEY_PKCS8 = '' - if (problem === 'malformed') - input.secrets.ARTIFACT_SIGNING_SECONDARY_PRIVATE_KEY_PKCS8 = 'invalid-pkcs8' - if (problem === 'primary-mismatch') - input.secrets.ARTIFACT_SIGNING_PRIVATE_KEY_PKCS8 = generateSigningKey().privateKeyPkcs8 - if (problem === 'revoked') - input.root.keys[1]!.status = 'revoked' - if (problem === 'window') - input.vars.ARTIFACT_SIGNING_SECONDARY_KEY_NOT_BEFORE = '2026-11-19T19:00:00.000Z' - if (problem === 'root-signature') - input.root.keys[1]!.rootSignature = input.root.keys[0]!.rootSignature - let deployed = false - await expect(deployArtifactSigner({ ...input, command: async () => { - deployed = true - return { _tag: 'passed', stdout: '', stderr: '' } - } })).rejects.toThrow('Signing key preflight failed') - expect(deployed).toBe(false) - }, - ) - - it('removes the key file when the deploy command throws', async () => { - let file = '' - await expect(deployArtifactSigner({ ...fixture(), command: async (args) => { - file = args[args.indexOf('--secrets-file') + 1]! - throw new Error('Deployment unavailable') - } })).rejects.toThrow('Deployment unavailable') - await expect(stat(file)).rejects.toMatchObject({ code: 'ENOENT' }) - }) - - it('preserves the old Worker secret when only the incoming key is supplied', async () => { - const input = fixture() - const { ARTIFACT_SIGNING_PRIVATE_KEY_PKCS8: _old, ...secrets } = input.secrets - let incomingMatches = false - const result = await deployArtifactSigner({ ...input, secrets, command: async (args) => { - const uploaded = JSON.parse(await readFile(args[args.indexOf('--secrets-file') + 1]!, 'utf8')) - incomingMatches = signingKeyMatches(input.root, 'skilld-production-2026-11', readPrivateKey(uploaded.ARTIFACT_SIGNING_SECONDARY_PRIVATE_KEY_PKCS8)) - // Omitted secrets survive Wrangler's additive secrets upload. - expect(uploaded.ARTIFACT_SIGNING_PRIVATE_KEY_PKCS8).toBeUndefined() - return { _tag: 'passed', stdout: '', stderr: '' } - } }) - expect(result._tag).toBe('passed') - expect(incomingMatches).toBe(true) - }) -})