feat(forward-auth): cache authorization decisions at the edge#13664
Open
shreemaan-abhishek wants to merge 1 commit into
Open
feat(forward-auth): cache authorization decisions at the edge#13664shreemaan-abhishek wants to merge 1 commit into
shreemaan-abhishek wants to merge 1 commit into
Conversation
forward-auth makes a synchronous HTTP call to the authorization service on every request. Add an opt-in cache block that stores allow/deny decisions in a per-worker lrucache, cutting calls to the auth service for repeated callers. Correctness guardrails, since this is an auth path: - Cache key is namespaced per plugin conf/version and built from the configured identity headers, optionally method/URI, and (for POST) a hash of the forwarded body, so decisions never cross identities. - Honors upstream Cache-Control (no-store/no-cache/private skip caching, max-age caps the TTL) and never caches transient 5xx; short opt-in TTL by default. - Both allow and deny outcomes are replayed faithfully on a hit. Adds t/plugin/forward-auth4.t (hit/miss, identity isolation, deny replay, no-store, include_uri, POST-body keying) and documents the cache attributes with an example.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
forward-authmakes a synchronous HTTP call to the external authorization service on every request, which dominates its per-request overhead. This adds an opt-in per-worker cache of authorization decisions so repeated calls from the same caller can be served without hitting the auth service.A new optional
cacheblock:When present, an allow/deny decision is stored in a per-worker
resty.lrucacheand replayed on subsequent matching requests.Because this is an authorization path, correctness is prioritized over speed:
plugin_ctx_id, so config edits invalidate it) and built from the operator-declaredkey_headersvalues, optionally the method/URI, and — forPOST— anmd5of the forwarded body.key_headersis required whenever caching is enabled, so there is no implicit "cache everything" default.no-store/no-cache/privateskip caching;max-agecaps the TTL (andmax-age=0skips).5xxresponses are never cached.cacheblock the plugin behaves exactly as before.Which issue(s) this PR fixes
N/A (enhancement).
Checklist
Tests
New
t/plugin/forward-auth4.tcounts actual auth-service invocations via a shared dict and asserts:key_headersand enforcesttlboundsCache-Control: no-storeis honored (not cached)include_urikeys on the request URIPOSTbody is part of the cache keyExisting
forward-auth.t/forward-auth2.t/forward-auth3.tstill pass unchanged.