Amazon Ergo 1.0 · Balanced

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

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

The normal review, with one generalist agent. Judge: Claude Opus 5.5.

Gold bugs found
2 of 15
Comments published
2
Comments matching a bug
2
Comments not matching
0
Cost of this PR
$2.162

Published comments (2)

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

Client removal listener's V1 gate skips V2 cleanup or hits unsupported V2 call — In V2-only deployments, the `Profile.Feature.ADMIN_FINE_GRAINED_AUTHZ` gate skips cleanup and orphans V2 authorization resources and permissions; with both features enabled, `ClientPermissionsV2.setPermissionsEnabled` throws `UnsupportedOperationException`. Account for V2 in the gate and use a V2-compatible cleanup path.

mediumbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:138-142

All-clients permission returns resource type name instead of client IDs — `getClientsWithPermission` adds `resource.getName()` for the synthetic all-clients resource, so callers receive a bogus entry and miss every actual client. Skip the resource named by `AdminPermissionsSchema.CLIENTS_RESOURCE_TYPE` and, when it grants `scope`, add all realm client IDs.

Gold bugs found (2)

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.

Gold bugs missed (13)

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.
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.
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.