Skip to content

fix(hosts): recover private control permissions - #486

Open
andrebrait wants to merge 1 commit into
mainfrom
fix/host-control-permission-recovery
Open

andrebrait wants to merge 1 commit into
mainfrom
fix/host-control-permission-recovery

Conversation

@andrebrait

@andrebrait andrebrait commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Restore owned Unix control directories and sockets to 0700/0600 during startup instead of repeatedly failing after permission drift.
  • Repair directories through a verified no-follow descriptor. For owner-unreadable directories, permit path repair only beneath a root-owned sticky parent with ownership and identity checks.
  • Retain strict control clients, symlink/type/foreign-owner refusal, live-daemon exclusion, and identity-checked stale-socket reclamation.
  • Remove owned sockets on shutdown even if their permissions changed.

Verification

  • Regression tests first reproduced startup failures and stale shutdown cleanup.
  • Focused host-control, launcher, local-bootstrap, and update-safety gates: 46 passed, 5 skipped (platform-specific).
  • Typecheck and changed-file ESLint passed.
  • Node+jiti runtime probe passed live-endpoint preservation and repaired control access.
  • Unprivileged Node crash-recovery probes passed directory777/socket000 and directory000/socket000; all probes were memory/time capped and cleaned up.
  • One condensed adversarial review completed; its recovery and cleanup findings were addressed.

No deployment, service configuration, or unrelated temporary-file permissions changed. macOS/Windows execution and the full suite are left to CI.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Unix host-daemon recovery when control-directory or socket permissions have changed. Stale sockets can now be reclaimed when it is safe to do so, while unsafe endpoints continue to block replacement.
    • Improved shutdown cleanup so the daemon can remove its own socket despite permission changes.
    • Added checks to avoid repairing or removing control paths that are not owned by the daemon.

Repair verified-owned Unix runtime entries before stale socket recovery, while preserving strict clients and refusing live or foreign endpoints. Use a no-follow directory descriptor; owner-unreadable directories require a root-owned sticky parent for safe path repair. Clean up owned sockets despite permission drift.
@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Unix host-control startup now repairs permissions on owned runtime directories and sockets. Stale sockets can be recovered after permission drift. Tests also cover permission changes while a daemon is live and socket removal on shutdown.

Changes: Unix host-control permission recovery

Layer / File(s) Summary
Secure the runtime directory
lib/hosts/host-control.ts, lib/hosts/host-control.test.mjs
Directory checks distinguish identity from mode. Startup repairs an owned directory to mode 0700; tests cover symlink refusal, initial permission repair, and rejection of a foreign-owned directory.
Recover stale sockets
lib/hosts/host-control.ts, lib/hosts/host-control.test.mjs
Stale-socket recovery secures the directory, repairs an owned socket to mode 0600, verifies identities around the probe, and removes a stale socket. Tests cover four directory and socket permission combinations.
Handle live socket permission drift
lib/hosts/host-control.test.mjs, CHANGELOG.md
Tests verify that permission drift does not replace a live socket and that shutdown removes the socket despite permission changes. The changelog records the recovery behavior and its stated limits.

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

Change: Bug fix

Merge Risk: Minimal · up to 2e443

Unix host-control startup now repairs permission drift on its own control directory and socket instead of failing repeatedly. Symlinks, foreign owners, and live endpoints are still refused. No actionable merge-blocking risk remains after the review.

Security architecture risk: Minimal · up to 2e443

The change restores private control access while preserving ownership checks, strict client permissions, and live-daemon exclusion. No introduced material security or failure-containment regression was identified in the inspected transitions.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The relevant authority boundary is the Unix UID, not a remote tenant identity. A control request addresses the selected agent directory's daemon and can affect its drain, retention, and recovery state. Same-UID processes already fall inside the filesystem ownership boundary; the inspected change does not introduce broader credentials or remote control ingress.

Trust Boundaries and Controls

  • observed — Repair still rejects symlinks, foreign ownership, and incorrect object types. Directory repair opens with O_DIRECTORY and O_NOFOLLOW, verifies descriptor identity, and verifies the resulting pathname. The EACCES fallback permits path-based chmod only after checking a root-owned sticky parent and unchanged directory identity. Socket chmod occurs after directory privacy has been restored.

Resilience and Maintainability Implications

  • observed — Only ECONNREFUSED qualifies an endpoint as stale; successful connection or timeout prevents reclamation. After the asynchronous probe, directory and socket identity are checked again before unlinking. Exclusive hard-link publication prevents concurrent starters from both claiming the public endpoint.
Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: restoring owned Unix host-control directories and sockets to private permissions (0700/0600) so permission drift no longer blocks recovery. The changeset matches this:…
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 names the main change: restoring owned Unix host-control directories and sockets to private permissions (0700/0600) so permission drift no longer blocks recovery. The changeset matches this: secureDirectory repairs permissions via a no-follow descriptor, stale-socket recovery tightens socket mode before probing, and tests cover the four permission combinations. The title is short, specific, and follows the fix(scope) convention.

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
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0fed5129-68f4-4f6e-8714-b44425041b02
Commits

Reviewing files that changed from the base of the PR and between a635065 and 2e443d5.

Files selected for processing: 3

  • CHANGELOG.md
  • lib/hosts/host-control.test.mjs
  • lib/hosts/host-control.ts

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

@andrebrait

Copy link
Copy Markdown
Collaborator Author

@codex review

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor
Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T01:20:54.449315Z 2e443d5 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 2e443d5e36

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant