Repository navigation
✨ Shadow-mode authorization decision seam for the push broker's changed-files guard - #19098
Conversation
…s guard Add src/crux/authz: a flat typed Request, a Decision, a pure in-process authz.Decide evaluator that mirrors one existing decision (empty push, then protected paths), and a Shadow recorder that compares the evaluation with the existing gate, keeps one versioned attributes-only event per call on its own bounded in-memory stream, and logs divergences. Default off (HIVE_AUTHZ_SHADOW, stream size HIVE_AUTHZ_SHADOW_BUFFER). It enforces nothing and changes no behaviour: the broker calls it after its own guard has decided and never reads a result back. Fail-closed semantics are documented and tested in Decide but not applied. Parity tests replay the push broker's existing cases through the seam. Docs: design record phase status, security model, env vars, crux README, changelog fragment. Refs #18988 Signed-off-by: Andrew Anderson <andy@clubanderson.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
|
Mutation testinggremlins found 8 surviving mutant(s) in changed files: the code ran under tests, but changing it did not fail any test.
ℹ️ 1 mutant(s) on added lines were SKIPPED because gremlins v0.6.0 only honours the first
Verdict: |
|
Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor. @clubanderson this PR is held at Why:
Next: the hive does not push to your branch. Push a new head (or reply here); CI and the review swarm re-run automatically and the PR returns to the normal path. Review findings from Docs-currency review at head 1926ed5. The new docs (env-vars rows, security-model section, phase status, README and documentation-map lines, changelog fragment) match the code I read: Stale line citations in the design record. This PR adds 1 import line and a 5-line Requested change: re-check each Not verified: I did not open Findings not on a changed line
|
Refs #18988 Signed-off-by: Andrew Anderson <andy@clubanderson.com>
…e-18988 Signed-off-by: Andrew Anderson <andy@clubanderson.com>
There was a problem hiding this comment.
Style review at 1926ed5: clean, well-commented, matches repo idioms (leaf package, nil-receiver-as-off, changelog.d fragment, docs updated). Three small readability advisories, inline. None blocking.
-- hive: agent=adjudicator-4 backend=claude model=claude-sonnet-5-5 claude=2.1.327
| if strings.HasSuffix(guard, "/") || strings.HasSuffix(g, "/") { | ||
| if strings.HasPrefix(clean, strings.TrimSuffix(g, "/")+"/") { | ||
| return true | ||
| } |
There was a problem hiding this comment.
normalise uses path.Clean, which strips trailing slashes, so strings.HasSuffix(g, "/") is only true for root. Suggest:
| } | |
| if strings.HasSuffix(guard, "/") { |
| res.ChangedFiles = files | ||
| protected := b.protectedPaths() | ||
| if len(files) == 0 { | ||
| b.observeChangedFiles(files, protected, authz.Verdict{Effect: authz.EffectDeny, ReasonCode: authz.ReasonEmptyPush}) |
There was a problem hiding this comment.
The observe call is repeated on all three return paths. Build the legacy authz.Verdict once and observe in one place so a fourth path can't forget it.
Refs #18988 Signed-off-by: Andrew Anderson <andy@clubanderson.com>
Refs #18988
First implementation slice of the authorization decision point: phase 0/1 of the design record, in shadow mode. It is off by default, enforces nothing and changes no behaviour, on or off. The RFC stays open until the enforcement phases are decided.
What this adds
src/crux/authz(a leaf package in the Crux module, no import of the proxy or the broker): flat typedRequest,Decision, a pure in-processauthz.Decide(Request) Decision, and aShadowrecorder.pushbroker.ProtectedPathViolationson purpose, so drift shows up in the parity tests and in the live divergence counter instead of being hidden by shared code.Shadow.Observe(req, legacyVerdict)runsDecide, compares with what the guard decided, keeps onev1decision event per call on its own bounded in-memory stream (default 1000,HIVE_AUTHZ_SHADOW_BUFFER, evictions counted), counts and logs divergences (once per distinct shape, still counted every time), and optionally hands events to aSink.HIVE_AUTHZ_SHADOW(parseable true value, read once per process). Unset or anything else means a nil recorder: nothing is recorded or allocated.Broker.guardChangedFilescalls the shadow after its own verdict and never reads a result back. A recorder panic is recovered and counted.Decidebut not applied: evaluator panic is a deny withauthz_error, a missing repo or branch is a deny withmissing_attribute, an action with no rule is a deny withunsupported_action. In this phase a shadow deny the guard did not issue is a divergence log line only.security-model.md(control inventory row and a short section),env-vars.md, the crux README package table. Changelog fragment included.Tests (run by CI, none run locally)
TestParityPushBrokerChangedFilesreplays the broker's existing cases (protected table, quoted names, rename endpoints, custom override, empty push) andTestParityPushBrokerPathShapescrosses every default guard with path spellings and edge guard sets, asserting the same effect, reason code and rejected count as the existing matcher.TestKindBranchPushIsTheEffectsKindpins one action vocabulary.Result, error and git commands are identical with the shadow on and off for an allowed, a protected and an empty push.Decision record for the open questions
Each row is a recommended answer with one line of reasoning from the code. The operator can overrule any row at review; nothing in this PR depends on any row. Rows 5, 6 and 11 describe follow-up work that builds on this slice.
proxyHTTPHost), so only a shadow comparison over a corpus can show equivalence; this slice adds the comparison machineryX-Hive-Proxy-Reason(ProxyDenialHeader), while relays are file-in, result-out (pr_request_watcher.gowrites a result and renames the request.denied)heldresult status carrying thedecision_idand reason code, and rename the request.held, not.denied.deniedrequest is never retried (pr_request_watcher.go), so a distinct suffix keeps a held request distinguishable and retryablePolicySourceinterface, with hub-delivered bundles added later by the org-policy work/data(toolapprove.DefaultInboxPathis/data/approvals/inbox.json), and the evaluator is already separated from its inputs byRequest.Contextgithub_proxy_violations.gologs blocks only), so there is no baseline;Shadow.Stats()and the bounded stream give one on a maintainer hiveaudit.jsonl; adopt hash chaining when the org-policy work landsaudit.go), which allow-rate events would evict; this PR's stream is in memory only and says sogithubBudgetRefusalreturns a 429, rate limiting rather than a deny code, and has no entry in the reason-code table (denial_message.go)ACMMCeilingafter evaluation and a base deny is terminal (toolapprove/desk.go), so the existing layer already refuses to widenhasLabeland a cost cap are already implemented twice with different request types (toolapprove/rules.go,celtrigger.go)contributortier (DefaultTier), which carries issue and PR write (app.go), and the forge cannot narrow a token below repository plus permission setActor.Mode); the proxy adapter keeps reading the file until phase 4, and agent-UID write access to the file stays a check to do (unverified)readAgentModereads/tmp/.hive-mode-<agent>per request and treats a missing or bad file as advisory (github_proxy_identity.go); the request type here already carries the mode as dataSequencing and overlap
Open PRs that touch the proxy or may touch files near the broker were checked. This PR does not edit
src/crux/proxy/github_proxy_mitm.goor any file changed by the other open proxy PRs. The only overlap issrc/docs/security-model.md, which one open proxy PR also edits (different section); it was rebased onto the latestv5before push. No open PR touchessrc/crux/pushbroker.Not in this PR
Enforcement through the seam, the proxy, relay and remaining broker rules, a durable decision stream or sink wiring, operator rules, and credentials.