8000 Add option to include parent groups in group membership mappers by tdebatty · Pull Request #55291 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
{"props":{"contextRegion":{"crumbs":[{"crumb_type":"organization","label":"keycloak","is_root":false,"href":"/keycloak"},{"crumb_type":"repository","label":"keycloak","is_root":false,"href":"/keycloak/keycloak"}],"localNavigation":[{"id":"code","icon":"code","label":"Code","href":"/keycloak/keycloak","selectedLinks":["repo_source","repo_downloads","repo_commits","repo_releases","repo_tags","repo_branches","repo_packages","repo_deployments","repo_attestations"],"popoverTarget":false,"commandId":"repositories:go-to-code","reactNav":{"appTarget":"code-view","anchor":"code-view-repo-link"},"turboNav":{"frame":"repo-content-turbo-frame"}},{"id":"issues","icon":"issue-opened","label":"Issues","href":"/keycloak/keycloak/issues","selectedLinks":["repo_issues","repo_labels","repo_milestones"],"count":2893,"popoverTarget":false,"commandId":"repositories:go-to-issues","reactNav":{"appTarget":"repo","anchor":null},"turboNav":{"frame":"repo-content-turbo-frame"}},{"id":"pull-requests","icon":"git-pull-request","label":"Pull requests","href":"/keycloak/keycloak/pulls","selectedLinks":["repo_pulls","checks"],"count":704,"popoverTarget":false,"commandId":"repositories:go-to-pull-requests","reactNav":{"appTarget":null,"anchor":null},"turboNav":{"frame":"repo-content-turbo-frame"}},{"id":"discussions","icon":"comment-discussion","label":"Discussions","href":"/keycloak/keycloak/discussions","selectedLinks":["repo_discussions"],"popoverTarget":false,"commandId":"repositories:go-to-discussions","reactNav":{"appTarget":null,"anchor":null},"turboNav":{"frame":"repo-content-turbo-frame"}},{"id":"actions","icon":"play","label":"Actions","href":"/keycloak/keycloak/actions","selectedLinks":["repo_actions"],"popoverTarget":false,"commandId":"repositories:go-to-actions","reactNav":{"appTarget":"repo","anchor":null},"turboNav":{"frame":"repo-content-turbo-frame"}},{"id":"projects","icon":"table","label":"Projects","href":"/keycloak/keycloak/projects","selectedLinks":["repo_projects","new_repo_project","repo_project"],"popoverTarget":false,"commandId":"repositories:go-to-projects","reactNav":{"appTarget":"repo","anchor":null},"turboNav":{"frame":"repo-content-turbo-frame"}},{"id":"security-and-quality","icon":"shield","label":"Security and quality","href":"/keycloak/keycloak/security","selectedLinks":["security","overview","alerts","policy","token_scanning","code_scanning"],"count":83,"popoverTarget":false,"commandId":"repositories:go-to-security","reactNav":{"appTarget":null,"anchor":null},"turboNav":{"frame":"repo-content-turbo-frame"}},{"id":"insights","icon":"graph","label":"Insights","href":"/keycloak/keycloak/insights","selectedLinks":["repo_graphs","repo_contributors","dependency_graph","dependabot_updates","pulse","people","community"],"popoverTarget":false,"commandId":"repositories:go-to-insights","reactNav":{"appTarget":null,"anchor":null},"turboNav":{"frame":"repo-content-turbo-frame"}}],"localNavigationUpdateChannel":null,"selectedLink":"repo_pulls"},"owner":null,"headerLogo":{"href":"/","aria-label":"Homepage "},"notifications":{"indicatorMode":"disabled","websocketChannel":null,"fetchIndicatorSrc":"/notifications/indicator","fetchIndicatorEnabled":false},"issues":{"href":"/issues"},"pulls":{"href":"/pulls"},"contributedRepos":{"href":"/repos"},"copilot":{"show":false,"showAgentsButton":false,"showRelaunchAnnouncement":false,"licenseGrantNudge":null,"copilotChatUrl":null,"copilotApiUrl":"https://api.githubcopilot.com"},"search":{"show":true,"showCommandPalette":false,"isSearchPage":false,"isJumpToSearch":false,"searchContext":{"scope":"repo:keycloak/keycloak","current_repo_name":"keycloak","current_repo_nwo":"keycloak/keycloak","current_repo_org":"keycloak","user_id":"keycloak"}},"commandPalette":null,"enterpriseBar":{"show":false},"globalTransactionalMessage":[],"payloadsUrl":"/_global-navigation/payloads.json?can_toggle_site_admin_and_employee_status=0\u0026is_admin_mode_on=0\u0026is_ui_opted_out=0\u0026show_ui_opt_out=0\u0026v=8","contextRegionUrl":null}}

