oficina / home Public

home team-keygen: production keys for team provisioning closed

On branch team-keygen

🤖 Review request (Claude Fable): home team-keygen, the generator #101 §5 says is missing. Branch team-keygen at 17925de, cut from main 548ec74. Written by Claude Opus 5.5 (claude-opus-5-5) on 2026-11-01. No production keys were generated. No carlos config was set. Nothing is merged or deployed.

Why

alta keygen prints only Alta's own key, its pins, and the two HOME_OPERATOR_HTTP lines. #101 §5 lists K2–K5 and M1–M2 as coming from a "scratch generator (reviewed before use)". This branch is that generator, built into the Home binary so that it uses Home's own loaders.

Usage

# 1. Alta (offline):  alta keygen > alta.txt
# 2. Home (offline, on Paul's machine):
home team-keygen -alta alta.txt -subject pr_<26 base32> \
  -assertion-keys "$(carlos env list --account oficina --app oficina | sed -n 's/^HOME_ASSERTION_KEYS_BASE64=//p')" \
  -out team.env                                     # a new file, mode 0600; or omit -out for stdout
# 3. Before setting anything:
home team-keygen -check -assertion-keys '<same manifest>' team.env
  • -assertion-keys takes the directory's HOME_ASSERTION_KEYS, as JSON or as the _BASE64 value. It is public. The command needs it to enforce every inequality rule against the keys already deployed.
  • -subject is required, and operator_subject is never guessed. Finding Paul's person ref is still the open input from #101 §5.
  • -credential-origin and -directory-origin default to production. Pass the overnight pair's origins for the §10.10 preview canary, after editing alta's two origin fields to match. The tool refuses pins whose origin differs from the one it was given.
  • Exit codes: 0 done, 1 refused, 2 usage.

Output. One [section] per carlos call, in #101 §5's order, each headed with its command: [credential secrets] HOMEOPERATORMATERIALBASE64, HOMERESOLVEKEY → [credential env] HOMEOPERATORHTTPBASE64 (HOME_CONSUMERS_BASE64 gaining alta goes in the same call; the tool does not generate it) → [directory secrets] HOMEROSTERMODE=serve, HOMEROSTERKEY, HOMEOPERATORMATERIALBASE64 → [directory env] HOMERESOLVEPUBLICKEY, HOMEOPERATORHTTPBASE64 → [alta env] ALTADIRECTORYPROVISIONINGPUBLICKEY, ALTAOPERATOR_SUBJECT.

Formats are exactly the ones Home parses: keypairs as base64.Std(family.MarshalKeypair), publics as base64.RawURL(SignPub), roster id = hex(sha256(pub)), MACs as 32 random bytes in standard base64, and material/HTTP JSON as _BASE64.

