Skip to content

feat: the external decision hook, ingress stage - #60

Merged
blakebauman merged 1 commit into
mainfrom
feat/decision-hook-ingress
Aug 13, 2026
Merged

blakebauman merged 1 commit into
mainfrom
feat/decision-hook-ingress

Conversation

@blakebauman

Copy link
Copy Markdown
Member

Phase 1 of docs/design-decision-hook.md (#59) — Horizon 2, item 9.

fold's one out-of-process seam, and what makes declining a plugin runtime honest: an organization that needs its own judgement on the request path now has somewhere to put it that is a wire contract rather than a code-loading mechanism — reviewable, versionable, and runnable by a different team than the one running the gateway.

{
  "url": "https://inspector.internal/decide",
  "timeoutMs": 300,          // required — no default
  "onError": "deny",         // required — no default
  "stages": ["ingress"]      // nothing runs unless a stage is named
}

The line the feature is built on

It decides; it cannot rewrite. fold either forwards a request verbatim or refuses it. A hook that could edit traffic would be the transformation non-goal with an extra hop. A hook that wants content changed refuses and says why — and the reason reaches the caller, deliberately, because unlike a policy denial (where the expected value is the operator's config) a hook denial is usually about the caller's own content.

Ingress runs after policy. The hook's allow is necessary but never sufficient, and its operator is never handed traffic the gateway already refused. A compromised hook therefore costs availability, not authorization — TestHookRunsAfterPolicy asserts it never sees a policy-denied call.

Both bounds are required, with no defaults. A hook without a timeout is a gateway without one, and fold will not guess between fail-open and fail-closed: both are legitimate, and guessing is wrong half the time in a direction operators discover during an incident. A timeout abandons rather than waits — a slow hook is more dangerous than a broken one, because failing open makes it an invisible bypass. So a fail-open error is recorded on the event that proceeded: hookOutcome: "error" under onError: "allow" is the only record that a call went uninspected, and FoldHookErrors alerts on exactly that.

Two scope decisions the design record did not make

resources/read is not inspectable yet, and says so. Its probe fallback tries several upstreams for one URI, so inspecting it would multiply one decision by the size of the federation. Naming it in methods is a config error, not a silent no-op — a method fold does not inspect is a hook an operator believes is running and is not. It joins with the egress stage, where a resource's content is what mattered anyway.

Opting in takes two acts. Configuring an endpoint does not put it on the request path until a stage is named. Deliberate for a feature whose misconfiguration is either an outage or an unnoticed bypass.

Cost, published rather than asserted

One decision, local no-op endpoint 42 µs, 107 allocs
Added p50 through the proxy, no hook configured 181 µs (unmoved — a nil check)

fold_hook_duration_seconds reports the real number in production, with FoldHookLatencyHigh framed as what inspection costs, not a fold regression.

Verification

make check including golangci-lint (which caught an unhandled Body.Close() — the drain-then-close matters here, since a fresh connection per decision would dominate the cost), make conformance 40/40, make helm-check, and 8 integration tests: the deny path with its reason, the wire envelope asserted field by field, both failure postures across four broken-hook shapes, a hanging hook against its bound, and the two off-by-default guarantees.

Docs: README hook section, security-model (it is both a trust boundary and a data-egress path), deploy checklist, operations. Phases 2–4 (egress, the reverse path, docs pass) remain.

🤖 Generated with Claude Code

fold's one out-of-process seam, and what makes declining a plugin runtime
honest: an organization that needs its own judgement on the request path now
has a place to put it that is a wire contract rather than a code-loading
mechanism — reviewable, versionable, and runnable by a different team than the
one running the gateway.

The hook decides and cannot rewrite. fold either forwards a request verbatim
or refuses it, which is what keeps the invisibility rule intact; a hook that
could edit traffic would be the transformation non-goal with an extra hop. A
hook that wants content changed refuses the call and says why, and the reason
reaches the caller — unlike a policy denial, where the expected value is the
operator's configuration, a hook denial is usually about the caller's own
content, and a refusal nobody can act on becomes a support ticket rather than
a fix.

Ingress runs after policy, so the hook's allow is necessary but never
sufficient and its operator is never handed traffic the gateway already
refused. The compromise of a hook therefore costs availability, not
authorization.

timeoutMs and onError are required with no defaults. A hook without a bound is
a gateway without one, and fold will not guess between fail-open and
fail-closed: both readings are legitimate and guessing would be wrong half the
time, in a direction an operator discovers during an incident. A timeout
abandons the request rather than waiting, because a slow hook is more
dangerous than a broken one — failing open turns it into an invisible bypass.
Which is why a fail-open error is recorded on the event that proceeded:
hookOutcome "error" under onError "allow" is the only record that a call went
uninspected, and FoldHookErrors alerts on exactly that.

Two scope decisions the design record did not make. resources/read is not
inspectable yet — its probe fallback tries several upstreams for one URI, so
inspecting it would multiply one decision by the size of the federation — and
naming it in methods is a config error rather than a silent no-op, because a
method fold does not inspect is a hook an operator believes is running and is
not. And opting in takes two acts: configuring an endpoint does not put it on
the request path until a stage is named.

Cost is published rather than asserted: ~42 µs per decision against a local
no-op endpoint, 107 allocations, with fold_hook_duration_seconds reporting the
real thing in production. The added-latency gate is unmoved at 181 µs, because
a deployment without a hook pays a nil check. Conformance 40/40.

Phase 1 of docs/design-decision-hook.md.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@blakebauman
blakebauman merged commit 0d27469 into main Aug 13, 2026
7 checks passed
@blakebauman
blakebauman deleted the feat/decision-hook-ingress branch August 13, 2026 19:30
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