8000 Add organization roles by ggomarighetti · Pull Request #50606 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Add organization roles - #50606

Open
ggomarighetti wants to merge 6 commits into
keycloak:mainfrom
ggomarighetti:feature/40585-organization-roles
Open

ggomarighetti wants to merge 6 commits into
keycloak:mainfrom
ggomarighetti:feature/40585-organization-roles

Conversation

@ggomarighetti
Copy link
Copy Markdown
Contributor

Resume

This PR adds Organization Roles as a first-class role type across the Keycloak model, persistence, admin APIs, protocol mapping, export/import, admin client, and Admin UI layers.

Organization roles belong to a single organization within a realm. They are isolated from realm and client roles, can reuse role names across different organizations, and can only be mapped to members of their owning organization. Existing realm and client role behavior is preserved by making role lookups, mappings, composites, authorization checks, and representation conversion aware of the role container/type instead of assuming the previous realm/client-only split.

The implementation introduces the model contracts for organization-owned roles, persists them in the existing role storage with explicit type and organization ownership, and wires the behavior through JPA, storage-private, Infinispan cache, role lookup APIs, composite handling, user role mappings, and organization lifecycle cleanup. Organizations now also have a protected default organization role that is created with the organization, assigned through membership lifecycle, exported/imported with the organization, and protected from direct user-mapping mutations.

The admin REST surface now exposes organization-scoped role management under organizations. It supports role CRUD, users-in-role, available users, composites, effective composites, permission checks, and admin events while keeping generic realm/client role endpoints from accepting organization roles where they should remain scoped to their original containers. Fine-grained admin permissions were updated so classic FGAP and FGAP v2 can evaluate organization role access consistently.

Protocol integration adds OIDC and SAML organization role membership mappers, plus IdP mapper support for hardcoded organization role assignments. Token claims expose organization role membership under the organization claim, while realm/client composites continue to resolve through the normal role resolution and client scope rules.

Export/import support was extended so organization roles, default roles, role mappings, composites, and references survive realm and organization round trips. Upgrade/migration logic initializes the new role type/organization columns and default role relationships for existing data.

The Admin UI now includes organization role management inside the organization detail area. Users can list, create, edit, delete, inspect permissions, assign members, manage composites, and view effective inherited composites for organization roles. The JS admin client and Java admin client were extended with matching organization role resources.

The change is covered across unit, model, cache, REST, protocol mapper, export/import, admin-client, Admin UI, and browser-level tests.

Evidence

Covered by unit, integration, admin-client, and Admin UI tests added with this change.

Reference

Closes #40585

Copilot AI balanced review requested due to automatic review settings July 4, 2026 09:01
@ggomarighetti
ggomarighetti requested review from a team as code owners July 4, 2026 09:01
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 wasn't able to review this pull request because it exceeds the maximum number of lines (20,000). Try reducing the number of changed lines and requesting a review from Copilot again.

@ggomarighetti
Copy link
Copy Markdown
Contributor Author

Design notes and review topics

