Skip to content

Governance layer v1: per-profile permission matrix, HMAC audit, Claude gate (#262) - #1655

Merged
currentbits merged 12 commits into
mainfrom
coder/governance-v1-262
Oct 16, 2026
Merged

currentbits merged 12 commits into
mainfrom
coder/governance-v1-262

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Implements the governance layer v1 from docs/superpowers/specs/2026-09-02-governance-layer-v1-design.md. #262 was closed when only the spec merged (23e8bd9), so none of this was on main. It's the prerequisite for #803 (Seatbelt), which follows as a stacked PR.

What it does

  • Per-profile matrix. AgentProfile.policy holds defaultAction (ask/allow) plus up to 40 rules. Each rule has a kind (tool / bash / write / network), a case-insensitive glob, and an action (block / deny / ask / allow). Every matching rule is collected and the most severe action decides.
  • Enforced on Claude's can_use_tool, after Orchestrator-owned guardrails: protected config, spawn-time hook packs, memory-write scanning #409. A deny is answered with no card and a Governance blocked … transcript event. An allow is answered with no card. An ask shows the card with a reason (layer / rule) strip.
  • Re-checked when the user answers the card. The edited command is classified and evaluated again. If it now hits a deny, the Allow is refused (Blocked by policy (layer)). This applies to every Claude thread, so editing a command to sudo … can no longer slip past Orchestrator-owned guardrails: protected config, spawn-time hook packs, memory-write scanning #409.
  • Fails closed. Write paths are realpath'd at the deepest existing ancestor, so a symlinked parent can't hide the target. Canonicalization errors (ELOOP, EACCES) deny with layer: normalize, and any evaluator exception is a visible deny.
  • HMAC-chained audit. governance-audit.jsonl plus a 0600 key under userData; layer, decision and actionHash are signed. Settings → Advanced shows the last 50 rows and a Verify chain button. Secrets are redacted before writing, even when guardrails are off.
  • Binding. threads.applyAgentProfile applies the full profile snapshot and stamps agentProfileId. Manual provider, effort or permission picks clear it. A fork copies it only while it stays on the profile's provider. Routing (Model routing: pick provider/model per task by complexity and cost #246), issue starts and Best of N go through the same path.
  • UI. Rule rows on the profile form, a · N rules summary, Allow always hidden on profile.ask, and the picker shows the applied profile.

Deliberate deviations from the spec

  • Bash rules match word prefixes per subcommand. npm publish matches cd x && npm publish --tag y. An allow must cover every subcommand and never covers $(…) or backticks.
  • No Claude session rules on governed threads. For threads whose profile has rules, Allow always grants only the exact actionHash for the run and does not send Claude addRules. A Claude session rule stops can_use_tool for that tool, which would silently bypass the matrix afterwards.

Not covered (by design)

Tests

  • New: governance.test.js (normalize, symlinks, ELOOP fail-closed, precedence), governance-audit.test.js (tampering), governance-runner.test.js (fake Claude seam), governance-store.test.js (heal, fork rule, IPC clear). Settings, permission card, composer and profile-row renderer tests are extended.
  • On this branch, merged with current main, in a CI-like env (no inherited CODER_*, node-only PATH):
    • test:electron: 4825 pass, 0 fail.
    • Renderer: 3103 pass, 0 fail.
    • npm run typecheck and npx vite build are clean.

Refs #262, unblocks #803.

🤖 Generated with Claude Code

Willem and others added 9 commits October 16, 2026 09:41
Per-profile policy (tool/bash/write/network rules, deny-wins) on Claude's
can_use_tool and re-checked on the card answer, so an edited command is
judged as what runs. Write paths canonicalize via realpath and fail
closed. Every governed decision lands in an HMAC-chained JSONL audit
under userData. Governed threads keep the CLI asking instead of sending
Claude session rules that would bypass the matrix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rofile (#262)

One write instead of setProvider/setReasoningEffort/setPermissionMode, so
the thread carries agentProfileId and its policy applies. The picker marks
the thread's profile row selected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…governance-macos-seatbelt-process-wrappe-f8ac1a
…rompts (#262)

Also re-attach setWebSearch's doc comment that applyAgentProfile split off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T08:08:12.665766Z 5854d27 PR opened
ℹ️ 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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5854d2789e

ℹ️ 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".

Comment thread electron/governance.js
Comment on lines +270 to +272
function subcommands(command) {
return command
.split(/&&|\|\||[;|\n]/)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Recognize every shell command separator before allowing

For Bash allow rules, this splitter cannot enforce the stated “every subcommand” condition: normalizeCommand has already collapsed newlines to spaces, and this regex also omits the single & separator. Thus a rule allowing git status auto-allows both git status\nnpm publish and git status & npm publish, because each is treated as one string matching the allowed prefix, so the appended command runs without confirmation. Preserve shell separators during normalization and account for all command separators before accepting an allow match.

Useful? React with 👍 / 👎.

await onSetReasoningEffort(entry.reasoningEffort, forked.id);
await onApplyAgentProfile(entry.id, forked.id);
}
if (planOnly) await onSetPermissionMode("plan", forked.id);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep the profile bound when forcing Best of N plan mode

When a user selects a profile and enables Plan only, the preceding onApplyAgentProfile stamps agentProfileId, but this call goes through threads:setPermissionMode, whose new leaveProfile logic immediately clears that ID. The fork's first Claude run therefore has no profile policy, so configured deny/block rules are not enforced. Apply the plan-mode override without treating it as a manual departure from the selected profile.

Useful? React with 👍 / 👎.

Comment on lines +213 to +216
try {
text = fs.readFileSync(logPath, "utf8");
} catch {
return { ok: true, entries: 0 };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Fail verification when an existing audit log disappears

After at least one audit entry has created the key, deleting or renaming governance-audit.jsonl makes readFileSync throw, but this catch reports ok: true with zero entries. The Advanced UI therefore labels a completely removed audit history as a valid chain, defeating the deletion detection promised by this feature. At minimum, distinguish a genuinely fresh installation from a missing log when the audit key already exists, and return failure for other read errors.

Useful? React with 👍 / 👎.

Comment thread electron/ipc-threads.js
Comment on lines +256 to +257
services.setRoute(ctx.store, { threadId: input.threadId, route: null });
const updated = services.applyAgentProfile(ctx.store, input);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate the profile before clearing the pending route

If the renderer submits a stale or deleted profile ID while the thread has a pending Auto route, this call saves route: null before applyAgentProfile validates the ID and throws. The failed operation therefore still mutates the thread, contrary to the API contract that an unknown profile is rejected before anything changes. Validate/apply the profile first, or perform the route clearing and profile update atomically.

Useful? React with 👍 / 👎.

Willem and others added 3 commits October 16, 2026 11:03
The renderer dropped its own snap when it moved to applyAgentProfile.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve against multi-folder projects (#514): the governance allow
answers first; the granted-secondary-folder auto-allow no longer
overrides a profile ask rule; folderGrant and guardrail.layer both ride
PendingPermissionInfo.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… egress (#803) (#1656)

* Seatbelt wrap for governed local CLIs: compiled writes, proxied egress (#803)

On macOS, a local thread whose agent profile has write or network rules
spawns its CLI (every provider) under sandbox-exec. Writes are denied
outside the worktree, its git common dir (hooks excluded), tmp, /dev,
CLI config homes and allow/ask write paths; deny/block write rules are
carved back out. Network rules deny outbound IP except loopback and route
HTTP(S)_PROXY through a host-filtering proxy that knows the thread from
the proxy URL's userinfo. Every deny rule is tagged solenta:<threadId>,
so a log-stream follower audits kernel denials as layer seatbelt and
flags matrix-allow / Seatbelt-deny disagreements. Anything that cannot be
canonicalized or compiled refuses the run instead of spawning unconfined.
sandbox.js reports the wrap with the same predicate the runner uses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Seatbelt tests: keep Stores in tmp so exit flushes cannot litter $HOME (#803)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Willem <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@currentbits
currentbits merged commit 4b88bf6 into main Oct 16, 2026
6 checks passed
@currentbits
currentbits deleted the coder/governance-v1-262 branch October 16, 2026 09:45
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