Skip to content
GatewayMarkdown

Decide locally

Pull the realm's policies and its revocation feed into your own enforcement point, and decide every request in process with no call to the realm.

Available, with limitsAPIRFC 9110, RFC 9068

An enforcement point that decides locally keeps its own copy of the realm’s policies and of everything the realm has revoked, polls both, and decides each request in process. No request waits on the realm, and a short outage of the realm doesn’t stop your API. The price is freshness: a decision is as current as the last poll. This is how the gateway works, and how you’d build your own.

Use it when a call to the realm per request is too slow or too fragile, and your policies decide from the request and its token alone. For a policy that needs the caller’s groups, which no token carries, ask the realm. The export and the revocation feed are available today, with or without the gateway.

  • A client for your enforcement point, with the scopes policies:read and revocations:read: registering it takes a realm administrator in a group holding RealmOwner, with the API.
  • A decision engine of your own that decides by the rules on Policies, or the gateway, which does.

The enforcement point pulls two things from the realm, each with its own scope:

AddressWhat it answersScope
GET /policies/v1/export?policySet=<set>The set’s active policies, in the shape the decision engine readspolicies:read
GET /policies/v1/revocationsEverything revoked that hasn’t yet expiredrevocations:read

The export is { "result": [...], "resultCount": n, "comparators": {...}, "acrValues": {...} }: the policies, each set’s comparator, and each acr value with the sign-in chain that earns it, so the enforcement point can ask for a step-up (see Step-up and re-authentication). The header X-Policies-Excluded counts the policies the realm left out of the set. policySet may repeat; with none, every set is returned.

The revocation feed lists revoked tokens, refresh families, sessions, principals, client grants and delegations: see Revocation feed.

Both answer an entity tag. Send If-None-Match, and an unchanged answer is a 304.

  1. Register your enforcement point as a client of its own, here orders-pep, that may read both:

    Terminal window
    curl "https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client?id=orders-pep" \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{ "status": "active",
    "tokenEndpointAuthMethod": "client_secret_basic",
    "clientSecret": "<a long random secret>",
    "grantTypes": ["client_credentials"],
    "scopes": ["policies:read", "revocations:read"],
    "defaultScopes": ["policies:read", "revocations:read"],
    "allowedResources": ["https://foobar.cvyuh.com/policies/v1"],
    "defaultAudience": "https://foobar.cvyuh.com/policies/v1" }'

    Call the API shows how to get $CVYUH_SESSION. For a key in place of a secret, as the gateway uses, see Choose how a client proves itself.

  2. Get its token, and pull. The token is good for five minutes; get a new one as it runs out:

    Terminal window
    TOKEN=$(curl -s https://foobar.cvyuh.com/oauth2/token -u "orders-pep:<the secret>" \
    -d grant_type=client_credentials | jq -r .access_token)
    curl -i "https://foobar.cvyuh.com/policies/v1/export?policySet=default" -H "Authorization: Bearer $TOKEN"
    curl -i https://foobar.cvyuh.com/policies/v1/revocations -H "Authorization: Bearer $TOKEN"

    Keep each answer’s ETag, and send it back as If-None-Match on the next poll.

  3. Choose how often it polls each. Poll the revocation feed most often: a stale policy is only wrong if the policy changed, but a stale revocation list lets through a token known to be bad. The gateway polls policies every minute and revocations every 10 seconds.

  4. Decide every request by the rules below.

Your enforcement point must decide by the rules on Policies, as the realm does. The checks around the decision are its own:

  • Verify every token yourself with the realm’s keys: its signature, its issuer, your audience, its type (at+jwt) and its expiry. Then check it against every list in the revocation feed.
  • Refuse when a set is empty or missing. Nothing decided is nothing allowed.
  • Apply X-Policies-Excluded. With a policy left out, an allow isn’t an allow (policies_excluded).
  • Use the set’s comparator from comparators. A set missing from it, or a comparator you don’t know, means refuse.
  • Treat groups as unknown. A token carries none. A policy that needs them stays undecided: refuse, or ask the realm. The gateway asks.
  • Decide the resource as the API will read it. Decide on the host and port you forward to, not the one the client named. Refuse a path the API might read differently: dot segments, empty segments, encoded letters or slashes.
  • Keep the last good copy when a poll fails, and stop trusting the revocation feed when polls have failed for long enough.
  • Log your own decisions. Decisions made locally aren’t on the realm’s audit trail.
WhatValue
Policies, policy sets or resource types the export readsUp to 10,000 of each; past that, the export is an error, never a partial set
The token to read the export and the feedAudience https://foobar.cvyuh.com/policies/v1, scopes policies:read and revocations:read
How often the gateway pollsPolicies every minute, revocations every 10 seconds

What your enforcement point sees when it fails

Section titled “What your enforcement point sees when it fails”
StatusWhyWhat to do
401The token is missing, expired or for another audienceGet a new token for https://foobar.cvyuh.com/policies/v1
403The token lacks the scopeAdd policies:read or revocations:read to the client
503, or no answerThe realm couldn’t answer, or holds more policies than one export readsKeep the last good copy

Reading the export or the feed writes no record, and decisions made locally aren’t on the realm’s audit trail: log them where your enforcement point runs. Changes to policies are recorded as CREATED, PATCHED and DELETED: see Change history.

SymptomCauseFix
Your export is emptyNo active policy is linked to the set you named, or the set doesn’t existLink the policies, and check policySet
X-Policies-Excluded isn’t 0A policy in the set is incomplete, such as linked to no resource typeLink it to its type, or delete it
Your decisions disagree with the realm’sYour engine doesn’t apply the set’s comparator, or decides on another host than you forward toFollow the checks above, one by one