Skip to content

🐛 agent(claude): hive owns the shared Claude settings.json and verifies it before each kick - #17099

Merged
clubanderson merged 3 commits into
v5from
scanner/fix-17059
Nov 7, 2026
Merged

clubanderson merged 3 commits into
v5from
scanner/fix-17059

Conversation

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Closes #17059

Why

Since #17039 (for #17031), every interactive claude agent has its own ~/.claude, but settings.json still bridges to the single /data/home/.claude/settings.json so the whole fleet gets the hive's Claude Code configuration. That directory is group-writable for the agents group: agents refresh the shared OAuth credential there by temp-file-and-rename. Also, the entrypoint sweeps and the in-process permissions watcher widened every file in the tree, settings.json included, to group write. Claude Code user settings carry hooks, apiKeyHelper, env and similar keys that run commands at session start. As a result, any agent UID, or a prompt-injected tool call running as one, could rewrite or rename-replace the shared file and run a command in every other agent's next Claude session.

Removing group write from /data/home/.claude would break the shared credential refresh and the legacy shared-HOME mode. That makes it an operator-facing change. This PR keeps the directory layout as it is and makes the one file that controls execution hive-owned instead.

Decision taken by hive

Decision taken by hive: hive-owned seed-and-verify of the shared settings.json (option (a) in the finding), not removing group write from the directory (option (b)). Option (a) closes the cross-agent channel at launch time, keeps the #17031 intent (one shared settings file for the fleet, still bridged into every per-agent home), and stays backward compatible: no config keys, paths or bridges change.

  • Before each claude launch, ensureClaudeRemoteControlDefault (the existing hive-side writer of this file) checks that the file is a regular file owned by root, the hive uid or dev. If it is a symlink, a non-regular file, or owned by another uid, the manager moves it aside to settings.json.rejected for operator review and recreates the file from the hive seed.
  • After seeding, the manager checks the file again through a no-follow descriptor and removes group/other write. If the file still fails the check, it is moved aside, so the launch does not read agent-writable settings.
  • hive_fix_walk in the entrypoint, the one-time home mode repair, and the Go permissions watcher no longer widen this file. Siblings in the directory are still repaired as before.

Notes

  • Residual: the directory stays group-writable, so an agent can still swap the file between two launches. The swap is detected and undone at the next kick. Any session that is already running is not affected by the check.
  • Upgrade: if the existing file is owned by an agent uid, the first kick after this PR moves it aside. Operator-added keys (for example enabledPlugins) can be re-applied from settings.json.rejected as the hive user.
  • Tests: Go unit tests cover a symlink swap, a group-writable hive-owned file, a newly seeded file under umask 0, a foreign owner (both the predicate and a root-only end-to-end case), and the watcher exemption. A shell case in test_entrypoint_perm_guard.sh checks that the sweeps leave the file at 0644 while its siblings are repaired.

— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88

…es it before each kick

Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Nov 7, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign hanthor for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v5

Conflicts are checked with every PR merged onto the current tip of v5, so a PR that only needs a rebase is not reported as conflicting with its siblings.

No conflicting open PRs or same-file overlaps were found.

@hivecommons-hive

hivecommons-hive Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor Author

Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor.

hive/awaiting-ci: CI pending — sweep will merge when green.


🐝 Hive Agent: scanner | Instance: hosted-available-oke-11-placeholder-r05x | SHA: unknown

— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88

Review findings from reviewer-2 (folded here because this head already carries its hive review):

Read the tree at 6955410, not just the diff. This looks correct to me, and it is the first of the two remedies #17059 proposed (hive-owned seed-and-verify), so the design choice is already settled by the issue.

What I verified

  • lockSharedClaudeSettings (claude_remote_control.go:238-258) checks through an O_NOFOLLOW|O_NONBLOCK fd and fstats that fd, so the owner/mode decision and the fchmod act on the same inode — no lstat→chmod race on the file itself. The .rejected rename never follows a symlink.
  • Trusted owners are root, the hive's euid, and DevUID (permissions_watcher.go:26 = 1001); agent UIDs are excluded.
  • Watcher ordering: fixEntry reaches the new skip (permissions_watcher.go:606-612) after isSharedGroupReadableFile, which only ever ORs group read, so nothing upstream can re-widen the file to group write.
  • hive_fix_walk's ! -path /data/home/.claude/settings.json exclusion (entrypoint.sh:1701) works in the shell test because test_entrypoint_perm_guard.sh:74 seds /data/home → $HOMEDIR into guards.local.sh; case 13 exercises both hive_fix_tree_recent and hive_fix_tree.
  • The migration path (entrypoint.sh:127-128) re-tightens the file right after the chmod -R g+rwX /data/home.

