Skip to content

Separate AuthZEN resource properties from request context - #55258

Open
Oluwatobi-Mustapha wants to merge 1 commit into
keycloak:mainfrom
Oluwatobi-Mustapha:authzen-attribute-sources
Open

Oluwatobi-Mustapha wants to merge 1 commit into
keycloak:mainfrom
Oluwatobi-Mustapha:authzen-attribute-sources

Conversation

@Oluwatobi-Mustapha

@Oluwatobi-Mustapha Oluwatobi-Mustapha commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Closes #54848

Policies can read resource properties and request context separately through authzen.resource.properties.* and authzen.context.*. Other existing attribute names keep their current behavior; for duplicate names, the context value is used. The name authzen is reserved for these new paths.

@Oluwatobi-Mustapha
Oluwatobi-Mustapha requested a review from a team as a code owner November 17, 2026 09:49
Copilot AI balanced review requested due to automatic review settings November 17, 2026 09:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.properties and authzen.context claim paths.
  • Adds tests for source-specific policy evaluation and legacy precedence.
  • Documents the reserved authzen claim 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

Copilot AI balanced review requested due to automatic review settings November 17, 2026 10:02
@Oluwatobi-Mustapha Oluwatobi-Mustapha changed the title Separate AuthZEN resource and context attributes Separate AuthZEN resource properties from request context Nov 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the change exposing separate AuthZEN resource properties and request context to policies.

No open issues 🎉

Review effort: Balanced

Closes keycloak#54848

Signed-off-by: Oluwatobi Mustapha <oluwatobimustapha539@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 10:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the AuthZEN attribute-path changes.

No open issues 🎉

Review effort: Balanced

@hakdogan hakdogan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"}}}} against authzen.context.region
  • an authzen key in resource.properties with 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:

  1. A scalar in the middle of a path ends the lookup with that scalar. With "resource":{"properties":{"meta":"eu"}}, a ^eu$ policy on authzen.resource.properties.meta.region grants. The flat nested path meta.region returns 500 for the same request on nightly (Failed to resolve value from claim: meta.region).
  2. Values are trimmed. " eu " matches ^eu$ on the new path but not on the flat key.
  3. 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AuthZEN: resource.properties and context share one attribute namespace, and context silently overrides resource properties

3 participants