feat(builtins): add identity/forward_auth resolver (draft — open to reshaping as an api_key backend) #154
All Vouch review confidence checks passed
Residual risk 0.45 = Change Risk (0.82) × (1 − Review Confidence (0.45)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.82 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Sensitive Paths
sensitive_paths
0.082
Real PR Conversation Timeline
1 comments
"Review active on #154"
general
weight: 0.35
guicassolato
Summary
Closes #212
Adds a new bundled identity resolver,
identity/forward_auth, that authenticates an opaque session credential (a BFF session cookie by default) by delegating to the endpoint that issued it — the TraefikForwardAuth/ nginxauth_requestpattern. It forwards the configured inbound headers verbatim to an external auth sub-request (e.g. oauth2-proxy's/oauth2/auth) and, on a success status, maps the response identity headers (X-Auth-Request-) into the samesubjectshape thejwtandapi_keyresolvers already produce.The credential never leaves the plugin: it is not written to
raw_credentials, so nothing downstream can replay a caller's own session to an upstream that never authenticated it. PPE never parses the cookie, never runs the OAuth code flow, and never holds a token — this stays strictly on the resource-server side (opaque-credential validation by delegation, structurally RFC 7662-style introspection).Why
PPE can already be the single edge for a stateless bearer-JWT seam. It cannot yet front a browser/BFF seam, where the credential is an opaque cookie whose contents are the BFF's secret — there is nothing for PPE to verify locally. The only correct way to authenticate it is to ask the issuer. This plugin fills that gap so one policy document can guard both the inference (JWT) and the dashboard (cookie) seams of the same app, with identity landing in one shape and metered/audited identically.
Concretely it's what lets PPE sit in front of an oauth2-proxy-fronted dashboard: verify the session in-flight, project the verified identity onto upstream headers, and bounce unauthenticated browsers to login.
Behaviour contract (the load-bearing part)
Three outcomes, kept deliberately apart:
deny. A hard identity-layerdenytakes the host's fixed-401 rejection path and skips a route'sdenyWith; leaving the identity unresolved lets the authorization layer emit a configured302bounce to login. This is what makes the plugin able to front a browser.deny(on_error: failis required of an identity resolver).--set-xauthrequestis off), rather than looping a signed-in user back to login forever.Config surface
endpoint,method(defaultGET),forward_headers(default[cookie]),identity_headers(default the oauth2-proxyX-Auth-Request-set),success_status(default[200, 202]),claim_map/claims(reusing the sharedConfiguredClaimMap), plustimeout_secs/connect_timeout_secs/max_response_bytes. Everything checkable is validated at load, so a misconfiguration stops startup rather than denying every request as though the endpoint were down.Open question — I'd like a steer before this is "final"
I've shipped this as a standalone plugin, but I suspect it shouldn't stay one, and I'd rather have the shape discussed than merged as-is. Opening as a draft for that reason.
It overlaps heavily with
identity/api_key. Both resolve an opaque credential to an identity record and project it onto the subject; both deliberately keep the credential out ofraw_credentials.api_keyalready abstracts "where records live" behind theKeyDirectorytrait (lookup(presented) -> Option<KeyRecord>) withfileandhttpbackends, a cache, arecord_map, and expiry handling.forward_authis, structurally, another directory backend — a "sub-request" backend that takes the presented credential, asks an endpoint, and returns an identity. So a plausible path forward (pun fully intended 🙂) is:identity/api_keyto something credential-generic (the mechanism isn't specific to API keys — it's "opaque credential → directory lookup → identity").KeyDirectorybackend alongsidefile/http, reusing the resolver, cache,record_map/claim_map, and expiry.Two things make it not a trivial fold-in, which is really what I want input on:
1. Verdict shape.
api_key'shttpbackend expects an identity record in the response body; forward-auth gets a status-code verdict + identity in response headers. That's a backend variation, but a real one.2. "Unauthenticated ≠ deny."
api_key's resolver denies onNone; browser-fronting requires unauthenticated-not-deny so the 302 bounce can happen. Folding these together means promoting that to a configurable resolver policy (e.g.on_unresolved: unauthenticated | deny) rather than a per-plugin hard-coded choice. That's a behavioural decision for the shared resolver, not just a new backend.Lighter overlap with
delegator/oauth. It shares the "call an external identity service over HTTP, with a cache, and never leak the credential" machinery. But it sits on the opposite hook and runs the opposite direction —token.delegateminting an outbound token (RFC 8693 exchange) vsidentity.resolveresolving an inbound session — so I don't think it's a merge candidate the wayapi_keyis. Flagging it only so the shared HTTP-callout/cache plumbing isn't reinvented a third time if the directory consolidation happens.None of this needs to land now — I'm happy to reshape the branch (rename + backend) if maintainers prefer that over a standalone plugin, or keep it standalone and converge later. Guidance on which way to go is the thing I'm after.
Tests & checks
New
forward_authtest binary (27 cases): 200/202 → authenticated subject with mapped id/groups/email, repeated headers → multi-valued claim, 401 → unauthenticated (no subject, no deny), missing credential → unauthenticated with no round-trip, transport failure → fail-closed deny, credential forwarded verbatim, configured method/timeouts reach the sub-request, and config rejection (non-absolute endpoint, zero ceilings, nosubjectsection).make check,make lint(fmt + clippy-D warnings), and the targeted tests pass; branch is rebased on currentmain.<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
New Features
Added a forward-auth identity plugin that checks configured credentials with an external authentication service and maps successful responses to identity attributes.
Supports configurable headers, HTTP method, accepted response statuses, timeouts, and response-size limits.
Rejected sessions and missing credentials remain unauthenticated; unavailable services or responses without a mappable identity are denied.
Documentation
Added guidance on configuring the plugin and its authentication outcomes.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->