From a1f0621456a41963eb3797aa8f6aba9e92db5041 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 12 Nov 2026 04:43:37 +0000 Subject: [PATCH 1/3] feat(prism-code): trust decisions in verify, signing in auth (Part of #449) - verify-closure.mjs (verify) makes every trust decision push and pull need: the claims about the pulled bytes, the attestation subjects, the verdict and the signer policy, and push's outgoing integrity check. push-pull.mjs only fetches and writes. prism.verify.pullClosure exposes it. - signing.mjs (auth) holds the Sigstore signing code that was in attest.mjs. Every signature goes through an auth identity; auth.identities.from turns the flat signer options into one. attest-write.mjs (images) writes signed statements; attest.mjs keeps only verification. - model/modules.toml: owners for the three files, and the pending "Signing parts of attest move to auth" cut is made. - runtimes.json registers the Rust shim (DK-42); the npm conformance suite job builds and runs it, and COMPLIANCE.md shows Rust and JavaScript both passing all 24 verify checks. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013Asa3Mf94yL5KHxQf3uUBS --- .github/workflows/npm-conformance.yml | 38 +- CHANGELOG.md | 1 + COMPLIANCE.md | 377 +++++++++++------- model/modules.toml | 17 +- sdk/npm/conformance/runtimes.json | 4 +- sdk/npm/conformance/test/matrix.test.mjs | 19 +- sdk/npm/conformance/test/run.test.mjs | 2 +- sdk/npm/prism-code/CHANGELOG.md | 1 + sdk/npm/prism-code/src/attest-cli.mjs | 3 +- sdk/npm/prism-code/src/attest-write.mjs | 181 +++++++++ sdk/npm/prism-code/src/attest.mjs | 309 +------------- sdk/npm/prism-code/src/auth.mjs | 41 +- sdk/npm/prism-code/src/node.mjs | 3 +- sdk/npm/prism-code/src/push-pull.mjs | 168 ++------ sdk/npm/prism-code/src/signing.mjs | 167 ++++++++ sdk/npm/prism-code/src/verify-closure.mjs | 201 ++++++++++ sdk/npm/prism-code/src/verify-namespace.mjs | 11 + sdk/npm/prism-code/test/attest.test.mjs | 3 +- sdk/npm/prism-code/test/auth.test.mjs | 33 +- sdk/npm/prism-code/test/check.test.mjs | 3 +- .../test/fixtures/package-files.json | 3 + .../prism-code/test/images-signed.test.mjs | 2 +- sdk/npm/prism-code/test/oci-live.test.mjs | 2 +- sdk/npm/prism-code/test/push-pull.test.mjs | 2 +- .../prism-code/test/verify-namespace.test.mjs | 27 +- 25 files changed, 986 insertions(+), 632 deletions(-) create mode 100644 sdk/npm/prism-code/src/attest-write.mjs create mode 100644 sdk/npm/prism-code/src/signing.mjs create mode 100644 sdk/npm/prism-code/src/verify-closure.mjs diff --git a/.github/workflows/npm-conformance.yml b/.github/workflows/npm-conformance.yml index e5414cd25..17d43cdb4 100644 --- a/.github/workflows/npm-conformance.yml +++ b/.github/workflows/npm-conformance.yml @@ -8,7 +8,9 @@ name: npm conformance # # A runtime joins by adding its shim to sdk/npm/conformance/runtimes.json and a # step to the suite job that writes results/.json; `matrix --check` refuses -# a registered runtime with no results. +# a registered runtime with no results. The Rust shim (DK-42) is built once, in +# the suite job, which is also where the unit tests that run every registered +# runtime run; the OS matrix skips those three and says why. on: pull_request: @@ -22,6 +24,12 @@ on: - sdk/npm/spec/schemas/verdict/** - sdk/npm/spec/test/json-schema.mjs - docs/adr/015-dual-digests.md + # The Rust runtime's shim and what it calls. + - crates/conformance/runtime/** + - crates/conformance/src/bin/prism-conformance-shim.rs + - crates/prismpm/src/inspect/** + - Cargo.lock + - rust-toolchain.toml - COMPLIANCE.md - .github/workflows/npm-conformance.yml push: @@ -35,6 +43,12 @@ on: - sdk/npm/spec/schemas/verdict/** - sdk/npm/spec/test/json-schema.mjs - docs/adr/015-dual-digests.md + # The Rust runtime's shim and what it calls. + - crates/conformance/runtime/** + - crates/conformance/src/bin/prism-conformance-shim.rs + - crates/prismpm/src/inspect/** + - Cargo.lock + - rust-toolchain.toml - COMPLIANCE.md - .github/workflows/npm-conformance.yml @@ -93,9 +107,9 @@ jobs: rm pack.json suite: - name: prism-code passes, and COMPLIANCE.md is current + name: prism-code and the Rust shim pass, and COMPLIANCE.md is current runs-on: ubuntu-24.04 - timeout-minutes: 15 + timeout-minutes: 30 steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: @@ -103,13 +117,21 @@ jobs: - uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 with: node-version: '24' - - name: Run the suite against the JavaScript runtime + # rust-toolchain.toml pins the toolchain; rustup installs it on first use. + - name: Build the Rust runtime's shim + run: cargo build --locked -p repo-conformance --bin prism-conformance-shim + - name: Unit tests that run every registered runtime + working-directory: sdk/npm/conformance + run: node --test test/matrix.test.mjs + - name: Run the suite against the JavaScript and Rust runtimes shell: bash run: | set -euo pipefail mkdir -p target/conformance/results node sdk/npm/conformance/bin/prism-conformance.mjs run --runtime js \ --out target/conformance/results/js.json | tee target/conformance/js.txt + node sdk/npm/conformance/bin/prism-conformance.mjs run --runtime rust \ + --out target/conformance/results/rust.json | tee target/conformance/rust.txt - name: Regenerate the matrix from those results run: node sdk/npm/conformance/bin/prism-conformance.mjs matrix --results target/conformance/results --write --output target/conformance/COMPLIANCE.md - name: Publish the matrix and the results with this run @@ -127,8 +149,10 @@ jobs: if [ -f target/conformance/COMPLIANCE.md ]; then sed -n '/^## Features/,/^## Checks/p' target/conformance/COMPLIANCE.md | sed '$d' >> "$GITHUB_STEP_SUMMARY" fi - if [ -f target/conformance/js.txt ]; then - tail -n 2 target/conformance/js.txt >> "$GITHUB_STEP_SUMMARY" - fi + for runtime in js rust; do + if [ -f "target/conformance/$runtime.txt" ]; then + tail -n 2 "target/conformance/$runtime.txt" >> "$GITHUB_STEP_SUMMARY" + fi + done - name: The committed COMPLIANCE.md is the one the suite just generated run: node sdk/npm/conformance/bin/prism-conformance.mjs matrix --results target/conformance/results --check diff --git a/CHANGELOG.md b/CHANGELOG.md index 16dfee48a..d6f7f5ab4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ To move to 1.0, read the [migration guide](docs/site/migration/to-1-0.md). ## [Unreleased] ### Features Added +- `COMPLIANCE.md` shows the Rust runtime (#449, #298): `sdk/npm/conformance/runtimes.json` registers `prism-conformance-shim`, the npm conformance suite job builds it and runs the suite against it beside prism-code, and the matrix shows both runtimes passing all 24 `verify` checks. `prism.verify.pullClosure` makes every trust decision a pull needs, and signing moves to `auth` (`auth.identities.from`), so the pending `auth.mjs` to `attest.mjs` cut in `model/modules.toml` is made; see the prism-code CHANGELOG. - `prismpm generate --lang --out ` (#289, experimental): the Rust CLI writes the same bindings and typed client as `prism-code generate`, byte for byte apart from the generator each file header names, beside the same `prism-generate.json` record, and a run whose record and files are in place writes nothing. Every decision is the LexLean model `bindings/src/Foundation/Bindings/V1`: the new `Source.lex.tex` reads the WIT world and the model document into the code model (the WIT subset, the world's exports and memory, the application's class name, the numeric profile's operations), and `Generate.lex.tex` joins it to the JS, Python and Rust writers. `cargo xtask bindings-package` exports the three roots and vendors them into the crate, so the published `prismpm` carries them and the unpublished `prism-bindings` crate is gone. A holo generate cannot bind is `PP3201`; an output directory holding a file generate did not write is `PP3202`. - `prismpm verify` writes the proof statement of a verified application (#266, #582): `proof-statement.json` in the verified directory, an unsigned in-toto statement with the predicate `https://uor.foundation/prism/proof/v1`. Its subject is the guest; it lists every theorem of the model with its verdict and axiom audit, the verifier, the model's identities, the named TCB and the evidence digests. The statement is the output of a LexLean model, `bindings/src/Foundation/Proof/V1/Statement.lex.tex`, exported by `cargo xtask bindings-package` into the `prismpm` crate; it writes the calculator statement of `docs/proposals/266-proof-predicate.md` byte for byte. A model with no theorem, or a project with no `prismpm.lock`, gets no statement and a line on stderr that says why. `prism-code attest --statement` signs it into the holo. - `prismpm verify` names each stage it enters on stderr as `prismpm: stage ` when `PRISMPM_PROGRESS` is set (#585): every process it runs (Lean export, Rust, WebAssembly, the acceptance run), the Lean proof and the holo. Without the variable it prints nothing new. The guided journey sets it, so `prism_build` reports the running stage in `latest` instead of one line for the whole build. diff --git a/COMPLIANCE.md b/COMPLIANCE.md index b01ea7d92..8d7ffe915 100644 --- a/COMPLIANCE.md +++ b/COMPLIANCE.md @@ -15,15 +15,15 @@ Which Prism runtime passes which part of the runtime contract, from the results | Feature | Checks | JavaScript | Rust | Python | | --- | --- | --- | --- | --- | -| Registry logins and signing identities (`auth`) | 16 | + | N/A | N/A | -| Capabilities, deny by default (`capabilities`) | 25 | + | N/A | N/A | -| Dual digests (`digests`) | 18 | + | N/A | N/A | -| Dispatch through the guest (`dispatch`) | 7 | + | N/A | N/A | -| Typed errors (`errors`) | 8 | + | N/A | N/A | -| Load a holo (`load`) | 21 | + | N/A | N/A | -| Histories and replay (`replay`) | 5 | + | N/A | N/A | -| Verify a holo (`verify`) | 24 | + | N/A | N/A | -| The world contract (`world`) | 16 | + | N/A | N/A | +| Registry logins and signing identities (`auth`) | 16 | + | - | N/A | +| Capabilities, deny by default (`capabilities`) | 25 | + | - | N/A | +| Dual digests (`digests`) | 18 | + | + | N/A | +| Dispatch through the guest (`dispatch`) | 7 | + | - | N/A | +| Typed errors (`errors`) | 8 | + | - | N/A | +| Load a holo (`load`) | 21 | + | - | N/A | +| Histories and replay (`replay`) | 5 | + | - | N/A | +| Verify a holo (`verify`) | 24 | + | + | N/A | +| The world contract (`world`) | 16 | + | - | N/A | ## Checks @@ -31,187 +31,264 @@ Which Prism runtime passes which part of the runtime contract, from the results | Check | Asks | JavaScript | Rust | Python | | --- | --- | --- | --- | --- | -| `auth.login.docker-config-entry` | A login with no helper configured writes the entry Docker writes. | + | N/A | N/A | -| `auth.login.keeps-the-config` | A login keeps everything else in the config and replaces older spellings of the registry. | + | N/A | N/A | -| `auth.login.docker-hub-by-default` | A login that names no registry is to Docker Hub, under Docker's key. | + | N/A | N/A | -| `auth.login.username-with-colon` | A username with a colon is refused: Docker's entry could not be read back. | + | N/A | N/A | -| `auth.login.registry-with-a-scheme` | A registry is a host name, not a URL. | + | N/A | N/A | -| `auth.login.config-not-json` | A config that does not parse is refused, not overwritten. | + | N/A | N/A | -| `auth.login.helper-not-installed` | A login that a configured helper cannot store fails: it never appears to work. | + | N/A | N/A | -| `auth.logout.removes-every-spelling` | A logout removes the registry under every key Docker may file it by, and leaves the others. | + | N/A | N/A | -| `auth.logout.nothing-there` | A logout with nothing to remove says so and is not an error. | + | N/A | N/A | -| `auth.logout.names-the-ambient-token` | A logout says which variable still gives ghcr.io a token, because it cannot clear one. | + | N/A | N/A | -| `auth.inspect.password` | Inspect reports a password credential's type, username and store. | + | N/A | N/A | -| `auth.inspect.identity-token` | Inspect reports an identity token by its type alone. | + | N/A | N/A | -| `auth.inspect.nothing-there` | Inspect of a registry with no credential is null. | + | N/A | N/A | -| `auth.stores.helper-for-a-registry` | A login goes to the registry's helper before the default one, and to the config when there is neither. | + | N/A | N/A | -| `auth.identities.unreadable-key` | A signing key that cannot be read is a signing error about the key. | + | N/A | N/A | -| `auth.identities.empty-token` | An empty identity token is a signing error about the identity. | + | N/A | N/A | +| `auth.login.docker-config-entry` | A login with no helper configured writes the entry Docker writes. | + | - | N/A | +| `auth.login.keeps-the-config` | A login keeps everything else in the config and replaces older spellings of the registry. | + | - | N/A | +| `auth.login.docker-hub-by-default` | A login that names no registry is to Docker Hub, under Docker's key. | + | - | N/A | +| `auth.login.username-with-colon` | A username with a colon is refused: Docker's entry could not be read back. | + | - | N/A | +| `auth.login.registry-with-a-scheme` | A registry is a host name, not a URL. | + | - | N/A | +| `auth.login.config-not-json` | A config that does not parse is refused, not overwritten. | + | - | N/A | +| `auth.login.helper-not-installed` | A login that a configured helper cannot store fails: it never appears to work. | + | - | N/A | +| `auth.logout.removes-every-spelling` | A logout removes the registry under every key Docker may file it by, and leaves the others. | + | - | N/A | +| `auth.logout.nothing-there` | A logout with nothing to remove says so and is not an error. | + | - | N/A | +| `auth.logout.names-the-ambient-token` | A logout says which variable still gives ghcr.io a token, because it cannot clear one. | + | - | N/A | +| `auth.inspect.password` | Inspect reports a password credential's type, username and store. | + | - | N/A | +| `auth.inspect.identity-token` | Inspect reports an identity token by its type alone. | + | - | N/A | +| `auth.inspect.nothing-there` | Inspect of a registry with no credential is null. | + | - | N/A | +| `auth.stores.helper-for-a-registry` | A login goes to the registry's helper before the default one, and to the config when there is neither. | + | - | N/A | +| `auth.identities.unreadable-key` | A signing key that cannot be read is a signing error about the key. | + | - | N/A | +| `auth.identities.empty-token` | An empty identity token is a signing error about the identity. | + | - | N/A | ### Capabilities, deny by default | Check | Asks | JavaScript | Rust | Python | | --- | --- | --- | --- | --- | -| `capabilities.none.denies-everything` | With no capability file, every kind is denied, wildcard resources included. | + | N/A | N/A | -| `capabilities.none.load-grants-nothing` | A load with no capability file names no set, and the reference holo still opens. | + | N/A | N/A | -| `capabilities.empty.default-set-denies` | An empty default set grants nothing. | + | N/A | N/A | -| `capabilities.empty.deny-only-denies` | A set of deny entries alone grants nothing. | + | N/A | N/A | -| `capabilities.allow.exact-names` | An allow entry grants exactly what it names, for each kind. | + | N/A | N/A | -| `capabilities.outbound.exact-match` | An outbound host entry matches on scheme, host and port, and ignores the path. | + | N/A | N/A | -| `capabilities.outbound.wildcards` | Subdomain, port and scheme wildcards match what they say and no further. | + | N/A | N/A | -| `capabilities.deny.wins-over-allow` | A deny entry wins over an allow entry, including a specific deny under a wildcard allow. | + | N/A | N/A | -| `capabilities.deny.same-entry-on-both-lists` | The same entry on both lists is denied. | + | N/A | N/A | -| `capabilities.set.default-applies` | A named set grants nothing until it is asked for. | + | N/A | N/A | -| `capabilities.set.named-applies` | A named set applies when it is asked for. | + | N/A | N/A | -| `capabilities.set.load-names-the-set` | A load under a named set reports that set. | + | N/A | N/A | -| `capabilities.set.missing-is-an-error` | A set the file does not hold is an error, never an empty grant. | + | N/A | N/A | -| `capabilities.set.named-without-a-file` | Naming a set with no file is an error, never an empty grant. | + | N/A | N/A | -| `capabilities.invalid.unknown-member` | A misspelled member is an error, so a typo cannot widen or narrow a grant silently. | + | N/A | N/A | -| `capabilities.invalid.no-default-set` | A file with no default set is an error. | + | N/A | N/A | -| `capabilities.invalid.wrong-schema` | Another schema version is an error. | + | N/A | N/A | -| `capabilities.invalid.malformed-entry` | A host entry with a path is an error. | + | N/A | N/A | -| `capabilities.invalid.repeated-entry` | A repeated entry is an error. | + | N/A | N/A | -| `capabilities.invalid.not-json` | A file that is not JSON is an error. | + | N/A | N/A | -| `capabilities.import.denied-with-no-file` | A guest import is denied at load when no capability file is given. | + | N/A | N/A | -| `capabilities.import.denied-under-a-full-grant` | A guest import is denied at load even when the file grants every resource, because the world lists no imports. | + | N/A | N/A | -| `capabilities.kind.unknown` | Asking about a kind that does not exist is an error, not a denial. | + | N/A | N/A | -| `capabilities.policy.invalid-grant` | A verify policy whose grant is malformed is an invalid policy. | + | N/A | N/A | -| `capabilities.policy.within-grant` | A world that imports nothing is within every grant. | + | N/A | N/A | +| `capabilities.none.denies-everything` | With no capability file, every kind is denied, wildcard resources included. | + | - | N/A | +| `capabilities.none.load-grants-nothing` | A load with no capability file names no set, and the reference holo still opens. | + | - | N/A | +| `capabilities.empty.default-set-denies` | An empty default set grants nothing. | + | - | N/A | +| `capabilities.empty.deny-only-denies` | A set of deny entries alone grants nothing. | + | - | N/A | +| `capabilities.allow.exact-names` | An allow entry grants exactly what it names, for each kind. | + | - | N/A | +| `capabilities.outbound.exact-match` | An outbound host entry matches on scheme, host and port, and ignores the path. | + | - | N/A | +| `capabilities.outbound.wildcards` | Subdomain, port and scheme wildcards match what they say and no further. | + | - | N/A | +| `capabilities.deny.wins-over-allow` | A deny entry wins over an allow entry, including a specific deny under a wildcard allow. | + | - | N/A | +| `capabilities.deny.same-entry-on-both-lists` | The same entry on both lists is denied. | + | - | N/A | +| `capabilities.set.default-applies` | A named set grants nothing until it is asked for. | + | - | N/A | +| `capabilities.set.named-applies` | A named set applies when it is asked for. | + | - | N/A | +| `capabilities.set.load-names-the-set` | A load under a named set reports that set. | + | - | N/A | +| `capabilities.set.missing-is-an-error` | A set the file does not hold is an error, never an empty grant. | + | - | N/A | +| `capabilities.set.named-without-a-file` | Naming a set with no file is an error, never an empty grant. | + | - | N/A | +| `capabilities.invalid.unknown-member` | A misspelled member is an error, so a typo cannot widen or narrow a grant silently. | + | - | N/A | +| `capabilities.invalid.no-default-set` | A file with no default set is an error. | + | - | N/A | +| `capabilities.invalid.wrong-schema` | Another schema version is an error. | + | - | N/A | +| `capabilities.invalid.malformed-entry` | A host entry with a path is an error. | + | - | N/A | +| `capabilities.invalid.repeated-entry` | A repeated entry is an error. | + | - | N/A | +| `capabilities.invalid.not-json` | A file that is not JSON is an error. | + | - | N/A | +| `capabilities.import.denied-with-no-file` | A guest import is denied at load when no capability file is given. | + | - | N/A | +| `capabilities.import.denied-under-a-full-grant` | A guest import is denied at load even when the file grants every resource, because the world lists no imports. | + | - | N/A | +| `capabilities.kind.unknown` | Asking about a kind that does not exist is an error, not a denial. | + | - | N/A | +| `capabilities.policy.invalid-grant` | A verify policy whose grant is malformed is an invalid policy. | + | + | N/A | +| `capabilities.policy.within-grant` | A world that imports nothing is within every grant. | + | + | N/A | ### Dual digests | Check | Asks | JavaScript | Rust | Python | | --- | --- | --- | --- | --- | -| `digests.archive.dual` | The archive is reported under both algorithms, over the whole file, as ADR-015 pins them. | + | N/A | N/A | -| `digests.footer.not-the-file-hash` | The footer is the BLAKE3 of the body, reported apart from the file's BLAKE3. | + | N/A | N/A | -| `digests.verdict.names-the-footer` | A verdict addresses the holo by its archive fingerprint. | + | N/A | N/A | -| `digests.blob.guest` | The guest's content is reported under both algorithms, and its label is the BLAKE3. | + | N/A | N/A | -| `digests.blob.model` | The model document's content is reported under both algorithms. | + | N/A | N/A | -| `digests.blob.view` | The view's content is reported under both algorithms. | + | N/A | N/A | -| `digests.blob.capability-set` | The capability set's content is reported under both algorithms. | + | N/A | N/A | -| `digests.section.covers-its-table-bytes` | A section's digest covers exactly its table bytes, label included. | + | N/A | N/A | -| `digests.damage.footer-reported` | A wrong footer is reported, and the labels stay good. | + | N/A | N/A | -| `digests.damage.label-reported` | A blob that differs from its label is reported under a correct footer. | + | N/A | N/A | -| `digests.pin.match` | Pins that hold under both algorithms pass. | + | N/A | N/A | -| `digests.pin.sha256-mismatch` | A sha256 pin that does not hold fails the policy and withholds no level. | + | N/A | N/A | -| `digests.pin.blake3-mismatch` | A blake3 pin that does not hold fails the policy. | + | N/A | N/A | -| `digests.pin.one-of-two-wrong` | Two pins on one target must both hold, so checking one algorithm is not enough. | + | N/A | N/A | -| `digests.pin.invalid-hex` | A pin that is not 64 lowercase hex characters is an invalid policy. | + | N/A | N/A | -| `digests.pin.unknown-algorithm` | A pin under an algorithm other than sha256 and blake3 is an invalid policy. | + | N/A | N/A | -| `digests.pin.unknown-target` | A pin on a part that does not exist is an invalid policy. | + | N/A | N/A | -| `digests.pin.empty` | A pin that names no digest is an invalid policy, not a pass. | + | N/A | N/A | +| `digests.archive.dual` | The archive is reported under both algorithms, over the whole file, as ADR-015 pins them. | + | + | N/A | +| `digests.footer.not-the-file-hash` | The footer is the BLAKE3 of the body, reported apart from the file's BLAKE3. | + | + | N/A | +| `digests.verdict.names-the-footer` | A verdict addresses the holo by its archive fingerprint. | + | + | N/A | +| `digests.blob.guest` | The guest's content is reported under both algorithms, and its label is the BLAKE3. | + | + | N/A | +| `digests.blob.model` | The model document's content is reported under both algorithms. | + | + | N/A | +| `digests.blob.view` | The view's content is reported under both algorithms. | + | + | N/A | +| `digests.blob.capability-set` | The capability set's content is reported under both algorithms. | + | + | N/A | +| `digests.section.covers-its-table-bytes` | A section's digest covers exactly its table bytes, label included. | + | + | N/A | +| `digests.damage.footer-reported` | A wrong footer is reported, and the labels stay good. | + | + | N/A | +| `digests.damage.label-reported` | A blob that differs from its label is reported under a correct footer. | + | + | N/A | +| `digests.pin.match` | Pins that hold under both algorithms pass. | + | + | N/A | +| `digests.pin.sha256-mismatch` | A sha256 pin that does not hold fails the policy and withholds no level. | + | + | N/A | +| `digests.pin.blake3-mismatch` | A blake3 pin that does not hold fails the policy. | + | + | N/A | +| `digests.pin.one-of-two-wrong` | Two pins on one target must both hold, so checking one algorithm is not enough. | + | + | N/A | +| `digests.pin.invalid-hex` | A pin that is not 64 lowercase hex characters is an invalid policy. | + | + | N/A | +| `digests.pin.unknown-algorithm` | A pin under an algorithm other than sha256 and blake3 is an invalid policy. | + | + | N/A | +| `digests.pin.unknown-target` | A pin on a part that does not exist is an invalid policy. | + | + | N/A | +| `digests.pin.empty` | A pin that names no digest is an invalid policy, not a pass. | + | + | N/A | ### Dispatch through the guest | Check | Asks | JavaScript | Rust | Python | | --- | --- | --- | --- | --- | -| `dispatch.vectors.reference` | Every acceptance vector of the reference holo answers byte for byte, with the vectors given by this suite and not read from the holo. | + | N/A | N/A | -| `dispatch.acceptance.reference` | The runtime's own replay of the holo's vectors passes all of them. | + | N/A | N/A | -| `dispatch.fresh-instance.repeat` | The same request answers the same bytes every time, in one process. | + | N/A | N/A | -| `dispatch.fresh-instance.no-state-between-requests` | A failed request changes nothing about the next one. | + | N/A | N/A | -| `dispatch.limits.over-the-request-maximum` | A request above the model's maximum reaches the guest and is answered as malformed. | + | N/A | N/A | -| `dispatch.limits.at-the-allocation-maximum` | A request of exactly the guest allocation maximum is dispatched. | + | N/A | N/A | -| `dispatch.limits.over-the-allocation-maximum` | A request above the guest allocation maximum is refused before the guest runs. | + | N/A | N/A | +| `dispatch.vectors.reference` | Every acceptance vector of the reference holo answers byte for byte, with the vectors given by this suite and not read from the holo. | + | - | N/A | +| `dispatch.acceptance.reference` | The runtime's own replay of the holo's vectors passes all of them. | + | - | N/A | +| `dispatch.fresh-instance.repeat` | The same request answers the same bytes every time, in one process. | + | - | N/A | +| `dispatch.fresh-instance.no-state-between-requests` | A failed request changes nothing about the next one. | + | - | N/A | +| `dispatch.limits.over-the-request-maximum` | A request above the model's maximum reaches the guest and is answered as malformed. | + | - | N/A | +| `dispatch.limits.at-the-allocation-maximum` | A request of exactly the guest allocation maximum is dispatched. | + | - | N/A | +| `dispatch.limits.over-the-allocation-maximum` | A request above the guest allocation maximum is refused before the guest runs. | + | - | N/A | ### Typed errors | Check | Asks | JavaScript | Rust | Python | | --- | --- | --- | --- | --- | -| `errors.verify.passed-does-not-throw` | Asking for an error on failure raises nothing when the verdict passes. | + | N/A | N/A | -| `errors.verify.level-shortfall` | A level below the policy is a verification error that carries the whole verdict. | + | N/A | N/A | -| `errors.verify.integrity` | A failed integrity check is a verification error naming the check. | + | N/A | N/A | -| `errors.verify.pinned-digest-first` | A digest the caller pinned explains the failure before a missing level does. | + | N/A | N/A | -| `errors.world.contract` | A guest that differs from its world is a world mismatch, not a generic failure. | + | N/A | N/A | -| `errors.world.pin` | A world hash the caller pinned and the holo broke is a world mismatch. | + | N/A | N/A | -| `errors.capability.denied-import` | A guest import nothing links is a capability denial at load, naming the import. | + | N/A | N/A | -| `errors.capability.denied-resource` | A denied resource is a capability denial naming the kind, the resource and the set. | + | N/A | N/A | +| `errors.verify.passed-does-not-throw` | Asking for an error on failure raises nothing when the verdict passes. | + | + | N/A | +| `errors.verify.level-shortfall` | A level below the policy is a verification error that carries the whole verdict. | + | + | N/A | +| `errors.verify.integrity` | A failed integrity check is a verification error naming the check. | + | + | N/A | +| `errors.verify.pinned-digest-first` | A digest the caller pinned explains the failure before a missing level does. | + | + | N/A | +| `errors.world.contract` | A guest that differs from its world is a world mismatch, not a generic failure. | + | + | N/A | +| `errors.world.pin` | A world hash the caller pinned and the holo broke is a world mismatch. | + | + | N/A | +| `errors.capability.denied-import` | A guest import nothing links is a capability denial at load, naming the import. | + | - | N/A | +| `errors.capability.denied-resource` | A denied resource is a capability denial naming the kind, the resource and the set. | + | - | N/A | ### Load a holo | Check | Asks | JavaScript | Rust | Python | | --- | --- | --- | --- | --- | -| `load.reference.opens` | The reference holo opens, with its name, limits, vector count and identities verified. | + | N/A | N/A | -| `load.refuse.empty` | An empty file is refused. | + | N/A | N/A | -| `load.refuse.too-short` | A file shorter than a header and a footer is refused. | + | N/A | N/A | -| `load.refuse.bad-magic` | A file that does not start with HOLO is refused. | + | N/A | N/A | -| `load.refuse.bad-version` | A physical version other than 4 is refused. | + | N/A | N/A | -| `load.refuse.bad-flags` | Non-zero flags are refused. | + | N/A | N/A | -| `load.refuse.truncated-table` | A section table that overruns the file is refused. | + | N/A | N/A | -| `load.refuse.section-overrun` | A section that overruns the body is refused, even under a correct footer. | + | N/A | N/A | -| `load.refuse.unknown-kind` | An unknown section kind is refused, even under a correct footer. | + | N/A | N/A | -| `load.refuse.manifest-uri` | An application manifest with the wrong URI is refused. | + | N/A | N/A | -| `load.refuse.label-not-a-blob` | A directory that names a blob the archive does not hold is refused. | + | N/A | N/A | -| `load.refuse.undecodable-guest` | A guest that does not compile is refused. | + | N/A | N/A | -| `load.refuse.undecodable-view` | A HOLOVIEW bundle that does not decode is refused. | + | N/A | N/A | -| `load.refuse.undecodable-model` | A model document with no application is refused. | + | N/A | N/A | -| `load.damage.footer-refused` | A wrong footer is refused: an altered holo does not open by default. | + | N/A | N/A | -| `load.damage.guest-label-refused` | A guest whose bytes differ from its label is refused, even under a correct footer. | + | N/A | N/A | -| `load.damage.footer-allowed` | Asked to open an altered holo, a runtime opens it and reports its identities unverified. | + | N/A | N/A | -| `load.damage.guest-label-allowed` | Asked to open a holo whose guest differs from its label, a runtime opens it and reports it unverified. | + | N/A | N/A | -| `load.attestation.tolerated` | An attestation section as the last row does not stop a load or change the identities. | + | N/A | N/A | -| `load.attestation.not-last` | An attestation section that is not the last row is refused. | + | N/A | N/A | -| `load.attestation.duplicate` | Two attestation sections are refused. | + | N/A | N/A | +| `load.reference.opens` | The reference holo opens, with its name, limits, vector count and identities verified. | + | - | N/A | +| `load.refuse.empty` | An empty file is refused. | + | - | N/A | +| `load.refuse.too-short` | A file shorter than a header and a footer is refused. | + | - | N/A | +| `load.refuse.bad-magic` | A file that does not start with HOLO is refused. | + | - | N/A | +| `load.refuse.bad-version` | A physical version other than 4 is refused. | + | - | N/A | +| `load.refuse.bad-flags` | Non-zero flags are refused. | + | - | N/A | +| `load.refuse.truncated-table` | A section table that overruns the file is refused. | + | - | N/A | +| `load.refuse.section-overrun` | A section that overruns the body is refused, even under a correct footer. | + | - | N/A | +| `load.refuse.unknown-kind` | An unknown section kind is refused, even under a correct footer. | + | - | N/A | +| `load.refuse.manifest-uri` | An application manifest with the wrong URI is refused. | + | - | N/A | +| `load.refuse.label-not-a-blob` | A directory that names a blob the archive does not hold is refused. | + | - | N/A | +| `load.refuse.undecodable-guest` | A guest that does not compile is refused. | + | - | N/A | +| `load.refuse.undecodable-view` | A HOLOVIEW bundle that does not decode is refused. | + | - | N/A | +| `load.refuse.undecodable-model` | A model document with no application is refused. | + | - | N/A | +| `load.damage.footer-refused` | A wrong footer is refused: an altered holo does not open by default. | + | - | N/A | +| `load.damage.guest-label-refused` | A guest whose bytes differ from its label is refused, even under a correct footer. | + | - | N/A | +| `load.damage.footer-allowed` | Asked to open an altered holo, a runtime opens it and reports its identities unverified. | + | - | N/A | +| `load.damage.guest-label-allowed` | Asked to open a holo whose guest differs from its label, a runtime opens it and reports it unverified. | + | - | N/A | +| `load.attestation.tolerated` | An attestation section as the last row does not stop a load or change the identities. | + | - | N/A | +| `load.attestation.not-last` | An attestation section that is not the last row is refused. | + | - | N/A | +| `load.attestation.duplicate` | Two attestation sections are refused. | + | - | N/A | ### Histories and replay | Check | Asks | JavaScript | Rust | Python | | --- | --- | --- | --- | --- | -| `replay.history.unchanged` | Replaying a recorded history against the same holo finds no divergence. | + | N/A | N/A | -| `replay.history.divergence` | Replaying against a changed model is a determinism violation (determinism_violation). | + | N/A | N/A | -| `replay.history.malformed` | A history that does not read is a replay error (replay_failed), not a divergence. | + | N/A | N/A | -| `replay.recorder.round-trip` | Dispatches recorded into prism/history/1 replay unchanged, refusals included. | + | N/A | N/A | -| `replay.statement.written` | A replay writes a prism/replay/v1 statement that names the guest and every history by dual digest. | + | N/A | N/A | +| `replay.history.unchanged` | Replaying a recorded history against the same holo finds no divergence. | + | - | N/A | +| `replay.history.divergence` | Replaying against a changed model is a determinism violation (determinism_violation). | + | - | N/A | +| `replay.history.malformed` | A history that does not read is a replay error (replay_failed), not a divergence. | + | - | N/A | +| `replay.recorder.round-trip` | Dispatches recorded into prism/history/1 replay unchanged, refusals included. | + | - | N/A | +| `replay.statement.written` | A replay writes a prism/replay/v1 statement that names the guest and every history by dual digest. | + | - | N/A | ### Verify a holo | Check | Asks | JavaScript | Rust | Python | | --- | --- | --- | --- | --- | -| `verify.reference.default-policy` | The default policy fails the reference holo at P0, and names every missing statement. | + | N/A | N/A | -| `verify.reference.minimum-p0` | A P0 policy accepts the reference holo. | + | N/A | N/A | -| `verify.level.not-raised-by-policy` | A policy that asks for P3 does not raise the level. | + | N/A | N/A | -| `verify.level.unsigned-claim-not-believed` | An unsigned statement that claims P3 never raises the level: the holo is P0, or it gets no verdict. | + | N/A | N/A | -| `verify.policy.name-echoed` | The verdict names the policy it was judged against. | + | N/A | N/A | -| `verify.damage.footer` | A wrong footer is a failed integrity check that withholds P1. | + | N/A | N/A | -| `verify.damage.guest-label` | A guest that differs from its label fails integrity even under a correct footer. | + | N/A | N/A | -| `verify.damage.label` | A forged blob label is a table the Wire codec refuses: no verdict. | + | N/A | N/A | -| `verify.damage.model-document` | A damaged model document fails integrity and the document check. | + | N/A | N/A | -| `verify.damage.manifest` | A damaged application manifest is not the Wire template, which the codec refuses: no verdict. | + | N/A | N/A | -| `verify.damage.p0-has-no-requirement` | P0 asks nothing of a holo, so damage is reported and the P0 policy still passes. | + | N/A | N/A | -| `verify.no-verdict.empty` | An empty file gets no verdict. | + | N/A | N/A | -| `verify.no-verdict.bad-magic` | A file that is not a holo gets no verdict. | + | N/A | N/A | -| `verify.no-verdict.bad-version` | An unknown physical version gets no verdict. | + | N/A | N/A | -| `verify.no-verdict.bad-flags` | Non-zero flags get no verdict. | + | N/A | N/A | -| `verify.no-verdict.truncated-table` | A truncated table gets no verdict. | + | N/A | N/A | -| `verify.no-verdict.section-overrun` | A section that overruns the body gets no verdict. | + | N/A | N/A | -| `verify.no-verdict.unknown-kind` | A section kind the Wire codec does not put in that row gets no verdict. | + | N/A | N/A | -| `verify.policy.unknown-level` | A minimum level that does not exist is an invalid policy, not a verdict. | + | N/A | N/A | -| `verify.policy.unknown-member` | A policy member nobody defined is an invalid policy, not ignored. | + | N/A | N/A | -| `verify.policy.statements-refused` | A policy cannot carry statements or claim their signature was checked: a level comes from the holo, never from an option. | + | N/A | N/A | -| `verify.env.sets-minimum` | PRISM_MINIMUM_LEVEL sets the minimum when the call names none. | + | N/A | N/A | -| `verify.env.call-wins` | A minimum named by the call replaces PRISM_MINIMUM_LEVEL. | + | N/A | N/A | -| `verify.env.invalid` | A PRISM_MINIMUM_LEVEL that names no level is an invalid policy. | + | N/A | N/A | +| `verify.reference.default-policy` | The default policy fails the reference holo at P0, and names every missing statement. | + | + | N/A | +| `verify.reference.minimum-p0` | A P0 policy accepts the reference holo. | + | + | N/A | +| `verify.level.not-raised-by-policy` | A policy that asks for P3 does not raise the level. | + | + | N/A | +| `verify.level.unsigned-claim-not-believed` | An unsigned statement that claims P3 never raises the level: the holo is P0, or it gets no verdict. | + | + | N/A | +| `verify.policy.name-echoed` | The verdict names the policy it was judged against. | + | + | N/A | +| `verify.damage.footer` | A wrong footer is a failed integrity check that withholds P1. | + | + | N/A | +| `verify.damage.guest-label` | A guest that differs from its label fails integrity even under a correct footer. | + | + | N/A | +| `verify.damage.label` | A forged blob label is a table the Wire codec refuses: no verdict. | + | + | N/A | +| `verify.damage.model-document` | A damaged model document fails integrity and the document check. | + | + | N/A | +| `verify.damage.manifest` | A damaged application manifest is not the Wire template, which the codec refuses: no verdict. | + | + | N/A | +| `verify.damage.p0-has-no-requirement` | P0 asks nothing of a holo, so damage is reported and the P0 policy still passes. | + | + | N/A | +| `verify.no-verdict.empty` | An empty file gets no verdict. | + | + | N/A | +| `verify.no-verdict.bad-magic` | A file that is not a holo gets no verdict. | + | + | N/A | +| `verify.no-verdict.bad-version` | An unknown physical version gets no verdict. | + | + | N/A | +| `verify.no-verdict.bad-flags` | Non-zero flags get no verdict. | + | + | N/A | +| `verify.no-verdict.truncated-table` | A truncated table gets no verdict. | + | + | N/A | +| `verify.no-verdict.section-overrun` | A section that overruns the body gets no verdict. | + | + | N/A | +| `verify.no-verdict.unknown-kind` | A section kind the Wire codec does not put in that row gets no verdict. | + | + | N/A | +| `verify.policy.unknown-level` | A minimum level that does not exist is an invalid policy, not a verdict. | + | + | N/A | +| `verify.policy.unknown-member` | A policy member nobody defined is an invalid policy, not ignored. | + | + | N/A | +| `verify.policy.statements-refused` | A policy cannot carry statements or claim their signature was checked: a level comes from the holo, never from an option. | + | + | N/A | +| `verify.env.sets-minimum` | PRISM_MINIMUM_LEVEL sets the minimum when the call names none. | + | + | N/A | +| `verify.env.call-wins` | A minimum named by the call replaces PRISM_MINIMUM_LEVEL. | + | + | N/A | +| `verify.env.invalid` | A PRISM_MINIMUM_LEVEL that names no level is an invalid policy. | + | + | N/A | ### The world contract | Check | Asks | JavaScript | Rust | Python | | --- | --- | --- | --- | --- | -| `world.reference.inspected` | Inspection names the world, its digests and its interface, and says the guest conforms. | + | N/A | N/A | -| `world.reference.loaded` | A load reports the world within the grant and pure, with no capability file. | + | N/A | N/A | -| `world.mismatch.extra-import` | A guest with an import the world does not declare fails the contract and withholds P1. | + | N/A | N/A | -| `world.mismatch.extra-export` | A guest with an export the world does not declare fails the contract. | + | N/A | N/A | -| `world.mismatch.renamed-export` | A guest missing an export the world declares fails the contract. | + | N/A | N/A | -| `world.mismatch.changed-signature` | A guest export with another signature fails the contract. | + | N/A | N/A | -| `world.mismatch.changed-kind` | A guest export of another kind fails the contract. | + | N/A | N/A | -| `world.mismatch.inspected` | Inspection reports that a changed guest does not conform, with every fingerprint correct. | + | N/A | N/A | -| `world.load.refuses-wrong-exports` | A load refuses a guest whose export names differ from the contract. | + | N/A | N/A | -| `world.pin.match` | A world pin that holds passes. | + | N/A | N/A | -| `world.pin.hash-mismatch` | A world hash that differs fails the policy and withholds no level. | + | N/A | N/A | -| `world.pin.contract-mismatch` | A pin on another contract fails the policy. | + | N/A | N/A | -| `world.pin.null` | A null pin fails the policy instead of passing silently. | + | N/A | N/A | -| `world.pin.invalid` | A world pin that is not hex is an invalid policy. | + | N/A | N/A | -| `world.effects.pure-passes` | A pure world passes a policy that allows no effects. | + | N/A | N/A | -| `world.effects.invalid` | An effect nobody defined is an invalid policy. | + | N/A | N/A | +| `world.reference.inspected` | Inspection names the world, its digests and its interface, and says the guest conforms. | + | + | N/A | +| `world.reference.loaded` | A load reports the world within the grant and pure, with no capability file. | + | - | N/A | +| `world.mismatch.extra-import` | A guest with an import the world does not declare fails the contract and withholds P1. | + | + | N/A | +| `world.mismatch.extra-export` | A guest with an export the world does not declare fails the contract. | + | + | N/A | +| `world.mismatch.renamed-export` | A guest missing an export the world declares fails the contract. | + | + | N/A | +| `world.mismatch.changed-signature` | A guest export with another signature fails the contract. | + | + | N/A | +| `world.mismatch.changed-kind` | A guest export of another kind fails the contract. | + | + | N/A | +| `world.mismatch.inspected` | Inspection reports that a changed guest does not conform, with every fingerprint correct. | + | + | N/A | +| `world.load.refuses-wrong-exports` | A load refuses a guest whose export names differ from the contract. | + | - | N/A | +| `world.pin.match` | A world pin that holds passes. | + | + | N/A | +| `world.pin.hash-mismatch` | A world hash that differs fails the policy and withholds no level. | + | + | N/A | +| `world.pin.contract-mismatch` | A pin on another contract fails the policy. | + | + | N/A | +| `world.pin.null` | A null pin fails the policy instead of passing silently. | + | + | N/A | +| `world.pin.invalid` | A world pin that is not hex is an invalid policy. | + | + | N/A | +| `world.effects.pure-passes` | A pure world passes a policy that allows no effects. | + | + | N/A | +| `world.effects.invalid` | An effect nobody defined is an invalid policy. | + | + | N/A | ## Expected failures -None. +| Runtime | Check | Why | +| --- | --- | --- | +| Rust | `auth.login.docker-config-entry` | The Rust runtime has no auth operation yet (#298). | +| Rust | `auth.login.keeps-the-config` | The Rust runtime has no auth operation yet (#298). | +| Rust | `auth.login.docker-hub-by-default` | The Rust runtime has no auth operation yet (#298). | +| Rust | `auth.login.username-with-colon` | The Rust runtime has no auth operation yet (#298). | +| Rust | `auth.login.registry-with-a-scheme` | The Rust runtime has no auth operation yet (#298). | +| Rust | `auth.login.config-not-json` | The Rust runtime has no auth operation yet (#298). | +| Rust | `auth.login.helper-not-installed` | The Rust runtime has no auth operation yet (#298). | +| Rust | `auth.logout.removes-every-spelling` | The Rust runtime has no auth operation yet (#298). | +| Rust | `auth.logout.nothing-there` | The Rust runtime has no auth operation yet (#298). | +| Rust | `auth.logout.names-the-ambient-token` | The Rust runtime has no auth operation yet (#298). | +| Rust | `auth.inspect.password` | The Rust runtime has no auth operation yet (#298). | +| Rust | `auth.inspect.identity-token` | The Rust runtime has no auth operation yet (#298). | +| Rust | `auth.inspect.nothing-there` | The Rust runtime has no auth operation yet (#298). | +| Rust | `auth.stores.helper-for-a-registry` | The Rust runtime has no auth operation yet (#298). | +| Rust | `auth.identities.unreadable-key` | The Rust runtime has no auth operation yet (#298). | +| Rust | `auth.identities.empty-token` | The Rust runtime has no auth operation yet (#298). | +| Rust | `capabilities.none.denies-everything` | The Rust runtime has no capabilities operation yet (#298). | +| Rust | `capabilities.none.load-grants-nothing` | The Rust runtime has no load operation yet (#298). | +| Rust | `capabilities.empty.default-set-denies` | The Rust runtime has no capabilities operation yet (#298). | +| Rust | `capabilities.empty.deny-only-denies` | The Rust runtime has no capabilities operation yet (#298). | +| Rust | `capabilities.allow.exact-names` | The Rust runtime has no capabilities operation yet (#298). | +| Rust | `capabilities.outbound.exact-match` | The Rust runtime has no capabilities operation yet (#298). | +| Rust | `capabilities.outbound.wildcards` | The Rust runtime has no capabilities operation yet (#298). | +| Rust | `capabilities.deny.wins-over-allow` | The Rust runtime has no capabilities operation yet (#298). | +| Rust | `capabilities.deny.same-entry-on-both-lists` | The Rust runtime has no capabilities operation yet (#298). | +| Rust | `capabilities.set.default-applies` | The Rust runtime has no capabilities operation yet (#298). | +| Rust | `capabilities.set.named-applies` | The Rust runtime has no capabilities operation yet (#298). | +| Rust | `capabilities.set.load-names-the-set` | The Rust runtime has no load operation yet (#298). | +| Rust | `capabilities.set.missing-is-an-error` | The Rust runtime has no load operation yet (#298). | +| Rust | `capabilities.set.named-without-a-file` | The Rust runtime has no load operation yet (#298). | +| Rust | `capabilities.invalid.unknown-member` | The Rust runtime has no capabilities operation yet (#298). | +| Rust | `capabilities.invalid.no-default-set` | The Rust runtime has no capabilities operation yet (#298). | +| Rust | `capabilities.invalid.wrong-schema` | The Rust runtime has no capabilities operation yet (#298). | +| Rust | `capabilities.invalid.malformed-entry` | The Rust runtime has no capabilities operation yet (#298). | +| Rust | `capabilities.invalid.repeated-entry` | The Rust runtime has no capabilities operation yet (#298). | +| Rust | `capabilities.invalid.not-json` | The Rust runtime has no capabilities operation yet (#298). | +| Rust | `capabilities.import.denied-with-no-file` | The Rust runtime has no load operation yet (#298). | +| Rust | `capabilities.import.denied-under-a-full-grant` | The Rust runtime has no load operation yet (#298). | +| Rust | `capabilities.kind.unknown` | The Rust runtime has no capabilities operation yet (#298). | +| Rust | `dispatch.vectors.reference` | The Rust runtime has no dispatch operation yet (#298). | +| Rust | `dispatch.acceptance.reference` | The Rust runtime has no acceptance operation yet (#298). | +| Rust | `dispatch.fresh-instance.repeat` | The Rust runtime has no dispatch operation yet (#298). | +| Rust | `dispatch.fresh-instance.no-state-between-requests` | The Rust runtime has no dispatch operation yet (#298). | +| Rust | `dispatch.limits.over-the-request-maximum` | The Rust runtime has no dispatch operation yet (#298). | +| Rust | `dispatch.limits.at-the-allocation-maximum` | The Rust runtime has no dispatch operation yet (#298). | +| Rust | `dispatch.limits.over-the-allocation-maximum` | The Rust runtime has no dispatch operation yet (#298). | +| Rust | `errors.capability.denied-import` | The Rust runtime has no load operation yet (#298). | +| Rust | `errors.capability.denied-resource` | The Rust runtime has no capabilities operation yet (#298). | +| Rust | `load.reference.opens` | The Rust runtime has no load operation yet (#298). | +| Rust | `load.refuse.empty` | The Rust runtime has no load operation yet (#298). | +| Rust | `load.refuse.too-short` | The Rust runtime has no load operation yet (#298). | +| Rust | `load.refuse.bad-magic` | The Rust runtime has no load operation yet (#298). | +| Rust | `load.refuse.bad-version` | The Rust runtime has no load operation yet (#298). | +| Rust | `load.refuse.bad-flags` | The Rust runtime has no load operation yet (#298). | +| Rust | `load.refuse.truncated-table` | The Rust runtime has no load operation yet (#298). | +| Rust | `load.refuse.section-overrun` | The Rust runtime has no load operation yet (#298). | +| Rust | `load.refuse.unknown-kind` | The Rust runtime has no load operation yet (#298). | +| Rust | `load.refuse.manifest-uri` | The Rust runtime has no load operation yet (#298). | +| Rust | `load.refuse.label-not-a-blob` | The Rust runtime has no load operation yet (#298). | +| Rust | `load.refuse.undecodable-guest` | The Rust runtime has no load operation yet (#298). | +| Rust | `load.refuse.undecodable-view` | The Rust runtime has no load operation yet (#298). | +| Rust | `load.refuse.undecodable-model` | The Rust runtime has no load operation yet (#298). | +| Rust | `load.damage.footer-refused` | The Rust runtime has no load operation yet (#298). | +| Rust | `load.damage.guest-label-refused` | The Rust runtime has no load operation yet (#298). | +| Rust | `load.damage.footer-allowed` | The Rust runtime has no load operation yet (#298). | +| Rust | `load.damage.guest-label-allowed` | The Rust runtime has no load operation yet (#298). | +| Rust | `load.attestation.tolerated` | The Rust runtime has no load operation yet (#298). | +| Rust | `load.attestation.not-last` | The Rust runtime has no load operation yet (#298). | +| Rust | `load.attestation.duplicate` | The Rust runtime has no load operation yet (#298). | +| Rust | `replay.history.unchanged` | The Rust runtime has no replay operation yet (#298). | +| Rust | `replay.history.divergence` | The Rust runtime has no replay operation yet (#298). | +| Rust | `replay.history.malformed` | The Rust runtime has no replay operation yet (#298). | +| Rust | `replay.recorder.round-trip` | The Rust runtime has no replay operation yet (#298). | +| Rust | `replay.statement.written` | The Rust runtime has no replay operation yet (#298). | +| Rust | `world.reference.loaded` | The Rust runtime has no load operation yet (#298). | +| Rust | `world.load.refuses-wrong-exports` | The Rust runtime has no load operation yet (#298). | diff --git a/model/modules.toml b/model/modules.toml index 4d550716c..85546f977 100644 --- a/model/modules.toml +++ b/model/modules.toml @@ -320,6 +320,10 @@ module = "verify" path = "sdk/npm/prism-code/src/attest-cli.mjs" module = "images" +[[owner]] +path = "sdk/npm/prism-code/src/attest-write.mjs" +module = "images" + [[owner]] path = "sdk/npm/prism-code/src/attest.mjs" module = "verify" @@ -540,6 +544,10 @@ module = "client" path = "sdk/npm/prism-code/src/sha256.mjs" module = "verify" +[[owner]] +path = "sdk/npm/prism-code/src/signing.mjs" +module = "auth" + [[owner]] path = "sdk/npm/prism-code/src/studio/" module = "client" @@ -568,6 +576,10 @@ module = "errors" path = "sdk/npm/prism-code/src/vendor/verify.mjs" module = "verify" +[[owner]] +path = "sdk/npm/prism-code/src/verify-closure.mjs" +module = "verify" + [[owner]] path = "sdk/npm/prism-code/src/verify.mjs" module = "verify" @@ -666,11 +678,6 @@ from = "crates/prismpm/src/sdk.rs" to = "crates/prismpm/src/verification.rs" cut = "Process helpers move to verify" -[[pending]] -from = "sdk/npm/prism-code/src/auth.mjs" -to = "sdk/npm/prism-code/src/attest.mjs" -cut = "Signing parts of attest move to auth" - # One member per line, so that removing one merges cleanly. [legacy_cycle] members = [ diff --git a/sdk/npm/conformance/runtimes.json b/sdk/npm/conformance/runtimes.json index 9b53bfca7..5a373ff99 100644 --- a/sdk/npm/conformance/runtimes.json +++ b/sdk/npm/conformance/runtimes.json @@ -7,8 +7,8 @@ }, "rust": { "title": "Rust", - "command": null, - "declaration": null + "command": ["target/debug/prism-conformance-shim"], + "declaration": "crates/conformance/runtime/declaration.json" }, "python": { "title": "Python", diff --git a/sdk/npm/conformance/test/matrix.test.mjs b/sdk/npm/conformance/test/matrix.test.mjs index bfaa4a72d..aa2eb69d1 100644 --- a/sdk/npm/conformance/test/matrix.test.mjs +++ b/sdk/npm/conformance/test/matrix.test.mjs @@ -2,7 +2,7 @@ import assert from 'node:assert/strict'; import { test } from 'node:test'; import { spawnSync } from 'node:child_process'; -import { mkdtempSync, readFileSync, writeFileSync } from 'node:fs'; +import { existsSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { fileURLToPath } from 'node:url'; @@ -10,6 +10,11 @@ import { allChecks, loadScenarios, renderMatrix, sameMatrix, RESULTS_SCHEMA } fr const BIN = fileURLToPath(new URL('../bin/prism-conformance.mjs', import.meta.url)); const COMPLIANCE = fileURLToPath(new URL('../../../../COMPLIANCE.md', import.meta.url)); +const JS_SHIM = fileURLToPath(new URL('../../prism-code/conformance/shim.mjs', import.meta.url)); +// runtimes.json registers the Rust shim at this path. The suite job in npm-conformance.yml builds it before these tests; +// where it is not built, a test that runs every registered runtime cannot run, and says why. +const RUST_SHIM = fileURLToPath(new URL('../../../../target/debug/prism-conformance-shim', import.meta.url)); +const everyRuntime = existsSync(RUST_SHIM) ? {} : { skip: 'the Rust shim is not built: cargo build -p repo-conformance --bin prism-conformance-shim' }; const features = [ { @@ -85,7 +90,7 @@ test('line endings do not make the file stale, and any other difference does', ( const cli = (...args) => spawnSync(process.execPath, [BIN, ...args], { encoding: 'utf8' }); -test('the committed COMPLIANCE.md is what the suite generates today, and it names all three runtimes', () => { +test('the committed COMPLIANCE.md is what the suite generates today, and it names all three runtimes', everyRuntime, () => { const check = cli('matrix', '--check'); assert.equal(check.status, 0, check.stdout + check.stderr); const text = readFileSync(COMPLIANCE, 'utf8').replace(/\r\n/g, '\n'); @@ -94,7 +99,7 @@ test('the committed COMPLIANCE.md is what the suite generates today, and it name for (const check of allChecks(loadScenarios())) assert.ok(text.includes(`\`${check.id}\``), check.id); }); -test('a hand edit of COMPLIANCE.md is stale, says how to fix it, and --write repairs it', () => { +test('a hand edit of COMPLIANCE.md is stale, says how to fix it, and --write repairs it', everyRuntime, () => { const dir = mkdtempSync(join(tmpdir(), 'prism-conformance-matrix-')); const output = join(dir, 'COMPLIANCE.md'); writeFileSync(output, readFileSync(COMPLIANCE, 'utf8').replace('| JavaScript |', '| JS, by hand |')); @@ -106,12 +111,16 @@ test('a hand edit of COMPLIANCE.md is stale, says how to fix it, and --write rep assert.equal(cli('matrix', '--check', '--output', output).status, 0); }); -test('--results reads saved runs, and a registered runtime with no results is an error, not a blank column', () => { +test('--results reads saved runs, and a registered runtime with no results is an error, not a blank column', everyRuntime, () => { const dir = mkdtempSync(join(tmpdir(), 'prism-conformance-results-')); const missing = cli('matrix', '--results', dir); assert.equal(missing.status, 2); assert.match(missing.stderr, /js has a shim .* a registered runtime cannot go unmeasured/); assert.equal(cli('run', '--runtime', 'js', '--out', join(dir, 'js.json')).status, 0); + const rustMissing = cli('matrix', '--results', dir); + assert.equal(rustMissing.status, 2); + assert.match(rustMissing.stderr, /rust has a shim .* a registered runtime cannot go unmeasured/); + assert.equal(cli('run', '--runtime', 'rust', '--out', join(dir, 'rust.json')).status, 0); const check = cli('matrix', '--check', '--results', dir); assert.equal(check.status, 0, check.stderr); assert.equal(cli('matrix', '--write', '--check').status, 64); @@ -120,6 +129,8 @@ test('--results reads saved runs, and a registered runtime with no results is an test('partial results cannot reach the matrix through the CLI', () => { const dir = mkdtempSync(join(tmpdir(), 'prism-conformance-partial-')); assert.equal(cli('run', '--runtime', 'js', '--only', 'load.refuse.empty', '--out', join(dir, 'js.json')).status, 0); + // Any shim gives a partial run; the JavaScript one stands in for Rust here, so this needs no build. + assert.equal(cli('run', '--runtime', 'rust', '--only', 'load.refuse.empty', '--out', join(dir, 'rust.json'), '--', process.execPath, JS_SHIM).status, 0); const refused = cli('matrix', '--results', dir); assert.equal(refused.status, 2); assert.match(refused.stderr, /partial run/); diff --git a/sdk/npm/conformance/test/run.test.mjs b/sdk/npm/conformance/test/run.test.mjs index 1f5555985..12436af23 100644 --- a/sdk/npm/conformance/test/run.test.mjs +++ b/sdk/npm/conformance/test/run.test.mjs @@ -206,7 +206,7 @@ test('the CLI: exit 0 passed, 1 failed, 2 cannot run, 64 bad usage, and --out wr assert.equal(cli('run', '--runtime', 'other', '--', process.execPath, FAKE, 'wrong-contract').status, 2); assert.equal(cli('run', '--runtime', 'nobody').status, 64); - assert.equal(cli('run', '--runtime', 'rust').status, 64, 'rust has no shim yet'); + assert.equal(cli('run', '--runtime', 'python').status, 64, 'python has no shim yet'); assert.equal(cli('run').status, 64); assert.equal(cli('nonsense').status, 64); assert.equal(cli('--unknown').status, 64); diff --git a/sdk/npm/prism-code/CHANGELOG.md b/sdk/npm/prism-code/CHANGELOG.md index 765af9b88..e288d8a8b 100644 --- a/sdk/npm/prism-code/CHANGELOG.md +++ b/sdk/npm/prism-code/CHANGELOG.md @@ -15,6 +15,7 @@ To move to 1.0, read the [migration guide](../../../docs/site/migration/to-1-0.m - `holo.verify()`, `holo.inspect()` and `prism-code check` give no verdict (`archive.table`) on any archive the Wire codec refuses (SPEC section 3), as the Rust verifier does: content blobs out of label order, an application manifest that is not the Wire template, a manifest reference that names no blob, a section kind or extension name out of place, or a row count other than eight (nine with the attestation row last). Such an archive used to get a failing verdict. ### Features Added +- Trust in `verify`, signing in `auth` (#449, #447, experimental). `prism.verify.pullClosure` judges what a pull fetched, steps 4 to 8 of the push and pull design: the claims about the bytes, the attestation subjects, the verdict under the policy and, with a signer, a passing bundle; `images.pull` and `experimental_pull` now get their answer only from it, with the same checks and errors as before. Every signature goes through an `auth` identity: `auth.identities.from(options)` turns the flat signer options `attest`, `signStatements` and `push` take into one, and the signing code moves out of `attest.mjs` into `auth`'s own `signing.mjs`. `experimental_attest` and `experimental_signStatements` are unchanged in `prism-code/node`. A keyless failure before any token was read keeps its `cause` through `auth`, as it did through `attest`. - `prism-code attest --unsigned` and `--statement ` (#582) sign what `prismpm` wrote: `--unsigned` signs each unsigned statement in the holo, such as the provenance `prismpm build` writes, in its place and over the same payload bytes; `--statement` signs a whole statement, such as the `proof-statement.json` `prismpm verify` writes, after checking that every subject is a content blob of the holo. Keyless on a GitHub Actions runner, or with `--key`. `experimental_signStatements` is the same from `prism-code/node`. A holo built on Actions and signed this way reaches P2 under a signer policy that names the workflow. - `prism-code build --remote github` trusts the repository's own workflows as the signer when it checks the holo that comes back (#582). The verdict counts a statement signed into the holo only when a workflow of that repository signed it through GitHub's OIDC issuer, so a build that signs its proof statement keylessly reaches P2. Before, the check named no signer and every remote build was P0. `repositorySigner(repo)` is that signer policy. - `prism-code generate --lang python` (#289): a package from the same code model, importing only the standard library (Python 3.9 and later), typed so that `mypy --strict` passes and laid out as `black` lays it out at 100 columns. `world.py` holds `WORLD`, `EXPORTS`, the protocol `Guest` and `dispatch`; the application's module holds the typed client (`Calculator`, `Operation`, `CalculatorErrorCode` with the model's messages, `CalculatorError`, `ResponseError`, `MODEL`), or a client over bytes. The test replays every typed acceptance vector, as the real guest answers it, through the Python client with `python3`. `--lang` now takes `js`, `rust` and `python`. diff --git a/sdk/npm/prism-code/src/attest-cli.mjs b/sdk/npm/prism-code/src/attest-cli.mjs index 01be12945..610f8e06f 100644 --- a/sdk/npm/prism-code/src/attest-cli.mjs +++ b/sdk/npm/prism-code/src/attest-cli.mjs @@ -8,7 +8,8 @@ import { readFile, writeFile, rename, rm } from 'node:fs/promises'; import { resolve } from 'node:path'; import { PrismCodeError, VerificationError } from './errors.mjs'; import { canonicalJson } from './archive.mjs'; -import { experimental_attest, experimental_signStatements, experimental_verifyAttestations } from './attest.mjs'; +import { experimental_verifyAttestations } from './attest.mjs'; +import { experimental_attest, experimental_signStatements } from './attest-write.mjs'; const present = (options, name) => typeof options[name] === 'string' && options[name] !== ''; const path = (options, name) => (present(options, name) ? resolve(options[name]) : undefined); diff --git a/sdk/npm/prism-code/src/attest-write.mjs b/sdk/npm/prism-code/src/attest-write.mjs new file mode 100644 index 000000000..096507ea6 --- /dev/null +++ b/sdk/npm/prism-code/src/attest-write.mjs @@ -0,0 +1,181 @@ +/** + * `attest` and `signStatements`: write signed in-toto statements into a holo's + * attestation section (issues #272 and #582, design in + * `docs/proposals/272-attest-verify.md`). + * + * This is the writing half of attestation, and it belongs to `images`, which + * may use both modules it needs and nothing more: the statement is built over + * the holo's blobs, and signed by an `auth` identity (`auth.identities.from`). + * Checking a statement again is `verify` (`attest.mjs`); signing keys never + * leave `auth`. Node only. + * + * Experimental until the v0.6 freeze, hence the `experimental_` prefix. + */ +import { createHash } from 'node:crypto'; +import { SigningError, SubjectMismatchError } from './errors.mjs'; +import { parseArchive, resolveArchive, canonicalJson } from './archive.mjs'; +import { blake3Hex } from './blake3.mjs'; +import { readAttestations, appendAttestations, stripAttestations, STATEMENT_TYPE } from './attestations.mjs'; +import { holoBytes } from './attest.mjs'; +import { auth } from './auth.mjs'; + +const ROLES = ['guest', 'view', 'model', 'capabilities']; +const encoder = new TextEncoder(); +const URI = /^[A-Za-z][A-Za-z0-9+.-]*:\S+$/; + +const sha256Hex = (bytes) => createHash('sha256').update(bytes).digest('hex'); + +function isObject(value) { + return value !== null && typeof value === 'object' && !Array.isArray(value); +} + +/** The signer the options name. Every signature goes through `auth`, which keeps the key or token out of every error. */ +const signerOf = (options) => auth.identities.from(options); + +function predicateOf(predicate) { + let value = predicate; + if (value instanceof Uint8Array || typeof value === 'string') { + try { + value = JSON.parse(typeof value === 'string' ? value : new TextDecoder('utf-8', { fatal: true }).decode(value)); + } catch (cause) { + throw new SigningError(`the predicate is not JSON: ${cause.message}`, { check: 'sign.predicate', cause }); + } + } + if (value === undefined || value === null) throw new SigningError('a predicate is required', { check: 'sign.predicate' }); + return value; +} + +/** + * The subjects of a statement, as `{ name, digest: { sha256, blake3 } }` over + * content blobs of the holo. A request is a role (`guest`, `view`, `model`, + * `capabilities`), a blob label (`blake3:`), or `name=`. + * Without a request the subject is the guest, which is what the proof and + * provenance predicates describe (#266, #268). + */ +export function resolveSubjects(parsed, requests = []) { + const wanted = requests.length === 0 ? ['guest'] : requests; + let roles = null; + const subjects = wanted.map((request) => { + if (typeof request !== 'string' || request === '') throw new SigningError('a subject is a role or a blob label', { check: 'sign.subject' }); + const eq = request.indexOf('='); + const name = eq > 0 ? request.slice(0, eq) : null; + const target = eq > 0 ? request.slice(eq + 1) : request; + let label; + if (ROLES.includes(target)) { + roles ??= resolveArchive(parsed).identities; + label = roles[`${target}Kappa`]; + } else if (/^blake3:[0-9a-f]{64}$/.test(target)) label = target; + else throw new SigningError(`subject ${JSON.stringify(request)} is neither a role (${ROLES.join(', ')}) nor a blake3 label`, { check: 'sign.subject' }); + const blob = parsed.blobs.find((b) => b.label === label); + if (!blob) throw new SigningError(`subject ${label} is not a content blob of this holo`, { check: 'sign.subject' }); + return { name: name ?? (ROLES.includes(target) ? target : label), digest: { sha256: sha256Hex(blob.content), blake3: blake3Hex(blob.content) } }; + }); + if (new Set(subjects.map((s) => s.name)).size !== subjects.length) throw new SigningError('two subjects have the same name', { check: 'sign.subject' }); + return subjects; +} + +/** The in-toto Statement v1 bytes that get signed. */ +export function buildStatement(parsed, { type, predicate, subjects }) { + if (typeof type !== 'string' || !URI.test(type)) throw new SigningError('the predicate type must be a URI, such as https://slsa.dev/provenance/v1', { check: 'sign.predicate' }); + const statement = { _type: STATEMENT_TYPE, subject: resolveSubjects(parsed, subjects), predicateType: type, predicate: predicateOf(predicate) }; + return { statement, bytes: encoder.encode(JSON.stringify(statement)) }; +} + +/** + * Sign a statement about a holo and return the holo with the bundle appended to + * its attestation section. The input holo is not modified. + * + * With `key`, the statement is signed by that private key (PEM or KeyObject) + * and no network is used. Without it the signing is keyless: an OIDC identity + * token (`identityToken`, else GitHub Actions or `SIGSTORE_ID_TOKEN`) is + * exchanged for a Fulcio certificate, and the Rekor v2 entry and RFC 3161 + * timestamp of the signing configuration (`signingConfig`, else the public + * instance's, from TUF) are embedded in the bundle. If the log refuses the entry + * as a duplicate of a re-sent request, the statement is signed once more, which + * makes a new entry; the first one stays in the log, unused. + * + * @param {Uint8Array | ArrayBuffer | string | object} source the holo as bytes, a path, or an opened holo + * @param {{ type: string, predicate: unknown, subjects?: string[], key?: string | KeyObject, identityToken?: string, signingConfig?: object | string, tufMirrorUrl?: string, tufRoot?: string, tufCache?: string }} options + * @returns {Promise<{ holo: Uint8Array, bundle: object, statement: object, attestations: number }>} `attestations` counts the bundles now in the holo + */ +export async function experimental_attest(source, options) { + if (!isObject(options)) throw new SigningError('attest takes an options object with a type and a predicate', { check: 'sign.predicate' }); + const parsed = parseArchive(await holoBytes(source)); + const { statement, bytes } = buildStatement(parsed, options); + const bundle = await signerOf(options).sign(bytes); + const holo = appendAttestations(parsed, [bundle]); + return { holo, bundle, statement, attestations: readAttestations(holo).length }; +} + +/** + * A whole statement someone else wrote, such as the proof statement + * `prismpm verify` writes (#266): an in-toto Statement v1 whose every subject + * is a content blob of this holo with both digests equal. Returns the bytes + * to sign, its canonical JSON. + */ +function statementBytes(parsed, statement) { + let value = statement; + if (value instanceof Uint8Array || typeof value === 'string') { + try { + value = JSON.parse(typeof value === 'string' ? value : new TextDecoder('utf-8', { fatal: true }).decode(value)); + } catch (cause) { + throw new SigningError(`the statement is not JSON: ${cause.message}`, { check: 'sign.statement', cause }); + } + } + if (!isObject(value) || value._type !== STATEMENT_TYPE) throw new SigningError(`the statement's _type is not ${STATEMENT_TYPE}`, { check: 'sign.statement' }); + if (typeof value.predicateType !== 'string' || !URI.test(value.predicateType)) throw new SigningError('the statement has no predicateType URI', { check: 'sign.statement' }); + if (!Array.isArray(value.subject) || value.subject.length === 0) throw new SigningError('the statement has no subject', { check: 'sign.statement' }); + for (const subject of value.subject) { + const blob = parsed.blobs.find((b) => b.label === `blake3:${subject?.digest?.blake3}`); + if (!blob || sha256Hex(blob.content) !== subject.digest.sha256) { + throw new SubjectMismatchError(`subject ${JSON.stringify(subject?.name)} is not a content blob of this holo with both digests equal`, { check: 'sign.subject' }); + } + } + return { statement: value, bytes: encoder.encode(canonicalJson(value)) }; +} + +/** + * Sign statements that are already written, and return the holo that carries + * them signed (#582). This is how a build on a CI runner turns what + * `prismpm build` and `prismpm verify` wrote into evidence a checker accepts: + * + * - `unsigned: true` signs each unsigned placeholder in the holo, such as + * the provenance statement `prismpm build` writes (#268), and puts the + * signed bundle in its place. The signed payload is the placeholder's, + * byte for byte. + * - `statements` are whole statements to add, such as the proof statement + * of the verified directory. Each is signed as canonical JSON. + * + * The signer options are `experimental_attest`'s. The input holo is not + * modified. Resolves to `{ holo, signed, attestations }`, where `signed` lists + * `{ statement, bundle }` in signing order. + * + * @param {Uint8Array | ArrayBuffer | string | object} source the holo as bytes, a path, or an opened holo + * @param {{ unsigned?: boolean, statements?: Array, key?: string | KeyObject, identityToken?: string, signingConfig?: object | string, tufMirrorUrl?: string, tufRoot?: string, tufCache?: string }} options + * @returns {Promise<{ holo: Uint8Array, signed: Array<{ statement: object, bundle: object }>, attestations: number }>} + */ +export async function experimental_signStatements(source, options) { + if (!isObject(options)) throw new SigningError('signStatements takes an options object', { check: 'sign.statement' }); + const statements = options.statements ?? []; + if (!Array.isArray(statements)) throw new SigningError('statements is an array of statements', { check: 'sign.statement' }); + const parsed = parseArchive(await holoBytes(source)); + const added = statements.map((statement) => statementBytes(parsed, statement)); + const present = readAttestations(parsed); + const placeholders = options.unsigned === true ? present.filter((a) => !a.signed) : []; + if (added.length === 0 && placeholders.length === 0) { + throw new SigningError(options.unsigned === true ? 'the holo has no unsigned statement, and no statement was given' : 'nothing to sign: pass statements, or unsigned: true', { check: 'sign.statement' }); + } + const signer = signerOf(options); + const signed = []; + const replaced = new Map(); + for (const attestation of placeholders) { + const bytes = Buffer.from(attestation.envelope.payload, 'base64'); + const bundle = await signer.sign(bytes); + replaced.set(attestation.index, bundle); + signed.push({ statement: attestation.statement, bundle }); + } + for (const { statement, bytes } of added) signed.push({ statement, bundle: await signer.sign(bytes) }); + const lines = [...present.map((a) => replaced.get(a.index) ?? a.bytes), ...signed.slice(placeholders.length).map((s) => s.bundle)]; + const holo = appendAttestations(stripAttestations(parsed), lines); + return { holo, signed, attestations: readAttestations(holo).length }; +} diff --git a/sdk/npm/prism-code/src/attest.mjs b/sdk/npm/prism-code/src/attest.mjs index 8ec72a982..ed36e6af0 100644 --- a/sdk/npm/prism-code/src/attest.mjs +++ b/sdk/npm/prism-code/src/attest.mjs @@ -1,14 +1,15 @@ /** - * `attest` and `verify-attestation`: sign an in-toto statement into a holo's - * attestation section and check it again (issue #272, design in - * `docs/proposals/272-attest-verify.md`). + * `verify-attestation`: check the in-toto statements of a holo's attestation + * section, or one Sigstore bundle, against a signer policy (issue #272, design + * in `docs/proposals/272-attest-verify.md`). This is the `verify` module's half + * of attestation; writing a statement is `attest-write.mjs` (`images`) and + * signing it is an `auth` identity (`signing.mjs`). * - * Node only. The signing and the DSSE, certificate and log checks belong to the - * official `sigstore` packages (`@sigstore/sign`, `@sigstore/verify`, - * `@sigstore/tuf`); this module only builds the statement, picks the key or the - * keyless signer, applies the identity policy and maps every refusal to a typed - * error. The packages are optional dependencies and load on first use, so the - * rest of `prism-code` keeps working, and stays browser-safe, without them. + * Node only. The DSSE, certificate and log checks belong to the official + * `sigstore` packages (`@sigstore/verify`, `@sigstore/tuf`); this module only + * applies the identity policy and maps every refusal to a typed error. The + * packages are optional dependencies and load on first use, so the rest of + * `prism-code` keeps working, and stays browser-safe, without them. * * What runs on a verify, in order, for each bundle of the requested type: * 1. every statement subject is a content blob of this holo, both digests equal; @@ -21,39 +22,28 @@ * Experimental until the v0.6 freeze, hence the `experimental_` prefix. */ import { readFile } from 'node:fs/promises'; -import { createHash, createPrivateKey, createPublicKey, sign as cryptoSign, KeyObject } from 'node:crypto'; -import { SigningError, SignatureInvalidError, IdentityMismatchError, TransparencyError, SubjectMismatchError, AttestationNotFoundError, TrustRootError, VerificationError, PrismError } from './errors.mjs'; -import { parseArchive, resolveArchive, asBytes, canonicalJson } from './archive.mjs'; +import { createHash, createPublicKey, KeyObject } from 'node:crypto'; +import { SignatureInvalidError, IdentityMismatchError, TransparencyError, SubjectMismatchError, AttestationNotFoundError, TrustRootError, VerificationError, PrismError } from './errors.mjs'; +import { parseArchive, asBytes } from './archive.mjs'; import { blake3Hex } from './blake3.mjs'; -import { readAttestations, appendAttestations, stripAttestations, STATEMENT_TYPE, DSSE_PAYLOAD_TYPE } from './attestations.mjs'; +import { readAttestations } from './attestations.mjs'; import { verifyTransparency } from './vendor/verify.mjs'; /** The Fulcio-issued certificates of GitHub Actions workflows name this issuer. */ export const GITHUB_ACTIONS_ISSUER = 'https://token.actions.githubusercontent.com'; -const SIGNING_CONFIG_TARGET = 'signing_config.v0.2.json'; -const ROLES = ['guest', 'view', 'model', 'capabilities']; -const encoder = new TextEncoder(); -const URI = /^[A-Za-z][A-Za-z0-9+.-]*:\S+$/; - let loaded = null; /** Load the optional sigstore packages once. Their absence is `attest.unavailable`, not a crash. */ async function sigstore() { loaded ??= (async () => { try { - const [sign, verify, tuf, bundle, specs] = await Promise.all([ - import('@sigstore/sign'), - import('@sigstore/verify'), - import('@sigstore/tuf'), - import('@sigstore/bundle'), - import('@sigstore/protobuf-specs'), - ]); - return { sign, verify, tuf, bundle, specs }; + const [verify, tuf, bundle, specs] = await Promise.all([import('@sigstore/verify'), import('@sigstore/tuf'), import('@sigstore/bundle'), import('@sigstore/protobuf-specs')]); + return { verify, tuf, bundle, specs }; } catch (cause) { loaded = null; throw new PrismError( - 'attest and verify-attestation need the sigstore packages (@sigstore/sign, @sigstore/verify, @sigstore/tuf, @sigstore/bundle, @sigstore/protobuf-specs), which are optional dependencies of prism-code and need Node 22.22.2 or newer: ' + + 'verify-attestation needs the sigstore packages (@sigstore/verify, @sigstore/tuf, @sigstore/bundle, @sigstore/protobuf-specs), which are optional dependencies of prism-code and need Node 22.22.2 or newer: ' + cause.message, { code: 'attest.unavailable', cause }, ); @@ -68,25 +58,13 @@ function isObject(value) { return value !== null && typeof value === 'object' && !Array.isArray(value); } -async function holoBytes(source) { +/** A holo's bytes from bytes, a path, or an opened holo. */ +export async function holoBytes(source) { if (source && typeof source === 'object' && source.kind === 'holo' && source.archive?.bytes) return source.archive.bytes; if (typeof source === 'string') return new Uint8Array(await readFile(source)); return asBytes(source); } -function keyId(publicKey) { - return createHash('sha256').update(publicKey.export({ type: 'spki', format: 'der' })).digest('hex'); -} - -function privateKeyOf(key) { - try { - if (key instanceof KeyObject) return key; - return createPrivateKey(key); - } catch (cause) { - throw new SigningError(`the signing key cannot be read: ${cause.message}; expected an unencrypted PKCS#8 or SEC1 PEM`, { check: 'sign.key', cause }); - } -} - function publicKeyOf(key) { try { if (key instanceof KeyObject) return key.type === 'private' ? createPublicKey(key) : key; @@ -95,70 +73,7 @@ function publicKeyOf(key) { throw new VerificationError(`the verification key cannot be read: ${cause.message}; expected a PEM public key`, { check: 'policy.invalid', cause }); } } - -function predicateOf(predicate) { - let value = predicate; - if (value instanceof Uint8Array || typeof value === 'string') { - try { - value = JSON.parse(typeof value === 'string' ? value : new TextDecoder('utf-8', { fatal: true }).decode(value)); - } catch (cause) { - throw new SigningError(`the predicate is not JSON: ${cause.message}`, { check: 'sign.predicate', cause }); - } - } - if (value === undefined || value === null) throw new SigningError('a predicate is required', { check: 'sign.predicate' }); - return value; -} - -/** - * The subjects of a statement, as `{ name, digest: { sha256, blake3 } }` over - * content blobs of the holo. A request is a role (`guest`, `view`, `model`, - * `capabilities`), a blob label (`blake3:`), or `name=`. - * Without a request the subject is the guest, which is what the proof and - * provenance predicates describe (#266, #268). - */ -export function resolveSubjects(parsed, requests = []) { - const wanted = requests.length === 0 ? ['guest'] : requests; - let roles = null; - const subjects = wanted.map((request) => { - if (typeof request !== 'string' || request === '') throw new SigningError('a subject is a role or a blob label', { check: 'sign.subject' }); - const eq = request.indexOf('='); - const name = eq > 0 ? request.slice(0, eq) : null; - const target = eq > 0 ? request.slice(eq + 1) : request; - let label; - if (ROLES.includes(target)) { - roles ??= resolveArchive(parsed).identities; - label = roles[`${target}Kappa`]; - } else if (/^blake3:[0-9a-f]{64}$/.test(target)) label = target; - else throw new SigningError(`subject ${JSON.stringify(request)} is neither a role (${ROLES.join(', ')}) nor a blake3 label`, { check: 'sign.subject' }); - const blob = parsed.blobs.find((b) => b.label === label); - if (!blob) throw new SigningError(`subject ${label} is not a content blob of this holo`, { check: 'sign.subject' }); - return { name: name ?? (ROLES.includes(target) ? target : label), digest: { sha256: sha256Hex(blob.content), blake3: blake3Hex(blob.content) } }; - }); - if (new Set(subjects.map((s) => s.name)).size !== subjects.length) throw new SigningError('two subjects have the same name', { check: 'sign.subject' }); - return subjects; -} - -/** The in-toto Statement v1 bytes that get signed. */ -export function buildStatement(parsed, { type, predicate, subjects }) { - if (typeof type !== 'string' || !URI.test(type)) throw new SigningError('the predicate type must be a URI, such as https://slsa.dev/provenance/v1', { check: 'sign.predicate' }); - const statement = { _type: STATEMENT_TYPE, subject: resolveSubjects(parsed, subjects), predicateType: type, predicate: predicateOf(predicate) }; - return { statement, bytes: encoder.encode(JSON.stringify(statement)) }; -} - -async function keyedBuilder(m, key) { - const privateKey = privateKeyOf(key); - const publicKey = createPublicKey(privateKey); - const hint = keyId(publicKey); - const pem = publicKey.export({ type: 'spki', format: 'pem' }); - // Ed25519 signs the message itself; every other scheme signs its SHA-256 digest. - const digest = privateKey.asymmetricKeyType === 'ed25519' ? null : 'sha256'; - const signer = { - sign: async (data) => ({ signature: cryptoSign(digest, data, privateKey), key: { $case: 'publicKey', publicKey: pem, hint } }), - }; - return new m.sign.DSSEBundleBuilder({ signer, witnesses: [] }); -} - -async function readJsonFile(path, what, Error = SigningError, check = 'sign.config') { +async function readJsonFile(path, what, Error, check) { try { return JSON.parse(await readFile(path, 'utf8')); } catch (cause) { @@ -174,190 +89,6 @@ function tufOptions(options) { return out; } -// sigstore's default is 5 s. A log entry can take longer than that to answer after it is stored, and the -// client then sends the same request again, which the log refuses as a duplicate. -const KEYLESS_FETCH = Object.freeze({ timeout: 30_000, retry: Object.freeze({ retries: 2 }) }); - -/** - * The log already holds this exact entry. Only a re-sent request can do that, because each signature is new: - * an earlier attempt was stored, and its answer was lost or was a 5xx. `bundleBuilderFromSigningConfig` does - * not expose `fetchOnConflict`, which would read that entry back. - */ -const isLogConflict = (error) => error?.code === 'TLOG_CREATE_ENTRY_ERROR' && error.cause?.statusCode === 409; - -/** - * The text with each token replaced, whole and part by part, because a service may quote only a JWT's payload. - * `@sigstore/sign` writes a token it cannot parse into its own message, and that message is printed. - */ -function withoutTokens(text, tokens) { - const parts = tokens.flatMap((token) => [token, ...token.split('.').filter((part) => part.length >= 8)]); - return parts.reduce((out, part) => out.split(part).join('[redacted]'), text); -} - -async function keylessBuilder(m, options, tokens) { - let signingConfig = options.signingConfig; - try { - if (typeof signingConfig === 'string') signingConfig = await readJsonFile(signingConfig, 'the signing configuration'); - if (!signingConfig) { - const tuf = await m.tuf.initTUF(tufOptions(options)); - signingConfig = JSON.parse(await tuf.getTarget(SIGNING_CONFIG_TARGET)); - } - signingConfig = m.specs.SigningConfig.fromJSON(signingConfig); - const source = options.identityToken ? { getToken: async () => options.identityToken } : new m.sign.CIContextProvider('sigstore'); - // Every token passes here, whichever source it came from, so a failure can be cleaned of it. - const identityProvider = { - getToken: async () => { - const token = await source.getToken(); - tokens.push(String(token)); - return token; - }, - }; - return m.sign.bundleBuilderFromSigningConfig({ signingConfig, identityProvider, bundleType: 'dsseEnvelope', fetchOptions: KEYLESS_FETCH }); - } catch (cause) { - if (cause instanceof SigningError) throw cause; - throw new SigningError(`the Sigstore signing configuration is unavailable or unusable:${cause.message}`, { check: 'sign.config', cause }); - } -} - -/** - * Sign statement bytes into a Sigstore bundle v0.3, with `key` or keyless. The - * bundle's JSON is returned; nothing else is written. `attest` stores it in the - * holo, and `push` (#292) stores it as a referrer. - * - * @param {Uint8Array} bytes the in-toto Statement v1 exactly as it is to be signed - * @param {{ key?: string | KeyObject, identityToken?: string, signingConfig?: object | string, tufMirrorUrl?: string, tufRoot?: string, tufCache?: string }} options - * @returns {Promise} - */ -export async function signStatement(bytes, options = {}) { - const m = await sigstore(); - const tokens = []; - const builder = options.key !== undefined ? await keyedBuilder(m, options.key) : await keylessBuilder(m, options, tokens); - try { - const artifact = { data: Buffer.from(bytes), type: DSSE_PAYLOAD_TYPE }; - const signed = await builder.create(artifact).catch((error) => { - if (isLogConflict(error)) return builder.create(artifact); - throw error; - }); - const bundle = m.bundle.bundleToJSON(signed); - // A DSSE verifier skips a signature whose keyid is not its own, and cosign's is not this hash, so a keyed bundle with one - // verifies nowhere but here. The keyid is not signed, and the hint in the verification material still names the key. - if (options.key !== undefined) for (const signature of bundle.dsseEnvelope.signatures) signature.keyid = ''; - return bundle; - } catch (cause) { - if (cause instanceof PrismError) throw cause; - const message = withoutTokens(cause?.message ?? String(cause), tokens); - // The CI identity provider rejects with a plain string; sigstore's own errors carry a code. - const identity = typeof cause === 'string' || /^IDENTITY_TOKEN/.test(cause?.code ?? ''); - throw new SigningError( - typeof cause === 'string' || cause?.code === 'IDENTITY_TOKEN_READ_ERROR' - ? `no OIDC identity token is available: set SIGSTORE_ID_TOKEN, pass identityToken, or run in GitHub Actions with id-token: write (${message})` - : identity - ? `the OIDC identity token cannot be used: ${message}` - : `signing failed: ${message}`, - // Once a token was read, the original error may hold it anywhere, so it is not passed on. - { check: identity ? 'sign.identity' : 'sign.service', cause: tokens.length === 0 ? cause : undefined }, - ); - } -} - -/** - * Sign a statement about a holo and return the holo with the bundle appended to - * its attestation section. The input holo is not modified. - * - * With `key`, the statement is signed by that private key (PEM or KeyObject) - * and no network is used. Without it the signing is keyless: an OIDC identity - * token (`identityToken`, else GitHub Actions or `SIGSTORE_ID_TOKEN`) is - * exchanged for a Fulcio certificate, and the Rekor v2 entry and RFC 3161 - * timestamp of the signing configuration (`signingConfig`, else the public - * instance's, from TUF) are embedded in the bundle. If the log refuses the entry - * as a duplicate of a re-sent request, the statement is signed once more, which - * makes a new entry; the first one stays in the log, unused. - * - * @param {Uint8Array | ArrayBuffer | string | object} source the holo as bytes, a path, or an opened holo - * @param {{ type: string, predicate: unknown, subjects?: string[], key?: string | KeyObject, identityToken?: string, signingConfig?: object | string, tufMirrorUrl?: string, tufRoot?: string, tufCache?: string }} options - * @returns {Promise<{ holo: Uint8Array, bundle: object, statement: object, attestations: number }>} `attestations` counts the bundles now in the holo - */ -export async function experimental_attest(source, options) { - if (!isObject(options)) throw new SigningError('attest takes an options object with a type and a predicate', { check: 'sign.predicate' }); - const parsed = parseArchive(await holoBytes(source)); - const { statement, bytes } = buildStatement(parsed, options); - const bundle = await signStatement(bytes, options); - const holo = appendAttestations(parsed, [bundle]); - return { holo, bundle, statement, attestations: readAttestations(holo).length }; -} - -/** - * A whole statement someone else wrote, such as the proof statement - * `prismpm verify` writes (#266): an in-toto Statement v1 whose every subject - * is a content blob of this holo with both digests equal. Returns the bytes - * to sign, its canonical JSON. - */ -function statementBytes(parsed, statement) { - let value = statement; - if (value instanceof Uint8Array || typeof value === 'string') { - try { - value = JSON.parse(typeof value === 'string' ? value : new TextDecoder('utf-8', { fatal: true }).decode(value)); - } catch (cause) { - throw new SigningError(`the statement is not JSON: ${cause.message}`, { check: 'sign.statement', cause }); - } - } - if (!isObject(value) || value._type !== STATEMENT_TYPE) throw new SigningError(`the statement's _type is not ${STATEMENT_TYPE}`, { check: 'sign.statement' }); - if (typeof value.predicateType !== 'string' || !URI.test(value.predicateType)) throw new SigningError('the statement has no predicateType URI', { check: 'sign.statement' }); - if (!Array.isArray(value.subject) || value.subject.length === 0) throw new SigningError('the statement has no subject', { check: 'sign.statement' }); - for (const subject of value.subject) { - const blob = parsed.blobs.find((b) => b.label === `blake3:${subject?.digest?.blake3}`); - if (!blob || sha256Hex(blob.content) !== subject.digest.sha256) { - throw new SubjectMismatchError(`subject ${JSON.stringify(subject?.name)} is not a content blob of this holo with both digests equal`, { check: 'sign.subject' }); - } - } - return { statement: value, bytes: encoder.encode(canonicalJson(value)) }; -} - -/** - * Sign statements that are already written, and return the holo that carries - * them signed (#582). This is how a build on a CI runner turns what - * `prismpm build` and `prismpm verify` wrote into evidence a checker accepts: - * - * - `unsigned: true` signs each unsigned placeholder in the holo, such as - * the provenance statement `prismpm build` writes (#268), and puts the - * signed bundle in its place. The signed payload is the placeholder's, - * byte for byte. - * - `statements` are whole statements to add, such as the proof statement - * of the verified directory. Each is signed as canonical JSON. - * - * The signer options are `experimental_attest`'s. The input holo is not - * modified. Resolves to `{ holo, signed, attestations }`, where `signed` lists - * `{ statement, bundle }` in signing order. - * - * @param {Uint8Array | ArrayBuffer | string | object} source the holo as bytes, a path, or an opened holo - * @param {{ unsigned?: boolean, statements?: Array, key?: string | KeyObject, identityToken?: string, signingConfig?: object | string, tufMirrorUrl?: string, tufRoot?: string, tufCache?: string }} options - * @returns {Promise<{ holo: Uint8Array, signed: Array<{ statement: object, bundle: object }>, attestations: number }>} - */ -export async function experimental_signStatements(source, options) { - if (!isObject(options)) throw new SigningError('signStatements takes an options object', { check: 'sign.statement' }); - const statements = options.statements ?? []; - if (!Array.isArray(statements)) throw new SigningError('statements is an array of statements', { check: 'sign.statement' }); - const parsed = parseArchive(await holoBytes(source)); - const added = statements.map((statement) => statementBytes(parsed, statement)); - const present = readAttestations(parsed); - const placeholders = options.unsigned === true ? present.filter((a) => !a.signed) : []; - if (added.length === 0 && placeholders.length === 0) { - throw new SigningError(options.unsigned === true ? 'the holo has no unsigned statement, and no statement was given' : 'nothing to sign: pass statements, or unsigned: true', { check: 'sign.statement' }); - } - const signed = []; - const replaced = new Map(); - for (const attestation of placeholders) { - const bytes = Buffer.from(attestation.envelope.payload, 'base64'); - const bundle = await signStatement(bytes, options); - replaced.set(attestation.index, bundle); - signed.push({ statement: attestation.statement, bundle }); - } - for (const { statement, bytes } of added) signed.push({ statement, bundle: await signStatement(bytes, options) }); - const lines = [...present.map((a) => replaced.get(a.index) ?? a.bytes), ...signed.slice(placeholders.length).map((s) => s.bundle)]; - const holo = appendAttestations(stripAttestations(parsed), lines); - return { holo, signed, attestations: readAttestations(holo).length }; -} - // --------------------------------------------------------------------------- const EMPTY_ROOT = { mediaType: 'application/vnd.dev.sigstore.trustedroot+json;version=0.1', tlogs: [], certificateAuthorities: [], ctlogs: [], timestampAuthorities: [] }; diff --git a/sdk/npm/prism-code/src/auth.mjs b/sdk/npm/prism-code/src/auth.mjs index 03a941b97..5c327f7ce 100644 --- a/sdk/npm/prism-code/src/auth.mjs +++ b/sdk/npm/prism-code/src/auth.mjs @@ -1,7 +1,9 @@ /** * `prism.auth`: who you are (issue #447, the `auth` module of #440). Registry * logins and credential stores over `oci-auth.mjs`, and the identities that sign - * attestations over `signStatement` in `attest.mjs`. Node only. + * attestations over `signing.mjs`. Node only. Every signature in prism-code is + * made through an identity of this module: `attest`, `signStatements` and `push` + * ask `identities.from` for one. * * Nothing this module returns, throws or logs holds a secret. A password goes * into a store and stays there, and `push` and `pull` read it from that store @@ -10,14 +12,14 @@ * * It decides nothing about trust. An identity signs; whether that signer is * acceptable is for `verify` to say. It may depend only on `errors`: `oci-auth` - * is its own code, and `attest.mjs` is loaded for its signing part only, until - * that file is split (#440, phase 3). + * and `signing` are its own code. * * Experimental until the v0.6 freeze (STABILITY.md section 6). */ import { createHash, createPrivateKey, createPublicKey, KeyObject } from 'node:crypto'; import { PrismError, RegistryAuthError, RegistryError, SigningError } from './errors.mjs'; import { describeCredential, eraseCredential, listStores, storeCredential, storeForRegistry } from './oci-auth.mjs'; +import { signStatement } from './signing.mjs'; const DOCKER_HUB = 'docker.io'; const REGISTRY_NAME = /^(?:[A-Za-z0-9](?:[A-Za-z0-9.-]*[A-Za-z0-9])?|\[[0-9A-Fa-f:]+\])(?::[0-9]+)?$/; @@ -37,8 +39,11 @@ function redactor(secrets) { return (text) => forms.reduce((out, form) => out.split(form).join(REDACTED), text); } -/** Make an error safe to hand out, in place, so its class, `code` and `check` stay. A `cause` may hold anything, so it goes. */ -function scrub(error, secrets) { +/** + * Make an error safe to hand out, in place, so its class, `code` and `check` stay. A `cause` may hold anything, so it goes, + * unless `keepCause` says no secret was in play, which is how a keyless failure before any token was read stays explainable. + */ +function scrub(error, secrets, keepCause = false) { const redact = redactor(secrets); const deep = (value) => { if (typeof value === 'string') return redact(value); @@ -46,7 +51,7 @@ function scrub(error, secrets) { if (value !== null && typeof value === 'object') return Object.fromEntries(Object.entries(value).map(([key, member]) => [redact(key), deep(member)])); return value; }; - delete error.cause; + if (!keepCause) delete error.cause; error.message = redact(error.message); if (typeof error.stack === 'string') error.stack = redact(error.stack); for (const member of ['details', 'reasons', 'verdict']) { @@ -85,7 +90,7 @@ function keyIdentity(key) { kind: 'key', keyId: createHash('sha256').update(publicKey.export({ type: 'spki', format: 'der' })).digest('hex'), publicKey: publicKey.export({ type: 'spki', format: 'pem' }), - sign: (statement) => signWith(statement, { key: privateKey }, []), + sign: (statement) => signWith(statement, { key: privateKey }, typeof key === 'string' ? [key] : [], false), }); } @@ -95,17 +100,29 @@ function keylessIdentity(options) { return Object.freeze({ kind: 'keyless', ambient: identityToken === undefined, - sign: (statement) => signWith(statement, { identityToken, signingConfig, tufMirrorUrl, tufRoot, tufCache }, [identityToken]), + sign: (statement) => signWith(statement, { identityToken, signingConfig, tufMirrorUrl, tufRoot, tufCache }, [identityToken], true), }); } -async function signWith(statement, options, secrets) { +/** + * The identity a set of signer options names: `key` is a private key, and + * without one the signing is keyless with `identityToken`, `signingConfig` and + * the TUF options. This is the one place a flat options object, as `attest` and + * `push` take it, becomes a signer. + */ +function identityFrom(options) { + const { key, ...keyless } = options ?? {}; + return key !== undefined ? keyIdentity(key) : keylessIdentity(keyless); +} + +async function signWith(statement, options, secrets, keyless) { if (!(statement instanceof Uint8Array)) throw new SigningError('sign takes the bytes of an in-toto statement', { check: 'sign.predicate' }); - const { signStatement } = await import('./attest.mjs'); try { return await signStatement(statement, options); } catch (error) { - throw scrub(error, [...secrets, ...AMBIENT_TOKENS.map((name) => process.env[name])]); + const all = [...secrets, ...AMBIENT_TOKENS.map((name) => process.env[name])].filter((s) => typeof s === 'string' && s !== ''); + // `signStatement` drops the cause itself once it has read a token; with no secret anywhere, the cause explains the failure. + throw scrub(error, all, keyless && all.length === 0); } } @@ -195,6 +212,8 @@ export function createAuth(options = {}) { * `SIGSTORE_ID_TOKEN` or GitHub Actions, and not from `env`, because `@sigstore/sign` reads it there. */ keyless: keylessIdentity, + /** `fromKey(options.key)` when there is a key, else `keyless(options)`: the signer options `attest` and `push` take. */ + from: identityFrom, }), }); } diff --git a/sdk/npm/prism-code/src/node.mjs b/sdk/npm/prism-code/src/node.mjs index 6960b35f5..6d40bbd0a 100644 --- a/sdk/npm/prism-code/src/node.mjs +++ b/sdk/npm/prism-code/src/node.mjs @@ -257,7 +257,8 @@ function fromEnv(options = {}) { export const Prism = Object.freeze({ fromEnv, create: createPrism }); // Signing and checking attestations (#272). The sigstore packages they need are optional and load on first use. -export { experimental_attest, experimental_signStatements, experimental_verifyAttestations, experimental_verifyBundle, GITHUB_ACTIONS_ISSUER } from './attest.mjs'; +export { experimental_verifyAttestations, experimental_verifyBundle, GITHUB_ACTIONS_ISSUER } from './attest.mjs'; +export { experimental_attest, experimental_signStatements } from './attest-write.mjs'; // Moving holos to and from a registry or a local store (#292). export { experimental_push, experimental_pull, openEndpoint, MAX_HOLO_BYTES, PUSH_SCHEMA, PULL_SCHEMA } from './push-pull.mjs'; diff --git a/sdk/npm/prism-code/src/push-pull.mjs b/sdk/npm/prism-code/src/push-pull.mjs index 358933509..dc512fcbf 100644 --- a/sdk/npm/prism-code/src/push-pull.mjs +++ b/sdk/npm/prism-code/src/push-pull.mjs @@ -6,18 +6,20 @@ * everything here works on either. `pull` holds everything in memory until every * check has passed, and only then writes. * + * This file fetches and writes; it decides nothing about trust (#449). Every + * check of what was fetched, and of what is about to leave, is `verify`'s, in + * `verify-closure.mjs`, and every signature is an `auth` identity's. + * * Experimental until the v0.6 freeze, hence the `experimental_` prefix. */ import { readFile, rename, rm, writeFile } from 'node:fs/promises'; import { resolve } from 'node:path'; -import { parseArchive, asBytes } from './archive.mjs'; +import { asBytes } from './archive.mjs'; import { blake3Hex } from './blake3.mjs'; -import { readAttestations, OCI_MANIFEST_SUBJECT, DSSE_PAYLOAD_TYPE, BUNDLE_MEDIA_TYPE } from './attestations.mjs'; -import { checkSubjects, experimental_verifyAttestations, experimental_verifyBundle, signStatement } from './attest.mjs'; -import { check, policyOf } from './check.mjs'; -import { MINIMUM_LEVEL_ENV } from './verify.mjs'; -import { errorFromVerdict, AttestationNotFoundError, DigestMismatchError, PrismCodeError, PrismError, PullVerificationError, ReferenceInvalidError, VerificationError } from './errors.mjs'; -import { ASSURANCE } from './vendor/verify.mjs'; +import { BUNDLE_MEDIA_TYPE } from './attestations.mjs'; +import { auth } from './auth.mjs'; +import { verifyHoloClaims, verifyOutgoing, verifyPullClosure } from './verify-closure.mjs'; +import { DigestMismatchError, PrismCodeError, PullVerificationError, ReferenceInvalidError } from './errors.mjs'; import { ANNOTATION, EMPTY_BYTES, @@ -112,130 +114,14 @@ async function fetchReferrers(endpoint, subject) { return out; } -/** Steps 4 and 5 of the proposal: the archive verifies and every BLAKE3 claim equals what its bytes give. */ -function verifyHolo(closure, reference) { - let parsed; - try { - parsed = parseArchive(closure.holo); - } catch (cause) { - if (!(cause instanceof PrismCodeError)) throw cause; - throw new DigestMismatchError(`the pulled bytes are not a holo: ${cause.message}`, { check: 'pull.archive', cause }); - } - if (!parsed.verification.footer) throw new DigestMismatchError(`the holo's footer ${parsed.footer} is not the BLAKE3 of its body, ${parsed.fingerprint}`, { check: 'pull.archive' }); - if (!parsed.verification.labels) throw new DigestMismatchError(`a content blob of the holo does not match its label: ${parsed.verification.labelMismatches.map((m) => m.label).join(', ')}`, { check: 'pull.archive' }); - const fingerprint = `blake3:${parsed.footer}`; - if (reference.fingerprint && reference.fingerprint !== fingerprint) { - throw new DigestMismatchError(`asked for the holo ${reference.fingerprint}, and the registry sent ${fingerprint}`, { check: 'digest.fingerprint' }); - } - const claimed = closure.manifest.annotations?.[ANNOTATION.FINGERPRINT]; - if (claimed !== undefined && claimed !== fingerprint) throw new DigestMismatchError(`the manifest says the holo is ${claimed}, its footer says ${fingerprint}`, { check: 'digest.annotation' }); - const file = closure.layer.annotations?.[ANNOTATION.BLAKE3]; - if (file !== undefined && file !== blake3Hex(closure.holo)) throw new DigestMismatchError(`the layer says its BLAKE3 is ${file}, its bytes say ${blake3Hex(closure.holo)}`, { check: 'digest.annotation' }); - return { parsed, fingerprint }; -} - -/** - * Step 7: the verdict, which is `check`'s, so one holo and one signer have one - * verdict. The signed statements in the holo count when the signer named here - * vouches for them. Bundles in the registry do not raise the level: they are about - * the manifest, and step 8 judges them. - */ -async function judge(parsed, options) { - const env = options.env ?? process.env; - const policy = await policyOf(options.policy === undefined ? { name: 'pull-default', minimum: env[MINIMUM_LEVEL_ENV] || 'P0' } : options.policy); - const { type, ...signer } = signerOptions(options); - let verdict; - try { - verdict = await check(parsed.bytes, { policy, env, signer: SIGNER_OPTIONS.some((name) => signer[name] !== undefined) ? signer : undefined }); - } catch (cause) { - if (!(cause instanceof VerificationError)) throw cause; - if (cause.check === 'policy.invalid' || cause.check === 'policy.unreadable') throw cause; - throw new PullVerificationError(`the holo has no verdict: ${cause.message}`, { check: 'pull.verdict', cause }); - } - if (!verdict.passed) { - const why = errorFromVerdict(verdict, ASSURANCE.RANK); - throw new PullVerificationError(`the holo failed policy ${verdict.policy.name}: level ${verdict.level}, requires ${verdict.policy.minimum}; ${why?.check ?? 'policy.level'}: ${why?.message ?? ''}`, { check: 'pull.verdict', verdict, reasons: verdict.reasons, cause: why ?? undefined }); - } - return verdict; -} - -/** Step 6: every line decodes, and every subject is a blob of this holo with both digests equal. The verdict reads these lines, so they come first. */ -function checkAttestations(parsed) { - let attestations; - try { - attestations = readAttestations(parsed); - for (const attestation of attestations) checkSubjects(parsed, attestation); - } catch (cause) { - if (!(cause instanceof PrismError)) throw cause; - throw new PullVerificationError(`an attestation in the holo does not hold: ${cause.message}`, { check: 'pull.attestation', cause }); - } - return attestations; -} - -/** What a registry bundle says about itself, or null when it is not a DSSE statement. */ -function readStatement(line) { - try { - const bundle = JSON.parse(decoder.decode(line)); - const envelope = bundle?.dsseEnvelope; - if (envelope?.payloadType !== DSSE_PAYLOAD_TYPE || typeof envelope.payload !== 'string') return null; - const statement = JSON.parse(decoder.decode(Uint8Array.from(atob(envelope.payload), (c) => c.charCodeAt(0)))); - return Array.isArray(statement?.subject) ? { bundle, statement } : null; - } catch { - return null; - } -} - -/** - * A referrer's statement must be about this holo: a subject's `sha256` is the - * manifest digest, and any subject that claims `blake3` is a blob of this holo; - * or every subject is a blob of this holo, which is an in-holo line pushed as is. - */ -function aboutThisHolo(parsed, statement, manifestDigest) { - const hex = hexOf(manifestDigest); - const labels = new Set(parsed.blobs.map((blob) => blob.label)); - const blobs = statement.subject.filter((subject) => typeof subject?.digest?.blake3 === 'string'); - if (blobs.some((subject) => !labels.has(`blake3:${subject.digest.blake3}`))) return false; - try { - checkSubjects(parsed, { subjects: blobs.map((subject) => ({ name: subject.name, digest: subject.digest, blob: `blake3:${subject.digest.blake3}` })) }); - } catch { - return false; - } - return statement.subject.some((subject) => subject?.digest?.sha256 === hex) || (blobs.length > 0 && blobs.length === statement.subject.length); -} - -const SIGNER_OPTIONS = ['key', 'certificateIdentity', 'certificateIdentityRegexp', 'certificateOidcIssuer']; -const signerOptions = (options) => Object.fromEntries(['type', ...SIGNER_OPTIONS, 'trustedRoot', 'entries', 'timestamps', 'tufMirrorUrl', 'tufRoot', 'tufCache'].filter((name) => options[name] !== undefined).map((name) => [name, options[name]])); - -/** Step 8: with a signer policy, at least one bundle of the holo or of the registry passes it. */ -async function checkSigner(parsed, closure, options) { - if (!SIGNER_OPTIONS.some((name) => options[name] !== undefined)) return null; - const policy = signerOptions(options); - const inHolo = await experimental_verifyAttestations(parsed.bytes, policy); - const passing = inHolo.results.filter((r) => r.passed).map((r) => ({ source: 'holo', predicateType: r.predicateType, signer: r.signer, time: r.time })); - // A failed signature explains more than a holo with no attestation, so it is what gets reported. - let first = inHolo.error instanceof AttestationNotFoundError ? null : inHolo.error; - const { type, ...rest } = policy; - const judged = new Set(readAttestations(parsed).map((a) => Buffer.from(a.bytes).toString('latin1'))); - for (const referrer of closure.referrers) { - // A line of the holo pushed as is was judged above; it counts once. - if (judged.has(Buffer.from(referrer.line).toString('latin1'))) continue; - const read = readStatement(referrer.line); - if (!read || (type !== undefined && read.statement.predicateType !== type)) continue; - if (!aboutThisHolo(parsed, read.statement, closure.digest)) continue; - try { - const outcome = await experimental_verifyBundle(read.bundle, rest); - passing.push({ source: 'referrer', digest: referrer.digest, predicateType: read.statement.predicateType, signer: { identity: outcome.identity, issuer: outcome.issuer, keyId: outcome.keyId }, time: outcome.time }); - } catch (cause) { - if (!(cause instanceof PrismError)) throw cause; - first ??= cause; - } - } - first ??= inHolo.error; - if (passing.length === 0) { - throw new PullVerificationError(`no attestation of this holo passes the signer policy${first ? `: ${first.code}: ${first.message}` : ''}`, { check: 'pull.signer', cause: first ?? undefined, details: { cause: first?.code ?? null } }); - } - return passing; -} +/** What `verify` judges of a fetched closure: the bytes, and what the manifest and the caller claim about them. */ +const factsOf = (closure, reference) => ({ + holo: closure.holo, + manifestDigest: closure.digest, + claims: { fingerprint: closure.manifest.annotations?.[ANNOTATION.FINGERPRINT], blake3: closure.layer.annotations?.[ANNOTATION.BLAKE3] }, + asked: { fingerprint: reference.fingerprint }, + referrers: closure.referrers.map(({ digest, line }) => ({ digest, line })), +}); /** Write a closure to an endpoint: blobs first, then referrers, then the tag, so a tag never names something half there. */ async function writeClosure(endpoint, closure, tag) { @@ -287,10 +173,8 @@ export async function experimental_pull(source, options = {}) { const reference = referenceOf(source, options); const endpoint = openEndpoint(reference, options); const closure = await fetchClosure(endpoint, reference, options); - const { parsed, fingerprint } = verifyHolo(closure, reference); - const attestations = checkAttestations(parsed); - const verdict = await judge(parsed, options); - const signers = await checkSigner(parsed, closure, options); + // Steps 4 to 8 are verify's; nothing is written unless every one passed. + const { fingerprint, attestations, verdict, signers } = await verifyPullClosure(factsOf(closure, reference), options); let output = null; if (typeof options.output === 'string' && options.output.startsWith('dir://')) { @@ -322,7 +206,7 @@ async function readSource(source, options) { if (typeof source === 'string' && source.startsWith('dir://')) { const reference = parseReference(source); const closure = await fetchClosure(openEndpoint(reference), reference, options); - verifyHolo(closure, reference); + verifyHoloClaims(factsOf(closure, reference)); return { holo: closure.holo, carried: closure.referrers, carriedFor: closure.digest }; } if (typeof source === 'string') { @@ -353,13 +237,8 @@ export async function experimental_push(source, target, options = {}) { const { holo, carried, carriedFor } = await readSource(source, options); const progress = options.onProgress ?? (() => {}); - // Step 1: nothing corrupt leaves this machine. - const parsed = parseArchive(holo); - if (!parsed.verification.footer || !parsed.verification.labels) { - throw new VerificationError('the holo does not verify: its footer or a content label differs from the bytes', { check: 'holo.integrity' }); - } - const attestations = readAttestations(parsed); - for (const attestation of attestations) checkSubjects(parsed, attestation); + // Step 1: nothing corrupt leaves this machine, as verify judges it. + const { parsed, attestations } = verifyOutgoing(holo); const built = await holoManifest(parsed); const { digest, bytes: manifestBytes, descriptor, layer, fingerprint } = built; @@ -384,8 +263,9 @@ export async function experimental_push(source, target, options = {}) { referrers.push({ digest: referrerDigest, predicateType: attestation.predicateType, source: 'holo', signed: attestation.signed }); } if (options.key !== undefined || options.keyless) { + const signer = auth.identities.from({ key: options.key, identityToken: options.identityToken ?? (options.env?.SIGSTORE_ID_TOKEN || undefined), signingConfig: options.signingConfig, tufMirrorUrl: options.tufMirrorUrl, tufRoot: options.tufRoot, tufCache: options.tufCache }); for (const statement of registryStatements(attestations, digest)) { - const signed = await signStatement(encoder.encode(JSON.stringify(statement)), { key: options.key, identityToken: options.identityToken ?? options.env?.SIGSTORE_ID_TOKEN, signingConfig: options.signingConfig, tufMirrorUrl: options.tufMirrorUrl, tufRoot: options.tufRoot, tufCache: options.tufCache }); + const signed = await signer.sign(encoder.encode(JSON.stringify(statement))); const line = encoder.encode(JSON.stringify(signed)); const { manifest, bytes, digest: referrerDigest, layer: bundleLayer, descriptor: bundleDescriptor } = await referrerManifest(line, descriptor, statement.predicateType); pending.push({ manifest, manifestBytes: bytes, digest: referrerDigest, layer: bundleLayer, line, descriptor: bundleDescriptor }); diff --git a/sdk/npm/prism-code/src/signing.mjs b/sdk/npm/prism-code/src/signing.mjs new file mode 100644 index 000000000..e32b3b24e --- /dev/null +++ b/sdk/npm/prism-code/src/signing.mjs @@ -0,0 +1,167 @@ +/** + * Signing: in-toto statement bytes into a Sigstore bundle v0.3, with a private + * key or keyless (issue #447, the signing cut of #440). This is the `auth` + * module's: an identity signs, and whether that signer is acceptable is for + * `verify` to say. Callers reach it through `auth.identities`, never directly. + * + * It may depend only on `errors`. The sigstore packages are optional + * dependencies and load on first use, so nothing else needs them. Node only. + * + * Experimental until the v0.6 freeze (STABILITY.md section 6). + */ +import { readFile } from 'node:fs/promises'; +import { createHash, createPrivateKey, createPublicKey, sign as cryptoSign, KeyObject } from 'node:crypto'; +import { PrismError, SigningError } from './errors.mjs'; + +/** `attestations.mjs` names the same type; it is a constant of DSSE, not something this module reads from `verify`. */ +const DSSE_PAYLOAD_TYPE = 'application/vnd.in-toto+json'; +const SIGNING_CONFIG_TARGET = 'signing_config.v0.2.json'; + +let loaded = null; + +/** Load the optional sigstore signing packages once. Their absence is `attest.unavailable`, not a crash. */ +async function sigstore() { + loaded ??= (async () => { + try { + const [sign, tuf, bundle, specs] = await Promise.all([import('@sigstore/sign'), import('@sigstore/tuf'), import('@sigstore/bundle'), import('@sigstore/protobuf-specs')]); + return { sign, tuf, bundle, specs }; + } catch (cause) { + loaded = null; + throw new PrismError( + 'signing needs the sigstore packages (@sigstore/sign, @sigstore/tuf, @sigstore/bundle, @sigstore/protobuf-specs), which are optional dependencies of prism-code and need Node 22.22.2 or newer: ' + + cause.message, + { code: 'attest.unavailable', cause }, + ); + } + })(); + return loaded; +} + +function keyId(publicKey) { + return createHash('sha256').update(publicKey.export({ type: 'spki', format: 'der' })).digest('hex'); +} + +function privateKeyOf(key) { + try { + if (key instanceof KeyObject) return key; + return createPrivateKey(key); + } catch (cause) { + throw new SigningError(`the signing key cannot be read: ${cause.message}; expected an unencrypted PKCS#8 or SEC1 PEM`, { check: 'sign.key', cause }); + } +} + + +async function keyedBuilder(m, key) { + const privateKey = privateKeyOf(key); + const publicKey = createPublicKey(privateKey); + const hint = keyId(publicKey); + const pem = publicKey.export({ type: 'spki', format: 'pem' }); + // Ed25519 signs the message itself; every other scheme signs its SHA-256 digest. + const digest = privateKey.asymmetricKeyType === 'ed25519' ? null : 'sha256'; + const signer = { + sign: async (data) => ({ signature: cryptoSign(digest, data, privateKey), key: { $case: 'publicKey', publicKey: pem, hint } }), + }; + return new m.sign.DSSEBundleBuilder({ signer, witnesses: [] }); +} + +async function readJsonFile(path, what, Error = SigningError, check = 'sign.config') { + try { + return JSON.parse(await readFile(path, 'utf8')); + } catch (cause) { + throw new Error(`${what} ${path} cannot be read: ${cause.message}`, { check, cause }); + } +} + +function tufOptions(options) { + const out = {}; + if (options.tufMirrorUrl) out.mirrorURL = options.tufMirrorUrl; + if (options.tufRoot) out.rootPath = options.tufRoot; + if (options.tufCache) out.cachePath = options.tufCache; + return out; +} + +// sigstore's default is 5 s. A log entry can take longer than that to answer after it is stored, and the +// client then sends the same request again, which the log refuses as a duplicate. +const KEYLESS_FETCH = Object.freeze({ timeout: 30_000, retry: Object.freeze({ retries: 2 }) }); + +/** + * The log already holds this exact entry. Only a re-sent request can do that, because each signature is new: + * an earlier attempt was stored, and its answer was lost or was a 5xx. `bundleBuilderFromSigningConfig` does + * not expose `fetchOnConflict`, which would read that entry back. + */ +const isLogConflict = (error) => error?.code === 'TLOG_CREATE_ENTRY_ERROR' && error.cause?.statusCode === 409; + +/** + * The text with each token replaced, whole and part by part, because a service may quote only a JWT's payload. + * `@sigstore/sign` writes a token it cannot parse into its own message, and that message is printed. + */ +function withoutTokens(text, tokens) { + const parts = tokens.flatMap((token) => [token, ...token.split('.').filter((part) => part.length >= 8)]); + return parts.reduce((out, part) => out.split(part).join('[redacted]'), text); +} + +async function keylessBuilder(m, options, tokens) { + let signingConfig = options.signingConfig; + try { + if (typeof signingConfig === 'string') signingConfig = await readJsonFile(signingConfig, 'the signing configuration'); + if (!signingConfig) { + const tuf = await m.tuf.initTUF(tufOptions(options)); + signingConfig = JSON.parse(await tuf.getTarget(SIGNING_CONFIG_TARGET)); + } + signingConfig = m.specs.SigningConfig.fromJSON(signingConfig); + const source = options.identityToken ? { getToken: async () => options.identityToken } : new m.sign.CIContextProvider('sigstore'); + // Every token passes here, whichever source it came from, so a failure can be cleaned of it. + const identityProvider = { + getToken: async () => { + const token = await source.getToken(); + tokens.push(String(token)); + return token; + }, + }; + return m.sign.bundleBuilderFromSigningConfig({ signingConfig, identityProvider, bundleType: 'dsseEnvelope', fetchOptions: KEYLESS_FETCH }); + } catch (cause) { + if (cause instanceof SigningError) throw cause; + throw new SigningError(`the Sigstore signing configuration is unavailable or unusable:${cause.message}`, { check: 'sign.config', cause }); + } +} + +/** + * Sign statement bytes into a Sigstore bundle v0.3, with `key` or keyless. The + * bundle's JSON is returned; nothing else is written. `attest` stores it in the + * holo, and `push` (#292) stores it as a referrer. + * + * @param {Uint8Array} bytes the in-toto Statement v1 exactly as it is to be signed + * @param {{ key?: string | KeyObject, identityToken?: string, signingConfig?: object | string, tufMirrorUrl?: string, tufRoot?: string, tufCache?: string }} options + * @returns {Promise} + */ +export async function signStatement(bytes, options = {}) { + const m = await sigstore(); + const tokens = []; + const builder = options.key !== undefined ? await keyedBuilder(m, options.key) : await keylessBuilder(m, options, tokens); + try { + const artifact = { data: Buffer.from(bytes), type: DSSE_PAYLOAD_TYPE }; + const signed = await builder.create(artifact).catch((error) => { + if (isLogConflict(error)) return builder.create(artifact); + throw error; + }); + const bundle = m.bundle.bundleToJSON(signed); + // A DSSE verifier skips a signature whose keyid is not its own, and cosign's is not this hash, so a keyed bundle with one + // verifies nowhere but here. The keyid is not signed, and the hint in the verification material still names the key. + if (options.key !== undefined) for (const signature of bundle.dsseEnvelope.signatures) signature.keyid = ''; + return bundle; + } catch (cause) { + if (cause instanceof PrismError) throw cause; + const message = withoutTokens(cause?.message ?? String(cause), tokens); + // The CI identity provider rejects with a plain string; sigstore's own errors carry a code. + const identity = typeof cause === 'string' || /^IDENTITY_TOKEN/.test(cause?.code ?? ''); + throw new SigningError( + typeof cause === 'string' || cause?.code === 'IDENTITY_TOKEN_READ_ERROR' + ? `no OIDC identity token is available: set SIGSTORE_ID_TOKEN, pass identityToken, or run in GitHub Actions with id-token: write (${message})` + : identity + ? `the OIDC identity token cannot be used: ${message}` + : `signing failed: ${message}`, + // Once a token was read, the original error may hold it anywhere, so it is not passed on. + { check: identity ? 'sign.identity' : 'sign.service', cause: tokens.length === 0 ? cause : undefined }, + ); + } +} diff --git a/sdk/npm/prism-code/src/verify-closure.mjs b/sdk/npm/prism-code/src/verify-closure.mjs new file mode 100644 index 000000000..33b1eace1 --- /dev/null +++ b/sdk/npm/prism-code/src/verify-closure.mjs @@ -0,0 +1,201 @@ +/** + * Every trust decision `push` and `pull` need, made here and in no other module + * (issue #449; the steps are those of docs/proposals/292-push-pull-oci.md). + * + * `images` fetches and writes; it hands this module what it fetched, as plain + * facts, and gets back a verdict or a typed refusal. A pull's closure is: + * + * - `holo`: the layer's bytes, already equal to the layer's sha256 digest; + * - `manifestDigest`: the digest of the manifest that names the layer; + * - `claims`: what the manifest and layer annotations say the holo is + * (`fingerprint`, `blake3`), which are only claims until they hold here; + * - `asked`: what the caller asked for (`fingerprint`), if it named one; + * - `referrers`: `{ digest, line }` for every bundle the registry listed. + * + * Nothing here reads the network or a file, apart from the policy file a policy + * option names, and nothing here writes. + * + * Experimental until the v0.6 freeze (STABILITY.md section 6). + */ +import { parseArchive } from './archive.mjs'; +import { blake3Hex } from './blake3.mjs'; +import { readAttestations, DSSE_PAYLOAD_TYPE } from './attestations.mjs'; +import { checkSubjects, experimental_verifyAttestations, experimental_verifyBundle } from './attest.mjs'; +import { check, policyOf } from './check.mjs'; +import { MINIMUM_LEVEL_ENV } from './verify.mjs'; +import { errorFromVerdict, AttestationNotFoundError, DigestMismatchError, PrismCodeError, PrismError, PullVerificationError, VerificationError } from './errors.mjs'; +import { ASSURANCE } from './vendor/verify.mjs'; + +const decoder = new TextDecoder('utf-8', { fatal: true }); +const hexOf = (digest) => digest.slice(digest.indexOf(':') + 1); + +/** The signer options `experimental_verifyAttestations` takes; any one of the first four makes a signer policy. */ +export const SIGNER_OPTIONS = Object.freeze(['key', 'certificateIdentity', 'certificateIdentityRegexp', 'certificateOidcIssuer']); +const signerOptions = (options) => Object.fromEntries(['type', ...SIGNER_OPTIONS, 'trustedRoot', 'entries', 'timestamps', 'tufMirrorUrl', 'tufRoot', 'tufCache'].filter((name) => options[name] !== undefined).map((name) => [name, options[name]])); +const namesSigner = (options) => SIGNER_OPTIONS.some((name) => options[name] !== undefined); + +/** + * Push, step 1: nothing corrupt leaves this machine. The holo's footer and + * labels verify, and every attestation's subjects are blobs of this holo. + * + * @param {Uint8Array} holo + * @returns {{ parsed: object, attestations: object[] }} + */ +export function verifyOutgoing(holo) { + const parsed = parseArchive(holo); + if (!parsed.verification.footer || !parsed.verification.labels) { + throw new VerificationError('the holo does not verify: its footer or a content label differs from the bytes', { check: 'holo.integrity' }); + } + const attestations = readAttestations(parsed); + for (const attestation of attestations) checkSubjects(parsed, attestation); + return { parsed, attestations }; +} + +/** + * Pull, steps 4 and 5: the bytes are a holo, and every BLAKE3 claim about it, + * the caller's and the registry's, equals what its bytes give. + * + * @param {{ holo: Uint8Array, claims?: { fingerprint?: string, blake3?: string }, asked?: { fingerprint?: string } }} closure + * @returns {{ parsed: object, fingerprint: string }} + */ +export function verifyHoloClaims(closure) { + let parsed; + try { + parsed = parseArchive(closure.holo); + } catch (cause) { + if (!(cause instanceof PrismCodeError)) throw cause; + throw new DigestMismatchError(`the pulled bytes are not a holo: ${cause.message}`, { check: 'pull.archive', cause }); + } + if (!parsed.verification.footer) throw new DigestMismatchError(`the holo's footer ${parsed.footer} is not the BLAKE3 of its body, ${parsed.fingerprint}`, { check: 'pull.archive' }); + if (!parsed.verification.labels) throw new DigestMismatchError(`a content blob of the holo does not match its label: ${parsed.verification.labelMismatches.map((m) => m.label).join(', ')}`, { check: 'pull.archive' }); + const fingerprint = `blake3:${parsed.footer}`; + const asked = closure.asked?.fingerprint; + if (asked && asked !== fingerprint) throw new DigestMismatchError(`asked for the holo ${asked}, and the registry sent ${fingerprint}`, { check: 'digest.fingerprint' }); + const claimed = closure.claims?.fingerprint; + if (claimed !== undefined && claimed !== fingerprint) throw new DigestMismatchError(`the manifest says the holo is ${claimed}, its footer says ${fingerprint}`, { check: 'digest.annotation' }); + const file = closure.claims?.blake3; + if (file !== undefined && file !== blake3Hex(closure.holo)) throw new DigestMismatchError(`the layer says its BLAKE3 is ${file}, its bytes say ${blake3Hex(closure.holo)}`, { check: 'digest.annotation' }); + return { parsed, fingerprint }; +} + +/** Pull, step 6: every line decodes, and every subject is a blob of this holo with both digests equal. The verdict reads these lines, so they come first. */ +function checkAttestations(parsed) { + let attestations; + try { + attestations = readAttestations(parsed); + for (const attestation of attestations) checkSubjects(parsed, attestation); + } catch (cause) { + if (!(cause instanceof PrismError)) throw cause; + throw new PullVerificationError(`an attestation in the holo does not hold: ${cause.message}`, { check: 'pull.attestation', cause }); + } + return attestations; +} + +/** + * Pull, step 7: the verdict, which is `check`'s, so one holo and one signer have + * one verdict. The signed statements in the holo count when the signer named + * here vouches for them. Bundles in the registry do not raise the level: they + * are about the manifest, and step 8 judges them. + */ +async function judge(parsed, options) { + const env = options.env ?? process.env; + const policy = await policyOf(options.policy === undefined ? { name: 'pull-default', minimum: env[MINIMUM_LEVEL_ENV] || 'P0' } : options.policy); + const { type, ...signer } = signerOptions(options); + let verdict; + try { + verdict = await check(parsed.bytes, { policy, env, signer: namesSigner(signer) ? signer : undefined }); + } catch (cause) { + if (!(cause instanceof VerificationError)) throw cause; + if (cause.check === 'policy.invalid' || cause.check === 'policy.unreadable') throw cause; + throw new PullVerificationError(`the holo has no verdict: ${cause.message}`, { check: 'pull.verdict', cause }); + } + if (!verdict.passed) { + const why = errorFromVerdict(verdict, ASSURANCE.RANK); + throw new PullVerificationError(`the holo failed policy ${verdict.policy.name}: level ${verdict.level}, requires ${verdict.policy.minimum}; ${why?.check ?? 'policy.level'}: ${why?.message ?? ''}`, { check: 'pull.verdict', verdict, reasons: verdict.reasons, cause: why ?? undefined }); + } + return verdict; +} + +/** What a registry bundle says about itself, or null when it is not a DSSE statement. */ +function readStatement(line) { + try { + const bundle = JSON.parse(decoder.decode(line)); + const envelope = bundle?.dsseEnvelope; + if (envelope?.payloadType !== DSSE_PAYLOAD_TYPE || typeof envelope.payload !== 'string') return null; + const statement = JSON.parse(decoder.decode(Uint8Array.from(atob(envelope.payload), (c) => c.charCodeAt(0)))); + return Array.isArray(statement?.subject) ? { bundle, statement } : null; + } catch { + return null; + } +} + +/** + * A referrer's statement must be about this holo: a subject's `sha256` is the + * manifest digest, and any subject that claims `blake3` is a blob of this holo; + * or every subject is a blob of this holo, which is an in-holo line pushed as is. + */ +function aboutThisHolo(parsed, statement, manifestDigest) { + const hex = hexOf(manifestDigest); + const labels = new Set(parsed.blobs.map((blob) => blob.label)); + const blobs = statement.subject.filter((subject) => typeof subject?.digest?.blake3 === 'string'); + if (blobs.some((subject) => !labels.has(`blake3:${subject.digest.blake3}`))) return false; + try { + checkSubjects(parsed, { subjects: blobs.map((subject) => ({ name: subject.name, digest: subject.digest, blob: `blake3:${subject.digest.blake3}` })) }); + } catch { + return false; + } + return statement.subject.some((subject) => subject?.digest?.sha256 === hex) || (blobs.length > 0 && blobs.length === statement.subject.length); +} + +/** Pull, step 8: with a signer policy, at least one bundle of the holo or of the registry passes it. */ +async function checkSigner(parsed, closure, options) { + if (!namesSigner(options)) return null; + const policy = signerOptions(options); + const inHolo = await experimental_verifyAttestations(parsed.bytes, policy); + const passing = inHolo.results.filter((r) => r.passed).map((r) => ({ source: 'holo', predicateType: r.predicateType, signer: r.signer, time: r.time })); + // A failed signature explains more than a holo with no attestation, so it is what gets reported. + let first = inHolo.error instanceof AttestationNotFoundError ? null : inHolo.error; + const { type, ...rest } = policy; + const judged = new Set(readAttestations(parsed).map((a) => Buffer.from(a.bytes).toString('latin1'))); + for (const referrer of closure.referrers ?? []) { + // A line of the holo pushed as is was judged above; it counts once. + if (judged.has(Buffer.from(referrer.line).toString('latin1'))) continue; + const read = readStatement(referrer.line); + if (!read || (type !== undefined && read.statement.predicateType !== type)) continue; + if (!aboutThisHolo(parsed, read.statement, closure.manifestDigest)) continue; + try { + const outcome = await experimental_verifyBundle(read.bundle, rest); + passing.push({ source: 'referrer', digest: referrer.digest, predicateType: read.statement.predicateType, signer: { identity: outcome.identity, issuer: outcome.issuer, keyId: outcome.keyId }, time: outcome.time }); + } catch (cause) { + if (!(cause instanceof PrismError)) throw cause; + first ??= cause; + } + } + first ??= inHolo.error; + if (passing.length === 0) { + throw new PullVerificationError(`no attestation of this holo passes the signer policy${first ? `: ${first.code}: ${first.message}` : ''}`, { check: 'pull.signer', cause: first ?? undefined, details: { cause: first?.code ?? null } }); + } + return passing; +} + +/** + * Judge a pulled closure, steps 4 to 8, in order: the claims, the attestation + * subjects, the verdict under `policy`, and, with a signer, at least one passing + * bundle. Resolves only when every step has passed; otherwise rejects with the + * typed error of the first that did not. + * + * `policy` is a policy file path or a policy object, as `check` takes; the + * default accepts P0, unless `PRISM_MINIMUM_LEVEL` says otherwise. The signer + * options are those of `experimental_verifyAttestations`. + * + * @param {{ holo: Uint8Array, manifestDigest: string, claims?: object, asked?: object, referrers?: Array<{ digest: string, line: Uint8Array }> }} closure + * @param {object} [options] `{ policy, env, key, certificateIdentity, certificateIdentityRegexp, certificateOidcIssuer, type, trustedRoot, entries, timestamps, tufMirrorUrl, tufRoot, tufCache }` + * @returns {Promise<{ parsed: object, fingerprint: string, attestations: object[], verdict: object, signers: object[] | null }>} + */ +export async function verifyPullClosure(closure, options = {}) { + const { parsed, fingerprint } = verifyHoloClaims(closure); + const attestations = checkAttestations(parsed); + const verdict = await judge(parsed, options); + const signers = await checkSigner(parsed, closure, options); + return { parsed, fingerprint, attestations, verdict, signers }; +} diff --git a/sdk/npm/prism-code/src/verify-namespace.mjs b/sdk/npm/prism-code/src/verify-namespace.mjs index ee4a9096d..fc080add8 100644 --- a/sdk/npm/prism-code/src/verify-namespace.mjs +++ b/sdk/npm/prism-code/src/verify-namespace.mjs @@ -44,6 +44,7 @@ function nodeOnly(member, load) { const checkModule = (member) => nodeOnly(member, () => import('./check.mjs')); const attestModule = (member) => nodeOnly(member, () => import('./attest.mjs')); +const closureModule = (member) => nodeOnly(member, () => import('./verify-closure.mjs')); /** * Refuse `statements`, whose `envelope.verified` is the caller's own claim of a @@ -150,6 +151,16 @@ export const verify = Object.freeze({ format: async (verdict, path = undefined) => (await checkModule('format')).formatVerdict(verdict, path), /** What a verdict at P2 or above trusts the signer for, because no check can know it. Node only. */ limits: async () => (await checkModule('limits')).LIMITS, + /** + * Judge what a pull fetched, before anything is written: the holo's bytes and + * the claims about them, its attestation subjects, the verdict under `policy`, + * and with a signer at least one passing bundle of the holo or the registry. + * `images.pull` gets its answer only from here. See `verifyPullClosure`. Node only. + * + * @param {{ holo: Uint8Array, manifestDigest: string, claims?: object, asked?: object, referrers?: Array<{ digest: string, line: Uint8Array }> }} closure + * @param {object} [options] + */ + pullClosure: async (closure, options = undefined) => (await closureModule('pullClosure')).verifyPullClosure(closure, withoutEvidence(options) ?? {}), policy, attestations, replay, diff --git a/sdk/npm/prism-code/test/attest.test.mjs b/sdk/npm/prism-code/test/attest.test.mjs index b5becd773..002a88e20 100644 --- a/sdk/npm/prism-code/test/attest.test.mjs +++ b/sdk/npm/prism-code/test/attest.test.mjs @@ -25,7 +25,8 @@ import { stripAttestations, blake3Hex, } from '../src/index.mjs'; -import { experimental_attest as attest, experimental_signStatements as signStatements, experimental_verifyAttestations as verifyAttestations, experimental_verifyBundle as verifyBundle, GITHUB_ACTIONS_ISSUER } from '../src/attest.mjs'; +import { experimental_verifyAttestations as verifyAttestations, experimental_verifyBundle as verifyBundle, GITHUB_ACTIONS_ISSUER } from '../src/attest.mjs'; +import { experimental_attest as attest, experimental_signStatements as signStatements } from '../src/attest-write.mjs'; const here = (relative) => fileURLToPath(new URL(relative, import.meta.url)); const holo = new Uint8Array(readFileSync(here('../fixtures/Calculator.holo'))); diff --git a/sdk/npm/prism-code/test/auth.test.mjs b/sdk/npm/prism-code/test/auth.test.mjs index cd13998fe..3c5548438 100644 --- a/sdk/npm/prism-code/test/auth.test.mjs +++ b/sdk/npm/prism-code/test/auth.test.mjs @@ -4,7 +4,7 @@ import { test } from 'node:test'; import assert from 'node:assert/strict'; import { execFile } from 'node:child_process'; -import { chmodSync, copyFileSync, mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs'; +import { chmodSync, copyFileSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs'; import { generateKeyPairSync } from 'node:crypto'; import { tmpdir } from 'node:os'; import { delimiter, join } from 'node:path'; @@ -319,17 +319,36 @@ test('nothing reaches stdout or stderr, even from a helper that prints the secre test('the namespace is what #440 names: it logs in, holds stores and identities, and has no trust decision to make', () => { assert.deepEqual(Object.keys(auth).sort(), ['identities', 'inspect', 'login', 'logout', 'stores']); assert.deepEqual(Object.keys(auth.stores).sort(), ['get', 'list']); - assert.deepEqual(Object.keys(auth.identities).sort(), ['fromKey', 'keyless']); + assert.deepEqual(Object.keys(auth.identities).sort(), ['from', 'fromKey', 'keyless']); assert.deepEqual(Object.keys(auth.identities.fromKey(keys().privateKey)).sort(), ['keyId', 'kind', 'publicKey', 'sign']); assert.deepEqual(Object.keys(auth.identities.keyless()).sort(), ['ambient', 'kind', 'sign']); for (const frozen of [auth, auth.stores, auth.identities]) assert.ok(Object.isFrozen(frozen)); }); -test('it depends only on errors and its own code: attest.mjs is loaded for signStatement and nothing else', () => { +test('it depends only on errors and its own code: oci-auth.mjs and signing.mjs', () => { const source = readFileSync(here('../src/auth.mjs'), 'utf8'); const imported = [...source.matchAll(/^import .* from '([^']+)';$/gm)].map((match) => match[1]).sort(); - assert.deepEqual(imported, ['./errors.mjs', './oci-auth.mjs', 'node:crypto']); - assert.deepEqual([...source.matchAll(/(?:const|let) (\{[^}]*\}) = await import\('([^']+)'\)/g)].map((match) => [match[1], match[2]]), [['{ signStatement }', './attest.mjs']]); - const owned = readFileSync(here('../src/oci-auth.mjs'), 'utf8'); - assert.deepEqual([...owned.matchAll(/^import .* from '(\.[^']+)';$/gm)].map((match) => match[1]), ['./errors.mjs']); + assert.deepEqual(imported, ['./errors.mjs', './oci-auth.mjs', './signing.mjs', 'node:crypto']); + assert.deepEqual([...source.matchAll(/await import\('([^']+)'\)/g)], []); + for (const file of ['oci-auth.mjs', 'signing.mjs']) { + const owned = readFileSync(here(`../src/${file}`), 'utf8'); + assert.deepEqual([...owned.matchAll(/^import .* from '(\.[^']+)';$/gm)].map((match) => match[1]), ['./errors.mjs'], file); + } +}); + +test('every signature in prism-code is made through an auth identity: only auth.mjs imports signing.mjs', () => { + const src = here('../src'); + const importers = readdirSync(src).filter((file) => file.endsWith('.mjs') && /from '\.\/signing\.mjs'|import\('\.\/signing\.mjs'\)/.test(readFileSync(join(src, file), 'utf8'))); + assert.deepEqual(importers, ['auth.mjs']); +}); + +test('identities.from turns the flat signer options attest and push take into one identity', () => { + const { privateKey } = keys(); + assert.equal(auth.identities.from({ key: privateKey }).kind, 'key'); + assert.equal(auth.identities.from({ key: privateKey }).keyId, auth.identities.fromKey(privateKey).keyId); + const keyless = auth.identities.from({ identityToken: 'a.b.c' }); + assert.equal(keyless.kind, 'keyless'); + assert.equal(keyless.ambient, false); + assert.equal(auth.identities.from({}).ambient, true); + assert.equal(auth.identities.from(undefined).kind, 'keyless'); }); diff --git a/sdk/npm/prism-code/test/check.test.mjs b/sdk/npm/prism-code/test/check.test.mjs index c527c3302..b42362f77 100644 --- a/sdk/npm/prism-code/test/check.test.mjs +++ b/sdk/npm/prism-code/test/check.test.mjs @@ -9,7 +9,8 @@ import { join } from 'node:path'; import { fileURLToPath } from 'node:url'; import { generateKeyPairSync } from 'node:crypto'; import { parseArchive, resolveArchive, appendAttestations } from '../src/index.mjs'; -import { experimental_attest, signStatement } from '../src/attest.mjs'; +import { experimental_attest } from '../src/attest-write.mjs'; +import { signStatement } from '../src/signing.mjs'; import { formatVerdict, titleOf, LIMITS, EXIT } from '../src/check.mjs'; const here = (relative) => fileURLToPath(new URL(relative, import.meta.url)); diff --git a/sdk/npm/prism-code/test/fixtures/package-files.json b/sdk/npm/prism-code/test/fixtures/package-files.json index 21c7ed064..d30ffceed 100644 --- a/sdk/npm/prism-code/test/fixtures/package-files.json +++ b/sdk/npm/prism-code/test/fixtures/package-files.json @@ -11,6 +11,7 @@ "src/agents.mjs", "src/archive.mjs", "src/attest-cli.mjs", + "src/attest-write.mjs", "src/attest.mjs", "src/attestations.mjs", "src/auth.mjs", @@ -91,6 +92,7 @@ "src/setup-machine.mjs", "src/setup.mjs", "src/sha256.mjs", + "src/signing.mjs", "src/studio/index.html", "src/studio/studio.css", "src/studio/studio.mjs", @@ -102,6 +104,7 @@ "src/vendor/spec/assurance-levels.mjs", "src/vendor/spec/constants.mjs", "src/vendor/verify.mjs", + "src/verify-closure.mjs", "src/verify-namespace.mjs", "src/verify.mjs", "src/version.mjs", diff --git a/sdk/npm/prism-code/test/images-signed.test.mjs b/sdk/npm/prism-code/test/images-signed.test.mjs index 50c5189e5..7af44df11 100644 --- a/sdk/npm/prism-code/test/images-signed.test.mjs +++ b/sdk/npm/prism-code/test/images-signed.test.mjs @@ -7,7 +7,7 @@ import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { fileURLToPath } from 'node:url'; -import { experimental_attest } from '../src/attest.mjs'; +import { experimental_attest } from '../src/attest-write.mjs'; import { parseArchive, resolveArchive } from '../src/archive.mjs'; import { check } from '../src/check.mjs'; import { PullVerificationError } from '../src/errors.mjs'; diff --git a/sdk/npm/prism-code/test/oci-live.test.mjs b/sdk/npm/prism-code/test/oci-live.test.mjs index c4d9b5dcc..1e02a48a6 100644 --- a/sdk/npm/prism-code/test/oci-live.test.mjs +++ b/sdk/npm/prism-code/test/oci-live.test.mjs @@ -13,7 +13,7 @@ import { join } from 'node:path'; import { fileURLToPath } from 'node:url'; import { parseArchive, resolveArchive } from '../src/archive.mjs'; import { readAttestations } from '../src/attestations.mjs'; -import { experimental_attest } from '../src/attest.mjs'; +import { experimental_attest } from '../src/attest-write.mjs'; import { PullVerificationError } from '../src/errors.mjs'; import { experimental_pull, experimental_push } from '../src/push-pull.mjs'; diff --git a/sdk/npm/prism-code/test/push-pull.test.mjs b/sdk/npm/prism-code/test/push-pull.test.mjs index 9b52c340e..c5732cf67 100644 --- a/sdk/npm/prism-code/test/push-pull.test.mjs +++ b/sdk/npm/prism-code/test/push-pull.test.mjs @@ -10,7 +10,7 @@ import { join } from 'node:path'; import { fileURLToPath } from 'node:url'; import { canonicalJson, parseArchive, resolveArchive } from '../src/archive.mjs'; import { appendAttestations, BUNDLE_MEDIA_TYPE, readAttestations } from '../src/attestations.mjs'; -import { experimental_attest } from '../src/attest.mjs'; +import { experimental_attest } from '../src/attest-write.mjs'; import { blake3Hex } from '../src/blake3.mjs'; import { check } from '../src/check.mjs'; import { DigestMismatchError, ManifestNotFoundError, PullVerificationError, RegistryError, SubjectMismatchError, VerificationError } from '../src/errors.mjs'; diff --git a/sdk/npm/prism-code/test/verify-namespace.test.mjs b/sdk/npm/prism-code/test/verify-namespace.test.mjs index 2b12edf1e..d0528c018 100644 --- a/sdk/npm/prism-code/test/verify-namespace.test.mjs +++ b/sdk/npm/prism-code/test/verify-namespace.test.mjs @@ -44,7 +44,7 @@ async function outcome(call) { } test('the namespace holds exactly these members, frozen all the way down', () => { - assert.deepEqual(Object.keys(verify).sort(), ['attestations', 'check', 'format', 'limits', 'policy', 'replay', 'verdict']); + assert.deepEqual(Object.keys(verify).sort(), ['attestations', 'check', 'format', 'limits', 'policy', 'pullClosure', 'replay', 'verdict']); assert.deepEqual(Object.keys(verify.policy).sort(), ['evaluate', 'input', 'levels', 'minimumLevelEnv', 'names', 'parse', 'read', 'resolve']); assert.deepEqual(Object.keys(verify.attestations).sort(), ['read', 'strip', 'verify', 'verifyBundle']); assert.deepEqual(Object.keys(verify.replay).sort(), ['acceptance', 'digest', 'historySchema', 'json', 'parse', 'predicateType', 'record', 'run']); @@ -236,12 +236,12 @@ test('at load the module needs no Node and reaches only what docs/proposals/440- 'version.mjs', ]); for (const [name, { eager }] of graph) assert.deepEqual(eager.filter((s) => !s.startsWith('.')), [], `${name} imports nothing outside the package at load`); - assert.deepEqual(graph.get('verify-namespace.mjs').lazy.sort(), ['./attest.mjs', './check.mjs'], 'the Node-only half loads on first use'); + assert.deepEqual(graph.get('verify-namespace.mjs').lazy.sort(), ['./attest.mjs', './check.mjs', './verify-closure.mjs'], 'the Node-only half loads on first use'); }); -test('on first use it adds only check.mjs and attest.mjs, whose own imports stay within the same set', () => { - const allowed = new Set([...closure(here('../src/verify-namespace.mjs')).keys(), 'check.mjs', 'attest.mjs']); - for (const entry of ['../src/check.mjs', '../src/attest.mjs']) { +test('on first use it adds only check.mjs, attest.mjs and verify-closure.mjs, whose own imports stay within the same set', () => { + const allowed = new Set([...closure(here('../src/verify-namespace.mjs')).keys(), 'check.mjs', 'attest.mjs', 'verify-closure.mjs']); + for (const entry of ['../src/check.mjs', '../src/attest.mjs', '../src/verify-closure.mjs']) { for (const [name, { eager }] of closure(here(entry))) { assert.ok(allowed.has(name), `${entry} reaches ${name}`); assert.deepEqual(eager.filter((s) => !s.startsWith('.') && !s.startsWith('node:')), [], `${name} imports no package at load`); @@ -253,3 +253,20 @@ test('adding the namespace leaves the package export map as it was: it is reacha const { exports: map } = JSON.parse(readFileSync(here('../package.json'), 'utf8')); assert.deepEqual(Object.keys(map), ['.', './node', './browser', './init', './canonical', './package.json']); }); + +test('pullClosure is the verdict pull gets: it refuses claims that do not hold, and passes a closure that does', async () => { + const holo = calculator; + const manifestDigest = `sha256:${'0'.repeat(64)}`; + const passed = await verify.pullClosure({ holo, manifestDigest, referrers: [] }, none); + assert.equal(passed.verdict.passed, true); + assert.equal(passed.signers, null); + assert.match(passed.fingerprint, /^blake3:[0-9a-f]{64}$/); + const asked = await outcome(() => verify.pullClosure({ holo, manifestDigest, asked: { fingerprint: `blake3:${'1'.repeat(64)}` } })); + assert.deepEqual(asked, { refused: 'digest.fingerprint', name: 'DigestMismatchError' }); + const claimed = await outcome(() => verify.pullClosure({ holo, manifestDigest, claims: { blake3: '2'.repeat(64) } })); + assert.deepEqual(claimed, { refused: 'digest.annotation', name: 'DigestMismatchError' }); + const broken = holo.slice(); + broken[broken.length - 1] ^= 0xff; + assert.equal((await outcome(() => verify.pullClosure({ holo: broken, manifestDigest }))).refused, 'pull.archive'); + assert.equal((await outcome(() => verify.pullClosure({ holo, manifestDigest }, { statements: [] }))).refused, 'policy.invalid'); +}); From 7fbe616deddf23b97908ccee6da23bf65d24bae3 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 12 Nov 2026 04:44:03 +0000 Subject: [PATCH 2/3] chore(prism-code): package allowance for the verify and auth cuts (Part of #449) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013Asa3Mf94yL5KHxQf3uUBS --- .../scripts/package-allowances/verify-trust-auth-signing.json | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 sdk/npm/prism-code/scripts/package-allowances/verify-trust-auth-signing.json diff --git a/sdk/npm/prism-code/scripts/package-allowances/verify-trust-auth-signing.json b/sdk/npm/prism-code/scripts/package-allowances/verify-trust-auth-signing.json new file mode 100644 index 000000000..b0a141eca --- /dev/null +++ b/sdk/npm/prism-code/scripts/package-allowances/verify-trust-auth-signing.json @@ -0,0 +1,4 @@ +{ + "kib": 8, + "reason": "Trust in verify and signing in auth (#449, #447): verify-closure.mjs, signing.mjs and attest-write.mjs split out of push-pull.mjs and attest.mjs, with prism.verify.pullClosure and auth.identities.from (about 9.5 KiB, with the 2.6 KiB left before it)." +} From c0f0c245ac42241d8e807ef3d18bb1e7d5f13ca2 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 12 Nov 2026 04:48:07 +0000 Subject: [PATCH 3/3] ci(conformance): the Rust column is a receipt keyed by its inputs; allowance covers 9.7 KiB (Part of #449) The suite job builds prism-conformance-shim only when no main push has measured the same content identity (git blob ids of the Rust sources, vendored crates, lockfile, toolchain pin, the suite and this workflow). Only receipts from this repository's main pushes are trusted. The matrix unit tests read that receipt or the built shim. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013Asa3Mf94yL5KHxQf3uUBS --- .github/workflows/npm-conformance.yml | 66 ++++++++++++++++--- sdk/npm/conformance/test/matrix.test.mjs | 35 +++++++--- .../verify-trust-auth-signing.json | 4 +- 3 files changed, 84 insertions(+), 21 deletions(-) diff --git a/.github/workflows/npm-conformance.yml b/.github/workflows/npm-conformance.yml index 17d43cdb4..098172395 100644 --- a/.github/workflows/npm-conformance.yml +++ b/.github/workflows/npm-conformance.yml @@ -8,9 +8,10 @@ name: npm conformance # # A runtime joins by adding its shim to sdk/npm/conformance/runtimes.json and a # step to the suite job that writes results/.json; `matrix --check` refuses -# a registered runtime with no results. The Rust shim (DK-42) is built once, in -# the suite job, which is also where the unit tests that run every registered -# runtime run; the OS matrix skips those three and says why. +# a registered runtime with no results. The Rust column (the DK-42 shim) is a +# receipt keyed by the content identity of its inputs: the suite job builds the +# shim only when no main push has measured those inputs. The unit tests that need +# every registered runtime run there; the OS matrix skips those three. on: pull_request: @@ -110,6 +111,10 @@ jobs: name: prism-code and the Rust shim pass, and COMPLIANCE.md is current runs-on: ubuntu-24.04 timeout-minutes: 30 + permissions: + contents: read + # To find and download the Rust receipt of an earlier main push. + actions: read steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: @@ -117,21 +122,62 @@ jobs: - uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 with: node-version: '24' + # The Rust column is a Factory receipt: results/rust.json keyed by the content identity of everything that + # decides it (the git blob ids of the Rust sources, vendored crates, lockfile, toolchain pin, the suite and this + # workflow). A main push that measured the same identity left it as an artifact, so an unchanged Rust input + # set is never rebuilt. Only receipts from this repository's main pushes are trusted. + - name: Identify the Rust runtime's inputs + id: rust + shell: bash + run: | + set -euo pipefail + kappa=$(git ls-files -s -- crates vendor Cargo.toml Cargo.lock rust-toolchain.toml .cargo sdk/npm/conformance \ + .github/workflows/npm-conformance.yml | sha256sum | cut -c1-64) + echo "receipt=conformance-rust-$kappa" >> "$GITHUB_OUTPUT" + - name: Reuse the receipt for those inputs + id: receipt + shell: bash + env: + GH_TOKEN: ${{ github.token }} + NAME: ${{ steps.rust.outputs.receipt }} + run: | + set -euo pipefail + mkdir -p target/conformance/results + run=$(gh api "repos/$GITHUB_REPOSITORY/actions/artifacts?name=$NAME&per_page=20" --jq '[.artifacts[] + | select(.expired == false and .workflow_run.head_branch == "main" + and .workflow_run.head_repository_id == .workflow_run.repository_id)][0].workflow_run.id // empty') + if [ -n "$run" ] && gh run download "$run" -n "$NAME" -D target/conformance/results; then + echo "hit=true" >> "$GITHUB_OUTPUT" + echo "Rust results reused from run $run ($NAME)" + else + echo "hit=false" >> "$GITHUB_OUTPUT" + fi # rust-toolchain.toml pins the toolchain; rustup installs it on first use. - - name: Build the Rust runtime's shim - run: cargo build --locked -p repo-conformance --bin prism-conformance-shim - - name: Unit tests that run every registered runtime + - name: Build the Rust runtime's shim and run the suite against it + if: steps.receipt.outputs.hit != 'true' + shell: bash + run: | + set -euo pipefail + cargo build --locked -p repo-conformance --bin prism-conformance-shim + node sdk/npm/conformance/bin/prism-conformance.mjs run --runtime rust \ + --out target/conformance/results/rust.json | tee target/conformance/rust.txt + - name: Keep the Rust results as the receipt for those inputs + if: steps.receipt.outputs.hit != 'true' && github.event_name == 'push' + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: ${{ steps.rust.outputs.receipt }} + path: target/conformance/results/rust.json + if-no-files-found: error + retention-days: 90 + - name: Unit tests that need every registered runtime working-directory: sdk/npm/conformance run: node --test test/matrix.test.mjs - - name: Run the suite against the JavaScript and Rust runtimes + - name: Run the suite against the JavaScript runtime shell: bash run: | set -euo pipefail - mkdir -p target/conformance/results node sdk/npm/conformance/bin/prism-conformance.mjs run --runtime js \ --out target/conformance/results/js.json | tee target/conformance/js.txt - node sdk/npm/conformance/bin/prism-conformance.mjs run --runtime rust \ - --out target/conformance/results/rust.json | tee target/conformance/rust.txt - name: Regenerate the matrix from those results run: node sdk/npm/conformance/bin/prism-conformance.mjs matrix --results target/conformance/results --write --output target/conformance/COMPLIANCE.md - name: Publish the matrix and the results with this run diff --git a/sdk/npm/conformance/test/matrix.test.mjs b/sdk/npm/conformance/test/matrix.test.mjs index aa2eb69d1..8ecdfd027 100644 --- a/sdk/npm/conformance/test/matrix.test.mjs +++ b/sdk/npm/conformance/test/matrix.test.mjs @@ -2,7 +2,7 @@ import assert from 'node:assert/strict'; import { test } from 'node:test'; import { spawnSync } from 'node:child_process'; -import { existsSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs'; +import { copyFileSync, existsSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { fileURLToPath } from 'node:url'; @@ -11,10 +11,12 @@ import { allChecks, loadScenarios, renderMatrix, sameMatrix, RESULTS_SCHEMA } fr const BIN = fileURLToPath(new URL('../bin/prism-conformance.mjs', import.meta.url)); const COMPLIANCE = fileURLToPath(new URL('../../../../COMPLIANCE.md', import.meta.url)); const JS_SHIM = fileURLToPath(new URL('../../prism-code/conformance/shim.mjs', import.meta.url)); -// runtimes.json registers the Rust shim at this path. The suite job in npm-conformance.yml builds it before these tests; -// where it is not built, a test that runs every registered runtime cannot run, and says why. +// The Rust column comes from the shim runtimes.json registers, or from the results the npm-conformance suite job +// placed for this exact Rust input identity (its receipt). Where neither is here, a test that needs every +// registered runtime cannot run, and says why. const RUST_SHIM = fileURLToPath(new URL('../../../../target/debug/prism-conformance-shim', import.meta.url)); -const everyRuntime = existsSync(RUST_SHIM) ? {} : { skip: 'the Rust shim is not built: cargo build -p repo-conformance --bin prism-conformance-shim' }; +const RUST_RESULTS = fileURLToPath(new URL('../../../../target/conformance/results/rust.json', import.meta.url)); +const everyRuntime = existsSync(RUST_RESULTS) || existsSync(RUST_SHIM) ? {} : { skip: 'no Rust results: cargo build -p repo-conformance --bin prism-conformance-shim' }; const features = [ { @@ -90,8 +92,22 @@ test('line endings do not make the file stale, and any other difference does', ( const cli = (...args) => spawnSync(process.execPath, [BIN, ...args], { encoding: 'utf8' }); +/** Put the Rust results in `dir`: the receipt's when there is one, else a run of the built shim. */ +function rustInto(dir) { + if (existsSync(RUST_RESULTS)) copyFileSync(RUST_RESULTS, join(dir, 'rust.json')); + else assert.equal(cli('run', '--runtime', 'rust', '--out', join(dir, 'rust.json')).status, 0); +} + +/** A results directory with every registered runtime measured. */ +function measured() { + const dir = mkdtempSync(join(tmpdir(), 'prism-conformance-measured-')); + assert.equal(cli('run', '--runtime', 'js', '--out', join(dir, 'js.json')).status, 0); + rustInto(dir); + return dir; +} + test('the committed COMPLIANCE.md is what the suite generates today, and it names all three runtimes', everyRuntime, () => { - const check = cli('matrix', '--check'); + const check = cli('matrix', '--check', '--results', measured()); assert.equal(check.status, 0, check.stdout + check.stderr); const text = readFileSync(COMPLIANCE, 'utf8').replace(/\r\n/g, '\n'); assert.match(text, /^