Repository navigation
feat(bep): T131 — Choose each key's store on Linux and start the proxy there - #3418
mitodrummer merged 6 commits into
Conversation
The Linux key store looks up each role in the TPM and in Secret Service. It makes a missing key in the TPM where the TPM creates and loads it, and otherwise in Secret Service. It never makes a key that a store holds. A store that does not answer keeps a missing key, so the start refuses without naming a replacement (BEP-088, BEP-089).
bep, bep serve and bep --replace-key now run on Linux over the Linux key store, in place of the refusal that said bep runs only on macOS (BEP-088, BEP-089).
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
|
Reviewed: no findings; approval withheld, 6 threads unresolved at APPROVE withheld: 6 unresolved threads — minimal-arch[bot] crates/bep/src/linux_store.rs:295, minimal-arch[bot] crates/bep/src/linux_store.rs, minimal-arch[bot] crates/bep/src/linux_store.rs, minimal-arch[bot] crates/bep/src/keys.rs:213, minimal-arch[bot] crates/bep/src/linux_store.rs:463, …. Resolving the last thread releases the approval on this head. Resolve the open threads. Resolving the last one releases the approval on this head; no new review is required. Clobber: not checked in depth. If that was not intentional, restore the earlier change. |
There was a problem hiding this comment.
arch-review: PASS_WITH_CONDITIONS · 1 condition · the full ruling
The Linux key store conforms to Gatehouse §6.10. It uses the TPM where the TPM makes the key, and Secret Service otherwise. It never moves a held key to the other store. One edge remains. relabel and remove_in treat a Secret Service that does not answer as empty. So a replacement can leave the old key in Secret Service, and a later start can load it. Section 6.10 line 839 says a replaced key is dead. A local refusal blocks bep --replace-key on headless hosts, so file the gap as an issue and name it in the PR body (C1).
Ruled at b1c27df against gominimal/arch@15b603e6afb8 by claude-opus-5-5.
| { | ||
| return self.secret_service.relabel(role, from, to); | ||
| } | ||
| if from == Slot::Held { |
There was a problem hiding this comment.
C1 · When Secret Service does not answer, this branch returns Ok(()) for the move of Held aside. The old key then stays under Held in Secret Service after a replacement. start() does not compare its kid with the identity, so a later start can load it. Section 6.10 line 839 says a replaced key is dead. File an issue for this gap and name it in the PR body (C1).
There was a problem hiding this comment.
Addressed in 8ad2f6282e39: The gap holds: relabel returns Ok(()) for Held when Secret Service does not answer, so a replaced key can stay under Held. No code change this round, because the unreachable-as-empty read is what lets a headless host replace a key. The coder cannot file issues. The C1 issue is described in the round notes for a person to file and link.
| self.tpm.remove_in(role, slot)?; | ||
| if self | ||
| .secret_service_answer(role, self.secret_service.holds_in(role, slot)) | ||
| .unwrap_or(false) |
There was a problem hiding this comment.
C1 · This line reads an unanswered Secret Service as false, and the removal skips it. Put this case in the C1 issue together with the relabel branch at line 260.
There was a problem hiding this comment.
Addressed in 8ad2f6282e39: The gap holds: secret_service_holds reads an unreachable Secret Service as false, so remove_in skips it. It belongs in the same C1 issue as the relabel branch. No code change this round. The coder cannot file issues, so a person must file it.
A locked Secret Service read as a keyring with no key. A first start with no identity file then made TPM keys that hid the keys in the keyring. The start now refuses and keeps the keys while a store that can hold them did not answer. generate_in, remove_in and relabel in the Linux key store stop on a locked keyring, so bep --replace-key does not skip an old key there (BEP-089).
|
Round 1 of 10 on the runtime's review findings, pushed as
Verify Review threads the coder judged:
On Linux, bep starts, keeps each key in the store it was generated in, and refuses with the role and the next step when a key is missing or its store cannot be read. A locked Secret Service is no longer read as empty, so a start with no identity file does not make TPM keys over the keys in the keyring. Notes from the agent: Revise round 1. load_with now refuses with the 'The key may be there, so it is kept.' message before it generates any key, while a store that can hold keys did not answer: a locked Secret Service or a TPM store that did not answer. A Secret Service that this session cannot reach does not stop a first start, because a headless host with a TPM must start on its TPM (BEP-088, pinned in linux_key_store_is_the_tpm_where_usable_else_secret_service). So a host whose keys are in a Secret Service that this session cannot reach, and that has no identity file, still makes new TPM keys. Behaviour change: with no usable TPM and a locked keyring, a first start now prints the 'kept' refusal for each role in place of the NoStore message ('no usable TPM and no unlocked Secret Service keyring'). The NoStore message still prints when Secret Service cannot be reached or does not make the key. The test no_tpm_and_no_secret_service_refuses_start now pins both cases. The directive said 2 findings but listed one thread. The second was not in the directive. Ran cargo nextest run -p bep once at the end: 316 passed. Did not run just clippy-strict. |
There was a problem hiding this comment.
arch-review: PASS_WITH_CONDITIONS · 2 conditions · the full ruling
The compare fixes the locked-keyring case correctly. A first start now refuses while a locked keyring can hold the keys, as §6.10 line 839 requires. One gap is left. secret_service_answer sorts every Secret Service error that is not Locked as "cannot be reached". Then can_hide_a_key() lets a first start make TPM keys over a keyring that answered with an error. C1 makes that path refuse. C2 amends spec line 308 and BEP-089 to match the new locked refusal, because the test for line 308 no longer proves its locked case.
Ruled at 6f7019b against gominimal/arch@15b603e6afb8 by claude-opus-5-5.
| Err(err) => { | ||
| let unread = match err { | ||
| KeyError::Locked { .. } => UnreadStore::SecretServiceLocked, | ||
| _ => UnreadStore::SecretServiceUnreachable, |
There was a problem hiding this comment.
C1 · Every Secret Service error that is not Locked comes here, and can_hide_a_key() then lets a first start make TPM keys. A KeyError::Store from a failed secret-tool run means a keyring answered, and it can hold the key. Mark SecretServiceUnreachable only for KeyError::Unreachable and a missing secret-tool. Return every other error, so the start refuses (§6.10 line 839).
There was a problem hiding this comment.
Addressed in f0b14a30616d: secret_service_answer now marks SecretServiceUnreachable only for KeyError::Unreachable and a missing secret-tool, and returns every other error so the start refuses. Tests cover both cases.
| /// Service that this session cannot reach is the headless host that | ||
| /// BEP-088 starts on its TPM, so a first start does not wait for it. | ||
| #[must_use] | ||
| pub fn can_hide_a_key(self) -> bool { |
There was a problem hiding this comment.
C1 · This test of the error kind is correct only when the SecretServiceUnreachable bucket holds a real absence of Secret Service. C1 narrows that bucket in linux_store.rs. Do not change this function.
There was a problem hiding this comment.
Addressed in f0b14a30616d: can_hide_a_key is unchanged. The narrowed bucket in linux_store.rs (thread C1) makes it hold only a real absence of Secret Service.
|
|
||
| // A locked keyring can hold the keys, so the start makes none and | ||
| // says which store it cannot read. | ||
| let locked = self::store(); |
There was a problem hiding this comment.
C2 · This case now asserts StartError::Kept for a locked keyring. Spec line 308 still requires the no-usable-TPM refusal for it. The design (§6.10 line 839) supports Kept. Amend line 308 and add the locked first-start requirement under BEP-089, with this case as its verify test.
There was a problem hiding this comment.
Disputed — not addressed: The code agrees with design section 6.10, as the finding says. The fix is a change to the spec text at line 308 and a new BEP-089 requirement. The spec document is outside this task's layers (crates/bep only), so the spec owner must amend it.
When a key store did not answer, load_with returned only the kept keys and dropped the roles that the store refused. The refusal now names each refused role with its bep --replace-key step, then the kept keys.
|
Round 2 of 10 on the runtime's review findings, pushed as
Verify Review threads the coder judged:
On Linux, Notes from the agent: Revise round 2. keys.rs: StartError::Kept now carries |
There was a problem hiding this comment.
arch-review: PASS · the full ruling
The compare conforms to Gatehouse §6.10. A key that the TPM refuses beside a kept key now prints with bep --replace-key <role>. Before, the Kept refusal dropped it. Line 839 requires a regenerated key to be a named replacement, and this change names it. A missing key in a store that did not answer still names no replacement, so the key is kept. The "keychain" wording on Linux is outside the design. Fix it in the product-text pass.
Ruled at 8ad2f62 against gominimal/arch@15b603e6afb8 by claude-opus-5-5.
Only an unreachable Secret Service or a missing secret-tool reads as a host with no Secret Service. Any other failure means a keyring answered and can hold the key, so the start now refuses and the TPM makes none.
|
Round 3 of 10 on a failed check suite, pushed as
Verify Review threads the coder judged:
On Linux, Notes from the agent: The failed checks are native-daemon-e2e and its aggregator ci-linux-native-success. The e2e failed on |
There was a problem hiding this comment.
arch-review: PASS · the full ruling
The new commit closes a silent-regeneration path. Before it, a Secret Service lookup that failed for any reason other than a lock let a first start make the keys in the TPM. Now only an absent Secret Service lets the TPM start. Any other failure refuses the start, which §6.10 line 839 requires. The baseline ruling stands for the files that the compare does not touch. The PR body still describes the old handling of a malformed item. Update it to match this head.
Ruled at f0b14a3 against gominimal/arch@15b603e6afb8 by claude-opus-5-5.
| fn remove_in(&self, role: Role, slot: Slot) -> Result<(), KeyError> { | ||
| self.tpm.remove_in(role, slot)?; | ||
| if self.secret_service_holds(role, slot)? { | ||
| self.secret_service.remove_in(role, slot)?; | ||
| } | ||
| Ok(()) | ||
| } |
There was a problem hiding this comment.
LOW · correctness · confidence 0.50 · in LinuxStore::remove_in
remove_in removes the TPM key first, and only then asks Secret Service whether it holds the key. If the keyring is locked, secret_service_holds returns an error after the TPM key is gone. The caller then sees a failed removal, but part of the removal has already happened. Check Secret Service first, or accept the locked error before the TPM removal.
What the reviewer checked
self.tpm.remove_in(role, slot)?; if self.secret_service_holds(role, slot)? { ... }
Hand this to an agent
Act on a code-review finding.
File: crates/bep/src/linux_store.rs
Lines: 263-269
Category: correctness
Severity: low (reviewer confidence 0.50)
Finding:
`remove_in` removes the TPM key first, and only then asks Secret Service whether it holds the key. If the keyring is locked, `secret_service_holds` returns an error after the TPM key is gone. The caller then sees a failed removal, but part of the removal has already happened. Check Secret Service first, or accept the locked error before the TPM removal.
First verify this against the code yourself. It is model output and
may be wrong. If it is wrong, or the tradeoff was deliberate, say so
and change nothing.
👍 useful · 👎 noise — react to tell the reviewer. Replying works too, and says more.
There was a problem hiding this comment.
Addressed in e2a9f4402a48: remove_in now asks Secret Service before it removes the TPM key, so a locked keyring stops the removal with the TPM key still in place. A test pins this.
A locked keyring now stops the removal before the TPM loses its key, so a failed removal changes nothing.
|
Round 4 of 10 on the runtime's review findings, pushed as
Verify Review threads the coder judged:
On Linux, Notes from the agent: Round 4 changes only |
There was a problem hiding this comment.
arch-review: PASS · the full ruling
The compare moves the Secret Service lookup in LinuxStore::remove_in before the TPM removal. A locked keyring now stops the removal before the TPM key is removed. This is fail-closed, and it keeps the §6.10 line 839 rule that a held key does not go silently. An absent Secret Service still holds none, so BEP-088 does not change. The new test asserts that the TPM key stays. The PASS on f0b14a3 holds for the rest of the change.
Ruled at e2a9f44 against gominimal/arch@15b603e6afb8 by claude-opus-5-5.
There was a problem hiding this comment.
APPROVE withheld: 6 unresolved threads — minimal-arch[bot] crates/bep/src/linux_store.rs:295, minimal-arch[bot] crates/bep/src/linux_store.rs, minimal-arch[bot] crates/bep/src/linux_store.rs, minimal-arch[bot] crates/bep/src/keys.rs:213, minimal-arch[bot] crates/bep/src/linux_store.rs:463, ….
minimal-review — advisory review
Verdict COMMENT — No findings.
Panel: 1 of 3 personas ran (correctness); did not complete: security, supply-chain.
T131 — Choose each key's store on Linux and start the proxy there
slice: S18
kind: task
covers: BEP-088, BEP-089
size: L
est: 360 code, 360 tests
executor: agent
difficulty: needs care
model: strongest
diagnostics: the refusals print to the person who started
bep, pinned by their tests: "The proxy did not start: this host has no usable TPM and no unlocked Secret Service keyring, so the proxy has nowhere to keep its keys." when neither store can generate a key; "The proxy did not start: no key store it can read holds the proxy's key, and <Secret Service is locked|Secret Service cannot be reached|the TPM cannot be reached>. The key may be there, so it is kept." when a store cannot be read; and "No key store on this host holds the proxy's key. Runbep --replace-key <role>to make a new one. Boxes created before then must be re-created." when every store is readable;bepno longer prints "bep runs only on macOS" on Linuxobservability:
beplogs, at each start on Linux, one line per role with the store that holds its key orstore=none, and one line when a first start chooses a store, with the reason the TPM was not usable when it was notlayers:
- store:
- crates/bep/src/linux_store.rs (new): a key store over the TPM store and the Secret Service store that looks up each role in every store, generates a missing key in the TPM where the TPM creates and loads it and otherwise in Secret Service, never generates a role that another store holds, and reports a store it cannot read
- crates/bep/src/lib.rs: declares the
linux_storemodule for Linux targets- crates/bep/src/keys.rs:
load_withrefuses a missing role without naming the replacement while a store cannot be read;custodyis unchanged, becauseSecretServiceKey::exportable()returnsfalseand a release build holds a Secret Service key (arch ruling 1238)test: cargo nextest run -p bep linux_key_store_is_the_tpm_where_usable_else_secret_service
test: cargo nextest run -p bep no_tpm_and_no_secret_service_refuses_start
test: cargo nextest run -p bep a_held_key_is_never_moved_to_another_store
test: cargo nextest run -p bep a_missing_role_key_refuses_start_and_names_replacement
test: cargo nextest run -p bep a_missing_role_with_an_unreadable_store_refuses_start_and_keeps_the_key
- binary:
- crates/bep/src/main.rs: on Linux,
runtakes the Linux key store in place of the "bep runs only on macOS" refusal, forbep,bep serveandbep --replace-keytest: cargo nextest run -p bep linux_start_runs_on_the_linux_key_store
produces:
- crates/bep/src/linux_store.rs
consumes:
- crates/bep/src/tpm.rs
- crates/bep/src/secret_service.rs
proof: On Linux,
bepstarts, keeps each key in the store it was generated in, and refuses with the role and the next step when a key is missing or its store cannot be read.depends on:
- blocked by #3324
- blocked by #3326
- blocked by #3325
Proof
On Linux,
bep,bep serveandbep --replace-keynow run on a key store over the TPM and Secret Service. The bep runs only on macOS refusal is gone. A first start makes each key in the TPM when the TPM makes and loads it, and otherwise in Secret Service. A later start loads each key from the store that holds it and never makes it in the other store. When a role's key is missing and every store answers, bep refuses with the role andbep --replace-key <role>. When a store is locked or cannot be reached, bep refuses 8000 with the role and that store, and names no replacement. When neither store can make a key, bep refuses with the no usable TPM and no unlocked Secret Service keyring message.Notes from the agent: Design: keys.rs gains a
KeyStore::reach()hook (defaultStoreReach::One, so the macOS keychain path and its texts are unchanged), aKeyError::NoStorevariant, and theStartError::NoStore,KeptandLostrefusals. Their texts are the task's diagnostics text, as written.load_withusesreach()only when a role is missing. A first start (no key in any store that answered, and no published role) still makes keys while Secret Service is locked or cannot be reached, because a headless host with a TPM must start. A locked keyring with keys in it and no identity file therefore looks like a first start. The spec defines a first start through the identity file, so this follows it, but a reviewer can disagree. The TPM store reads only files to find a key, sothe TPM cannot be reachedcomes only from a TPM storeStoreerror during a lookup (for example an I/O error on the key directory). Any Secret Service lookup error that is notLockedcounts asSecret Service cannot be reached, including a missingsecret-tooland a malformed item. That wording is imprecise for a malformed item. When a store refuses a key at lookup (KeyError::Refused) and another role is missing, the old keychain wording (The keychain refused ...) still prints …[truncated]Tests
cargo nextest run -p bep linux_key_store_is_the_tpm_where_usable_else_secret_servicecargo nextest run -p bep no_tpm_and_no_secret_service_refuses_startcargo nextest run -p bep a_held_key_is_never_moved_to_another_storecargo nextest run -p bep a_missing_role_key_refuses_start_and_names_replacementcargo nextest run -p bep a_missing_role_with_an_unreadable_store_refuses_start_and_keeps_the_keycargo nextest run -p bep linux_start_runs_on_the_linux_key_storeVerify
min task run agent-verifypassed ([tasks.verify]).Closes #3327