311 lines
19 KiB
Markdown
311 lines
19 KiB
Markdown
# Team vaults, policies and team signing (core 0.18.0; review fixes 0.18.1)
|
||
|
||
A **team vault** is a `.custos` file that a small team (1 to 32 people) shares: the team's release-signing keys,
|
||
its target credentials, its external-signer credentials and its approval policy. Each member opens it with the
|
||
**member key** kept in their own vault, so any member's Custos can open it and no server ever can. The pure parts
|
||
live here: the member key, the member slot, the team body, policy evaluation, the `sign.request` canonical form,
|
||
approval statements, the policy proof and the signature envelopes. Transport, prompts and storage are the app's
|
||
(Custos `docs/27_team_vault.md`).
|
||
|
||
```
|
||
member's own vault (two factors) ──► member key (X25519 + Ed25519)
|
||
│ opens its member slot
|
||
team vault ── member slots: team key sealed to each member's X25519 key
|
||
└─ body (XChaCha20-Poly1305 under the team key): roster, policy, signing keys, targets, signers, audit
|
||
```
|
||
|
||
## The member key
|
||
|
||
Every person who is in a team has one member key, made at random the first time they create or join a team, and
|
||
kept in their own vault (body member `member`, below). It never leaves that vault.
|
||
|
||
| Part | |
|
||
| :-- | :-- |
|
||
| `x25519` | 32-byte X25519 secret: the team key is sealed to its public half (custos-seal) |
|
||
| `ed25519` | 32-byte Ed25519 seed: signs the member's approvals |
|
||
| member id | the first 16 bytes of `SHA-256("custos member v1" ‖ ed25519 public ‖ x25519 public)`, 32 hex |
|
||
|
||
The **join code** a joining member's screen shows is `custos_seal::match_code(x25519 public)` (SEAL.md): the member
|
||
who approves the join compares it with the code on their own card.
|
||
|
||
In the member's own vault:
|
||
|
||
```json
|
||
"member": {
|
||
"x25519": "<64 hex>", "ed25519": "<64 hex>", "created": 1794000000000,
|
||
"teams": [ { "id": "<32 hex>", "name": "Domi", "epoch": 3, "identity": "<64 hex: the team identity's public key>" } ]
|
||
}
|
||
```
|
||
|
||
`teams` is what this member has seen: a team vault whose identity differs, or whose epoch is lower than the one
|
||
recorded, is refused (`TeamRollback`): an old copy of the file, or a fork made with an old team key, does not open
|
||
as current. An older Custos drops `member` when it saves: every Custos that saves a member's vault must be 0.18.0
|
||
or later (the member would have to be invited again).
|
||
|
||
## The team vault file
|
||
|
||
Version 2 (FACTORS.md) with one new slot kind and no factor slots:
|
||
|
||
```
|
||
kind 6, member slot (144 bytes)
|
||
16 team id
|
||
16 member id
|
||
4 epoch u32
|
||
108 sealed team key custos-seal box of the 32-byte team key, to the member's X25519 key,
|
||
context "custos team key v1:<team id hex>:<epoch>:<member id hex>"
|
||
```
|
||
|
||
- A team vault has 1 ..= 32 member slots and **only** member slots; a file that mixes member slots with factor,
|
||
pair, single or recovery slots is malformed. All member slots carry the same team id and epoch.
|
||
- The slot is authenticated by its box: the context binds team, epoch and member, so a slot moved to another
|
||
member, team or epoch does not open. The body AAD is the whole header, as for every vault.
|
||
- **Opening** (`Vault::open_team(bytes, &member_key)`): the slot with this member's id, its box opened, the body
|
||
decrypted with the team key. The body must be `"kind": "team"` with the same team id and epoch, and the member
|
||
must be on its roster; else `NotAMember` (no slot, a removed member) or `Corrupted`.
|
||
- A core before 0.18.0 skips kind 6, finds no factor slot and refuses the file: it never misreads a team vault.
|
||
|
||
### Rotation: removing a member
|
||
|
||
`team_remove_member` makes a **new random team key**, raises the epoch and writes member slots for the remaining
|
||
members only. The body (every key, credential and policy) is encrypted under the new key at the next save, so the
|
||
removed member cannot open anything written after. What they could read before stays read: Custos never hands out
|
||
a signing key, but the target and signer credentials they could reveal should be rotated at their source (the
|
||
app's card says which).
|
||
|
||
The **team identity** (an Ed25519 key in the body) does not rotate: it is what Fabrica and every target pin, and a
|
||
removed member never held it outside Custos. Rotating it is a new team.
|
||
|
||
## The team body
|
||
|
||
```json
|
||
{ "format": 2, "kind": "team", "items": [],
|
||
"team": {
|
||
"id": "<32 hex>", "name": "Domi", "created": 1794000000000, "epoch": 1,
|
||
"identity": { "secret": "<64 hex>", "public": "<64 hex>" },
|
||
"members": [ { "id": "<32 hex>", "name": "Mark", "handles": ["mnovak"], "ed25519": "<64 hex>",
|
||
"x25519": "<64 hex>", "added": 1794000000000, "by": "<member id or empty for the founder>",
|
||
"code": "684361" } ],
|
||
"removed": [ { "id": "<32 hex>", "name": "Old", "at": 1794100000000, "by": "<member id>", "epoch": 2 } ],
|
||
"policy": { "text": "<canonical policy JSON>", "sig": "<base64: the identity's signature>" },
|
||
"targets": [ { "id": "<16 hex>", "kind": "ssh-key", "name": "web-1", "project": "mnovak/Arca", "env": "production",
|
||
"host": "web-1.example", "user": "deploy", "secret": "<the credential>", "created": 1794000000000,
|
||
"by": "<member id>" } ],
|
||
"signers": [ { "id": "<16 hex>", "name": "Cloud signing", "adapter": "command", "endpoint": "…",
|
||
"account": "…", "secret": "<the credential>", "certificate": "<base64 DER or empty>",
|
||
"created": 1794000000000, "by": "<member id>" } ],
|
||
"seen": [ { "request": "<64 hex>", "at": 1794000000 } ],
|
||
"audit": [ { "at": 1794000000000, "action": "member-added", "by": "<member id>", "detail": "Petra" } ] },
|
||
"signing": { "keys": [ … ], "audit": [ … ] } }
|
||
```
|
||
|
||
- `handles`: the names Fabrica knows the member by (git host user names), 0 ..= 8 of `[A-Za-z0-9._-]{1,64}`. The
|
||
policy's author rule matches a request's `author` against them (ASCII case-insensitive) and against the member id.
|
||
- `targets` and `signers` are **not items**: an item can be revealed, copied, shared and exported, and these are
|
||
reached only through `team_target_*` and `team_signer_*`. `secret` is never in a view, a `Debug` or an error.
|
||
- `seen`: every request a member of this vault signed or refused as replayed, kept 48 hours (longer than any
|
||
request lives, 25 hours). A request whose hash is in it is refused (`Replayed`).
|
||
- `audit` (team actions; signatures are in `signing.audit`): `team-created`, `member-added`, `member-removed`,
|
||
`policy-set`, `target-added`, `target-removed`, `target-released`, `signer-added`, `signer-removed`,
|
||
`keys-created`. `detail` names, never holds a value. Append-only, newest 5 000.
|
||
- `signing` is the store of SIGNING.md, with the team's keys (below) and its audit; a team audit entry carries
|
||
`by` (the signing member's id), `env`, `release`, `request` (the request hash) and `approvers`.
|
||
|
||
### Team keys
|
||
|
||
`team_create_keys` makes the team's set, once:
|
||
|
||
| id | kind | role | Signs |
|
||
| :-- | :-- | :-- | :-- |
|
||
| `team-release` | `ed25519` | release | `minisign`, `tauri-updater` when the policy asks for 1+ approvals |
|
||
| `team-preview` | `ed25519` | test | the same, when the environment's policy asks for **0** approvals |
|
||
| `team-cosign` | `ecdsa-p256` (new kind) | release | `cosign` when the policy asks for 1+ approvals |
|
||
| `team-cosign-preview` | `ecdsa-p256` | test | `cosign` at 0 approvals |
|
||
|
||
An Android key (`android`, SIGNING.md) is made per app with `team_create_android`; at 0 approvals an `apk` request
|
||
needs a test Android key, else it is `NoKey`. Authenticode is never signed with a key in the vault: a request goes
|
||
to an external signer (`signers`) after the policy is met.
|
||
|
||
**Why 0 approvals uses a different key.** A preview signature is made without anyone looking. It must not be
|
||
mistakable for a release: it is made by a test-role key that production targets do not trust, exactly as today's
|
||
test keys (SIGNING.md). A signature by `team-release` always means the policy's people approved it.
|
||
|
||
## Policy
|
||
|
||
One rule per environment, signed by the team identity:
|
||
|
||
```
|
||
{"v":1,"team":"<32 hex>","rev":2,"envs":[{"env":"preview","approvals":0,"others":false,"approvers":[]},{"env":"staging","approvals":1,"others":false,"approvers":[]},{"env":"production","approvals":1,"others":true,"approvers":[]}]}
|
||
```
|
||
|
||
| Key | |
|
||
| :-- | :-- |
|
||
| `rev` | starts at 1, +1 on every change |
|
||
| `envs` | 1 ..= 8 rules, `env` unique, `[a-z][a-z0-9-]{0,31}`, sorted as written by `Policy::canonical` (the order given) |
|
||
| `approvals` | 0 ..= 10: how many members must approve |
|
||
| `others` | the approvers must not include the release's author, **when the team has 2 or more members** |
|
||
| `approvers` | member ids allowed to approve; empty = every member |
|
||
|
||
Canonical form as for deploy approvals (SIGNING.md): this key order, no spaces, minimal escaping, no newline;
|
||
anything else is refused, not normalised. Signature: Ed25519 by the team identity over
|
||
`"custos team policy v1\0" ‖ text`.
|
||
|
||
**Defaults** (`Policy::default_for(team)`): preview 0, staging 1, production 1 with `others`. A team of one approves
|
||
its own production releases (the `others` rule needs two members); when a second member joins, it applies.
|
||
|
||
### Evaluation
|
||
|
||
`evaluate(policy, roster, env, author, approvers) -> Verdict`, pure:
|
||
|
||
1. No rule for `env`: `UnknownEnv`.
|
||
2. `approvals == 0`: `Allowed { key_role: Test }`.
|
||
3. Eligible = roster members in `approvers` (or all); minus the author when `others` and the roster has ≥ 2 members.
|
||
The author is the member whose id equals `author` or whose handles contain it. Under `others` with 2+ members,
|
||
an author no member is (or an empty one) is `Unsatisfiable` (core 0.18.1): the rule cannot exclude someone it
|
||
cannot recognise, so it refuses instead of letting anyone approve.
|
||
4. Counted = distinct eligible members among `approvers` given. Members not on the roster, ineligible members and
|
||
duplicates are not counted (and listed in `ignored`).
|
||
5. Counted ≥ `approvals`: `Allowed { key_role: Release }`. Eligible < `approvals`: `Unsatisfiable` (no set of
|
||
approvals can ever meet it: say so instead of waiting a day). Else `Need { more }`.
|
||
|
||
## The signing request (`sign.request`, v1)
|
||
|
||
Fabrica asks for a signature with one line of canonical JSON (the app relays it; the core checks it):
|
||
|
||
```
|
||
{"v":1,"op":"sign.request","team":"<32 hex>","id":"<32 hex>","project":"mnovak/Arca","release":"0.7.0","env":"production","author":"mnovak","format":"minisign","artifact":{"name":"Arca_0.7.0_x64-setup.exe","size":25145977,"sha256":"<64 hex>"},"artifact_digest":"<base64>","image":"","pub":"<base64, 32 bytes>","expires":1794003600}
|
||
```
|
||
|
||
| Key | |
|
||
| :-- | :-- |
|
||
| `team` | the team id |
|
||
| `id` | 16 random bytes, hex: the request's own nonce |
|
||
| `project` | 1–128 of `[A-Za-z0-9._/-]` |
|
||
| `release` | 1–64 of `[A-Za-z0-9._+-]` (the version) |
|
||
| `env` | as in the policy |
|
||
| `author` | the release's author as Fabrica knows them, 0–64 of `[A-Za-z0-9._@-]` (empty: unknown) |
|
||
| `format` | `minisign`, `tauri-updater`, `apk`, `cosign`, `authenticode` |
|
||
| `artifact` | `name` (1–200 characters, no `/`, `\` or control characters), `size`, `sha256` (64 lower-case hex) |
|
||
| `artifact_digest` | base64; minisign and tauri-updater: BLAKE2b-512 of the file (64 bytes); apk: 1–4 SHA-512 digests of APK Signature Scheme signed data (64·n); cosign: the image manifest's SHA-256 (32); authenticode: signtool's 32-byte `.dig` |
|
||
| `image` | cosign only, else empty: the image reference without tag or digest, 1–255 of `[a-z0-9._/:-]` |
|
||
| `pub` | Fabrica's one-time X25519 key: the reply is sealed to it, and its match code is the request's code |
|
||
| `expires` | Unix seconds, later than now, at most 25 hours ahead |
|
||
|
||
The **request hash** is `SHA-256(text)`, hex. The **match code** is `match_code(pub)`: Fabrica shows it beside the
|
||
release, every member's card shows it.
|
||
|
||
### Approval statements
|
||
|
||
A member who approves signs, with their member key:
|
||
|
||
```
|
||
Ed25519( "custos team approval v1\0" ‖ request hash (32) ‖ match code (6 ASCII digits) ‖ member id (16) ‖ at (u64 BE, Unix seconds) )
|
||
```
|
||
|
||
`approve(request, shown_code, member_key, now)` refuses (`WrongMatch`) when the code the card showed is not the
|
||
request's match code: a request whose `pub` was swapped after the card was drawn is not approved. A statement whose
|
||
code is not the request's never counts.
|
||
|
||
### Signing
|
||
|
||
`Vault::team_sign(request_text, statements, signer, shown_code, now)` in the vault of the member whose Custos signs:
|
||
|
||
1. parses the request (canonical, fields as above, `team` = this team, not expired), refuses a hash in `seen`
|
||
(`Replayed`);
|
||
2. checks every statement's signature against the roster, and that its code is the request's;
|
||
3. evaluates the policy with the signer's own approval added (a signer approves by signing, and their shown code
|
||
must match: `WrongMatch` otherwise);
|
||
4. picks the key: by format and the verdict's role (`team-release` / `team-preview`, `team-cosign` /
|
||
`team-cosign-preview`, the Android key of that role whose `repos` holds the request's `project`, or for
|
||
authenticode the team's first external signer, never at 0 approvals);
|
||
5. signs, records the request in `seen` and an audit entry with `by`, `env`, `release`, `request`, `approvers`;
|
||
6. returns the reply.
|
||
|
||
A refusal by the policy, the code or the clock changes nothing. A member who refuses on the card records an audit
|
||
entry `refused` and the request's hash in `seen` (`team_refuse`).
|
||
|
||
### The reply (`sign.reply`, v1)
|
||
|
||
Sealed to the request's `pub` with the context `team-sign:<request id>`:
|
||
|
||
```json
|
||
{ "v": 1, "op": "sign.reply", "request": "<request hash>", "format": "minisign",
|
||
"signature": "<the envelope, below>", "payload": "<cosign: the signed payload, else absent>",
|
||
"key": { "id": "team-release", "public": "<minisign.pub text | cosign.pub PEM | certificate PEM>" },
|
||
"signer": { "member": "<member id>", "name": "Petra" },
|
||
"proof": { … } }
|
||
```
|
||
|
||
### The policy proof
|
||
|
||
What makes a signature checkable as *approved by the team's rules*, by anyone who pinned the team identity:
|
||
|
||
```
|
||
{"v":1,"team":"<id>","request":"<request hash>","env":"production","author":"mnovak","policy":"<policy text>","policy_sig":"<b64>","roster":[{"id":"<id>","name":"Mark","handles":["mnovak"],"ed25519":"<hex>"}],"approvals":[{"member":"<id>","code":"684361","at":1794000000,"sig":"<b64>"}],"signer":"<id>","role":"release","signature":"<sha256 hex of the envelope>","at":1794000100}
|
||
```
|
||
|
||
plus `"sig"`: Ed25519 by the team identity over `"custos team proof v1\0" ‖ that text`, carried next to it as
|
||
`{"text": …, "sig": …}`. `role` is `release` or `test` (0 approvals: no approvals listed). For `release`, the
|
||
signer's own approval is one of those that count: the signature is made in an approving member's Custos. `verify_proof(proof, team_identity_public, request_text, envelope, now)` checks both
|
||
signatures, every approval against the roster and the request's code, the request hash and the envelope hash, and
|
||
evaluates the policy again: it accepts only what `team_sign` itself would have signed.
|
||
|
||
## Signature envelopes
|
||
|
||
| `format` | `signature` in the reply | Check it with |
|
||
| :-- | :-- | :-- |
|
||
| `minisign` | the `.minisig` text (prehashed, SIGNING.md) | `minisign -V -P <pub> -m <file>`, minisign-verify |
|
||
| `tauri-updater` | base64 of that `.minisig` text: the content of Tauri's `<file>.sig` | Tauri's updater (minisign-verify) with `pubkey` = base64 of `minisign.pub` |
|
||
| `apk` | base64 of the n RSA PKCS#1 v1.5 SHA-512 signatures (512 bytes each) | apksig pass 2 then `apksigner verify` (the app's `custos-sign apk`) |
|
||
| `cosign` | base64 of the ECDSA P-256 SHA-256 signature (ASN.1 DER) over `payload` | `cosign verify --key cosign.pub --insecure-ignore-tlog=true <image>@<digest>` once attached; `openssl dgst -sha256 -verify cosign.pub -signature sig.der payload.json` |
|
||
| `authenticode` | base64 of what the external signer returned for the `.dig` (RSA PKCS#1 v1.5 over the SHA-256 DigestInfo) | `signtool sign /di`, then `signtool verify /pa`, `osslsigncode verify` |
|
||
|
||
**cosign.** The payload is cosign's *simple signing* JSON, written by Custos (never taken from the request), with the
|
||
keys in this order and no spaces:
|
||
|
||
```
|
||
{"critical":{"identity":{"docker-reference":"<image>"},"image":{"docker-manifest-digest":"sha256:<64 hex>"},"type":"cosign container image signature"},"optional":null}
|
||
```
|
||
|
||
No transparency log is involved: Fabrica attaches it with
|
||
`cosign attach signature --payload payload.json --signature <base64> <image>@sha256:<digest>`, and a target checks it
|
||
with the team's `cosign.pub` (PEM, SubjectPublicKeyInfo) and `--insecure-ignore-tlog=true`, or by fetching the
|
||
`sha256-<digest>.sig` manifest and checking the layer's `dev.cosignproject.cosign/signature` annotation over the
|
||
layer's bytes, which are this payload.
|
||
|
||
## Target credentials
|
||
|
||
A target credential is handed to the Fabrica server for one deployment: `team_target_release(target id, request,
|
||
deployment, now)` returns the plaintext to seal, only when the target's `project` and `env` equal the deployment's,
|
||
**and the request's `mac` was made with that deployment's ticket** (core 0.18.1), and records `target-released`
|
||
with the deployment's request hash.
|
||
|
||
**The ticket.** `team_sign` makes 32 random bytes per signed request, keeps them in the team body (`tickets`, 25
|
||
hours) and puts them in the reply (`"ticket"`, base64), which only the requester can open. A `target.request` ends
|
||
with `"mac":"<base64>"`: HMAC-SHA256(ticket, `"custos team target v1\0"` ‖ the canonical request up to and including
|
||
`"expires":N`, without the closing brace). Knowing a deployment's hash (the service stores every request text; a
|
||
proof names it) is not enough: without the ticket nobody else, not the service and not another connection, can ask
|
||
for its credentials or use up its one release. One release per (target, deployment): a second
|
||
call is `Replayed`. The app seals it to the server's one-time key (`team-target:<id>`); the service hands the box
|
||
out once, to the caller that asked (Custos `docs/27_team_vault.md`).
|
||
|
||
`kind`: `ssh-key` (an OpenSSH private key), `winrm` (user and password), `openssh` (user and password),
|
||
`registry` (a Docker registry token), `kubeconfig` (the kubeconfig text). `secret` ≤ 64 KiB.
|
||
|
||
## Limits (known, not fixed in 0.18.x)
|
||
|
||
- **Every member holds the team's secrets in their Custos**: the team identity, the release keys and the credentials
|
||
are in the body every member decrypts. Custos never hands them out, but a member running a modified build of the
|
||
public core can copy them before they are removed, and then sign directly, write proofs, or build a fork at a higher
|
||
epoch for the remaining members, which `member_note_team` would accept as current. Removing a member you no longer
|
||
trust means a new team (new identity, new keys), not only a new epoch.
|
||
- **Any member can change the policy.** `team_set_rule` is one member's action (audited as `policy-set`, signed by the
|
||
identity). A member who loosens production and then signs their own release passes `verify_proof`. Policy changes
|
||
that need the current policy's approvals are future work; until then, review the team audit.
|
||
|
||
## Crates
|
||
|
||
`custos-team` (pure): member keys, wrapping, policy, request, statements, proof, envelopes, on `ed25519-dalek`,
|
||
`x25519-dalek` through `custos-seal`, `sha2`, `p256` (cosign verification only). `custos-sign` gains `cosign`
|
||
(ECDSA P-256 with `p256`, RFC 6979 deterministic nonces) and `tauri_updater`. `custos-vault` holds the file format,
|
||
the body and `team_sign`.
|