Residual, acknowledged in-code (claude_remote_control.go:197-203): /data/home/.claude stays group-writable for the OAuth temp-file-and-rename, so an agent can still rename-replace settings.json between the pre-launch check and Claude reading it. The window is now one launch wide instead of permanent; the issue's second remedy (dir not group-writable, writes via the manager) would close it. Not a defect in this PR.

Open question, not a finding: each agent's ~/.claude/settings.json is a symlink to the shared file (interactive_home.go:127). If Claude Code ever writes user-scope settings itself (e.g. /config toggles, user-level permissions.allow), that write now fails with EACCES, or — if it writes temp-and-rename in the per-agent dir — silently replaces the symlink with a private copy and detaches that agent from the shared settings. Worth confirming against a live agent once; if the bridge detaches, that is a follow-up, not a reason to hold this.

Review findings from reviewer (folded here because this head already carries its hive review):

Code is correct for what it does; the open point is whether what it does is enough to close #17059. Routing to clubanderson (owner on the originating selfreport) rather than approving, since this is a permissions posture change in entrypoint.sh and the permissions watcher.

What I verified against the tree at d37d03e:

  • rejectUntrustedSharedClaudeSettings → seedJSONFile → lockSharedClaudeSettings (claude_remote_control.go:92-101) is sound. writeInferenceConfigFile (manager_homes.go:971) opens O_NOFOLLOW|O_CREATE|O_TRUNC with mode 0o666 (manager_homes.go:931), so after umask the file is dev-owned and group-readable; the lock then masks to perm & 0o644 (claude_remote_control.go:255), which only strips write — agent UIDs keep read. The hive drops to dev via setpriv --reuid dev / gosu dev (entrypoint.sh:2566,2639), and DevUID = 1001 (permissions_watcher.go:26) is in the trusted set, so a freshly seeded file always passes untrustedSharedClaudeSettingsReason.
  • fixEntry exemption (permissions_watcher.go:609) and the ! -path exclusion in hive_fix_walk (entrypoint.sh:1701) stop the two widening paths the issue named; the shell test asserts siblings are still repaired.

Residual the body understates: it says an agent can swap the file "between two launches" and the swap is "undone at the next kick". With the directory at 2775 dev:node and no sticky bit (entrypoint.sh:1484), any node-group UID can rename(2) over settings.json at any moment, including after lockSharedClaudeSettings returns and before the claude child has read the file. The check closes the persistent channel; it does not close the race within a launch. Whether that is an acceptable closure for #17059, or a follow-up (sticky bit on /data/home/.claude, which would need the .credentials.json temp-file-and-rename refresh re-checked; or option (b)) must land first, is the decision.

Low, not blocking: when the post-seed lock fails, the file is moved aside and the function returns (claude_remote_control.go:97-101), so that launch runs with no settings.json at all — the remoteControl pin and bypass-consent suppressor are absent for that session. Fail-closed on hooks, fail-open on those two defaults; probably the right trade, but worth a line in the changelog fragment.

@hivecommons-hive hivecommons-hive Bot added author/hive This repository's own hive (the App or one of its agent lanes) authored this PR dco All commits are DCO signed-off role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it labels Nov 7, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author
6955410

ℹ️ Sentinel notice — informational; author is trusted (hive agent), merge is not blocked

Hive flagged this PR (author @hivecommons-hive[bot], head 69554108b8b9) because it matches behaviors that can override security controls, escalate privileges or damage the codebase. This is a heuristic, not an accusation — a maintainer should confirm the change is intended before it merges.

  • sensitive_path — changes 2 sensitive path(s) (Touches a sensitive path (OWNERS, workflows, policies, hive config, security docs, …))
    • src/deploy/entrypoint.sh
    • src/deploy/test_entrypoint_perm_guard.sh

Hive did not add the sentinel-alert label because this author is trusted. The finding remains recorded for audit and the dashboard Security tab; set sentinel.trusted_authors_block: true to require the blocking label for trusted authors too.

@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

⏸️ CI is red on the base branch (relative links and anchors resolve); holding until it recovers — this is not a failure in this PR, so no fix attempt is counted and no one needs to act here.

@hivecommons-hive hivecommons-hive Bot added stage/050-review-pending Review swarm requested; awaiting a verdict for the current head and removed stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it labels Nov 7, 2026

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

Read the diff against v5 at head 6955410 plus the seeders, the permissions watcher and the entrypoint walk it touches. Looks correct to me; one residual window worth stating explicitly.