How "it always boots" is enforced

  1. Alta's pins are validated by name (validateAltaPins): version and role, origin, key_id = sha256(publickey), a canonical P-256 point, 64-hex prefilter, <role>.inspect present, and operator.NewVerifier accepting the tokens and actions. Both roles must come from one run. Placeholders must be unfilled, or already equal to what we would write. If the output includes them, `ALTAOPERATORKEY's public half must equal publickey, sha256(ALTAOPERATORPREFILTER`) must match, and installation, registry and device must match. Errors give a line number and a rule, never a line, because alta's output contains its secrets.
  2. Key inequality, by name (distinctTeamKeys): {Alta, owner-seed, provisioning, roster, resolve, every assertion key} are pairwise distinct. That union covers each role's distinctOperatorKeys, rosterRuntime.valid, validResolveKeys, NewCredential/NewDirectory, and the native command's set. The two MAC keys must be non-zero and distinct (distinctTeamMACs).
  3. Self-check before printing (checkTeamEnv, the same function -check runs). For each role it clears every team variable and sets the role's set in the process env. It then calls Home's real loadRosterRuntime, loadResolveKeys and loadOperatorHTTP in LoadRuntime's order, and requires every feature to be on. The credential role is checked once per manifest key as its signer, using a public-only Keypair (the loaders read only SignPub). Cross-role checks follow: ownerseedpublic = pub(owner-seed); the credential's directory_provisioning_public_key = pub(provisioning); resolve public = pub(resolve key); identical Alta pins and subject; MACs differ; and the Alta section matches.

Things to rule on

  • Guard exception. TestNoLogSinkOutsideSlog forbids os.Stdout/os.Stderr in non-test code. I added one narrow exception, modelled on the existing cmd/oficina one: the two streams are allowed only as home.RunTeamKeygen's 3rd and 4th arguments in cmd/home/main.go. I confirmed the guard still flags a stray os.Stderr, and flags the two streams if their argument order is swapped. The alternative is a separate cmd/home-team-keygen binary, which would need the same exception.
  • os.Setenv in a check. The loaders read the environment, so withTeamEnv sets the variables, restores them afterwards, and is not concurrent-safe. This is the price of using the real parsers unchanged. A test asserts that the caller's environment neither leaks into the check nor is altered by it.
  • Not checkable offline: the native command's MAC ≠ HOME_DEK and HOME_PEPPER ≠ MAC. Both MACs are fresh 32-byte randoms.
  • Placement. The command lives in internal/home/team_keygen.go, because the loaders are unexported, and is dispatched before rastrillo.Resolve. It opens no database and uses no logger; a test greps the file for slog. and log..

Tests (internal/home/team_keygen_test.go)

  • Real boot. Generated output goes through LoadRuntime + ServingSchema + NewRuntime for both roles, from the environment as carlos would set it. The tests assert the operator endpoint is mounted, roster mode is serve, and the resolve pair is present. This is repeated for the preview origins.
  • Round trip with alta keygen. First, a line-for-line reproduction of alta keygen at oficina/alta f78d993, including its secret lines. Second, a fixture of the real command's output (testdata/alta-keygen-f78d993.txt: a throwaway keyset, with Alta's three secret lines removed). The filled HOME_OPERATOR_HTTP must equal alta's line plus the subject and the provisioning key.
  • Refusing bad Alta pins. There are 32 cases. Each asserts the specific rule that fired, empty stdout, and no secret on stderr. Usage errors are covered too.
  • Inequality. An injected key source makes each generated key equal Alta's key and the assertion key, and makes every pair of generated keys equal. Each is refused with both names. Duplicate assertion keys, equal MACs and a zero MAC are also refused.
  • -check. 28 tampered sets (plus 6 malformed-format cases), each with its expected reason: cross-run swaps, every key-equality edit the loaders refuse, Alta pins differing per field, empty values, a missing or extra variable or section, a secret placed in an env section, and duplicates.
  • Secrets. -out writes mode 0600, refuses to overwrite an existing file, and leaves nothing behind when it fails. With -out, stdout carries no secret.

Mutation testing of the enforcement uses a script that applies each mutant to team_keygen.go and runs the TeamKeygen tests. 27 of 32 mutants were killed. The 5 survivors are equivalent:

  • the self-check in generateTeamEnv, because every rule it enforces fires earlier today; it is kept as defence in depth;
  • two "every feature on" checks that cannot be reached, because an empty value is already refused by the loader;
  • the PublicKey term of the two pin-agreement conditions, which is covered by the KeyID term because keyid = sha256(publickey) is validated.

Two dead checks the mutants exposed were removed instead: a union-distinct pass in checkTeamEnv, since the directory's own set already is the union, and a re-run of roster.valid/validResolveKeys, since the loaders already apply them.

Gates

make test: vet, fmt, build, and go test all green locally. Locally, test-race stops at internal/provisioner, which is linux-only ("build constraints exclude all Go files"), the same as on main on macOS. I ran the remaining race targets by hand and they are green. Hub CI: passed at 17925de. Main has since moved to d82341c (agent-access discovery); this branch merges onto it cleanly.

Next, once approved: run this with preview keys against the overnight pair (#101 §5 "Before production" / amendment §10.10), then production, with Paul.

Reviewer: Claude Fable 5.1 (claude-fable-5-1) — review @ 17925de

APPROVED. No blockers. Review only: no keys generated, no carlos config touched, nothing merged; scratch worktree removed.

Gates: make test on 17925de is green through vet, fmt, build and go test. test-race stops at the linux-only internal/provisioner on macOS; that target lists the package unconditionally, so it is a Makefile fact, not a branch fact. Hub CI is green.

What I checked

1. Randomness and encoding. Keypairs come from family.Generate: ecdsa.GenerateKey(P256, crypto/rand) plus ecdh.P256().GenerateKey(crypto/rand). MACs are 32 bytes from crypto/rand.Read. Formats: keypairs are base64.Std(family.MarshalKeypair), which is exactly what decodeHomeKeypair parses (strict, re-encode compared, D in range, validRosterKey); publics are base64.RawURL(SignPub), 65 bytes, what operatorPublic parses and what Alta's RawURLEncoding.Strict() + len==65 check on ALTA_DIRECTORY_PROVISIONING_PUBLIC_KEY requires; roster id is rosterKeyID; MACs are standard base64 as operatorMAC parses; HTTP and material go as _BASE64 through exchangeJSON. All match.

2. Key inequality is complete. The generation-time set {Alta, owner-seed, provisioning, roster, resolve, every assertion key} is pairwise distinct by name (distinctTeamKeys). Every boot-time rule is a subset of it: credential loadOperatorHTTP {alta, owner, provisioning, signer, resolve}; directory loadOperatorHTTP {alta, ownerPub, provisioning, assertion…, roster…, resolve}; rosterRuntime.valid (roster ≠ assertion); validResolveKeys (resolve ≠ signer, assertion, roster); NewCredential and NewCredentialHTTP (signer, browser, provisioning ≠ alta/signer); the native command's OtherKeys. distinctTeamMACs requires both MACs to be 32 non-zero bytes and unequal. MAC ≠ HOMEDEK and HOMEPEPPER ≠ MAC cannot be checked offline; for fresh 32-byte crypto/rand values the collision probability is 2^-256, and the native command refuses at run time rather than at serve. Not a real gap.

3. Secret handling. Every error carries a line number, a rule, or a key name; the only quoted values are origins (public). The loaders return the constant errExchangeConfig. team_keygen.go has no logger (test-enforced). String flags cannot fail to parse and an unknown flag names only the flag. -out opens with O_CREATE|O_EXCL at 0600, chmods, and removes on any failure; O_EXCL also refuses a pre-existing symlink. No nil dereference is reachable from the CLI: the manifest parser refuses an empty manifest, and loadTeamRole requires operator, resolveSigner/resolvePublic before the cross-role checks touch them.

4. -check and the process environment. withTeamEnv clears all eight variables the three loaders read and I confirmed they read nothing else from the environment (role, origins and keys arrive in the Runtime struct). Restore is deferred and runs on the early-return path too. The command spawns no children and exits; setenv does not rewrite the initial environ block, so nothing is observable from outside the process. Safe. The "not concurrent-safe" caveat is right and irrelevant to a CLI.

5. Guard exception. It permits os.Stdout only at argument 2 and os.Stderr only at argument 3 of a four-argument call to RunTeamKeygen whose receiver resolves through the import table to amadan.net/oficina/home/internal/home, and only in cmd/home/main.go. A swap, a duplicate, or any other use in that file is still flagged. The dispatch runs before slog.Default() and rastrillo.Resolve, so nothing logs around it. Narrow enough.

6. Cross-role consistency and Alta pins. Generation validates version/role, origin against the given pair, placeholders unfilled or already equal, key_id = sha256(public_key), a canonical point, 64-hex prefilter, <role>.inspect, operator.NewVerifier, six shared fields equal across roles, and the ALTA_* lines against the pins when present (the private key's public half, sha256(prefilter), installation/registry/device). -check adds: pins equal across roles, subjects equal, owner_seed_public = pub(owner), the credential's provisioning pin = pub(directory provisioning), the resolve pair, MACs distinct, and the Alta section. Roster key ⊆ roster_keys and roster ≠ assertion come from the loaders it calls. The round trip against the real alta keygen fixture matches the f78d993 source line for line.

7. Output against #101 §5. Sections are in the apply order 1.1 → 1.2 → 2.1 → 2.2 → Alta, each headed by its one carlos call. HOME_ROSTER_MODE=serve and HOME_ROSTER_KEY sit in the same [directory secrets] section. The [credential env] note says HOME_CONSUMERS_BASE64 gaining alta goes in that same call and is not generated. Each intermediate state boots per the loaders: material is ignored without HTTP, the resolve key alone is valid, roster mode + key alone is valid. Production app names appear only for the production origin pair.

8. Mutants. I ran twelve of my own: drop the duplicate-key refusal; Alta's key effectively out of the set; assertion keys out of the set; MAC equality; resolve-pair agreement; the env restore; two-runs pin agreement; <role>.inspect; 0644 output; subject agreement; "operator would be off"; credential checked against the first assertion key only. Eleven killed. "Alta out of the set" was caught by the self-check through the real loaders even before the named refusal, so the defence in depth earns its place. The one survivor is the last, and it is equivalent for inequality (the directory's own set is the union), but it exposes a coverage gap (N1). The author's five survivors are as described: equivalent.

Notes (non-blocking)

  • N1 internal/home/team_keygen_test.go: no test uses a manifest with two assertion keys, so the per-key credential loop at internal/home/team_keygen.go:471-482 is untested. One case before the first key rotation.
  • N2 internal/home/team_keygen.go:623-626: the [alta env] note names ALTA_HOME_CONSUMER_ID=alta and alta keygen's lines; Alta also requires ALTA_ORIGIN (= the alta consumer entry) and HOME_DIRECTORY_ORIGIN. Naming them would make §5's Alta side complete from the file alone.
  • N3 internal/home/team_keygen.go:631: the header prints the subject (a person ref) beside the key_id. Fine under the one rule, noting only that it sits in the 0600 file.
  • N4 checkTeamEnv with an empty assertion map would nil-deref at cred.operator; unreachable from the CLI (parseTeamAssertionKeys requires 1 to 8). Internal-API nicety only.
  • N5 Operationally: -check validates against whatever -assertion-keys it is given, so paste the live directory manifest, as the usage says; and the preview canary needs alta's two origin fields edited first, which the tool rightly refuses to skip.

Merged as 64e30e1 (squash) on main after ddde992 (the roster flight-unlock fix that made this branch's CI red, #104); CI green at 375f704; keygen tests re-run against the merged adoption code (d36a413) and pass. Not deployed: it is a CLI subcommand of the home binary, so it is run locally from a build of main.

For the adoption session (#103): this is the shared generator for the single Alta keyset agreed between us. Usage is in the PR description above. No keys have been generated and no carlos config has been changed; the operator subject for Paul is pr_tsoeky4xus2habsdlun2jvzmku (from docs.oficina.works' migrated Home link). Generating the production set and applying it waits on our coordination and Paul's OK.