← Back to Pull requests

feat(builtins): add identity/forward_auth resolver (draft — open to reshaping as an api_key backend) #154

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 01, 2026 14:02 UTC
Author

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 Traefik ForwardAuth / nginx auth_request pattern. 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 same subject shape the jwt and api_key resolvers 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:

  • Unauthenticated — the endpoint is reachable and says the session is invalid, or the request carried no forwardable credential. No subject, and crucially no deny. A hard identity-layer deny takes the host's fixed-401 rejection path and skips a route's denyWith; leaving the identity unresolved lets the authorization layer emit a configured 302 bounce to login. This is what makes the plugin able to front a browser.

  • Error — the endpoint can't be reached. Fail-closed deny (on_error: fail is required of an identity resolver).

  • Mapped — a success status; the identity headers project onto the subject. A success carrying no mappable identity denies as a misconfiguration (e.g. --set-xauthrequest is off), rather than looping a signed-in user back to login forever.
  • Config surface

    endpoint, method (default GET), forward_headers (default [cookie]), identity_headers (default the oauth2-proxy X-Auth-Request- set), success_status (default [200, 202]), claim_map / claims (reusing the shared ConfiguredClaimMap), plus timeout_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 of raw_credentials. api_key already abstracts "where records live" behind the KeyDirectory trait (lookup(presented) -> Option<KeyRecord>) with file and http backends, a cache, a record_map, and expiry handling. forward_auth is, 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:

  • Rename identity/api_key to something credential-generic (the mechanism isn't specific to API keys — it's "opaque credential → directory lookup → identity").

  • Add this forward-auth behaviour as a third KeyDirectory backend alongside file / 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's http backend 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 on None; 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.delegate minting an outbound token (RFC 8693 exchange) vs identity.resolve resolving an inbound session — so I don't think it's a merge candidate the way api_key is. 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_auth test 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, no subject section). make check, make lint (fmt + clippy -D warnings), and the targeted tests pass; branch is rebased on current main.

    <!-- 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 -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: guicassolato Review duration: 73113m
    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
    0.82
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 44.7% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 82.2% (HIGH) · Higher = larger blast radius
    82.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.7% · Lower = rushed or shallow review
    44.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 45.5% · Moderate risk
    45.5%