These are the main design choices behind the implementation. Some of them are straightforward extensions of existing organization/group patterns, while others are called out because they affect public SPI, storage semantics, or review expectations.

  1. Role rename events now carry the role model itself. RoleNameChangeEvent extends RoleEvent, so consumers classify the renamed role through event.getRole().getType() and its container. This follows the direction used by group events and avoids adding one accessor per possible role container.

  2. Role type is now explicit. RoleModel.Type distinguishes realm, client, and organization roles, with stable persisted integer values. This removes the old binary assumption that a role is either “client” or “realm”, which would not be safe once organization roles exist.

  3. Organization-role SPI additions were introduced in a source-compatible way. Built-in providers implement the new behavior, while providers that do not support organization roles are not made to silently return partial data.

  4. Realm-wide role lookup remains broad, while organization lookup is scoped. getRoleById(realm, id) can still resolve any role in the realm, matching the group lookup precedent. Organization APIs use the organization-aware lookup and generic role endpoints reject organization roles so callers use the organization-scoped surface.

  5. Organization role composites keep structure inside the organization but may aggregate realm/client permissions. A role from one organization cannot be composed into another organization, and realm/client roles cannot contain organization roles. The allowed direction mirrors organization groups: organization-owned structure can grant global permissions, but global structures do not absorb organization-owned roles.

  6. The default organization role is a real protected role. It is created with the organization, assigned through membership lifecycle, preserved in export/import, and protected from direct user-mapping mutations. Membership remains the source of truth for who has that default role.

  7. Existing organizations are reconciled during upgrade. The migration eagerly creates missing default roles and assigns them to existing members, rather than relying on lazy repair later. That makes the post-upgrade model immediately consistent at the cost of bounded migration work.

  8. Organization role claims are attributed under the organization claim. Dedicated OIDC and SAML mappers emit organization roles under each organization entry. Realm/client composites can also appear there as organization-attributed effective permissions, while top-level realm/client claims continue to follow the normal global role and client-scope rules.

  9. IdP mappers do not create organization membership implicitly. The hardcoded organization role mapper uses the organization linked to the IdP as authority. Stale configuration is skipped with diagnostics, but trying to grant an existing organization role to a non-member fails to preserve the membership invariant.

  10. IdP mapper configuration uses a typed organization-role selector. The mapper stores a role id, but the UI exposes a scoped selector instead of asking administrators to paste raw ids. Save-time validation was added through the IdP mapper validation hook so invalid references are caught before runtime when possible.

  11. Organization roles participate in full realm export/import. This extends the existing full organization round trip instead of introducing a separate organization import/export API. Partial import remains out of scope, matching the current organization export/import boundary.

  12. Export/import references follow existing role conventions. Role definitions can preserve ids, but member mappings refer to organization roles by name, like realm and client role mappings. This keeps the payload portable and avoids ambiguous fallback behavior between names and ids.

  13. Organization role definitions stay in local role storage. Federated user mappings are still validated against organization membership, but external role providers are not asked to define organization roles unless they explicitly implement the new capability. This avoids stretching legacy role storage contracts beyond the containers they can represent.

  14. Organization roles map directly to members, not organization groups. Direct group mappings are intentionally left out of the initial model. Removing a member from an organization removes that member’s organization role mappings for that organization.

  15. Users-in-role is queried through organization membership first. The organization provider intersects organization membership and role membership before pagination. This avoids paging role members globally and filtering the page afterward, which would produce short or misleading result pages.

  16. FGAP decisions are evaluated by the backend, not inferred by the UI. Organization role responses include access information where the UI needs it. The UI uses those capabilities for view/manage/map/composite actions instead of deriving permissions from broad organization permissions.

  17. Available composites are resolved by an organization-role-specific endpoint. The backend has the parent role, organization boundary, topology rules, existing composites, and permission context needed to return an authoritative page. The UI does not fetch generic pages and filter them client-side.

  18. Effective composites are exposed for organization roles. The UI shows direct composites by default and can show effective inherited composites, matching the inspection pattern users already expect from role mapping screens. This avoids making organization roles harder to audit than existing role containers.

  19. Cache invalidation stays targeted. Duplicate invalidation paths were removed or kept behind the responsible helper, and cache tests cover rename, removal, composites, membership pagination, and default-role relationships. The implementation avoids generalizing client-specific cache records unless there is an organization-specific consumer.

  20. Admin events use organization-specific resource types and paths. Organization role CRUD, composites, and user mappings emit events under organization-aware paths. Empty or failed mutations do not emit misleading success events.

  21. The Admin UI follows the organization surface. Organization role management lives under organization details, with CRUD, members, composites, effective composites, permissions, and default-role protection handled there. Generic role screens are not expanded to silently manage organization roles.

  22. Test structure was adjusted to match the feature boundaries. Backend tests cover model, storage, cache, REST, protocol, export/import, and permission behavior; Admin UI tests were split into focused unit/component and browser flows. The browser flow exercises creation, editing, composites, effective composites, members, default-role protection, and deletion.

@ggomarighetti
ggomarighetti force-pushed the feature/40585-organization-roles branch 2 times, most recently from feed236 to 771cc26 Compare July 4, 2026 09:35
Copilot AI review requested due to automatic review settings July 4, 2026 09:35
< 8000 a class="TimelineItem-avatar circle mt-n1 " aria-label="Copilot PR reviewer" data-hovercard-type="copilot" data-hovercard-url="/copilot/hovercard?bot=copilot-pull-request-reviewer" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="/apps/copilot-pull-request-reviewer">
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 wasn't able to review this pull request because it exceeds the maximum number of lines (20,000). Try reducing the number of changed lines and requesting a review from Copilot again.

Copilot AI review requested due to automatic review settings July 4, 2026 10:45
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 wasn't able to review this pull request because it exceeds the maximum number of lines (20,000). Try reducing the number of changed lines and requesting a review from Copilot again.

@martin2844
Copy link
Copy Markdown

LGTM - rather helpful, let's get it reviewed by code owners

Copilot AI review requested due to automatic review settings July 4, 2026 13:36
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 wasn't able to review this pull request because it exceeds the maximum number of lines (20,000). Try reducing the number of changed lines and requesting a review from Copilot again.

