Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dev.vars.example
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ ARTIFACT_KEY_WRAP_KEY_SECONDARY=
ARTIFACT_GRANT_IDEMPOTENCY_KEY=
# Public verification material. The signer keeps private keys in its Worker.
ARTIFACT_TRUSTED_ROOT_JSON=
# A JSON array of trusted roots, served by root key id. The first one lists
# every signing key the site accepts. skilld CLI 3.7.0 and later read these.
ARTIFACT_TRUSTED_ROOTS_JSON=
ANTHROPIC_API_KEY=
VOYAGE_API_KEY=
X_BEARER_KEY=
Expand Down
6 changes: 6 additions & 0 deletions GLOSSARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ Existing route paths, table names, and protocol fields keep their identifiers.

**Never:** signature (bare), certificate, receipt.

### trusted root

**Is:** the list of signing keys an Artifact attestation may use, each signed by an offline root key. Each skilld CLI release pins one root key and fetches that root by its id.

**Never:** keyring, trust store, certificate chain.

### linked file

**Is:** a Skill file the Artifact attestation lists by path, size, and Git blob SHA, without packing its bytes. The skilld CLI reads it from GitHub at the attested commit and checks it against that SHA. Only a CLI that sends `Skilld-Capabilities: linked-files` gets one. See ADR-0013.
Expand Down
2 changes: 1 addition & 1 deletion checks/_helpers/signing-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { fail, pass, readBoundedResponseText, warn } from '@harlan-zw/nuxt-check
import { z } from 'zod'
import { ARTIFACT_SIGNING_KEY_SLOTS, selectSigningKey } from '../../workers/artifact-signer/src/slots'

export const TRUSTED_ROOT_URL = 'https://skilld.dev/api/v1/trusted-root'
export const TRUSTED_ROOT_URL = 'https://skilld.dev/api/v1/trusted-roots/skilld-root-2026-11'
export const SIGNING_KEY_WARN_DAYS = 30
export const SIGNING_KEY_FAIL_DAYS = 7
const DAY_SECONDS = 86_400
Expand Down
356 changes: 159 additions & 197 deletions docs/runbooks/signing-key-rotation.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { createPublicArtifactGrant } from '../../../../../utils/grant'
import { privateArtifactAccessEnabled } from '../../../../../utils/private-feature'
import { createPrivateArtifactGrant } from '../../../../../utils/private-grant'
import { parseTrustedRoot } from '../../../../../utils/trusted-root'
import { siteTrustedRoot } from '../../../../../utils/trusted-root'

