Skip to content

Allow extending fine-grained admin permissions for groups to their children - #55019

Open
baptistegh wants to merge 13 commits into
keycloak:mainfrom
baptistegh:43865-group-permission-extend-children
Open

baptistegh wants to merge 13 commits into
keycloak:mainfrom
baptistegh:43865-group-permission-extend-children

Conversation

@baptistegh

@baptistegh baptistegh commented Nov 10, 2026 •

Copy link
Copy Markdown

Closes #43865

Decisions

  • Opt-in flag: the option is the extendChildren key of a new config map on ScopePermissionRepresentation. Only the keys supported by the resource type are accepted (otherwise 400), internal keys like defaultResourceType are not exposed, and a request without config keeps the existing values. Existing permissions keep their behavior, so there is no upgrade impact. The flag is rejected for resource types other than Groups, for permissions without specific groups, and outside admin permissions.
  • Most specific wins: a subgroup's own permission for a scope always decides that scope. Otherwise the closest extended parent decides, so a subgroup can be extended to override its parent. An inherited permission only decides the scopes not already decided lower down, even if it has more scopes.
  • Non-extended permissions are local: for group scopes (view, manage, manage-membership), a permission without the option only applies to its own groups and does not stop the inheritance. An admin can therefore be granted a subgroup while being denied its parent. This is intentional, so that only extended permissions take part in inheritance, and it is documented with an example.
  • Member scopes: for view-members and the other member scopes, a deny from any parent wins. User evaluation already applies the member scopes of every ancestor permission, extended or not, so once a member scope is inherited from an extended parent, the non-extended permissions of the other parents are evaluated too. This keeps group member checks, user checks and user search consistent, and the option stays opt-in: without an extended parent, group checks are unchanged.
  • Search: group and user search include inherited permissions, so members of subgroups now appear in user search and count when view-members is extended (partially addresses Unable to view childgroup users with view-members permission on the parent group #16966).
  • Permissions that do not reference the admin: partial evaluation only returns the permissions whose policies reference the current admin, so the other extended permissions are evaluated with the same logic, because a policy denying another admin grants access to the current one. When none of their policies can be partially evaluated (e.g. a group policy for a group the admin is not a member of, or a client policy), they neither grant nor deny access to the descendants in search, as for permissions that are not extended, rather than hiding them.
  • No cost without the option: the parent walk and the search expansion are skipped when no extended permission exists in the realm. This is checked with an uncached limit-1 query, run once per request, because a stale cached result could ignore inherited denies. The query can report an extended permission that does not apply (LIKE matching, case-insensitive collations), which only costs evaluating the permissions.

Known limitations

  • Search walks each extended group's subtree with one query per subgroup, so its cost grows with the hierarchy. A single recursive query is not portable through JPA across the supported databases.
  • Search does not include groups granted only by a negative policy targeting someone else, or by a client policy, since partial evaluation does not support them. This already happens without the option, so I left it out of scope.
  • A permission without policies (only possible through the REST API) is not returned by findByResourceType, so search ignores it while direct checks treat it as the group's own permission. For member scopes, the members of that group can appear in user search while being denied when accessed directly. I did not change the shared named query for this edge case; it is documented with the recommendation to associate at least one policy with every permission.

Testing

GroupResourceTypeExtendChildrenTest (67 tests) covers validation of the config map, precedence, member scopes and their composition with user evaluation, group, role and aggregated policies (including negative policies targeting others), several extended permissions on the same group, moving groups in and out of an extended hierarchy, user search and count, all member scopes (manage-membership, impersonate-members, delegate-members, manage-membership-of-members), disabling or removing an extended permission, permissions for several groups, and deeper hierarchies with siblings. Two Playwright tests cover the permission form. Unit tests cover the config options, the session caches and the default store query. The Group* and User* tests in org.keycloak.tests.admin.authz.fgap pass with the embedded server.

🤖 Generated with Claude Code

@baptistegh
baptistegh marked this pull request as ready for review November 11, 2026 16:44
@baptistegh
baptistegh requested review from a team as code owners November 11, 2026 16:44
Copilot AI balanced review requested due to automatic review settings November 11, 2026 16:44

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.

🟡 Changes recommended

An unresolved authorization flaw exposes descendant members in search/count despite ancestor denies, and resource UUIDs bypass validation of invalid extendChildren settings.

2 open issues
What changed in this PR

Adds opt-in inheritance for fine-grained group admin permissions, allowing delegated administrators to manage existing and newly created subgroups without separate grants.

Changes:

  • Adds API support, persistence, and validation for extendChildren.
  • Implements inherited permission evaluation and expands group and user searches.
  • Adds an Admin Console switch, integration and UI tests, and documentation.
File Description
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​admin/​authz/​fgap/​GroupResourceTypeExtendChildrenTest.java Tests inheritance, precedence, validation, and search.
server-spi-private/​src/​main/​java/​org/​keycloak/​authorization/​fgap/​evaluation/​partial/​ScopeRestrictedPolicy.java Restricts inherited permissions to applicable scopes.
server-spi-private/​src/​main/​java/​org/​keycloak/​authorization/​fgap/​evaluation/​partial/​PartialEvaluator.java Integrates inheritance into search filtering and separates cache contexts.
server-spi-private/​src/​main/​java/​org/​keycloak/​authorization/​fgap/​evaluation/​partial/​GroupResourceTypePolicyEvaluator.java Evaluates ancestor permissions for group access.
server-spi-private/​src/​main/​java/​org/​keycloak/​authorization/​fgap/​evaluation/​partial/​ExtendChildrenPartialEvaluator.java Resolves inherited search allowances and denials.
server-spi-private/​src/​main/​java/​org/​keycloak/​authorization/​fgap/​evaluation/​FGAPPolicyEvaluator.java Registers group-specific evaluation.
server-spi-private/​src/​main/​java/​org/​keycloak/​authorization/​fgap/​evaluation/​FGAPEvaluation.java Gives inherited grants precedence over all-groups permissions.
server-spi-private/​src/​main/​java/​org/​keycloak/​authorization/​fgap/​AdminPermissionsSchema.java Validates and detects extended permissions.
js/​libs/​keycloak-admin-client/​src/​defs/​policyRepresentation.ts Exposes the flag in the TypeScript client.
js/​apps/​admin-ui/​test/​permissions/​main.spec.ts Tests switch visibility and persistence.
js/​apps/​admin-ui/​src/​permissions-configuration/​resource-types/​ResourceType.tsx Adds the group permission switch.
js/​apps/​admin-ui/​maven-resources/​theme/​keycloak.v2/​admin/​messages/​messages_en.properties Adds explanatory help text.
docs/​documentation/​server_admin/​topics/​admin-console-permissions/​fine-grain-v2.adoc Documents inheritance rules and limitations.
docs/​documentation/​release_notes/​topics/​27_0_0.adoc Announces group hierarchy delegation.
core/​src/​main/​java/​org/​keycloak/​representations/​idm/​authorization/​ScopePermissionRepresentation.java Adds the nullable API property.
authz/​policy/​common/​src/​main/​java/​org/​keycloak/​authorization/​policy/​provider/​permission/​ScopePolicyProviderFactory.java Persists and serializes the flag.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 11, 2026 17:15

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.

🟡 Changes recommended

The evaluator treats missing permissions as denials even though permissions are filtered by the current admin, incorrectly hiding descendants from authorized group search results.

1 open issue
2 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 11, 2026 20:20
@baptistegh

Copy link
Copy Markdown
Author

While adding more tests I hit two gaps in search. They aren't caused by this PR, they also happen without extend children:

  • A permission whose policy is negative and targets someone else (for example "deny Bob") grants access when checked directly, but search only shows the group if another permission grants it too. Search only looks at permissions whose policies reference the current admin.
  • Client policies can't be evaluated in search at all, so permissions that only use them are ignored there.

In the extended case, if search can't decide a permission, it now just falls back to the other permissions instead of hiding the subgroups. I didn't try to fix the two gaps themselves since they're outside the scope of this PR, but I can open a separate issue if that helps.

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

🟡 Changes recommended

Critical flaws in scope filtering, deny propagation, and persisted inheritance flags cause inconsistent access decisions and can silently re-enable subtree permissions.

3 open issues
1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 12, 2026 07:35

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.

🔵 Needs a closer look

Human assessment is needed because the help text conflates group- and member-scope precedence, potentially misleading administrators about ancestor denies overriding closer member-scope grants.

1 open issue
2 resolved since last review

Review effort: Balanced

@baptistegh

Copy link
Copy Markdown
Author

Hi @vramik,

I answered the last Copilot thread.

This PR is ready for review on my end.

@vramik

vramik commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Thanks for the update and for marking it ready, @baptistegh. I've started going through the changes — the evolution across the 5 commits looks solid so far. I need a bit more time to finish the full review. I should get back to you by the end of next week.

@vramik vramik 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 @baptistegh for you work on this PR!

I believe I have found an issue in ExtendChildrenPartialEvaluator.evaluate().

Inherited member access bypasses restrictive policies during search.

If I take a look at the example from tests: Department > Team > Subteam and grant the admin extended view-members on Department, then restrict Team's view-members to a group the admin does no belong to, partial evaluation returns SKIP for Team's policy, so Team never enters deniedGroups. The inherited grant consequently reaches Subteam.

Direct lookup of a Subteam member returns 403, but user search returns that same user’s representation.

I have prepared regression test (just add it into your GroupResourceTypeExtendChildrenTest):

@Test
public void reviewPositiveGroupPolicyOnIntermediate() {
    GroupRepresentation others = createGroup("others");
    GroupPolicyRepresentation onlyOthers = createGroupPolicy(realm, adminPermissionsClient, "Only Others", Logic.POSITIVE, others.getId());
    createGroupPermission(department, Set.of(VIEW_MEMBERS), true, allowMyAdmin);
    createGroupPermission(team, Set.of(VIEW_MEMBERS), false, onlyOthers);
    UserRepresentation member = createMember("restricted-subteam-member", subteam);
    assertCannotView(member);
    assertThat(searchUserIds(member), empty());
}

PTAL once you have time.

@vramik
vramik requested a review from pedroigor November 20, 2026 09:26
@baptistegh

Copy link
Copy Markdown
Author

Thanks @vramik, good catch.

I've pushed a fix:

  • For permissions evaluated by the extended evaluator itself, a skipped group policy is now treated as "does not match the admin", just like in direct evaluation. A positive policy denies access, while a negative one grants it.
  • For member scopes, if a group's own permission still can't be determined (e.g. all policies in an aggregated policy are skipped), it now blocks inherited grants, just like a deny. This means search might hide members that a direct lookup would return, but it won't expose members it shouldn't.

I've also added your test.

@baptistegh
baptistegh requested a review from vramik November 20, 2026 16:58
@baptistegh
baptistegh force-pushed the 43865-group-permission-extend-children branch from 198d368 to 9ae98ab Compare November 20, 2026 16:59
Copilot AI balanced review requested due to automatic review settings November 20, 2026 16:59

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.

🟡 Changes recommended

Skipped group-policy checks can cache unauthorized grants that expose descendant groups or members in search/count results, while generic policy updates can silently reactivate inheritance.

3 open issues

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 20, 2026 18:14
baptistegh and others added 10 commits November 27, 2026 16:56
…ildren

Adds an opt-in "Extend to children" option (extendChildren in the REST API) to admin permissions for specific groups. When enabled, the permission also applies to all the subgroups of the selected groups, including subgroups created later, so that the administration of a group hierarchy can be delegated.

A subgroup's own permission for a scope takes precedence over inherited ones. For group scopes, the closest ancestor with an extended permission decides. For member scopes, a deny from any extended ancestor wins, consistently with the existing member scope cascading. Inherited permissions are also taken into account when searching groups and users.

Closes keycloak#43865

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Baptiste Gouhoury <gouhoury.baptiste@gmail.com>
When evaluating users, the member scopes of any ancestor permission, extended or not, already protect the members of a group. Group checks and searches only considered extended permissions, so a deny without extend children on an intermediate group was ignored for the members of its subgroups in group member checks and user searches, while users were denied when accessed directly.

Once a member scope is inherited from an extended ancestor, the permissions of the other ancestors for that scope are now also evaluated, and an inherited grant no longer reaches the descendants of a group whose own permission denies.

Also adds tests for the composition with user evaluation and documents the inheritance through groups with a permission that is not extended and the behavior of permissions without policies.

Closes keycloak#43865

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Baptiste Gouhoury <gouhoury.baptiste@gmail.com>
A member scope grant extended from a group was propagated to its descendants in group and user searches even when the group itself or one of its ancestors had a permission denying that scope, while direct checks denied the members. The grant is no longer propagated in that case.

Also rejects extending permissions to children when the resource for all groups is referenced by the id of its authorization resource, which was accepted and then silently treated as not extended.

Closes keycloak#43865

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Baptiste Gouhoury <gouhoury.baptiste@gmail.com>
The permissions returned by the policy providers during partial evaluation only include those whose policies reference the current admin. Extended permissions missing from them were considered as denying access, although a permission whose policy denies another admin grants access during direct evaluation, so their descendants were wrongly hidden from searches.

These permissions are now evaluated with the same logic as the others. When none of their policies can be partially evaluated, they neither grant nor deny access to the descendants, as for permissions that are not extended, instead of hiding them.

Also adds tests for other policy types, several extended permissions on the same group, moving groups, user counts, the remaining member scopes, disabling or removing an extended permission, permissions for several groups, and deeper hierarchies.

Closes keycloak#43865

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Baptiste Gouhoury <gouhoury.baptiste@gmail.com>
…pecific groups

The flag was kept when a client unaware of it updated a permission without sending it. After changing an extended permission to all groups, the flag was hidden but still stored, so changing it back to specific groups without sending the flag silently extended it to their subgroups again.

The flag is now removed once the permission no longer targets specific groups.

Closes keycloak#43865

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Baptiste Gouhoury <gouhoury.baptiste@gmail.com>
…cy in search

A group policy whose groups do not include the admin is skipped during partial evaluation. When it protected the member scopes of an intermediate group, that group did not stop a grant extended from an ancestor, so its descendants' members were returned by user searches while direct checks denied them.

For the permissions evaluated to resolve extended permissions, a skipped group policy is now resolved as during direct evaluation, where it does not match the admin and its logic applies. For member scopes, a group whose own permission still can not be decided also stops inherited grants, as a deny does.

Closes keycloak#43865

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Baptiste Gouhoury <gouhoury.baptiste@gmail.com>
The outcome of the permissions returned by the policy providers ignored their skipped group policies, so a permission whose user policy granted access to the admin, but whose group policy required a group the admin is not a member of, was extended to the descendants in group and user searches while direct checks denied it. All permissions are now evaluated again when resolving extended permissions.

Also removes the extend children flag when a permission no longer targets specific groups through the generic policy endpoints, which copy the config as is. A permission left without any resource by such an update is no longer considered to target specific groups.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Baptiste Gouhoury <gouhoury.baptiste@gmail.com>
Clarified the description of the 'extendToChildrenPermissionHelp' property to specify precedence rules for permissions.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Baptiste Gouhoury <gouhoury.baptiste@gmail.com>
The flag is specific to permissions for groups, so scope permissions now expose a config map where each resource type declares the settings it supports, with their allowed values and default value. Unsupported keys and invalid values are rejected, default values are not stored, and only the supported settings with a valid value are returned, so that internal settings such as the default resource type stay hidden and clients sending the representation back are not rejected for values stored through generic representations. When the config is not sent on update, the existing values are kept.

The flag is now only enabled by the exact value true, as generic policy endpoints store the config without validation and the admin console would otherwise show an extended permission as not extended. In search, an extended permission with a policy that can not be partially evaluated, such as a client policy, is no longer considered granted, as admin permissions are unanimous and that policy might deny access during direct evaluation. The subgroups walked when resolving extended permissions are also cached, as the subtrees of extended groups can overlap.

The permissions of a group and of its ancestors are cached for the lifetime of the session, as they are looked up for every ancestor of a group on each direct evaluation. The caches are cleared whenever a scope permission changes, including when permissions are updated or removed along with the object they are associated with.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Baptiste Gouhoury <gouhoury.baptiste@gmail.com>
Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Baptiste Gouhoury <gouhoury.baptiste@gmail.com>
@baptistegh
baptistegh force-pushed the 43865-group-permission-extend-children branch from afb48dc to b89f745 Compare November 27, 2026 15:56
Copilot AI balanced review requested due to automatic review settings November 27, 2026 15:56
@baptistegh
baptistegh requested a review from a team as a code owner November 27, 2026 15:56

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.

🟡 Changes recommended

Partial evaluation can expose denied group descendants and their members in search, while switching non-group permissions to all resources produces payloads rejected by server validation.

3 open issues

Review effort: Balanced

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Baptiste Gouhoury <gouhoury.baptiste@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 27, 2026 16:16

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.

🔵 Needs a closer look

Human assessment is needed because an unpublished critical finding indicates that pending permission changes can be missed and the false result cached, causing inherited permissions, including denies, to be skipped.

1 open issue
2 resolved since last review

Review effort: Balanced

… permissions in search

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Baptiste Gouhoury <gouhoury.baptiste@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 27, 2026 16:39

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.

🔵 Needs a closer look

Human assessment is needed because missing policy-store delegation defeats the optimization, while enabling delegation exposes transaction-visibility risks that could incorrectly skip inherited permission checks.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

…ending changes

Signed-off-by: Baptiste Gouhoury <gouhoury.baptiste@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 27, 2026 16:57
@baptistegh

Copy link
Copy Markdown
Author

@pedroigor Both done. Permissions now have a config map that only accepts the supported keys (5ef7c5b). hasExtendChildrenPermissions uses an uncached limit-1 existence query that also sees changes not yet committed in the same transaction (b89f745, cdf6361).

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.

🔵 Needs a closer look

Authorization precedence changes across runtime checks, search filters, and cached policies require maintainer validation of access consistency and supported database behavior, particularly because dependency-backed integration checks could not be run.

No open issues 🎉

Review effort: Balanced

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.

Add "extend to children" capability for group permissions in FGAP v2

4 participants