@pedroigor
Copy link
Copy Markdown
Contributor

@ggomarighetti Do you mind if I squash all commits? Rebasing is becoming tricky ...

@ggomarighetti
Copy link
Copy Markdown
Contributor Author

@pedroigor Sure, no problem. Please go ahead and squash them. Thanks!

Copilot AI review requested due to automatic review settings August 5, 2026 18:23
@pedroigor
pedroigor force-pushed the feature/40585-organization-roles branch from e8b36f0 to e1aa9da Compare August 5, 2026 18:23
@keycloak-github-bot keycloak-github-bot Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.forms.BruteForceTest#testExceedMaxTemporaryLockouts

Keycloak CI - Base IT (5)

org.opentest4j.AssertionFailedError: Expected error event ==> expected: <true> but was: <false>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertTrue.failNotTrue(AssertTrue.java:63)
	at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:36)
...

Report flaky test

@pedroigor
Copy link
Copy Markdown
Contributor

@ggomarighetti Added the commit to support assigning org roles to org groups, additional validation/access checks, and tests.

Regarding the change to avoid assigning default roles directly to users, feel free to change the outline. From my side, the general idea is to grant the default role to the organization's internal group so that all members of the group/org will automatically inherit the roles from the group.

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

A critical export/import defect and multiple moderate authorization, inheritance, and Admin UI regressions remain unresolved.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (4)

docs/documentation/upgrading/topics/changes/changes-26_8_0.adoc:222

  • This upgrade note documents the new type checks but omits the source-incompatible SPI additions: custom RoleContainerModel implementations must now implement getRealm(), and custom RoleProvider implementations must implement the new generic role methods. Document these required provider changes here so extension authors can upgrade without unexpected compilation failures.
=== Generic role type checks

`RoleModel` now distinguishes realm, client and organization roles through `getType()` and the new `isType(RoleModel.Type)` convenience method.
The existing `RoleModel#isClientRole()` method remains available for compatibility but is deprecated; new code should use `isType(RoleModel.Type.CLIENT)`.

js/apps/admin-ui/src/components/role-mapping/RoleMapping.tsx:218

  • getRoleMappings() now returns organization mappings for users as well as groups, and the table makes those rows selectable. On a user page groupsResource is undefined, so selecting an organization role reaches this false branch, performs no deletion, and still shows the success alert; either disable/hide these rows outside group mappings or implement deletion through the owning organization role resource.
          ...(orgRoles.length > 0 && groupsResource
            ? [
                (groupsResource as any).delOrganizationRoleMappings({
                  id,
                  roles: orgRoles.map((row) => cleanRole(row.role)),
                }),
              ]
            : []),

js/apps/admin-ui/src/components/role-mapping/RoleMapping.tsx:165

  • When inherited roles are shown, mapRoles renders only allEffectiveRoles; that backend response intentionally excludes organization roles, so all direct organization mappings in orgMapping disappear from the table when the checkbox is unchecked. Merge the direct organization rows into the effective set before mapping.
    return [
      ...mapRoles(
        [...clientMapping, ...realmRolesMapping, ...orgMapping],
        allEffectiveRoles,
        hide,
      ),
    ];

server-spi-private/src/main/java/org/keycloak/organization/validation/OrganizationsValidation.java:76

  • Organization groups from a different organization pass this branch: once both the group and role are organization-scoped, the method returns without comparing their owners. A direct model-layer group.grantRole(roleFromOtherOrg) can therefore grant cross-organization access; reject organization roles whose container ID differs from group.getOrganization() before returning.
  • Files reviewed: 144/145 changed files
  • Comments generated: 4
  • Review effort level: Balanced

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

A critical cross-organization isolation flaw and five moderate correctness, export, token, and Admin UI issues remain unresolved.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (7)

js/apps/admin-ui/src/components/role-mapping/AddRoleMappingModal.tsx:124

  • AddRoleButton is reused by user, client-scope, policy, and role-composite screens, but this unconditional option is shown to every manage-organizations user; those callers pass no group resource, so choosing it opens an always-empty picker. Gate this option on an explicit organization-group capability from the caller.
        {canViewOrganizationRoles && (
          <DropdownItem
            data-testid="org-roles"
            component="button"
             => {
              onFilerTypeChange("orgRoles");
            }}
          >
            {t("organizationRoles")}
          </DropdownItem>
        )}

