Repository navigation
🐛 agent(claude): hive owns the shared Claude settings.json and verifies it before each kick - #17099
Conversation
…es it before each kick Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of No conflicting open PRs or same-file overlaps were found. |
|
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: — hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 Review findings from Read the tree at What I verified
Residual, acknowledged in-code ( Open question, not a finding: each agent's Review findings from Code is correct for what it does; the open point is whether what it does is enough to close #17059. Routing to What I verified against the tree at
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 Low, not blocking: when the post-seed lock fails, the file is moved aside and the function returns ( |
6955410
ℹ️ Sentinel notice — informational; author is trusted (hive agent), merge is not blockedHive flagged this PR (author @hivecommons-hive[bot], head
Hive did not add the |
|
⏸️ 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. |
There was a problem hiding this comment.
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.rejectUntrustedSharedClaudeSettingsusesLstatso a planted symlink is caught by type before anything follows it;os.Renameon the symlink moves the link, not its target.seedJSONFile→writeInferenceConfigFile(manager_homes.go:971) opens withO_NOFOLLOW|O_CREATE|O_TRUNC, so a re-seed after move-aside creates a hive-owned file;lockSharedClaudeSettingsthenfstats the same no-follow fd it checks, closing the stat/chmod race.sharedClaudeSettingsOwnerTrustedaccepts root, the hive euid andDevUID.permissions_watcher.go:606skips after the root→DevUIDchown above it, so a root-seeded file is still handed toDevUIDand 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 inisSharedClaudeSettingsFilecannot stop the watcher widening anything but the shared file.entrypoint.sh:1701! -path /data/home/.claude/settings.json— the walk roots atentrypoint.sh:1781/1794are exactly/data/home/.claude(no trailing slash), so the literal path matches whatfindprints.
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
There was a problem hiding this comment.
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 withO_NOFOLLOWandinferenceConfigFileMode = 0o666(manager_homes.go:931), so a freshly seeded file is umask-reduced and thenlockSharedClaudeSettingsclips 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. sharedClaudeSettingsOwnerTrustedacceptsDevUID(1001). The watcher comment calls that "the uid agents run as" (permissions_watcher.go:25), butentrypoint.sh:597,637show it is the uid the hive process itself drops to, and in uid-isolation mode agents arehive-<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 becausetest_entrypoint_perm_guard.sh:74rewrites/data/home→$HOMEDIRin the sourced copy. moveSharedClaudeSettingsAsideusesos.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>
There was a problem hiding this comment.
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. BothreadInferenceConfigFileandwriteInferenceConfigFile(src/crux/agent/manager_homes.go) already open withO_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 inlockSharedClaudeSettingsand moved aside before launch. The residual window (replace after lock, before claude starts) is the one the comment atclaude_remote_control.go:193-199already 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 (whichsharedClaudeSettingsOwnerTrustedaccepts) but never widened to0660.hive_fix_walk(src/deploy/entrypoint.sh:1701):! -path /data/home/.claude/settings.jsonis a literal, but every caller (hive_fix_slow_cycle,hive_fix_full_cycle, lines 1781/1794) passes/data/home/.claudewith no trailing slash, sofindprints exactly that path. The shell test'ssed 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
|
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 ( How to release it:
Clear the cause and the hive re-evaluates on its next pass; the stage moves to |
clubanderson
left a comment
There was a problem hiding this comment.
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.
|
LGTM label has been added. DetailsGit tree hash: e671a09b16b996cdcfdfc6b6fe5765c97171f0f3 |
|
Thank you for your contribution! Your PR has been merged. We'd love to hear how your experience was: share feedback |
Closes #17059
Why
Since #17039 (for #17031), every interactive claude agent has its own
~/.claude, butsettings.jsonstill bridges to the single/data/home/.claude/settings.jsonso 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 carryhooks,apiKeyHelper,envand 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/.claudewould 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.
ensureClaudeRemoteControlDefault(the existing hive-side writer of this file) checks that the file is a regular file owned by root, the hive uid ordev. If it is a symlink, a non-regular file, or owned by another uid, the manager moves it aside tosettings.json.rejectedfor operator review and recreates the file from the hive seed.hive_fix_walkin 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
enabledPlugins) can be re-applied fromsettings.json.rejectedas the hive user.test_entrypoint_perm_guard.shchecks 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