Skip to content

fix(bep): refuse a tpm authorization file that other users can read - #3510

Open
bryan-minimal wants to merge 1 commit into
mainfrom
fix/tpm-auth-file-mode
Open

bryan-minimal wants to merge 1 commit into
mainfrom
fix/tpm-auth-file-mode

Conversation

@bryan-minimal

@bryan-minimal bryan-minimal commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

What

The proxy reads the authorization value of a TPM-held key from a file. Spec 24 says that file is one "only its user can read" (BEP-088). Nothing checked that: a file with mode 0644 loaded like any other.

The proxy now opens the file once, checks on that open file that it belongs to the running user and has no group or other permission bits, and then reads from the same handle, so there is no gap between the check and the read. If the check fails the proxy does not start, keeps the key, and says what to run:

The proxy did not start: other users can read or write <path>, which holds the authorization of the proxy's <role> key (mode 0644). The key is kept; run chmod 600 <path>, then start the proxy again.

A file owned by another user gets its own message.

Is this safe for existing installs

The only writer of this file creates it at mode 0600 in a 0700 directory, and nothing in the repository creates it any other way. So no setup the product itself produces is refused. A file that was copied or restored with wider permissions will now stop the proxy with the message above.

For the spec owner

The spec names the property and does not say what to do when it does not hold. This follows the neighbouring rule for a file the user cannot read (refuse to start, keep the key). The message text is ours; change it freely. One open point: a file that was readable by others may already have been copied, and chmod does not change the value. Whether the message should also point at replacing the key is a call the spec does not make.

Testing

  • A control: files at 0600 and 0400 load.
  • Modes 0644, 0640, 0604, 0620 and 0606 are refused, both at the lookup and at proxy start; neither file changes; after chmod 600 the key loads.
  • A file of another user is refused; the part that needs chown runs only as root.
  • Workspace lint, tests and the native end-to-end script pass on this commit.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • TPM authorization files are now checked to ensure they belong to the proxy’s user and do not grant other users read or write access.
    • If an authorization file is missing, unreadable, owned by another user, or too broadly accessible, the associated key is kept. The resulting message includes file details and guidance for correcting ownership or permissions.

BEP-088 says the proxy reads a TPM key's authorization value from a file
only its user can read. The store wrote the file at mode 0600 but loaded
it at any mode and owner.

At start, the store now opens the authorization file once and checks
the open file: it must belong to this user and give no permission to
group or others. Otherwise the start is refused, the key is kept, and
the message names the file, its mode, and the chmod that fixes it, or
says that the file belongs to another user.

Tests: a 0600 or 0400 file loads; modes that let other users read or
write the file are refused through find and through the start, and
the files are left unchanged; the message for another owner.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bryan-minimal
bryan-minimal requested a review from a team as a code owner November 17, 2026 22:44
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

TPM key lookup now checks the authorization file’s owner and permissions before opening the key. It keeps the key when the file belongs to another user or grants group or other users access, and reports the detected condition with remediation guidance.

Changes: TPM authorization file checks

Layer / File(s) Summary
Kept-key error cases
crates/bep/src/keys.rs
TpmKept now represents ownership and permission failures, includes file details in its display, and provides remediation guidance in StartError messages.
Authorization-file validation
crates/bep/src/tpm.rs
read_auth checks ownership and permissions using the opened file’s metadata. TpmStore::find uses it before key loading. Tests cover accepted modes, rejected modes, ownership mismatch, and key retention.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Find as TpmStore::find
  participant Read as read_auth
  participant AuthFile as Authorization file
  participant Key as TPM key
  Find->>Read: Read authorization file
  Read->>AuthFile: Open once and inspect metadata
  alt Owner differs or group/other permissions are set
    Read-->>Find: Return OtherOwner or NotPrivate
  else File passes checks
    Read->>AuthFile: Read accepted contents
    Read-->>Find: Return authorization contents
    Find->>Key: Open key
  end
Loading

Possibly related issues

