8000 feat(bep): T129 — Refuse a TPM key the proxy cannot load, and keep a key that may come back by minimal-foundry[bot] · Pull Request #3412 · gominimal/minimal · GitHub
[go: up one dir, main page]

Skip to content

feat(bep): T129 — Refuse a TPM key the proxy cannot load, and keep a key that may come back - #3412

Merged
mitodrummer merged 3 commits into
mainfrom
agent/3326-refuse-a-tpm-key-the-proxy-cannot-load-and-keep
Nov 14, 2026
Merged

mitodrummer merged 3 commits into
mainfrom
agent/3326-refuse-a-tpm-key-the-proxy-cannot-load-and-keep

Conversation

@minimal-foundry
Copy link
Copy Markdown
Contributor

T129 — Refuse a TPM key the proxy cannot load, and keep a key that may come back

slice: S18
kind: task
covers: BEP-089
size: M
est: 180 code, 240 tests
executor: agent
difficulty: needs care
model: standard
diagnostics: each refusal prints to the person who started bep, pinned by its test: "The proxy did not start: the TPM cannot load the proxy's key now (<the TPM's response>). The key is kept; start the proxy again when the TPM is available." for an unreachable TPM or a temporary response; "The proxy did not start: this user cannot read , which holds the proxy's key. The key is kept." for an unreadable file; "The proxy did not start: <the key file|the authorization file> of the proxy's key is missing: . Run bep --replace-key <role> to make a new one. Boxes created before then must be re-created." for a missing file; and "The proxy did not start: this TPM no longer holds the proxy's key. Run bep --replace-key <role> to make a new one. Boxes created before then must be re-created." for a key file the TPM refuses as not its own
observability: each refusal also logs one error line with the role, store=tpm, the TPM's response code and whether the key is kept or lost
layers:
- store:
- crates/bep/src/tpm.rs: sorts a failed load into kept (the TPM cannot be reached, or answers with a temporary response such as TPM_RC_OBJECT_MEMORY or TPM_RC_RETRY, or a file this user cannot read) and lost (a missing key or authorization file, or an integrity or hierarchy error on the key file), as a KeyError that names the role and the case
- crates/bep/src/keys.rs: StartError carries the kept and lost TPM cases, and its Display prints the four refusals above
test: cargo nextest run -p bep an_unreachable_tpm_refuses_start_and_keeps_the_key
test: cargo nextest run -p bep a_tpm_key_the_tpm_cannot_load_refuses_start
test: cargo nextest run -p bep an_unreadable_tpm_key_file_refuses_start_and_keeps_the_key
produces: none
consumes:
- crates/bep/src/tpm.rs
proof: A proxy whose TPM is unreachable, busy or whose key file it cannot read refuses to start and keeps the key, and one whose key is gone refuses and names bep --replace-key for that role.
depends on:
- blocked by #3324

Proof

A proxy whose TPM key does not load at start now refuses to start with one of four messages. If the TPM is unreachable or busy, or this user cannot read the key file or the authorization file, the message says the key is kept and does not name bep --replace-key. If the key file or the authorization file is missing, or the TPM refuses the key file as not its own (TPM_RC_INTEGRITY or TPM_RC_HIERARCHY), the message names bep --replace-key <role> for that role. The tests in crates/bep/src/tpm.rs pin each message.