Add option to include parent groups in group membership mappers - #55291

Open
tdebatty wants to merge 4 commits into
keycloak:mainfrom
tdebatty:main
Open

tdebatty wants to merge 4 commits into
keycloak:mainfrom
tdebatty:main

Conversation

@tdebatty
Copy link
Copy Markdown

This adds a new "include.parent.groups" configuration option (default false) to the OIDC and SAML GroupMembershipMapper protocol mappers. When enabled, the group claim/attribute contains not only the groups the user is a direct member of, but also all parent groups, de-duplicated by group ID. This makes the claim more useful for downstream authorization decisions based on ancestor groups.

The hierarchy is computed by a new KeycloakModelUtils.getGroupHierarchy helper, which walks up the parent chain and returns the groups ordered from the top-level ancestor down to the given group. Organization groups are treated as top-level, so their hierarchy consists of the group itself. De-duplication is done by group ID rather than name, since names are not unique across the hierarchy.

Closes #51755

@tdebatty
tdebatty requested a review from a team as a code owner November 17, 2026 19:59
Copilot AI balanced review requested due to automatic review settings November 17, 2026 19: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

The test flattens all attribute values without asserting two single-valued attributes, so it can pass even if the mapper ignores single=false when parent groups are enabled.

1 open issue
What changed in this PR

Adds an opt-in setting to include ancestor groups in OIDC group claims and SAML group attributes, supporting authorization based on inherited group membership while preserving existing defaults.

Changes:

  • Adds include.parent.groups, defaulting to false, to both protocol mappers.
  • Introduces a shared hierarchy helper and de-duplicates expanded memberships by group ID.
  • Adds unit and integration coverage for parent inclusion, full paths, and de-duplication.
File Description
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​admin/​group/​GroupMappersTest.java Adds an OIDC parent-group integration test.
services/​src/​test/​java/​org/​keycloak/​protocol/​saml/​mappers/​GroupMembershipMapperTest.java Tests parent inclusion and SAML attribute modes.
services/​src/​test/​java/​org/​keycloak/​protocol/​oidc/​mappers/​GroupMembershipMapperTest.java Tests defaults, ancestor expansion, paths, and distinct group IDs.
services/​src/​main/​java/​org/​keycloak/​protocol/​saml/​mappers/​GroupMembershipMapper.java Adds optional ancestor expansion for SAML attributes.
services/​src/​main/​java/​org/​keycloak/​protocol/​oidc/​mappers/​GroupMembershipMapper.java Adds optional ancestor expansion for OIDC claims.
server-spi-private/​src/​main/​java/​org/​keycloak/​models/​utils/​KeycloakModelUtils.java Adds the shared group hierarchy helper.

Review effort: Balanced

… attributes when parent groups are enabled'

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Thibault Debatty <thibault.debatty@proton.me>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 20:47
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 reported for the opt-in ancestor-group mapping change.

No open issues 🎉

1 resolved since last review

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.

OIDC and SAML group mappers do not include parent groups

2 participants

0