js/apps/admin-ui/src/components/role-mapping/RoleMapping.tsx:218

  • getRoleMappings now returns organization mappings for users, but a user-role page has no groupsResource; selecting such a row makes this condition false, sends no deletion request, and then shows success. These rows must be disabled outside organization-group mappings (or removed through an organization-scoped endpoint).
          ...(orgRoles.length > 0 && groupsResource
            ? [
                (groupsResource as any).delOrganizationRoleMappings({
                  id,
                  roles: orgRoles.map((row) => cleanRole(row.role)),
                }),
              ]
            : []),

server-spi-private/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java:255

  • Organization role mappings on groups are collected here but never written to GroupRepresentation, and the import path likewise has no organization-role field. Consequently, exporting and re-importing an organization silently drops all organization roles assigned to its groups; extend the group representation and both export/import paths to preserve this map.
    services/src/main/java/org/keycloak/services/resources/admin/RoleMapperResource.java:402
  • Unlike the realm-role equivalent, this available-role query does not filter through canMapRole. Through the generic group endpoint, a caller with group-view access can therefore enumerate organization roles they are not authorized to map.
    services/src/main/java/org/keycloak/services/resources/admin/RoleMapperResource.java:443
  • This path checks permission to manage the group but never checks permission to map the requested role. The generic group endpoint can therefore assign an organization role without the owning organization's canMapRole authorization; call requireMapRole before granting it.
    services/src/main/java/org/keycloak/services/resources/admin/RoleMapperResource.java:478
  • Removal has the same authorization gap as addition: group-manage permission alone can remove an organization role mapping through the generic group endpoint. Require mapping permission on the role before deleting the mapping.
    services/src/main/java/org/keycloak/utils/RoleResolveUtil.java:117
  • Filtering organization roles here is too late for full-scope clients: TokenManager.getAccess has already expanded their composites, so realm/client children of an organization role remain in the stream and are emitted into top-level realm_access/resource_access. This leaks organization-derived privileges outside the organization claim; exclude organization-role roots before regular token role expansion while retaining their separate organization-claim resolution.
  • Files reviewed: 145/146 changed files
  • Comments generated: 3
  • Review effort level: Balanced

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

@ggomarighetti
ggomarighetti commented Sep 13, 2026 •
Copy link
Copy Markdown
Contributor Author

@pedroigor assignment of default role through default group pushed. GH Copilot comments and rebase conflicts remains pending.

EDIT: GH Copilot comments solved and closed, conflicts remains..

EDIT2: Conflicts solved, branch updated...

EDIT3: I'm solving now idp selector conflicts...

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

@ggomarighetti
Copy link
Copy Markdown
Contributor Author

@pedroigor refactor pushed, comments solved, branch updated, remaining failed checks it's external doc, not from this PR.

ggomarighetti and others added 5 commits September 16, 2026 00:24
Add organization-scoped role models, persistence, admin APIs, protocol mappers, admin UI support, and integration coverage.

Closes keycloak#40585

Signed-off-by: Guillermo Orue Marighetti <ggomarighetti@gmail.com>
Signed-off-by: Pedro Igor <pigor.craveiro@gmail.com>
Signed-off-by: Pedro Igor <pigor.craveiro@gmail.com>
Signed-off-by: Pedro Igor <pigor.craveiro@gmail.com>
Closes keycloak#40585

Signed-off-by: Guillermo Orue Marighetti <ggomarighetti@gmail.com>
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 was unable to review this pull request because the user who requested the review has reached their quota limit.

Scope role uniqueness by container type and bound default role names.
Respect client role scopes in organization claims and preserve the
configured or default membership claim name.

Honor listing permissions and independent pagination parameters, and
show client identifiers for composite roles.

Cover organization role LDAP, federation, export and SAML scenarios in
the new test framework while preserving the historical tests.

Refs keycloak#40585

Signed-off-by: Guillermo Orue Marighetti <ggomarighetti@gmail.com>
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 was unable to review this pull request because the user who requested the review has reached their quota limit.

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.cluster.ClientScopeInvalidationClusterTest#crudWithoutFailover

Keycloak CI - Clustering IT

org.opentest4j.AssertionFailedError: expected: <false> but was: <true>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertFalse.failNotFalse(AssertFalse.java:63)
	at org.junit.jupiter.api.AssertFalse.assertFalse(AssertFalse.java:36)
...

Report flaky test

org.keycloak.testsuite.cluster.ClientScopeInvalidationClusterTest#crudWithFailover

Keycloak CI - Clustering IT