Possibly related PRs

  • gominimal/minimal#3314 — This PR defines the Linux key-custody requirement that the TPM authorization file is accessible only to the proxy’s user; this change enforces its ownership and permission rule.

Suggested reviewers: norrietaylor, jtnkminimal

Merge Risk: Minimal · up to dc038

The proxy now refuses to start with a TPM authorization file that another user can read, or that another user owns. It keeps the key and tells the operator how to fix the permissions. No merge-blocking risk is identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title uses a Conventional Commit form (fix(bep): ...), is imperative and lower-case, and names the main change: the proxy now refuses a TPM authorization file that other users can read. The raw …
Description check Passed The description follows the template's main sections. The Summary explains what changes and why, and cites the spec requirement (BEP-088). The Testing section lists the cases run and reports lint, tes…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title uses a Conventional Commit form (fix(bep): ...), is imperative and lower-case, and names the main change: the proxy now refuses a TPM authorization file that other users can read. The raw summary confirms the mode check in read_auth and the new NotPrivate refusal path. The title is concise and matches the changeset.

Full details: Description check

Explanation

The description follows the template's main sections. The Summary explains what changes and why, and cites the spec requirement (BEP-088). The Testing section lists the cases run and reports lint, tests, and the end-to-end script passing. The Checklist is absent. The description does not link an issue with Refs or Closes, and it does not say whether docs were updated. The template asks for both, so the description is mostly complete but has gaps.

Resolution

Consider adding a Closes or Refs line for a related issue, if one exists. Also tick or address the Checklist items: state whether docs were updated for the behavior change, and state whether a BREAKING CHANGE footer applies. The Testing section could paste the relevant command output as evidence, as the template asks.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks the file’s attire,
And guards the key from broad desire.
If modes are loose or owners stray,
The key stays safe another day.
Set six-zero-zero, then hop away.

Recent review info

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: Essentials
  • Run ID: da60b57e-e3f9-4685-be7a-39342af05f89
Commits

Reviewing files that changed from the base of the PR and between a6dd8c9 and dc038e4.

Files selected for processing: 2

  • crates/bep/src/keys.rs
  • crates/bep/src/tpm.rs

Included review availability: This review used your included allowance. Your plan provides up to 5 included reviews per hour; 0 remain after this review.

@minimal-foundry

minimal-foundry Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Approved: no findings at dc038e48f8fc.

Nothing to do.

Clobber: none seen.

@minimal-foundry minimal-foundry Bot left a comment

Copy link
Copy Markdown
Contributor

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 — No findings.

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

@minimal-foundry minimal-foundry Bot added the review:approved minimal-review approved the current head label Nov 17, 2026

@norrietaylor norrietaylor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving. The check and the read share one open handle, find is the only place that reads an authorization file, and every existing writer (write_private, and the integration test that overwrites an existing 0600 file) keeps the mode the new check needs. Two small points inline.

Comment thread crates/bep/src/tpm.rs
// only as root.
// SAFETY: `geteuid` takes no argument, reads process state and
// cannot fail.
if unsafe { libc::geteuid() } != 0 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[low] The OtherOwner branch of read_auth only runs through find when the tests run as root, and CI does not run them as root, so the owner check itself is never exercised there. If the uid comparison were dropped, every test would still pass. One way to test it without root: split the check into a function that takes the metadata's uid and mode plus the expected uid, and pass it a uid that differs from geteuid().

Comment thread crates/bep/src/tpm.rs
}
// Sized up front, so the value is not left behind in a smaller buffer
// that a growing read gives back unzeroed.
let mut auth = Zeroizing::new(Vec::with_capacity(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[nit] The capacity comes from the file's size, and nothing bounds it. An oversized or corrupt authorization file of a few GiB makes the start abort on allocation, with no message. Capping it, for example meta.len().min(4 * AUTH_LEN as u64), keeps the up-front sizing for the real 32-byte file.

This branch has not been deployed

No deployments
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.

2 participants