Notes from the agent: Design: keys.rs adds KeyError::TpmKept / TpmLost, which carry the role and a TpmKept or TpmLost case, and matching StartError variants. StartError::from_store is now pub(crate) so that the tpm.rs tests can use it. It logs one error line with role, store=tpm, response and key=kept|lost. Only the load at start (TpmKey::load, called from find) is sorted. A reload during use after a TPM reset still gives Refused or Store, as before. Sorting: only TPM_RC_INTEGRITY and TPM_RC_HIERARCHY (layer 0, any parameter or handle) are lost. Every other load failure is kept: TCTI or tool errors, warnings such as 0x902 and 0x922, and other codes such as TPM_RC_INITIALIZE and TPM_RC_BAD_AUTH from an owner authorization. This avoids naming a replacement for a key that is not proven lost. A key file that fails to parse or fails check_public is still KeyError::Refused, as before. The TPM never sees such a file, so the task's cases do not cover it. A missing key file counts as lost only when the held authorization file exists and no key file is in the New or Old slot. Otherwise find returns None, so the interrupted-move recovery and the missing-role logic keep their behaviour. The unreadable test chmods the files to 000 for its end-to-end part, and skips that part when the files stay readable (root). The read_error part runs for any user. Printed text: the kept-TPM message comes from the task's diagnostics line and contains a semicolon ("The key …[truncated]

Tests

line exit tail
cargo nextest run -p bep an_unreachable_tpm_refuses_start_and_keeps_the_key 0 warning: unknown fields in task runtime-implement-test-0: network warning: unknown fields in task runtime-implement-test-1: network warning: unknown fields in task runtime-implement-test-2: network help: do you need to update to a newer version of minimal? Running task runtime-implement-test-0 in bo
cargo nextest run -p bep a_tpm_key_the_tpm_cannot_load_refuses_start 0 warning: unknown fields in task runtime-implement-test-0: network warning: unknown fields in task runtime-implement-test-1: network warning: unknown fields in task runtime-implement-test-2: network help: do you need to update to a newer version of minimal? Running task runtime-implement-test-1 in bo
cargo nextest run -p bep an_unreadable_tpm_key_file_refuses_start_and_keeps_the_key 0 warning: unknown fields in task runtime-implement-test-0: network warning: unknown fields in task runtime-implement-test-1: network warning: unknown fields in task runtime-implement-test-2: network help: do you need to update to a newer version of minimal? Running task runtime-implement-test-2 in bo

Verify

min task run agent-verify passed ([tasks.verify]).

Closes #3326

A proxy key in the TPM that does not load at start now stops the start
with a refusal that says whether the key is kept or lost (BEP-089).

Kept: the TPM cannot be reached, answers with a temporary or any other
response that does not say the key is lost, or a key file or
authorization file this user cannot read. These refusals name no
replacement.

Lost: a missing key file or authorization file, or TPM_RC_INTEGRITY or
TPM_RC_HIERARCHY on the key file. These refusals name
`bep --replace-key <role>`.

Each refusal logs one error line with the role, store=tpm, the
response code and whether the key is kept or lost.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai
coderabbitai Bot commented Nov 13, 2026 •
Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 74a7048a-31b8-497a-b92b-cc3a75f39ceb

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@minimal-foundry
minimal-foundry Bot commented Nov 13, 2026 •
Copy link
Copy Markdown
Contributor Author

Approved: every review thread resolved at d4269e5fd013.

@norrietaylor resolved the last thread, which releases the approval this review had withheld.

Nothing to do.

@minimal-foundry minimal-foundry Bot left a comment
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minimal-review — advisory review

Verdict COMMENT — 3 findings, 3 inline.

Panel: 3 of 3 personas ran (correctness, security, supply-chain).

Comment thread crates/bep/src/tpm.rs Resolved
Comment thread crates/bep/src/tpm.rs Resolved
Comment thread crates/bep/src/tpm.rs Resolved
@minimal-arch minimal-arch Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arch-review: CONDITIONS · 2 conditions · the full ruling

Most of the change conforms to Gatehouse §6.10, and the store and refusal code are in the right files. Two paths report the wrong state of the key. First, load_error treats a TPM_RC_HIERARCHY from tpm2_createprimary as a lost key. A disabled owner hierarchy returns that code, and the key still works after a TPM reset. Section 6.10 line 839 says the key persists across restarts, so C1 keeps that case. Second, generate_files now passes TpmKept/TpmLost out of a failed generation after it removes the files. C2 maps them to KeyError::Store.

Outside the diff

  • crates/bep/src/tpm.rs:910: C2 · Map KeyError::TpmKept and KeyError::TpmLost to store_err(..) here, as Refused is mapped. A failed generation must be KeyError::Store, as KeyStore::generate_in says. The BEP-088 store choice (§6.10 line 837) depends on it.

Ruled at d99e74f against gominimal/arch@15b603e6afb8 by claude-opus-5-5.

Comment thread crates/bep/src/tpm.rs Resolved
Comment thread crates/bep/src/tpm.rs Resolved
A hierarchy error from tpm2_createprimary says the owner hierarchy is
off now, not that the key file is bad, so the start keeps the key and
names no replacement. Only tpm2_load can report a lost key.

A replacement over a key whose key file is gone now treats the label
as empty, and reports that no key is in use when generation fails.

read_key no longer passes a missing-file case that it cannot reach.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@minimal-foundry
Copy link
Copy Markdown
Contributor Author

Round 1 of 10 on the runtime's review findings, pushed as 92d780e7cd01.

line exit tail
cargo nextest run -p bep an_unreachable_tpm_refuses_start_and_keeps_the_key 0 warning: unknown fields in task runtime-implement-test-0: network warning: unknown fields in task runtime-implement-test-1: network warning: unknown fields in task runtime-implement-test-2: network help: do you need to update to a newer version of minimal? Running task runtime-implement-test-0 in bo
cargo nextest run -p bep a_tpm_key_the_tpm_cannot_load_refuses_start 0 warning: unknown fields in task runtime-implement-test-0: network warning: unknown fields in task runtime-implement-test-1: network warning: unknown fields in task runtime-implement-test-2: network help: do you need to update to a newer version of minimal? Running task runtime-implement-test-1 in bo
cargo nextest run -p bep an_unreadable_tpm_key_file_refuses_start_and_keeps_the_key 0 warning: unknown fields in task runtime-implement-test-0: network warning: unknown fields in task runtime-implement-test-1: network warning: unknown fields in task runtime-implement-test-2: network help: do you need to update to a newer version of minimal? Running task runtime-implement-test-2 in bo

Verify min task run agent-verify passed.

Review threads the coder judged:

  • 👍 valid — crates/bep/src/tpm.rs:217: load_error now reports a lost key only when tpm2_load gives the integrity or hierarchy code. The same code from tpm2_createprimary keeps the key. A test pins this.
  • 👍 valid — crates/bep/src/tpm.rs:1184: replace_outcome now treats a lost key file as an empty label and runs the recovery path. Any other lost TPM key sets held to false, so a failed generation reports that no key is in use.
  • 👍 valid — crates/bep/src/tpm.rs:821: read_key now calls a new unreadable_error helper, which takes no missing-file case. read_error keeps that case only for the authorization file.

A proxy whose TPM is unreachable, busy, or whose owner hierarchy is off, or whose key file this user cannot read, refuses to start and keeps the key. A proxy whose key file or authorization file is gone, or whose key file the TPM refuses as not its own, refuses to start and names bep --replace-key <role>.

Notes from the agent: Revise round 1. The full bep suite also passed once after the change (309 passed). No new test pins the replace_outcome change for a lost key file. That state reaches recover_interrupted, which finds no side-slot key because lost_key_file needs both side slots empty, so held becomes false. MissingAuthFile and NotThisTpm set held to false without recovery, because a key file is still under the label.

@minimal-arch minimal-arch Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arch-review: PASS · the full ruling

The change conforms to Gatehouse §6.10 line 839. A TPM key that does not load at start refuses the start. The proxy never regenerates the key silently and never falls back to another store. The commit 92d780e7 keeps a key when tpm2_createprimary returns a hierarchy error, and when a key file exists but the read fails. Only a missing file or a tpm2_load integrity or hierarchy error names bep --replace-key. No conditions are open.

Ruled at 92d780e against gominimal/arch@15b603e6afb8 by claude-opus-5-5.

@minimal-foundry minimal-foundry Bot left a comment
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minimal-review — approval withheld

Verdict COMMENT — APPROVE withheld: 5 unresolved threads — minimal-foundry[bot] crates/bep/src/tpm.rs:217, minimal-foundry[bot] crates/bep/src/tpm.rs:1184, minimal-foundry[bot] crates/bep/src/tpm.rs:821, minimal-arch[bot] crates/bep/src/tpm.rs, minimal-arch[bot] crates/bep/src/tpm.rs:1000. No findings.

Panel: 3 of 3 personas ran (correctness, security, supply-chain).

@norrietaylor
Copy link
Copy Markdown
Member

/revise arch C2 (thread PRRT_kwDOPdfcxM63UKOJ): a fresh key that does not load is reported as kept or lost after its files are removed.

Evidence at 92d780e7: in crates/bep/src/tpm.rs, generate_files calls self.open(role, &bytes, auth). On an error it removes the key file and the authorization file, and maps only KeyError::Refused to a store error. A TpmKept or TpmLost from load_error passes through unchanged. The start path then logs key = "kept" (keys.rs line 545) or names a lost key for a key that no longer exists.

Do:

  1. In generate_files, map every error from open() after the files are removed to KeyError::Store for the role, with the detail of the original error (TpmKept, TpmLost and Refused alike). A generation failure is a store error, as KeyStore::generate_in promises.
  2. Keep find as it is: load_error's TpmKept/TpmLost sorting applies only to a stored key at start.
  3. Add a unit test: a fake tpm2_load that fails with a lost-key code during generate_in gives KeyError::Store, leaves no key or auth file in the slot, and is not TpmKept or TpmLost.

generate_files removes the key and authorization files when the new
key does not load. The kept and lost sorting is for a stored key at
start, so map every load error there to KeyError::Store for the role.
@minimal-foundry
Copy link
Copy Markdown
Contributor Author

Round 2 of 10 on a /revise note, pushed as d4269e5fd013.

line exit tail
cargo nextest run -p bep an_unreachable_tpm_refuses_start_and_keeps_the_key 0 warning: unknown fields in task runtime-implement-test-0: network warning: unknown fields in task runtime-implement-test-1: network warning: unknown fields in task runtime-implement-test-2: network help: do you need to update to a newer version of minimal? Running task runtime-implement-test-0 in bo
cargo nextest run -p bep a_tpm_key_the_tpm_cannot_load_refuses_start 0 warning: unknown fields in task runtime-implement-test-0: network warning: unknown fields in task runtime-implement-test-1: network warning: unknown fields in task runtime-implement-test-2: network help: do you need to update to a newer version of minimal? Running task runtime-implement-test-1 in bo
cargo nextest run -p bep an_unreadable_tpm_key_file_refuses_start_and_keeps_the_key 0 warning: unknown fields in task runtime-implement-test-0: network warning: unknown fields in task runtime-implement-test-1: network warning: unknown fields in task runtime-implement-test-2: network help: do you need to update to a newer version of minimal? Running task runtime-implement-test-2 in bo

Verify min task run agent-verify passed.

Review threads the coder judged:

  • 👎 invalid — PRRT_kwDOPdfcxM63UKOH: Already so on this branch: load_error sorts a response as lost only when it comes from tpm2_load. A tpm2_createprimary failure, including TPM_RC_HIERARCHY, is TpmKept::Unavailable. The an_unreachable_tpm_refuses_start_and_keeps_the_key test pins this. (not posted on the thread: not an open thread on the pull request)
  • 👍 valid — crates/bep/src/tpm.rs:1014: generate_files now maps every error from open() to KeyError::Store after it removes the files. A new test with a fake tpm2_load checks the store error and that no key or auth file remains.

A proxy whose TPM is unreachable, busy or whose key file it cannot read refuses to start and keeps the key. A proxy whose key is gone refuses and names bep --replace-key for that role. A new key that the TPM does not load is now a store error, and the log does not call it kept or lost.

Notes from the agent: Revise round 2. generate_files now maps every error from open() to KeyError::Store for the role, after it removes the files. The detail of the original error stays in the message. find does not change. The new unit test needs fake tpm2-tools, so TpmStore has a private tools: Option<PathBuf> field. It is None in production, where the tools come from PATH as before, and only the test sets it. The new test name starts with a_tpm_key_the_tpm_cannot_load_refuses_start, so that test: line runs it. cargo clippy -p bep --all-targets is clean. I did not run just ci or clippy-strict.

@minimal-arch minimal-arch Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arch-review: PASS · the full ruling

The change conforms to the design. The new commit makes a failed load of a just-generated TPM key a store error, and it removes both files. Thus the kept and lost refusals apply only to a stored key, as section 6.10 line 839 requires. The test seam for tpm2-tools is private and is None in production. The PASS on 92d780e7 stands for the rest of the change.

Ruled at d4269e5 against gominimal/arch@15b603e6afb8 by claude-opus-5-5.

@minimal-foundry minimal-foundry Bot left a comment
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minimal-review — approval withheld

Verdict COMMENT — APPROVE withheld: 1 unresolved thread — minimal-arch[bot] crates/bep/src/tpm.rs:1014. No findings.

Panel: 3 of 3 personas ran (correctness, security, supply-chain).

@minimal-foundry minimal-foundry Bot left a comment
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minimal-review — approved

Verdict APPROVE — every review thread is resolved; @norrietaylor closed the last one. The review of d4269e5fd013 withheld this approval on the threads open then. Posted as a comment: the App cannot approve its own pull request; the check and the label carry it.

@minimal-foundry minimal-foundry Bot added the review:approved minimal-review approved the current head label Nov 13, 2026
@mitodrummer
mitodrummer added this pull request to the merge queue Nov 14, 2026
Merged via the queue into main with commit 8c5716f Nov 14, 2026
40 checks passed
@mitodrummer
mitodrummer deleted the agent/3326-refuse-a-tpm-key-the-proxy-cannot-load-and-keep branch November 14, 2026 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:approved minimal-review approved the current head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

T129 — Refuse a TPM key the proxy cannot load, and keep a key that may come back

2 participants

0