jakarta.ws.rs.WebApplicationException: Create method returned status Forbidden (Code: 403); expected status: Created (201). Response body: {"error":"HTTP 403 Forbidden"}
	at org.keycloak.testsuite.admin.ApiUtil.getCreatedId(ApiUtil.java:38)
	at org.keycloak.testsuite.cluster.ClientScopeInvalidationClusterTest.createEntity(ClientScopeInvalidationClusterTest.java:56)
	at org.keycloak.testsuite.cluster.ClientScopeInvalidationClusterTest.createEntity(ClientScopeInvalidationClusterTest.java:32)
	at org.keycloak.testsuite.cluster.AbstractInvalidationClusterTest.createEntityOnCurrentFailNode(AbstractInvalidationClusterTest.java:111)
...

Report flaky test

@keycloak-github-bot keycloak-github-bot Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@martin2844 martin2844 left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM (lets get this merged)

@HosseinNejatiJavaremi
Copy link
Copy Markdown

Thanks for your work on organization roles! Is there an estimated timeline for merging this PR, or a target Keycloak release for this feature?

@vramik
vramik commented Nov 9, 2026
Copy link
Copy Markdown
Contributor

@HosseinNejatiJavaremi

The current aim is to have it ready for KC27.

@judsonx
judsonx commented Nov 9, 2026 •
Copy link
Copy Markdown

@ggomarighetti , @pedroigor Thank you for this work. I have pulled down this code for testing and noticed an important behavior that caught my attention.

Some of the below content was generated with the help of Claude, but I did test the behavior manually.

Organization-derived realm/client roles ignore the selected organization

Setup: A user belongs to tenant-1 and tenant-2. In tenant-1 they hold an org role that is a composite containing the client role document-processor-api:use. In tenant-2 they hold no org roles. The client requests scope=organization document-processor-api:use. The user picks tenant-2 on the select-organization page.

Result:

  • "organization": ["tenant-2"], which is correct.
  • resource_access.document-processor-api.roles contains api:use, granted only through the tenant-1 org role.
  • The optional client scope document-processor-api:use is also granted, for the same reason.

Expected: When the session is bound to one organization, only that organization's org roles (and their composites) should contribute to the token's roles. As it stands, an API that checks top-level resource_access can't tell which tenant granted a role. A role granted in one tenant carries over into sessions for another.

Cause: Both role computations call RoleUtils.getDeepUserRoleMappings(user):

  • TokenManager.getAccess() builds the top-level realm_access/resource_access.
  • DefaultClientSessionContext.loadUserRoles() checks whether an optional client scope is granted.

That method collects direct role mappings and role-mapping groups for every organization (getRoleMappingsGroupsStream()), then expands composites. It never reads the client session's kc.org note. RoleResolveUtil.addToToken() hides only the org role itself, not the realm and client roles inside it. Only the Organization Role Membership mapper's per-org organization.<alias> claim respects the selection.

Docs: managing-roles.adoc says associated realm and client roles go into the top-level claims "whenever the member effectively holds the organization role". So this may be intended. It's still surprising for multi-tenant clients that use the organization (ANY) scope or organization:<alias>.

Possible fix: When the client session has a selected organization, drop role mappings that come from other organizations before expanding composites. That covers both direct org-role grants and roles mapped to other orgs' groups. Apply it to the token and client-scope role computation. Keep the current behavior when no org is selected. Leave user.hasRole() and admin/authorization checks unchanged unless there's a reason to change them.

Questions:

  1. Is the current behavior intentional?
  2. If it is, is the recommended pattern to read organization.<alias>.resource_access instead of top-level resource_access?

See also, proposed patch:
organization-roles-selected-org.patch

@ggomarighetti
Copy link
Copy Markdown
Contributor Author

Hi @judsonx,

Thanks for the analysis and the proposed patch, and of course for the enthusiasm. To be honest, this PR ended up stalled. I made the last changes Pedro asked for and didn't hear back after that. That's understandable, since the release date we had originally agreed on was getting too close and this PR had grown much bigger than any of us expected.

I didn't hear anything more from the Keycloak team, and I also have some personal matters to take care of. So I put the PR on hold until they tell me how they'd like to move forward. One idea I had was to split it into several smaller PRs and track them as tasks or sub-issues under the original issue. That idea was never decided on, so nothing moved forward.

I also stopped working on the PR because of all the new features they've been shipping. Every day new issues change the code and cause conflicts with the branch.

In the meantime, I've covered this feature with an extension I wrote myself. We'll see what the maintainers want to do with this when things pick back up next year.

@kdureidy
Copy link
Copy Markdown

Any plans to merge this PR?

@ggomarighetti is the extension you mentioned in your last comment open-source?

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.

Manage Organization Roles

9 participants

0