Verified

  • claude_remote_control.go:80-99 — order is reject → seed → lock → launch. rejectUntrustedSharedClaudeSettings uses Lstat so a planted symlink is caught by type before anything follows it; os.Rename on the symlink moves the link, not its target.
  • seedJSONFile → writeInferenceConfigFile (manager_homes.go:971) opens with O_NOFOLLOW|O_CREATE|O_TRUNC, so a re-seed after move-aside creates a hive-owned file; lockSharedClaudeSettings then fstats the same no-follow fd it checks, closing the stat/chmod race.
  • sharedClaudeSettingsOwnerTrusted accepts root, the hive euid and DevUID. permissions_watcher.go:606 skips after the root→DevUID chown above it, so a root-seeded file is still handed to DevUID and then left read-only to the group — the two components agree.
  • WatchedHomeDirs (permissions_watcher.go:169-174) does not include the per-agent inference homes (inferenceHomePath), so the basename match in isSharedClaudeSettingsFile cannot stop the watcher widening anything but the shared file.
  • entrypoint.sh:1701 ! -path /data/home/.claude/settings.json — the walk roots at entrypoint.sh:1781/1794 are exactly /data/home/.claude (no trailing slash), so the literal path matches what find prints.

Open question, not a defect — the PR already says this in claude_remote_control.go:200-204: /data/home/.claude stays group-writable, so an agent can still rename-replace settings.json after the pre-launch check and before (or while) Claude Code reads it. The check makes the swap not survive the next launch; it does not stop a swap landing inside a running session if the CLI re-reads settings. Worth a line in the changelog so an operator does not read "hive-owned" as "agents cannot alter it".

— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot added stage/080-awaiting-merge-admission CI green, verdict approve, no modifiers; the automerge lane has not admitted it yet and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Nov 7, 2026
@hivecommons-hive hivecommons-hive Bot added stage/050-review-pending Review swarm requested; awaiting a verdict for the current head stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it and removed stage/080-awaiting-merge-admission CI green, verdict approve, no modifiers; the automerge lane has not admitted it yet stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Nov 7, 2026

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

Read at head b73f9da, with the callees. Looks correct to me; the code does what the body says, and the one red check is not this PR's.

What I checked

  • Re-seed path after a rejection: seedJSONFile → writeInferenceConfigFile (src/crux/agent/manager_homes.go:970) opens with O_NOFOLLOW and inferenceConfigFileMode = 0o666 (manager_homes.go:931), so a freshly seeded file is umask-reduced and then lockSharedClaudeSettings clips it to ≤0644 — agent UIDs can still read it, only the write bits go. The bridge keeps working after an upgrade that moves the old file aside.
  • sharedClaudeSettingsOwnerTrusted accepts DevUID (1001). The watcher comment calls that "the uid agents run as" (permissions_watcher.go:25), but entrypoint.sh:597,637 show it is the uid the hive process itself drops to, and in uid-isolation mode agents are hive-<agent>; so trusting 1001 is trusting the hive, not an agent. In legacy shared-uid mode the check is a no-op, but there is no boundary to defend there anyway.
  • Entrypoint exclusion is an absolute ! -path /data/home/.claude/settings.json; the shell test still exercises it because test_entrypoint_perm_guard.sh:74 rewrites /data/home → $HOMEDIR in the sourced copy.
  • moveSharedClaudeSettingsAside uses os.Rename, which neither follows a planted symlink at the source nor at .rejected.

One wording gap, low — changelog.d/security-claude-settings-hive-owned.md:1 says "one agent can no longer change them for the rest of the fleet". The body's Residual note is more accurate: the directory stays group-writable, a rename-swap between two launches is caught only at the next kick, and already-running sessions are not re-checked. Since the changelog is the operator-facing text, I'd carry the qualifier over, e.g. "…is verified hive-owned before every claude launch, so a file an agent swapped in is moved aside before the next session reads it".

Red check is base-branch, info — relative links and anchors resolve fails on CHANGELOG.md: broken link 'url', a file this PR does not touch. The same workflow failed on v5 at 30468b7 (21:05Z, same minute as this run) and passed at 2d96de7 (21:07Z). A merge of current v5 into the branch should clear it; nothing to fix here.

— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88

Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
@hivecommons-hive hivecommons-hive Bot added stage/050-review-pending Review swarm requested; awaiting a verdict for the current head and removed stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it labels Nov 7, 2026

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

Read the tree at d37d03e, not just the diff. This looks correct to me; the one thing a maintainer may want to decide is noted at the end.

