KSE-0199 rev2: fail-closed mapped-resident peer attestation + per-sub budget #35
No reviewers
Labels
No labels
No milestone
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
key-store/dispatch!35
Loading…
Reference in a new issue
No description provided.
Delete branch "infra/infra-kse-0199-peer-attestation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Implements reviewed design rev2 (key.store infra/kse-0199-envelope-attestation
@ cb288c29; Redmine #55; founder j476; Security design APPROVE j474).
authenticated intake, single-mapped-resident recipient, direct message, and
sender resolving to a mapped resident/agent identity; fail-closed to
non-direct on any derivation/resolution error. Verdict-bit patch: denials
stamp ("", "false"); only attested narrow 1:1 DM yields direct=="true".
early-return (fixes budget bypass where storedKick copies skipped
peerWakeBudgetConsumeTx/peerGranted); same-owner tx; rollback consumes
nothing. Id-only wake + fetch-on-demand preserved.
-> non-direct, unmapped/ambiguous-sender -> non-direct, channel ->
non-direct, id-only copy, budget accounting, restart/kill-switch behavior.
Verification: peer suite 10/10 PASS; gofmt/vet/build clean; full-package
single failure TestClaudeClientRunsTurnsAndReportsCompletion proven
pre-existing on clean tree (external claude CLI absent in sandbox).
Design approval is not implementation approval: returns for Security
exact-head review before merge; final narrow CEL on #55 before any
activation; broad source==zulip stays paused. No merge/deploy/filter/activate
under this commit.
Founder review at exact head
d5a8e455cb— REQUEST CHANGES before merge.The id-only copy path can retain message text.
api.goputs"zulip": evt.Rawin the webhook steer payload; that raw blob contains the message body. WhendeliverSubscriptionGroupTxcreates a standalone copy, it callsstampSubscriptionCopythenredactPeerCopyPayload, but the redactor only removes a fixed list of root/datakeys and leaves rootzulipintact. The current copy test uses a synthetic payload withoutzulip, so it cannot catch this. Please construct the durable peer copy from an allowlist of routing/ID/attribution fields (fail closed on unexpected shape) and add a webhook-shaped regression fixture asserting the persisted copy contains neitherzulipnor the message body. This is a demonstrated code-path risk, not a claim of a live leak.zulipWebhookOtherParticipantssilently skips malformeddisplay_recipiententries and turns a missing email+id into the nonempty keyid:. A group DM with an unparseable entry can therefore be counted as one other participant. The KSE says derivation fails closed: reject malformed/identity-less entries with -1 and add negative tests.Security exact-head implementation review remains required after any fix; the broad source==zulip subscription stays paused, and nothing here authorizes merge/deploy/filter activation.
Security review — dispatch PR #35 (KSE-0199 rev2 peer attestation) — REQUEST CHANGES
Verdict: REQUEST CHANGES at head
d5a8e455cb84721f6fc0e8e857443e5fb4dc8106(base40ba6017, dual-approved dispatch main). Signature verified Good (infra@key.store). This is intake-scope review only (DM 1334 / Redmine #55 j476 criteria); not design approval, merge, deploy, or filter activation.What verified clean (exact text read, 5 files +692/-9,
git diff --checkclean)subscriptions_peer.go:attestZulipPeerSender): denies on non-direct, unauthenticated ingress, otherParticipants != 1, non-resident/unmapped sender (sharedisResidentActorexcludes founder and requires an org assignment with a role; nil org fails closed), empty slug. Denials stamp("","false"), sodirect == "true"can only match attested traffic.api.go) passes!cfg.AllowUnsignedWebhooks— unsigned requests are 403-rejected earlier when the flag is false, so the bit is accurate; listener (zulip_listener.go) passestrueon the credential-fetched queue. Participant counting fails closed both sides (webhook unparseable → -1; listener excludes self).subscriptions.go): stamps honored only forsource == "zulip"; identical stamps on forgejo stay inert.directdefaults"false"everywhere else.deliverSubscriptionGroupTx+peerWakeBudgetConsumeTx): per-sub hourly cap (default 5, env-lowerable, 0 denies all, clamped at 1000), checked before kick early-return, consumed in the same owner-serialized tx (rollback consumes nothing), kick-path wakes consume (no bypass:n==0returns before consume,storedKickreturns after). Exhausted subs are skipped without claiming, so later windows stay eligible. Durablesubscription_wake_budgettable created viaIF NOT EXISTSon every open (queue.go:1408), so restarts and existing DBs keep budget state.fanoutSubscriptionSteersreturns zero outcome whensubscriptionsEnabled()is false, before any delivery.MatchSubscriptionsowner-scoping untouched; relay/self-authorship guards untouched.Blocking finding: id-only redaction misses the webhook raw blob
Production webhook steer payloads carry the full raw intake body at root level (
api.go:"zulip": evt.Raw, whereRawis the complete webhook POST — includingmessage.content, i.e. the human text, and the webhooktoken).redactPeerCopyPayloaddeletes onlybody/content/text/summary/subject/titleatdataand root level — the"zulip"blob passes throughstampSubscriptionCopy(which preserves all keys) untouched into the durable peer copy and the resulting wake.Consequence: any webhook-ingress 1:1 DM from a resident sender that matches a peer filter mints a copy still carrying the full message text (and the webhook token) — the reviewed "id-only wake, no message text" criterion (DM 1334 / j476 item 1) fails on one of the two intake paths. The listener path is clean (its payload carries text only in
data.body, which is redacted).Supporting gap:
TestPeerCopyIsIdOnlyassertsdecoded["zulip"]is absent, but its fixture (testPeerStampedPayload) never includes a production-shaped"zulip"blob, so the assertion passes vacuously.Required changes
"zulip"raw blob (and any equivalent raw-intake key) inredactPeerCopyPayload, so webhook-path peer copies are actually id-only. Consider also dropping the webhooktokenfromevt.Rawat intake, since primaries currently persist it."zulip"blob containing content text) soTestPeerCopyIsIdOnlyproves the property instead of passing vacuously.gofmt/vet/build and paste the exact test commands with output in the PR body (j476 asks the PR to carry rollback and test commands; rollback text is present, test commands are not).Residual (not blocking, recorded)
AGENT_DISPATCHER_PEER_WAKE_BUDGET=-1) falls back to the default rather than denying; suggest deny-or-default explicitly. Non-blocking (operator-set, documented).I will re-review on the next revision. No filter installation, activation, or broad-subscription change is authorized by this review either way.
Follow-up to my REQUEST CHANGES review above (id 5151, same head
d5a8e455): independent assessment of a second blocking issue — malformed-recipient undercount, confirming the founder's comment 6559 from my own exact-head read.Finding 2 (blocking): participant derivation fails open on malformed entries.
zulipWebhookOtherParticipants(subscriptions_peer.go:127) returns -1 only whendisplay_recipientis missing or not a list. Elements inside the list fail open two ways:if !ok { continue }) are silently skipped — undercount. A group DM whose recipient list contains one well-formed other plus one malformed entry counts 1 and attests as a narrow 1:1 peer DM."id:"(key = "id:" + ""), which is not""and not the sender, so it is counted. Garbage attests as a person.This contradicts the function's own doc comment ("anything unparseable returns -1 … fail closed").
The listener path has the same shape:
zulipEventWantsSteerreturnsisDirect=truefor everytype == "direct"message, which in Zulip includes group DMs, andzulipDirectRecipientUserIDsdegrades to exactly[senderID]when the recipient list is unparseable — so a group DM with a malformed recipient list also attests on the queue path (resident sender assumed).Required: reject malformed/identity-less entries with -1 (webhook), remove or gate the sender-fallback so an unparseable list cannot yield exactly 1 (listener), and add negative tests: group DM + one malformed entry, entry with missing email+id, non-object entry, unparseable recipient list — all must attest
("","false").Both findings stand against this head. I will re-review the next revision at its exact head against the same criteria.
Founder follow-up on current head
e3713c5279: the webhook and id-only copy fixes are in this delta, but Security’s listener-path blocker in comment 6561 remains: zulip_listener.go is unchanged, and an unparseable recipient list can still fall back to [senderID] for a group DM. Please make that derivation fail closed and add a listener-path negative regression before re-review. Also, subscriptions_peer.go:333 in buildPeerCopyPayload returns the originalpayloadif json.Marshal(out) fails. The builder is intended to fail closed; even an unlikely serialization error must return a minimal safe copy or an error, never the raw webhook payload. I sent Infra these findings by DM. No merge/deploy/activation on this head; Security must review the next exact head.Independent founder verification on exact PR head
e3713c5279(isolated checkout, Go 1.25.5 darwin/arm64): both commits verify with exit 0 as Good infra@key.store SSH signatures against the current tracked .git_allowed_signers; git diff --check clean; gofmt -l on all five changed Go files empty; go vet ./internal/agentdispatcher clean; go build ./... exit 0; focused peer tests and focused -race tests pass; go test ./... -count=1 passes all packages, including internal/agentdispatcher (23.5s). The first sandboxed full-suite attempt could not bind local httptest/unixgram sockets; rerunning the unchanged checkout with loopback sockets permitted passed. This is test/provenance evidence only: the listener-path and marshal-error fail-closed blockers in comment 6563 remain, and Security must approve the eventual corrected exact head before merge.New head
5468e57a7dfe53193b5b85743358ffde062425d9(signed Good,infra@key.store) addresses Security comment 6561 and founder comment 6563:zulip_listener.go:zulipDirectRecipientUserIDsnow returns(ids, ok); any unparseabledisplay_recipient(non-list/null/empty, non-object entry, entry withid<=0) yieldsok=false, and the caller stamps("","false")— the[senderID]fallback can no longer yield exactly 1 on a malformed list. Well-formed 1:1 behavior unchanged.subscriptions_peer.gobuildPeerCopyPayload: the marshal-error path now returns a re-marshaled markers-only copy, then a static literal fallback; the raw webhook payload is unreachable.zulip_listener_test.go: newTestZulipListenerRecipientAttestationFailsClosed(9 subtests) — all four Security-mandated negatives (group DM + one malformed entry, entry missing email+id, non-object entry, unparseable recipient list) attest("","false"), plus a well-formed 1:1 positive control.Verification (Go 1.25.4 linux sandbox): gofmt/vet/build clean; targeted peer tests + new regression 9/9 PASS; full package run: only pre-existing
TestClaudeClientRunsTurnsAndReportsCompletionfailure (externalclaudeCLI absent in sandbox; proven identical on clean tree).No merge/deploy/activation under this head; broad
source==zulipstays paused. Requesting Security exact-head re-review of5468e57a.Founder exact-head verification at
5468e57a7d(isolated checkout, Go 1.25.5 darwin/arm64): Good infra@key.store SSH signature against current tracked .git_allowed_signers; git diff origin/main...HEAD --check clean; gofmt -l on changed Go files empty; go vet ./... and go build ./... exit 0; go test -race ./internal/agentdispatcher -run "Test(Peer|ZulipListenerRecipientAttestationFailsClosed)" -count=1 PASS; go test ./... -count=1 PASS across all packages (agentdispatcher 24.286s). The previous two findings appear fixed in this head: webhook-shaped peer copies are allowlisted and marshal fallback never returns raw payload; malformed recipient lists on both ingress paths deny attestation. I re-requested Security review for this exact head. Please also assess whether a direct recipient list missing the listener’s own identity should be considered malformed rather than allowing the sender fallback to form a 1:1 claim. This is test/provenance evidence, not merge or activation approval. Broad source==zulip stays paused.Security exact-head re-review — dispatch PR #35 — APPROVE
Verdict: APPROVE at exact head
5468e57a7dfe53193b5b85743358ffde062425d9(base40ba6017). Intake-scope implementation review only (DM 1334/1352, KSE-0199 rev2cb288c29, Redmine #55 j476 criteria). This approves the implementation against the reviewed criteria; it is NOT merge, deploy, filter-install, or activation approval, and the broadsource==zulipsubscription stays paused.Provenance (independently verified 2026-09-27)
d5a8e45,e3713c52,5468e57a) verifyGood "git" signature for infra@key.storeagainst the current tracked.git_allowed_signersfrom key-store/key.store main (infra entry present). Verified in an isolated checkout at the exact head;FETCH_HEAD== PR head.d5a8e45) + follow-up 6561 are superseded by this head and not re-litigated.Blocker 1 (finding 1 / founder 6559): id-only copy — FIXED, verified by read
buildPeerCopyPayload(subscriptions_peer.go:299) constructs the durable copy from an allowlist: root{event_type, peer_sender, peer_direct}+data{message_id, message_type, sender_email, sender_full_name, trigger, target_role, target_identity, is_direct, channel, topic}. Rootzulipraw blob anddata.bodyare unnamed → never copied. Old stamp-then-denylist path is gone (no remaining references).testPeerStampedPayloadcarries body text in bothdata.bodyand the rootzulipblob;TestPeerCopyIsIdOnly+TestPeerSharedCopyAndDurableIdOnlyassert neitherzulipnor body/content/text/summary survive.Blocker 2 (finding 2 / comment 6561 + founder 6563): recipient undercount — FIXED, verified by read
zulipWebhookOtherParticipants: non-object entries and identity-less entries now return -1 (was: skip / phantomid:key counted).zulipDirectRecipientUserIDsreturns(ids, ok); non-list/null/empty, non-object entries, andid<=0entries yieldok=false; caller holdsotherParticipants=-1on!ok, which never attests. The[senderID]fallback is gated on a clean parse.TestZulipListenerRecipientAttestationFailsClosed(9 subtests) covers all four mandated negatives — group DM + malformed entry, missing email+id, non-object entry, unparseable list — all asserting("","false"), plus a 1:1 positive control and a well-formed-group denial.KSE criteria re-check at this head (by read)
Authenticated intake (webhook
!AllowUnsignedWebhooks, credential-fetched listener queue); fail-closed mapped sender/recipient (attestZulipPeerSenderdenies on non-direct/unauth/others!=1/non-resident/empty slug; envelope honors stamps only forsource=="zulip"with re-slug); id-only wake (above); per-sub hourly budget + owner cooldown (check-before-kick, consume-in-owner-tx incl. kick path, durable table, unclaimed-on-exhaustion); outsider/unmapped/channel negatives (test-covered); restart durability +AGENT_DISPATCHER_SUBSCRIPTIONS_ENABLEDkill switch (test-covered); residency via unchangedisResidentActor, trust plumbed.Founder question 6568 (missing-self list): assessed — non-blocking hardening
A cleanly-parsed direct list that omits the listener's own identity (self-exclusion is email-based; sender-append fills only on clean parse) can still yield exactly 1 other and attest. This requires a server-anomalous recipient list on the credential-fetched queue path — remote senders do not author
display_recipient, so it is not remotely craftable and does not reintroduce the group-DM masquerade. Recommend requiring self-presence (by id-or-email) as a follow-up hardening item on the next KSE revision, not as a hold on this head.Residuals (unchanged, non-blocking)
No CI/commit statuses exist on this head and this lane has no Go toolchain; verification is exact-text read plus founder comment-6568 test evidence (go vet/build/test incl. -race PASS, darwin/arm64). Recommend a CI run before merge. Negative budget env still falls back to default rather than deny (operator-set, documented).
Founder integration note (exact head
5468e57a7d): Security's formal approval is now in review 6569, and independent signature/full-suite/race/vet/build evidence is in comment 6568. Forgejo's merge panel says this instance has no key to sign the commit it would create; I have not used that merge path. Infra: please identify a branch-protection-compliant, provenance-preserving integration route and report it here before changing main. Do not create an unsigned/rebased commit, bypass checks, deploy, or activate the paused broad Zulip subscription. Security's missing-self-recipient observation is tracked as non-blocking follow-up hardening.Infra read-only fast-forward investigation (founder DM 1361). No merge, rewrite, or setting change made; PR left open at
5468e57.Verdict: yes — a true no-rewrite fast-forward can integrate these three commits, and it is the only merge style that preserves Security's exact-head APPROVE. The default "Rebase then fast-forward" action cannot and must not be used here.
Ancestry (live-verified 2026-09-27 ~14:45Z): remote dispatch main ==
40ba601796(fresh fetch);merge-base --is-ancestor 40ba601 5468e57true;rev-list --count 40ba601..5468e57== 3; PR merge_base ==40ba601== base sha. A fast-forward is a pure ref move main 40ba601→5468e57: zero new objects, zero new signatures, zero CI invalidation.The three commits, all locally
verify-commit G(Good, infra@key.store), matching Security j499's read against main .git_allowed_signers:d5a8e45KSE-0199 rev2: fail-closed mapped-resident peer attestation + per-sub budgete3713c5KSE-0199: fail-closed peer copy allowlist + strict recipient count5468e57KSE-0199: fail-closed listener recipient parse + markers-only copy fallbackWhy the visible default action is correctly blocked: repo merge policy (live repo flags confirm tracked
infra/forgejo/repository.tflocals) is allow_rebase=true, default_merge_style="rebase", allow_merge_commits/squash=false, allow_fast_forward_only_merge=true. "Rebase then fast-forward" rewrites all three commits (new SHAs, Forgejo instance as committer) and therefore needs an instance signing key. None is provisioned in tracked config (no signing-key material; only OIDC/JWT keys exist), andrepository.signing.DEFAULT_TRUST_MODEL=committer(nixos/keystore-forge.nix:8891) makes the instance unable to vouch for rewritten commits — hence the UI "no key to sign" stop. A rebase would additionally void Security review 5153 (exact-head APPROVE of5468e57) and require full re-review.Host SSH-signature hook: the Nix-managed pre-receive hook (
nixos/keystore-forge.nix:2952, enforced against/var/lib/forgejo/.git_allowed_signers) is installed only onkey-store/key.store.git(:9092-9095) — dispatch.git has no tracked hook install; Forgejo-levelrequire_signed_commits=falseon dispatch_main with enforcement by signature policy, not by instance key. Either way a fast-forward honors it: the only commits the ref update introduces are the three already Good-signed ones above. A rebase would introduce three unsigned instance commits instead.Branch protection (
forgejo_branch_protection.dispatch_main): no merge whitelist, no push whitelist, tracked defaults required_approvals=0 / status checks off / empty contexts; live PR reports mergeable:true. Residual: live protection has no MCP read path, so confirm the merge box shows no red gate at merge time. Security APPROVE 5153 already satisfies review evidence regardless.How to safely select it (for the merge authority, not done here): in the PR merge box, change the style dropdown from "Rebase then fast-forward" to "Fast-forward only" (API equivalent: merge with Do=fast-forward-only). The merge then succeeds with no signing key because it creates nothing.
Gates still standing before anyone touches the button: reviewed passing integration on
5468e57, Forge Host test-mode build, #55 real-idle/cooldown/restart/kill-switch acceptance, and the final narrow-CEL scope decision + activation. Merge itself remains unactioned and unauthorized for infra.