Skip to content

fix(minvmd): add peer-credential check and provider-directory verification to minvmd control socket - #1853

Merged
norrietaylor merged 3 commits into
mainfrom
inbox-patch/issue-804-peer-cred-b5d014cb8813e861
Oct 3, 2026
Merged

norrietaylor merged 3 commits into
mainfrom
inbox-patch/issue-804-peer-cred-b5d014cb8813e861

Conversation

@gominimal-aw-bot

@gominimal-aw-bot gominimal-aw-bot Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

The minvmd control socket lacked peer credential checks and provider-directory verification, allowing any local process to connect and register boxes.

Changes

  • Peer-credential check on every connection: check_peer_credentials() uses SO_PEERCRED on Linux and getpeereid on macOS to verify the connecting process has the same uid as the daemon. Refused connections are logged once per distinct foreign uid (warn on first, debug thereafter) to avoid log flooding.
  • Provider-directory verification at bind time: the bind tightens a provider dir the daemon owns to 0700 (restrict_owned_dir; StateDir::new creates it 0755 under the umask, so a plain refusal would disable the control socket on every existing install), then verify_provider_dir_ownership() refuses a dir owned by another uid or not 0700, naming the dir, owner, and mode.
  • Trust model documented in the control module docs: same-uid writers are accepted; a per-boot creator token is the pattern if rows must come only from the host-side creator (not built here).
  • Unit tests: control_socket_admits_own_uid (real socket, SO_PEERCRED / getpeereid), control_socket_refuses_foreign_uid (uid decision, no root needed), bind_tightens_an_owned_provider_dir_to_0700, plus sock tests for the dir verification and tightening.

Verification

cargo build --workspace --locked     # passes
cargo fmt --all --check              # clean
cargo clippy -p minvmd -- -D warnings # clean
cargo test -p minvmd --locked        # 219 passed, 0 failed

Routing-Key: inbox-route/I_kwDOSUhdos8AAAABUs9W9g

Summary by CodeRabbit

  • Security
    • Control socket connections are now limited to processes running under the daemon’s system account; connections from other accounts are refused.
    • Provider directories must be owned by the current account and have restricted permissions. Existing directories owned by the daemon are tightened to those permissions when needed.
    • Requests are handled serially, with a 30-second limit per request.

… minvmd control socket

The minvmd control socket lacked peer credential checks and
provider-directory verification, allowing any local process to
connect and register boxes.

Changes:
- Add check_peer_credentials() using SO_PEERCRED (Linux) /
  getpeereid (macOS) on every control-socket connection
- Add verify_provider_dir_ownership() to refuse bind when the
  provider directory is not owned by the daemon's uid or not 0700
- Deduplication logging: warn once per distinct foreign uid,
  debug thereafter
- Unit tests for both checks
- Integration tests (gated behind libkrun + MINVMD_E2E=1)

Routing-Key: inbox-route/I_kwDOSUhdos8AAAABUs9W9g

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@gominimal-aw-bot
gominimal-aw-bot Bot requested a review from a team as a code owner October 3, 2026 05:04
@gominimal-aw-bot gominimal-aw-bot Bot added the agent:fix Agentic fix PR eligible for review iteration; min-aw's worker-iterate gates on it. label Oct 3, 2026
@coderabbitai

coderabbitai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 66333b82-7edf-4ff6-9b14-c51071fb8343
📥 Commits

Reviewing files that changed from the base of the PR and between 6ede29d and 142e2ed.

📒 Files selected for processing (2)
  • crates/minvmd/src/control.rs
  • crates/minvmd/src/sock.rs

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.


📝 Walkthrough

Walkthrough

minvmd now restricts and verifies the provider directory before binding the control socket. It checks each connection’s peer UID before reading a request and drops connections when credential checks fail or the UID does not match.

Changes

Control socket access

Layer / File(s) Summary
Provider directory guard
crates/minvmd/src/sock.rs, crates/minvmd/src/control.rs
Startup tightens an existing provider directory to mode 0700 when the daemon owns it, then verifies directory ownership and permissions before binding. Tests cover validation and startup behavior.
Peer UID admission
crates/minvmd/src/control.rs
Connection handling checks peer credentials before reading requests. Linux uses SO_PEERCRED; other Unix targets use getpeereid. Tests cover matching and foreign UIDs.