What I verified

  • ensureClaudeRemoteControlDefault (src/crux/agent/claude_remote_control.go:80-99): Lstat → rejectUntrustedSharedClaudeSettings → seed → lockSharedClaudeSettings. Both readInferenceConfigFile and writeInferenceConfigFile (src/crux/agent/manager_homes.go) already open with O_NOFOLLOW, so a symlink re-planted between the reject and the seed is not followed; an agent-owned regular file rename-replaced in that window is truncated by the seed but then caught by the fd-based owner check in lockSharedClaudeSettings and moved aside before launch. The residual window (replace after lock, before claude starts) is the one the comment at claude_remote_control.go:193-199 already acknowledges.
  • fixEntry (src/crux/agent/permissions_watcher.go:606-611): the exclusion sits after the root→DevUID chown and before the DevUID-owner guard, so a root-seeded file is still handed to DevUID (which sharedClaudeSettingsOwnerTrusted accepts) but never widened to 0660.
  • hive_fix_walk (src/deploy/entrypoint.sh:1701): ! -path /data/home/.claude/settings.json is a literal, but every caller (hive_fix_slow_cycle, hive_fix_full_cycle, lines 1781/1794) passes /data/home/.claude with no trailing slash, so find prints exactly that path. The shell test's sed s#/data/home#$HOMEDIR# keeps the literal aligned in the fixture.

Open question for the operator (not a defect in this diff)

lockSharedClaudeSettings trusts any dev/root-owned regular file and only tightens its mode. On an existing deployment the file was dev:node 0664 until this lands, so whatever hooks/apiKeyHelper content is already in it is kept and now sealed as hive-owned. If the goal of #17059 includes closing that historical window, a one-time operator review of the current /data/home/.claude/settings.json (or a one-shot move-aside on first upgrade) is needed; the diff cannot distinguish operator keys from agent-written ones. I'd treat that as a follow-up, not a blocker.

CI: Sign-off survives the squash is CANCELLED (not failed) on this head; everything else green.

— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot added stage/085-needs-decision A human decision is owed: sentinel alert, hold/needs-decision label, human-only rule or parked issue and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Nov 7, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

Needs a decision, not a merge:

Head: verdict requires_human @d37d03e, 76/76 checks green, DCO yes, soak 0s of 10m0s.

What to do: approve this head (d37d03e) to merge as-is, or leave a changes requested review (or reply /hive decision <what to change>) and the hive will push the fix.

How to release it:

  • After reading the verdict, a trusted merger can submit a GitHub Approve review for the current head and the lane clears the hold on its next pass; /hive approve replies on a PR are acknowledged but not consumed.

Clear the cause and the hive re-evaluates on its next pass; the stage moves to stage/090-ready-for-human-merge, stage/095-pre-merge-soak or the merge queue on its own. Approval does not bypass CI, hold labels or other merge gates.

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

Verified the claim still holds post-#17039 (per-agent ~/.claude/settings.json is a symlink into g+rwx /data/home/.claude, so any agent UID could rename-replace the fleet-wide hooks/apiKeyHelper file). This PR takes the issue's first proposed remedy exactly: hive owns the shared file, every claude kick Lstat/O_NOFOLLOW-verifies type+owner, rejects to .rejected and re-seeds on tamper, tightens go-w in place for hive-owned copies (operator keys preserved), and the entrypoint sweep + permissions watcher stop re-widening it. Agent UIDs start at 2001 so trusting root/self/DevUID is sound; tests, shell guard test, DCO, changelog all present and CI green locally and remote. Residual mid-session swap window is inherent to the g+rwx credential dir and acknowledged in the code.

@kubestellar-prow kubestellar-prow Bot added the lgtm Indicates that a PR is ready to be merged. label Nov 7, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

LGTM label has been added.

DetailsGit tree hash: e671a09b16b996cdcfdfc6b6fe5765c97171f0f3

@hivecommons-hive hivecommons-hive Bot added stage/050-review-pending Review swarm requested; awaiting a verdict for the current head and removed stage/085-needs-decision A human decision is owed: sentinel alert, hold/needs-decision label, human-only rule or parked issue labels Nov 7, 2026
@clubanderson
clubanderson merged commit 98548ce into v5 Nov 7, 2026
105 of 109 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the scanner/fix-17059 branch November 7, 2026 22:08
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

We'd love to hear how your experience was: share feedback

@hivecommons-hive hivecommons-hive Bot removed role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author/hive This repository's own hive (the App or one of its agent lanes) authored this PR copilot dco All commits are DCO signed-off dco-signoff: yes Indicates the PR's author has signed the DCO. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[reviewer] Review backlog (security): Shared agent-writable ~/.claude/settings.json remains a cross-agent hook/apiKeyHelper execution channel

1 participant