# alta.attestation/0.1: who signed which files of a chart

<p class="generated-note">Generated from <a href="https://github.com/altasystem-ai/alta/blob/main/docs/standards/alta-attestation-0.1.md"><code>docs/standards/alta-attestation-0.1.md</code></a> · <code>npm run docs:gen</code></p>

Code: [`core/charts/attest.ts`](https://docs.altasystem.ai/reference/advanced/core-api/charts-attest) (the format, the DSSE pre-authentication encoding, `verifyEnvelope`, pure),
[`core/charts/risk.ts`](https://docs.altasystem.ai/reference/advanced/core-api/charts-risk) (`riskOf`, the computed risk level), `tools/cli/src/{attest,verify,ed25519}.ts` (`alta attest`,
`alta verify`, `alta repo sign`), `verifyIndex` in `tools/cli/src/repos.ts` (the index signature at `alta repo
update`). Tests: [`tests/attest.test.ts`](https://github.com/altasystem-ai/alta/blob/main/tests/attest.test.ts), [`tests/risk.test.ts`](https://github.com/altasystem-ai/alta/blob/main/tests/risk.test.ts), [`tests/cli-verify.test.ts`](https://github.com/altasystem-ai/alta/blob/main/tests/cli-verify.test.ts), [`tests/cli-repos.test.ts`](https://github.com/altasystem-ai/alta/blob/main/tests/cli-repos.test.ts).
Fixture: [`examples/charts-repo/index.json.sig`](https://github.com/altasystem-ai/alta/blob/main/examples/charts-repo/index.json.sig) and `repo-key.pub`.

Status: **alpha**. This format can still change before its 1.0; a change follows the versioning rules of the project and is announced in the changelog.

An **attestation** is a signed statement about one version of a chart: "these exact files, whose tree digest is this,
are `<id>@<version>`, and I publish them" (or "I reviewed them"). It answers one question: **who signed these exact
files**. It does not say the files are harmless; the boundary stays the closed lists, the permissions floor and the
consent step ([alta-chart-0.1](alta-chart-0.1) §8 and §15).

Everything is checked offline, with Ed25519 keys and nothing but `node:crypto`. The format is the one the supply-chain
tools already read: a DSSE envelope (Dead Simple Signing Envelope, the `secure-systems-lab/dsse` specification) around
an in-toto Statement v1 (https://in-toto.io, the `in-toto/attestation` specification).

## 1. Format

```
Envelope (DSSE) {
  payloadType: "application/vnd.in-toto+json"
  payload: base64 of the Statement's JSON bytes
  signatures: [ { keyid?: string, sig: base64 of the Ed25519 signature } ]   at least one
}

Statement (in-toto v1) {
  _type: "https://in-toto.io/Statement/v1"
  subject: [ { name: "<chart id>@<version>", digest: { sha256: <tree digest, alta.tree/1> } } ]
  predicateType: one of the table below
  predicate: object
}
```

The tree digest is the one `alta package` prints (`alta.tree/1`: the sha256 of one line per file,
`<sha256 of the file> <size> <path>\n`, sorted by path). It depends only on the files' paths and bytes, so the same attestation holds for the
chart folder, its archive, and a checkout of its source at the pinned commit.

| Type | predicateType | Who signs | predicate |
|---|---|---|---|
| `publish` | `https://altasystem.ai/attestations/chart-publish/v0.1` | the publisher, about what they publish | `{ chart, version, kind, publisher?, created }` |
| `review` | `https://altasystem.ai/attestations/chart-review/v0.1` | a maintainer of a repository, about a review | `{ chart, version, tier, audit: { status, at } }` |
| `provenance` | `https://slsa.dev/provenance/v1` | a CI build (SLSA provenance v1, https://slsa.dev/spec/v1.0/provenance) | named only: not written by `alta` in this version |
| `index` | `https://altasystem.ai/attestations/index/v0.1` | a repository, about its `index.json` (subject `index.json`, the sha256 of its bytes) | `{ repo?, generatedAt? }` |

Files: `<id>-<version>.publish.intoto.json` (or `.review.intoto.json`) next to the archive, never inside the chart
folder (it would change the digest). An index's signature is `index.json.sig` next to `index.json`. The index lists a
version's attestations in `attestations: [ { type, url, keyid? } ]` ([alta-index-0.1](alta-index-0.1) §2).

## 2. Signature

Ed25519 (RFC 8032) over the DSSE **pre-authentication encoding**, never over the payload alone:

```
PAE(type, body) = "DSSEv1" SP LEN(type) SP type SP LEN(body) SP body
```

where `LEN` is the length in bytes, in ASCII decimal, and `SP` one space. The DSSE specification's test vector,
`PAE("http://example.com/HelloWorld", "hello world")` = `DSSEv1 29 http://example.com/HelloWorld 11 hello world`, is in
[`tests/attest.test.ts`](https://github.com/altasystem-ai/alta/blob/main/tests/attest.test.ts), with the first Ed25519 vector of RFC 8032.

Base64 is standard (with padding) when written; standard and URL-safe are both read, as DSSE allows. `keyid` is a
hint (`alta attest` writes `ed25519:` and the first 16 hex characters of the sha256 of the public key): a verifier
tries every key it trusts, so a wrong `keyid` never makes a signature pass or fail.

## 3. Keys

| Key | Where it is | Who trusts it |
|---|---|---|
| a publisher's | `publishers.<id>.keys: [ { id, alg: "ed25519", public, revoked? } ]` of an index (`public`: the 32 raw bytes in base64) | `alta verify --repo <name>` for the charts of that publisher |
| a repository's | given to `alta repo add <name> <url> --key <file>`, kept in `repos.json` (`key: { alg: "ed25519", public }`) | `alta repo update` for `index.json.sig`; `alta verify --repo <name>` too |
| any | a file given to `alta verify --key <file>` | that one command |

A public key file holds the 32 raw bytes in base64, or a PEM `PUBLIC KEY` (SPKI). A **revoked** key (`revoked`: the
ISO date) is refused, and the refusal names it: `signed by a revoked key: <id> (<publisher>), revoked on <date>`. A
signature by a revoked key is refused whatever its date: the date says when the publisher stopped trusting it, not
since when.

A private key is an Ed25519 key in PEM (PKCS#8, `PRIVATE KEY`). It is read **from a file path only** (`--key <file>`,
or the environment variable `ALTA_SIGNING_KEY_FILE`), never from an argument value; the file must be readable by its
owner only (`chmod 600`), or it is refused. Its content is never printed, logged or copied. `alta` never generates a
key: `openssl genpkey -algorithm ed25519 -out publisher.key` and `openssl pkey -in publisher.key -pubout -out
publisher.pub` do.

## 4. Commands

```
alta attest <dir|archive> --key <private key file> [--type publish|review] [--audit <status>] [--tier <tier>] [--out <file>] [--json]
alta verify <chart folder | archive | index.json> [--attestation <file>] [--key <public key file> | --repo <name>] [--json]
alta repo sign <index.json> --key <private key file> [--out <file>]
```

- `alta attest` lints the folder, computes its tree digest, signs a `publish` statement (or a `review`, which needs
  `--audit` and `--tier`) and writes `<id>-<version>.<type>.intoto.json` in the current folder. It is for publishers
  and reviewers.
- `alta verify` recomputes the tree digest of the folder or the archive, reads the attestation (`--attestation`, or
  `<id>-<version>.publish.intoto.json`, then `.review.intoto.json`, next to it and in the current folder), checks the
  subject and the digest, then the signature against `--key`, or against the keys of a repository added here (`--repo`:
  the chart's publisher's keys of its cached index, and the repository's key). With `--repo`, the digest must also be
  the one the index lists for that version. It prints who signed what and the chart's computed risk level (§6), and
  says that a signature does not mean harmless. Given an `index.json`, it checks `index.json.sig`. Exit 0 verified, 1
  not verified, 2 bad usage. `--json` prints `alta.verify/1`
  with `ok`, `subject`, `digest`, `attestation`, `type`, `signer`, `predicate`, `risk` and `problems`.
- `alta repo sign` writes `index.json.sig` for a repository's maintainers (or its CI, with the key in a secret file).

## 5. The index signature (`alta repo update`)

`alta repo update` fetches `index.json`, then `index.json.sig`, and checks the signature before anything is cached:

| The repository was added | `index.json.sig` | Result |
|---|---|---|
| with `--key` | verifies, subject `index.json` with the sha256 of the bytes fetched | cached, `signature verified with the key of <name>` |
| with `--key` | absent, malformed, another key, or another index | refused; the previous cache is kept |
| without `--key` | present | refused: nothing can check it ("add it again with --key") |
| without `--key` | absent | refused, unless the repository was added with `--insecure-unsigned` (a warning at every use) |
| with `--insecure-unsigned` and no `--key` | present | cached, "signature present, not checked" |

`meta.json` keeps the state (`verified`, `present-not-checked`, `absent-allowed`); `alta repo list --json` shows it.

## 6. Risk level (computed)

Every chart has a risk level, `low`, `medium` or `high`, **computed** from what it names (`riskOf` in
[`core/charts/risk.ts`](https://docs.altasystem.ai/reference/advanced/core-api/charts-risk)), never declared by its author. It is written in the index (`risk`), shown on the consent step
before any change (one line for the level, then one line per reason, in English and French) and printed by `alta
verify`. The rules are in [alta-chart-0.1](alta-chart-0.1) §8, "Risk level".

## 7. Errors

| Id | Says |
|---|---|
| `attest.envelope` | not a DSSE envelope: payloadType, payload or signatures missing or malformed |
| `attest.statement` | the payload is not an in-toto Statement v1 with a subject, a known predicateType and a predicate |
| `attest.subject` | the attestation is about another chart, version or type |
| `attest.digest` | the files' tree digest is not the one signed |
| `attest.key` | no key to check against |
| `attest.signature` | no trusted key verifies the signature |
| `attest.revoked` | signed by a revoked key |

`alta verify` prints the fix of each and the page that explains it (`/reference/errors`).

## 8. What it is not

- Not a scan, not a review, not "safe". A `review` attestation records that a maintainer reviewed a version and what
  they concluded; the index's `audit` says the same, and only the index decides what is installable.
- Not keyless: Sigstore (Fulcio, Rekor) may sign the official charts repository's CI later; it needs the network to
  verify fully, which `alta verify` does not.
- No JSON Schema file: an envelope has no `schema` field (it is DSSE's format, not Alta's), so `alta lint` does not
  read it; `alta verify` does.
