Skip to content
Workforce IdentityMarkdown

Test a policy safely

There's no report-only mode, so try a new rule in a policy set nothing enforces, ask the realm what it would decide, then move it in.

APIOpenID AuthZEN Authorization API 1.0

A policy decides real calls the moment it’s active in a set an enforcement point reads, and one deny refuses everything it covers. The realm has no report-only mode and no sign-in simulation. What it has is enough to test safely: a test set that no enforcement point reads, and the realm’s decision API, which answers what a set would decide for any caller you describe. This guide writes a rule in a test set, checks the answers, then moves it into the real set.

Before you start:

  • Who can do it: a realm administrator, in a group that holds RealmOwner (Delegated administration). Your session can ask the decision API.
  • Where: today this is done through the API, with your session in $CVYUH_SESSION (Call the API).
  • What you need: the rule you want, such as one from Common access policies, and the claims of a token for each kind of caller you want to try.
  1. Make a test set for the same resource type, with the same settings as the real one. Read default first and copy its comparator, subjectTypes and conditionTypes:

    Terminal window
    curl "https://foobar.cvyuh.com/api/v0/am/objects/v1/policySet?id=default-test" \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{ "comparator": "prefix",
    "conditionTypes": ["OAuth2Scope", "OAuth2AuthorizationDetails", "IPv4", "IPv6", "SimpleTime",
    "AuthenticateToService", "AND", "OR", "NOT"] }'
    curl https://foobar.cvyuh.com/api/v0/am/objects/v1/policySet/default-test/relationships/resourceTypes \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{ "targetId": "url" }'

    No enforcement point reads default-test, so nothing in it decides a real call.

  2. Write the rule in the test set, active, and link it to default-test and url, as on Policies. Add copies of the real set’s policies that the rule works beside, so the test answers as the real set will.

  3. Ask what it decides, once for each kind of caller: one it should allow, one it should refuse, and one at the edge. Name the test set in context.policySet:

    Terminal window
    curl https://foobar.cvyuh.com/access/v1/evaluation \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{ "subject": { "type": "user", "id": "<maya id>",
    "properties": { "claims": { "sub": "<maya id>", "acr": "urn:example:acr:mfa" } } },
    "resource": { "type": "url", "id": "https://admin.example.com:443/users" },
    "action": { "name": "DELETE" },
    "context": { "policySet": "default-test", "ip": "198.51.100.4" } }'
    { "decision": false, "context": { "reason": "policy_denied", "decidingPolicy": "office-network-only" } }

    Leave groups out and the realm reads the user’s groups itself. To see who a rule would let in, ask POST https://foobar.cvyuh.com/access/v1/search/subject with the same body and "subject": { "type": "user" } (Ask the realm).

  4. Move it into the real set once every answer is what you meant. Take the link to the test set away, and link the policy to default:

    Terminal window
    curl -X DELETE https://foobar.cvyuh.com/api/v0/am/objects/v1/policy/office-network-only/relationships/policySet/default-test \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
    curl https://foobar.cvyuh.com/api/v0/am/objects/v1/policy/office-network-only/relationships/policySet \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{ "targetId": "default" }'

    To change the moment it starts deciding, write it in default with "active": false instead, and set "active": true when you’re ready.

  • In the real set, ask the same questions with "policySet": "default": the answers match the test set’s.
  • At the gateway, a refused call answers 403 with the same reason.
  • On the audit trail, each deny, and each decision about an agent, is recorded as POLICY_DECIDED (Audit → Authentication). Watch it for the first hour for refusals you didn’t expect. To keep every allow too while you watch, set authorizationSettings.auditDecisions to all, and back to agents after (What is recorded).
SymptomCauseFix
404 from the decision APIThe set or resource type named doesn’t existCheck context.policySet and resource.type
Every answer is no_matching_policyThe policy isn’t linked to the test set and the type, or it’s inactiveLink both, and set active: true
The answer is policies_excludedA policy in the set breaks the set’s rulesFix it, or widen the set’s conditionTypes
The test set allows, the real set refusesThe real set holds a deny the test set doesn’tCopy the real set’s denies into the test set and ask again
The answer is subject_not_activeThe user or agent you named isn’t activeName an active one

Delete the test set’s policies, then the test set. In the real set, set a policy’s active to false to take it out of every decision at once.