Amazon Ergo 1.0 · Heavy

add-client-resource-type-and-scopes-to-authorization-schema-keycloak

Keycloak · Java · L · 300–799 lines · 5 files

The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Opus 5.5.

Gold bugs found
3 of 15
Comments published
5
Comments matching a bug
3
Comments not matching
2
Cost of this PR
$4.816

Published comments (5)

highbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:138-141

All-clients permission resource is returned as a client ID — `AvailableRoleMappingResource.getRoleIdsWithPermissions` looks up every returned value as a client, so `getClientById("Clients")` returns null and the endpoint fails with an NPE. Handle the all-clients resource separately in `getClientsWithPermission`, expanding it to real client IDs instead of adding `resource.getName()`.

highbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:192-195

ClientPermissionsV2.setPermissionsEnabled breaks client removal in FGAP v2 — The `AdminPermissions` removal listener calls `setPermissionsEnabled(client, false)` on every `ClientRemovedEvent`, so this unconditional throw makes client removal fail in FGAP v2. Implement the V2 cleanup, or make disable a safe no-op when no per-client permission state exists.

highbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:214-222

All-clients permissions ignored when a per-client resource exists — A per-client resource for any scope suppresses all-clients permissions for every scope, so `canManage` or `canConfigure` can deny access despite an all-clients grant. If the per-client resource has no permission for the requested scope, also evaluate the all-clients resource while preserving negative-policy semantics.

mediumbugtests/base/src/test/java/org/keycloak/tests/admin/authz/fgap/PermissionClientTest.java:357-364

Map-role test grants CONFIGURE, masking broken map-scope checks — `CONFIGURE` also grants client access, so both operations can pass even if their `MAP_ROLES` or `MAP_ROLES_COMPOSITE` checks are broken. Test each scope separately with `VIEW`, and add a `VIEW`-only negative case asserting the unsupported operation is forbidden.

mediumbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/AdminPermissions.java:77

Client removal cleanup is skipped when only fine-grained authz V2 is enabled — `ADMIN_FINE_GRAINED_AUTHZ_V2` does not enable `ADMIN_FINE_GRAINED_AUTHZ`, so V2-only realms never run the removal listener and leave the deleted client's permission resource and policies in the admin-permissions client. Include `ADMIN_FINE_GRAINED_AUTHZ_V2` in the condition, or check whether realm admin permissions are enabled.

Gold bugs found (3)

mediumClaims the removal-cleanup listener is guarded by the V1 fine-grained flag, so client/role/group permissions are orphaned when V1 is disabled or only V2 is enabled.
highgetClientsWithPermission in ClientPermissionsV2 only finds the type-level 'Clients' resource and returns its name, never actual client ids, so callers that resolve the returned values as client ids get wrong results or null clients.
highIn ClientPermissionsV2.hasPermission, an admin granted a permission on all clients is denied on any client that also has its own per-client permission resource, because only the per-client resource is evaluated.

Gold bugs missed (12)

mediumClaims getResourceTypeResource can return null in ClientPermissionsV2.hasPermission, causing a NullPointerException in findByResource.
mediumClientPermissionsV2.canView() ignores a global MANAGE permission, so admins with only global manage take the unpaginated, per-client evaluated listing path.
highcanView(client) short-circuits on the global all-clients VIEW permission, so a client-specific permission denying an admin is never evaluated and the client is still viewable.
mediumThe negative check for removing a default client scope expects ForbiddenException, but it can come from the preceding getDefaultClientScopes() call, so the test passes even without a permission check on removal.
mediumAdminPermissionsSchema.getResourceName handles only USERS, so for the new CLIENTS resource type the admin API returns a null/UUID display name instead of 'All clients' or the clientId.
highClientPermissionsV2.canExchangeTo throws UnsupportedOperationException, but AbstractTokenExchangeProvider still calls clients().canExchangeTo for client-to-client exchange, so with token exchange and FGAP V2 enabled the request fails with a server error instead of a permission decision.
mediumAfter granting all-clients VIEW, testViewAllClients asserts only not(empty()) on the client listing. It would pass if only myclient were exposed instead of all clients.
highClaims that the CLIENTS type and new scopes are added only to the static schema and that init() skips realms that already have the admin-permissions client. Realms with V2 enabled earlier would then miss the Clients resource and the configure/map-roles scopes, which breaks creating and evaluating client permissions.
mediumClientPermissionsV2.canView(ClientModel) chains canView(), canManage(client), canConfigure(client) and the VIEW check, so one client can cost up to four full policy evaluations of the same resource. ClientsResource.getClients repeats this for every client in the listing.
mediumtestMapRolesAndCompositesOnlyOneClient grants role-mapping scopes on myclient and only exercises myclient, without checking that a second client stays forbidden. A regression that applies a per-client grant to all clients would still pass.
mediumtestConfigureOnlyOneClient grants CONFIGURE only on myclient, and every post-grant operation targets myclient. The test would still pass if canConfigure ignored the client argument and applied the grant to every client.
mediumAfter granting all-clients MANAGE, testManageAllClients asserts only that the client listing is not empty. It would pass if the endpoint omitted some authorized clients.