Repository navigation
Separate AuthZEN resource properties from request context - #55258
Oluwatobi-Mustapha wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the change separating AuthZEN resource properties from request context.
No open issues 🎉
What changed in this PR
This PR addresses #54848 by letting authorization policies distinguish AuthZEN resource properties from request context, while preserving existing unqualified attributes and context-first precedence.
Changes:
- Adds separate
authzen.resource.propertiesandauthzen.contextclaim paths. - Adds tests for source-specific policy evaluation and legacy precedence.
- Documents the reserved
authzenclaim root and compatibility behavior.
| File | Description |
|---|---|
| docs/guides/securing-apps/authzen-authorization.adoc | Explains source-qualified paths and unqualified attribute precedence. |
| authzen/tests/base/src/test/java/org/keycloak/tests/authzen/AuthZenEvaluationTest.java | Tests source separation and compatibility; corrects a resource-properties comment. |
| authzen/services/src/main/java/org/keycloak/authorization/authzen/AuthZenResource.java | Centralizes claim creation and exposes both sources under the reserved root. |
Review effort: Balanced
c21ce13 to
5bc4674
Compare
Closes keycloak#54848 Signed-off-by: Oluwatobi Mustapha <oluwatobimustapha539@gmail.com>
5bc4674 to
aa4723a
Compare
hakdogan
left a comment
There was a problem hiding this comment.
Thanks for working on this. As the reporter of #54848, I think a reserved namespace is a good fit for the options listed there. It keeps the existing flat keys working and gives policies a way to read each source separately.
I tested the PR locally: I replaced the AuthZEN services jar in today's quay.io/keycloak/keycloak:nightly image (999.0.0-SNAPSHOT, built 2026-11-17) with one built from this branch and compared it with the unmodified image. I also ran the authzen/tests/base suite (119/119, Spotless clean).
authzen.resource.properties.* and authzen.context.* are read independently, in single evaluations and in per-item values of an Access Evaluations request. Flat keys keep the current behavior, where context wins.
The reservation also closes a hole that exists today. On nightly, the PEP fully controls authzen.* paths by sending an authzen key, because the flat key holds the PEP's own JSON. All four of these grant a ^eu$ policy on authzen.resource.properties.region on nightly and deny with this PR:
"context":{"authzen":{"resource":{"properties":{"region":"eu"}}}}- the same object sent as a JSON string
"resource":{"properties":{"authzen":{"context":{"region":"eu"}}}}againstauthzen.context.region- an
authzenkey inresource.propertieswith no context at all
A dotted flat key such as "authzen.resource.properties.region" has no effect, on nightly or with the PR. Escaped dots in the path (a\.b), nested objects, numbers, booleans and a context nested 999 levels deep also work as expected.
Three differences between the new paths and the flat keys come from JsonUtils.getJsonValue rather than from this PR. They may be worth a sentence in the guide:
- A scalar in the middle of a path ends the lookup with that scalar. With
"resource":{"properties":{"meta":"eu"}}, a^eu$policy onauthzen.resource.properties.meta.regiongrants. The flat nested pathmeta.regionreturns 500 for the same request on nightly (Failed to resolve value from claim: meta.region). - Values are trimmed.
" eu "matches^eu$on the new path but not on the flat key. - Arrays become
[a, b]on the new path and["a","b"]on the flat key, so the same pattern can match differently.
null is also handled better on the new path. The flat key turns it into the string "null", so it matches ^null$.
Once #55264 is merged, action.properties could go under the same namespace as authzen.action.properties, and subject.properties could go under authzen.subject.properties. That would settle the open question in #54542 without new collisions. The two PRs merge cleanly, and the combined suite passes (126/126).
Closes #54848
Policies can read resource properties and request context separately through
authzen.resource.properties.*andauthzen.context.*. Other existing attribute names keep their current behavior; for duplicate names, the context value is used. The nameauthzenis reserved for these new paths.