export default withArtifactProblems(defineApiHandler({
response: artifactGrantSchema,
Expand All @@ -30,7 +30,7 @@ export default withArtifactProblems(defineApiHandler({
})
}
const now = Math.floor(Date.now() / 1000)
const trustedRoot = parseTrustedRoot(platform.env.ARTIFACT_TRUSTED_ROOT_JSON, now)
const trustedRoot = siteTrustedRoot(platform.env, now)
const publicResult = await createPublicArtifactGrant({
db: platform.db,
trustedRoot,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { getRouterParam, setHeader } from 'h3'
import { defineApiHandler } from '#shared/server/handler'
import { trustedRootSchema } from '../../../schemas/contracts'
import { withArtifactProblems } from '../../../utils/artifact-problem'
import { parseTrustedRoots } from '../../../utils/trusted-root'

// skilld CLI 3.7.0 and later fetch the root they pin by its id, so a new root
// never replaces the one an older CLI pins.
export default withArtifactProblems(defineApiHandler({
response: trustedRootSchema,
handler({ event, platform }) {
const rootKeyId = getRouterParam(event, 'rootKeyId')
const root = parseTrustedRoots(platform.env.ARTIFACT_TRUSTED_ROOTS_JSON, Math.floor(Date.now() / 1000))
.find(served => served.rootKeyId === rootKeyId)
if (!root)
throw createError({ statusCode: 404, message: 'Trusted root not found' })
setHeader(event, 'cache-control', 'public, max-age=300, s-maxage=300')
return root
},
}))
4 changes: 2 additions & 2 deletions layers/artifact-delivery/server/utils/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { privateArtifactAccessEnabled } from './private-feature'
import { putPrivateArtifact } from './private-storage'
import { createRequesterGithubSource, forgetResolutionRequester } from './requester-github'
import { getResolution } from './state'
import { parseTrustedRoot } from './trusted-root'
import { siteTrustedRoot } from './trusted-root'

export const ARTIFACT_BUILD_QUEUE_NAME = 'skilld-artifact-build'

Expand Down Expand Up @@ -228,7 +228,7 @@ export function createArtifactBuildDependencies(env: Cloudflare.Env): ArtifactBu
}),
bucket: env.PUBLIC_ARTIFACTS,
signer: createArtifactSigner(env.ARTIFACT_SIGNER),
trustedRoot: parseTrustedRoot(env.ARTIFACT_TRUSTED_ROOT_JSON, Math.floor(Date.now() / 1000)),
trustedRoot: siteTrustedRoot(env, Math.floor(Date.now() / 1000)),
now: () => Math.floor(Date.now() / 1000),
reviewBehaviors: createBehaviorReviewer({
db: env.DB,
Expand Down
61 changes: 61 additions & 0 deletions layers/artifact-delivery/server/utils/trusted-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,67 @@ export function parseTrustedRoot(value: string, now: number) {
})
}

/**
* The roots served at `/api/v1/trusted-roots/{rootKeyId}`, from a JSON array.
* skilld CLI 3.7.0 and later fetch the root they pin by its id. Older CLIs pin
* `skilld-root-2026`, whose key was lost, and read `/api/v1/trusted-root`.
*/
export function parseTrustedRoots(value: string | undefined, now: number): TrustedRoot[] {
return readTrustedRoots(value, now).flatMap(result => result._tag === 'valid' ? [result.root] : [])
}

type RootResult = { _tag: 'valid', root: TrustedRoot } | { _tag: 'invalid' }

function readTrustedRoots(value: string | undefined, now: number): RootResult[] {
if (!value?.trim())
return []
const configs: unknown = JSON.parse(value)
if (!Array.isArray(configs) || configs.length === 0)
throw new Error('Served trusted roots must be a non-empty JSON array')
// Preserve each position so an invalid primary never selects a later root.
const parsed = configs.map((config: unknown, index): RootResult => {
try {
return { _tag: 'valid', root: parseTrustedRoot(JSON.stringify(config), now) }
}
catch {
// Config can contain secrets or untrusted text. Report only its array position.
console.error(`Rejected trusted root at array index ${index}: invalid or duplicate entry`)
return { _tag: 'invalid' }
}
})
const counts = new Map<string, number>()
for (const result of parsed) {
if (result._tag === 'valid')
counts.set(result.root.rootKeyId, (counts.get(result.root.rootKeyId) ?? 0) + 1)
}
return parsed.map((result, index): RootResult => {
if (result._tag === 'valid' && counts.get(result.root.rootKeyId)! > 1) {
console.error(`Rejected trusted root at array index ${index}: duplicate valid entry`)
return { _tag: 'invalid' }
}
return result
})
}

interface TrustedRootEnv {
ARTIFACT_TRUSTED_ROOTS_JSON?: string
ARTIFACT_TRUSTED_ROOT_JSON: string
}

/**
* The root whose signing keys the site verifies attestations with: the first
* served root, which lists every key the site accepts. Until roots are served,
* the legacy root.
*/
export function siteTrustedRoot(env: TrustedRootEnv, now: number): TrustedRoot {
const selected = readTrustedRoots(env.ARTIFACT_TRUSTED_ROOTS_JSON, now)[0]
if (!selected)
return parseTrustedRoot(env.ARTIFACT_TRUSTED_ROOT_JSON, now)
if (selected._tag === 'invalid')
throw new Error('The selected site trusted root is invalid')
return selected.root
}

function decodeCanonicalBase64Url(value: string): Uint8Array | null {
if (value.length % 4 === 1)
return null
Expand Down
28 changes: 27 additions & 1 deletion scripts/lib/trusted-root-ceremony.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ export function addTrustedKey(root: TrustedRootConfig, rootPrivateKey: KeyObject
})
}

/**
* Starts a trusted root under a new root key with its first signing key. A
* root lists at least one key, so the root and its first key are made together.
*/
export function createTrustedRoot(rootKeyId: string, rootPrivateKey: KeyObject, firstKey: NewTrustedKey): TrustedRootConfig {
return addTrustedKey({ version: 1, rootKeyId, rootPublicKey: publicKeyOf(rootPrivateKey), keys: [] }, rootPrivateKey, firstKey)
}

/** Removes one signing key. Removal needs no root signature. */
export function removeTrustedKey(root: TrustedRootConfig, keyId: string): TrustedRootConfig {
if (!root.keys.some(key => key.keyId === keyId))
Expand All @@ -128,8 +136,26 @@ export function removeTrustedKey(root: TrustedRootConfig, keyId: string): Truste
* Checks a root by the rules every released skilld CLI applies, then by the
* site's own parser. Each failed rule is one problem.
*/
export function verifyTrustedRoot(root: TrustedRootConfig, pin: RootPin, now: number): VerifyResult {
export function verifyTrustedRoot(
root: TrustedRootConfig,
pin: RootPin,
now: number,
peers: { root: TrustedRootConfig, pin: RootPin }[] = [],
): VerifyResult {
const problems: string[] = []
const coverage = (config: TrustedRootConfig) => canonicalJson(config.keys.map(({ statement: _statement, rootSignature: _signature, ...key }) => key)
.sort((a, b) => a.keyId.localeCompare(b.keyId)))
const seenRoots = new Set([root.rootKeyId])
for (const peer of peers) {
if (seenRoots.has(peer.root.rootKeyId))
problems.push('A rollout root ID appears twice.')
seenRoots.add(peer.root.rootKeyId)
const result = verifyTrustedRoot(peer.root, peer.pin, now)
if (result._tag === 'invalid')
problems.push(...result.problems)
if (coverage(root) !== coverage(peer.root))
problems.push('Rollout roots have different signing key coverage.')
}
if (root.rootKeyId !== pin.rootKeyId || root.rootPublicKey !== pin.rootPublicKey)
problems.push('The root key differs from the pin the released CLIs carry.')
const rootKey = attempt(() => decodePublicKey(root.rootPublicKey))
Expand Down
58 changes: 43 additions & 15 deletions scripts/trusted-root.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// The Artifact signing key ceremony. docs/runbooks/signing-key-rotation.md
// gives the order. No command prints a private key: each one reads or writes
// key files with mode 600.
import type { RootPin, TrustedRootConfig } from './lib/trusted-root-ceremony'
import type { NewTrustedKey, RootPin, TrustedRootConfig } from './lib/trusted-root-ceremony'
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
import { join } from 'node:path'
import { parseArgs } from 'node:util'
import {
addTrustedKey,
createTrustedRoot,
generateSigningKey,
parseRootConfig,
readPrivateKey,
Expand All @@ -15,20 +16,27 @@ import {
verifyTrustedRoot,
} from './lib/trusted-root-ceremony'

const LIVE_ROOT = 'https://skilld.dev/api/v1/trusted-root'
// The root that skilld CLI 3.7.0 and later pin first. Each root is served at
// its own path, so CLIs pinned to an older root keep reading theirs.
const LIVE_ROOT = 'https://skilld.dev/api/v1/trusted-roots/skilld-root-2026-11'

const USAGE = `Usage: pnpm exec tsx scripts/trusted-root.ts <command> [options]

signing-key --key-id <id> --out <dir>
Write <dir>/<id>.pkcs8 (the signer secret) and <dir>/<id>.pub.
Write <dir>/<id>.pkcs8 and <dir>/<id>.pub. Also makes a root key pair.
create-root --root-key-id <id> --root-key <file> --key-id <id> --public-key-file <file>
--not-before <iso> --not-after <iso> [--status active|overlapping] --out <file>
Start a trusted root under a new root key, with its first signing key.
add-key --root <file|url> --root-key <file> --key-id <id> --public-key-file <file>
--not-before <iso> --not-after <iso> [--status active|overlapping] --out <file>
Sign the key statement with the offline root key and write the new root.
remove-key --root <file|url> --key-id <id> --out <file>
Write the root without that key. Removal needs no root key.
verify --root <file|url> [--pin <file|url>] [--key-id <id> --signing-key <file>]
[--peer-root <file|url> --peer-pin <file|url>]
Check the root as every released skilld CLI does. --pin defaults to ${LIVE_ROOT}.
With --signing-key, also check the private key matches that key ID.`
With --signing-key, also check the private key matches that key ID.
With --peer-root and --peer-pin, verify both roots and require matching signing key coverage.`

const { positionals, values } = parseArgs({
allowPositionals: true,
Expand All @@ -38,9 +46,12 @@ const { positionals, values } = parseArgs({
'not-before': { type: 'string' },
'out': { type: 'string' },
'pin': { type: 'string' },
'peer-root': { type: 'string' },
'peer-pin': { type: 'string' },
'public-key-file': { type: 'string' },
'root': { type: 'string' },
'root-key': { type: 'string' },
'root-key-id': { type: 'string' },
'signing-key': { type: 'string' },
'status': { type: 'string' },
},
Expand Down Expand Up @@ -70,6 +81,19 @@ function writeNew(path: string, value: string, mode: number): void {
writeFileSync(path, value, { mode, flag: 'wx' })
}

function newKeyFromArgs(): NewTrustedKey {
const status = values.status ?? 'active'
if (status !== 'active' && status !== 'overlapping')
throw new Error('--status must be active or overlapping.')
return {
keyId: required('key-id'),
publicKey: readFileSync(required('public-key-file'), 'utf8').trim(),
notBefore: required('not-before'),
notAfter: required('not-after'),
status,
}
}

function printKeys(root: TrustedRootConfig): void {
const now = Date.now()
for (const key of root.keys) {
Expand All @@ -89,18 +113,16 @@ async function main(command: string | undefined): Promise<void> {
console.log(`Wrote ${join(out, `${keyId}.pkcs8`)} (private, mode 600) and ${join(out, `${keyId}.pub`)}.`)
return
}
case 'create-root': {
const next = createTrustedRoot(required('root-key-id'), readPrivateKey(readFileSync(required('root-key'), 'utf8')), newKeyFromArgs())
writeNew(required('out'), JSON.stringify(next), 0o600)
console.log(`Wrote ${required('out')} for root ${next.rootKeyId}:`)
printKeys(next)
return
}
case 'add-key': {
const root = await readRoot(required('root'))
const status = values.status ?? 'active'
if (status !== 'active' && status !== 'overlapping')
throw new Error('--status must be active or overlapping.')
const next = addTrustedKey(root, readPrivateKey(readFileSync(required('root-key'), 'utf8')), {
keyId: required('key-id'),
publicKey: readFileSync(required('public-key-file'), 'utf8').trim(),
notBefore: required('not-before'),
notAfter: required('not-after'),
status,
})
const next = addTrustedKey(root, readPrivateKey(readFileSync(required('root-key'), 'utf8')), newKeyFromArgs())
writeNew(required('out'), JSON.stringify(next), 0o600)
console.log(`Wrote ${required('out')}:`)
printKeys(next)
Expand All @@ -117,7 +139,13 @@ async function main(command: string | undefined): Promise<void> {
const root = await readRoot(required('root'))
const pinRoot = await readRoot(values.pin ?? LIVE_ROOT)
const pin: RootPin = { rootKeyId: pinRoot.rootKeyId, rootPublicKey: pinRoot.rootPublicKey }
const result = verifyTrustedRoot(root, pin, Math.floor(Date.now() / 1000))
const peers = []
if (values['peer-root'] || values['peer-pin']) {
const peerRoot = await readRoot(required('peer-root'))
const peerPin = await readRoot(required('peer-pin'))
peers.push({ root: peerRoot, pin: peerPin })
}
const result = verifyTrustedRoot(root, pin, Math.floor(Date.now() / 1000), peers)
const problems = result._tag === 'invalid' ? [...result.problems] : []
if (values['signing-key']) {
const keyId = required('key-id')
Expand Down
Loading
Loading