From 26686347fbcff844b3643260519b44a7c9be88c4 Mon Sep 17 00:00:00 2001 From: lex00 <121451605+lex00@users.noreply.github.com> Date: Fri, 16 Oct 2026 20:52:59 -0600 Subject: [PATCH 1/3] trust: signed green and revoked tags, a release gate for who may cut, signed release cuts (#4031) A ci tag on a commit committed at or after ci.green.signedSince counts only when its annotation carries an in-toto statement in a DSSE envelope, signed by a runner key .chant/trust.json lists under runners for a principal holding the runner role. An older commit's tag counts unsigned, and without signedSince every tag counts as before. ci tick signs what it makes from --key or CHANT_RUNNER_KEY and refuses a key the policy does not list; ci tick, ci list, ci last-green and release cut ignore and report a tag without a valid statement. ci last-green gains --from, which release-preflight.sh uses once signedSince is set. ci workflow --runner-key-secret passes the key from a repository secret. identity.gates.release says who may cut: release cut then needs --sign by an actor in its class. A cut's signature is an ssh signature in the chant-release namespace over the digest, label, actor and time; release list and workspace status verify it on every read (signatureCheck, releaseCuts). --- docs/src/content/docs/cli/ci.mdx | 67 +++- docs/src/content/docs/cli/release.mdx | 39 ++- .../src/content/docs/cli/workspace-status.mdx | 13 + .../docs/reference/level-0-exceptions.mdx | 1 + .../docs/reference/workspace-declaration.mdx | 5 +- .../reference/workspace-read-contract.mdx | 8 +- packages/core/src/cli/handlers/release.ts | 20 +- packages/core/src/cli/main.ts | 27 +- packages/core/src/cli/parse-args.ts | 9 +- packages/core/src/cli/registry.ts | 4 +- .../src/lifecycle/release-cut-signed.test.ts | 171 +++++++++ packages/core/src/lifecycle/release-cut.ts | 98 +++++- packages/core/src/lifecycle/release-store.ts | 7 +- packages/core/src/workspace/ci-green-cli.ts | 40 ++- .../src/workspace/ci-green-signed.test.ts | 264 ++++++++++++++ .../src/workspace/ci-green-workflow.test.ts | 16 + .../core/src/workspace/ci-green-workflow.ts | 12 + packages/core/src/workspace/ci-green.test.ts | 4 + packages/core/src/workspace/ci-green.ts | 324 ++++++++++++++---- .../src/workspace/ci-last-green.schema.json | 34 +- .../core/src/workspace/ci-list.schema.json | 44 +++ .../src/workspace/declaration.schema.json | 5 + packages/core/src/workspace/declaration.ts | 14 +- .../core/src/workspace/identity-gate-rule.ts | 98 +++++- packages/core/src/workspace/identity.ts | 15 +- packages/core/src/workspace/ls.schema.json | 3 +- packages/core/src/workspace/ls.ts | 3 + .../core/src/workspace/releases.schema.json | 31 +- packages/core/src/workspace/releases.ts | 22 +- .../core/src/workspace/status.schema.json | 26 ++ packages/core/src/workspace/status.ts | 63 +++- .../src/workspace/trust/ci-tag-statement.ts | 150 ++++++++ packages/core/src/workspace/trust/seal.ts | 10 + scripts/release-preflight.sh | 29 ++ 34 files changed, 1531 insertions(+), 145 deletions(-) create mode 100644 packages/core/src/lifecycle/release-cut-signed.test.ts create mode 100644 packages/core/src/workspace/ci-green-signed.test.ts create mode 100644 packages/core/src/workspace/trust/ci-tag-statement.ts diff --git a/docs/src/content/docs/cli/ci.mdx b/docs/src/content/docs/cli/ci.mdx index e127782a4c..2d8664a72c 100644 --- a/docs/src/content/docs/cli/ci.mdx +++ b/docs/src/content/docs/cli/ci.mdx @@ -7,11 +7,12 @@ diataxis: reference ## Synopsis ``` -chant ci last-green [--json] +chant ci last-green [--json] [--from ] chant ci list [--json] [--limit ] [--since ] [--forge github] -chant ci tick [--dry-run] [--forge github] +chant ci tick [--dry-run] [--forge github] [--key ] chant ci workflow [--workflow ]... [--output ] [--chant ] [--install ] [--token-secret | --app-id-var --app-key-secret ] + [--runner-key-secret ] ``` `chant ci` records which commits of a branch passed CI as git tags, from the [`ci.green`](/chant/reference/workspace-declaration/#ci) block of the workspace declaration ([#3573](https://github.com/INTENTIUS/chant/issues/3573), [ws-103](https://github.com/INTENTIUS/chant/blob/main/docs/design/decisions/ws-103-ci-green-and-revoked-tags.md)). A commit that passes every required phase gets `ci/green/`. A green commit that later fails one gets `ci/revoked/`. Anyone with a clone can then find the newest commit that passed, for example to freeze it and release from it. @@ -25,9 +26,9 @@ git fetch origin --tags git checkout "$(chant ci last-green)" ``` -When no commit qualifies, a message goes to stderr and the exit code is 1. +When no commit qualifies, a message goes to stderr and the exit code is 1. `--from ` walks the first-parent commits of `rev` instead of the branch, so `chant ci last-green --from ` prints `` exactly when that commit counts as green. With [signed tags](#signed-tags), each tag the walk ignores is printed on stderr as a warning. -`--json` prints a [read contract](/chant/reference/workspace-read-contract/) document, `ci-last-green.schema.json`, whose `commit` is `{ sha, tag, tagged, committed }` or `null`, and exits 0 in both cases. A failure has an `error` and exits 1. Its code is `ci-green-undeclared` for a declaration with no `ci.green`, `ci-branch-unknown` when the branch has no ref in this checkout, or the code of a declaration that can't be read. +`--json` prints a [read contract](/chant/reference/workspace-read-contract/) document, `ci-last-green.schema.json`, whose `commit` is `{ sha, tag, tagged, committed }` or `null`, and exits 0 in both cases. `ignored` lists the tags the walk passed over for want of a valid statement, newest first, each with `tag`, `status` and `reason`. A failure has an `error` and exits 1. Its code is `ci-green-undeclared` for a declaration with no `ci.green`, `ci-branch-unknown` when the branch has no ref in this checkout, or the code of a declaration that can't be read. ## ci list @@ -43,6 +44,8 @@ A phase's result comes from the tags. A green tag's annotation records the runs A line for an `unlinked` or `wrong` commit ends with `; why unknown:` and the reason. [Link commits to work items](/chant/guide/work-items/#link-commits-to-work-items) says how a commit names one. +With [signed tags](#signed-tags), the state counts only the tags that carry a valid statement. A tag that does not is listed on its own line under the commit, as `ignored (): `, and in `--json` under the commit's `ignored`. The `green` and `revoked` objects name the runner that signed the tag in `signer`, which is `null` for a tag that counts unsigned. + `--limit ` keeps the newest `n`. `--since ` lists what came after `rev` and replaces the window, so a reader holding the last sha it saw can ask for what is new. `--json` prints a [read contract](/chant/reference/workspace-read-contract/) document, `ci-list.schema.json`, with `window`, `since`, `require` and a `commits` array. Each entry has `sha`, `committed`, `state`, `phases`, and a `green` and a `revoked` object holding the tag and the time it was made, plus the failed phase and run for a revoked tag. Either object is `null` when the tag is absent. Each entry also has `work` ([#4029](https://github.com/INTENTIUS/chant/issues/4029)), `{ state, ids, problems }`, where `state` says whether the commit names its work item. The judgement is the one [`workspace check --changes`](/chant/cli/workspace-check/#commits-that-name-no-work-item) makes, against the work records at the listed ref. `work` is `null` when the workspace declares no work kind. chant 0.124.28 added it within contract 1, and a reader ignores fields it does not know. A failure uses the codes of `ci last-green`, and `revision-unknown` when `--since` names no commit, with exit code 1. @@ -57,10 +60,60 @@ One pass over the branch. It fetches the branch and the `ci/*` tags from `origin | a green tag and no revoked tag | fails a required phase | `ci/revoked/` | | a revoked tag | anything | nothing, and its check runs are not read | -Running it again over the same check runs changes nothing. `--dry-run` prints what it would tag and makes no tag. A commit that names no work item, or a wrong one, has `; why unknown:` and the reason at the end of its line, as in `ci list`. +Running it again over the same check runs changes nothing. `--dry-run` prints what it would tag and makes no tag. With [signed tags](#signed-tags), the tick signs each tag it makes and judges the tags already there as every other reader does, so a hand-pushed tag doesn't count. Since chant never moves or deletes a tag, a hand-pushed tag that holds the name of a tag the tick would make stops it, and the tick says which tag to delete. A commit that names no work item, or a wrong one, has `; why unknown:` and the reason at the end of its line, as in `ci list`. The check runs come from the forge. GitHub is the only one so far: the tick reads `GITHUB_REPOSITORY`, a token from `CHANT_FORGE_TOKEN`, `GITHUB_TOKEN` or `GH_TOKEN` with `checks: read`, and `GITHUB_API_URL` for GitHub Enterprise Server. `--forge gitlab` and `--forge forgejo` are refused. GitLab and Forgejo get no status reader. The decision is to cover them through the results of chant's own runs ([#4044](https://github.com/INTENTIUS/chant/issues/4044)) instead of mapping pipeline jobs and commit statuses to check runs: GitLab reports jobs per pipeline and Forgejo reports statuses per context. Each mapping needs its own rules for retries and skips. A run result is the same on every forge. Until #4044 ships, the tags and `ci list` work on any forge's repository, but `ci tick` has no status source there. Pushing the tags needs `contents: write` on the remote. +## Signed tags + +The tags are plain git tags, so anyone who may push a tag could make `ci/green/` by hand and go around CI ([#4031](https://github.com/INTENTIUS/chant/issues/4031)). Setting `ci.green.signedSince` in the [declaration](/chant/reference/workspace-declaration/#ci) closes that: a tag on a commit committed at or after that time counts only when its annotation carries a statement signed by a runner key. Without `signedSince`, every tag counts, as before. + +```json +"ci": { + "green": { + "branch": "main", + "phases": { "test": ["test"] }, + "require": ["test"], + "signedSince": "2026-11-01T00:00:00Z" + } +} +``` + +The statement is the one [runner evidence](/chant/cli/workspace-evidence/) and [agent-run statements](/chant/cli/workspace-runs/#signed-statements) use: an in-toto statement in a DSSE envelope, signed with an Ed25519 key. Its subject is the tagged commit, and its predicate (`https://intentius.io/chant/ci-tag/v1`) holds the signer and the tag's JSON record. The envelope sits in that record as `statement`, so a reader that doesn't know it reads the record as before. + +A reader counts a tag after `signedSince` when all of these hold, and otherwise ignores it with one of four statuses: + +| Status | When | +|---|---| +| `unsigned` | The annotation carries no statement, as with a lightweight tag or one made by hand. | +| `invalid` | The envelope or its payload is not a ci-tag statement, or it names another signer than the key's. | +| `untrusted` | No key that `.chant/trust.json` lists under `runners` signed it, or its principal holds no `runner` role there. Both are read where the branch is, at `refs/remotes/origin/` or the local branch. | +| `mismatch` | It signs another commit, another kind of tag or another branch, the annotation's record is not the one signed, or the tag points at another commit than its name gives. | + +A tag on a commit committed before `signedSince` counts without a statement, so the tags a workspace already has keep working. The commit's committer time decides, never the tag's date, which whoever makes the tag chooses. A backdated tag on a new commit therefore gains nothing. Every reader judges the tags the same way: `ci tick`, `ci list`, `ci last-green`, [`release cut`](/chant/cli/release/#release-cut) and chant's own `scripts/release-preflight.sh`. + +### The runner key + +The tick signs with an Ed25519 private key in PEM, from `--key ` or from the `CHANT_RUNNER_KEY` environment variable. `.chant/trust.json` lists its public half under `runners`, and the principal it names holds the `runner` role: + +```json +{ + "schema": 1, + "runners": [{ "principal": "ci:acme/app", "class": "runner", "key": "ssh-ed25519 AAAA..." }], + "roles": { "runner": ["ci:acme/app"] } +} +``` + +The tick refuses a key the file doesn't list, a principal without the role and a key the signers file lists, before it makes any tag. A person's key never signs a tag. With `signedSince` set, the tick refuses to run without a key, apart from `--dry-run`. Both files are read at the branch's tip, and changing either is a protected write, as for [runner evidence](/chant/cli/workspace-evidence/). Make the key as for runner evidence: + +```bash +openssl genpkey -algorithm ed25519 -out runner.pem +``` + +A tick given a key the file doesn't list yet refuses it and prints the key's `ssh-ed25519` line to add under `runners`. Keep `runner.pem` out of the repository. + +On GitHub the key lives in a repository secret, and `chant ci workflow --runner-key-secret ` hands it to the tick as `CHANT_RUNNER_KEY`. Turn signing on in this order: add the key to `runners` and the principal to `roles.runner`, store the secret and regenerate the workflow, then set `signedSince`. A chant older than 0.124.28 refuses a declaration with `signedSince`, so set `minReader` to `0.124.28` with it. + ## ci workflow Writes `.github/workflows/chant-ci-green.yml` (or `--output`), the root CI file that runs the tick. A tick starts when a workflow holding a required check run completes on the branch, so a result or a re-run is acted on within seconds. A cron every 15 minutes covers an event that was dropped or late. All ticks share one concurrency group that never cancels, so they run one at a time. @@ -87,6 +140,8 @@ A GitHub App with Contents and Workflows write works too. Put its id in an Actio chant ci workflow --app-id-var CI_GREEN_APP_ID --app-key-secret CI_GREEN_APP_KEY ``` +`--runner-key-secret ` passes the repository secret `NAME` to the tick step as `CHANT_RUNNER_KEY`, so the tick [signs its tags](#signed-tags). The secret holds the runner key as PEM, and the key's principal needs the `runner` role in `.chant/trust.json`. When the declaration sets `ci.green.signedSince` and the flag is missing, `ci workflow` warns, since every tick would fail. + Regenerating keeps the token flags you passed, since the header records them. Leave them out and the file comes out byte for byte as 0.108.0 wrote it. ## chant's own repository @@ -99,4 +154,4 @@ Its tick runs the source at the commit it checks out, so a change to `chant ci` chant ci workflow --chant 'npx tsx packages/core/src/cli/main.ts' --install 'npm install --ignore-scripts' ``` -The install skips the lexicon builds, and the tick needs none of them. `just release` picks the commit it tags from these tags: `scripts/release-preflight.sh` reads them whenever the declaration on `origin/main` sets `ci.green` for `main`. When no commit has a green tag, it refuses to release. It doesn't fall back to asking GitHub, and `CHANT_RELEASE_SKIP_PREFLIGHT=1` skips the check. The publish workflow has a second gate, `release-gate`, that waits for a green run on the released commit. A tag push skips that gate and publishes. To get it, start `publish.yml` by hand with `verify_ci` checked. The repository variable `CHANT_RELEASE_SKIP_CI_GATE` that used to skip it is no longer read. +The install skips the lexicon builds, and the tick needs none of them. `just release` picks the commit it tags from these tags: `scripts/release-preflight.sh` reads them whenever the declaration on `origin/main` sets `ci.green` for `main`. When no commit has a green tag, it refuses to release. It doesn't fall back to asking GitHub, and `CHANT_RELEASE_SKIP_PREFLIGHT=1` skips the check. chant does not set `signedSince` yet, so its tags are unsigned and the script checks that they exist. Once the declaration on `origin/main` sets it, the script asks chant instead. It runs `ci last-green --from ` through `$CHANT_CLI`, which defaults to this checkout's source through tsx. Each tag chant ignored is printed as it goes. Turning signing on for chant itself waits on a runner key in its secrets ([#4040](https://github.com/INTENTIUS/chant/issues/4040)). The publish workflow has a second gate, `release-gate`, that waits for a green run on the released commit. A tag push skips that gate and publishes. To get it, start `publish.yml` by hand with `verify_ci` checked. The repository variable `CHANT_RELEASE_SKIP_CI_GATE` that used to skip it is no longer read. diff --git a/docs/src/content/docs/cli/release.mdx b/docs/src/content/docs/cli/release.mdx index 654774a685..b28e059e70 100644 --- a/docs/src/content/docs/cli/release.mdx +++ b/docs/src/content/docs/cli/release.mdx @@ -7,7 +7,7 @@ diataxis: reference ## Synopsis ``` -chant release cut [