Priority: ⬇️ Low

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

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant serve_connection
  participant PeerCredentialAPI
  Client->>serve_connection: Open control-socket connection
  serve_connection->>PeerCredentialAPI: Retrieve peer UID
  PeerCredentialAPI-->>serve_connection: Return UID or credential error
  serve_connection->>Client: Read request only if UID matches daemon effective UID
Loading

Suggested reviewers: norrietaylor

Merge Risk: ⚪ Minimal · up to 142e2

The provider-path concern does not block merging. The peer-UID check remains in place before requests are read.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the peer-credential check and provider-directory verification added to the minvmd control socket. It is a concise Conventional Commit subject, though it could be shorter.
Description check ✅ Passed The description explains the changes and their purpose, and includes testing commands and reported results. It omits the template's Checklist section.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 2 files.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks the socket gate,
Then peers must show their UID straight.
The folder’s mode is snug and tight,
The daemon reads when names align,
And hops along to guard the line.

Comment @coderabbitai help to get the list of available commands.

…d read

StateDir::new creates the provider dir under the umask (0755) before the
control socket binds, so refusing any non-0700 dir disabled the control
socket on every existing install. Tighten a dir the daemon owns to 0700,
then verify; a dir another uid owns is still refused.

getpeereid writes the gid unconditionally, so the null gid pointer
faulted on macOS on every connection. Pass a live gid.

Split the uid decision from the socket read so the foreign-uid refusal
is tested without root, use temp dirs instead of fixed /tmp paths, drop
the VM integration tests (they ran 'minvmd boot', which never binds the
control socket), fix the unused test imports clippy rejected, and record
the same-uid trust model in the module docs.
@norrietaylor norrietaylor changed the title fix: add peer-credential check and provider-directory verification to minvmd control socket fix(minvmd): add peer-credential check and provider-directory verification to minvmd control socket Oct 3, 2026
…the control socket

Recover a poisoned refusal-log lock instead of panicking, build ucred
without zeroed(), add the missing SAFETY comment on geteuid, log a failed
peer-credential read, and correct two comments that overclaimed (passed
descriptors carry the connector's uid; a bad provider dir returns
PermissionDenied rather than refusing to start).
@gominimal-aw-bot gominimal-aw-bot Bot added the agent:resolve Consent gate: pr-conflict-resolver may rewrite this branch label Oct 3, 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.

Approved per norrie's instruction: CodeRabbit approved, no open threads, independent review applied, lanes green.

@norrietaylor
norrietaylor enabled auto-merge October 3, 2026 08:10
@norrietaylor

Copy link
Copy Markdown
Member

/review

@minimal-foundry

minimal-foundry Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Reviewed: 1 finding, none blocking at 142e2edb9a6f.

Address the comments on the diff.

Clobber: none: git log --oneline -8 on both files shows the prior three commits are earlier iterations of this same change, and no unrelated fix is reverted; HEAD is the PR head.

@norrietaylor
norrietaylor disabled auto-merge October 3, 2026 08:21

@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 — advisory review

Verdict COMMENT — 1 finding, 1 inline.

Comment thread crates/minvmd/src/control.rs Resolved

@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.

CodeRabbit approved at head, minimal-review advisory finding (LOW, debug log) answered, all lanes green.

@norrietaylor
norrietaylor enabled auto-merge October 3, 2026 08:26
@norrietaylor
norrietaylor added this pull request to the merge queue Oct 3, 2026
Merged via the queue into main with commit aba6823 Oct 3, 2026
34 checks passed
@norrietaylor
norrietaylor deleted the inbox-patch/issue-804-peer-cred-b5d014cb8813e861 branch October 3, 2026 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent:fix Agentic fix PR eligible for review iteration; min-aw's worker-iterate gates on it. agent:resolve Consent gate: pr-conflict-resolver may rewrite this branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant