DeepSeek V4 Pro · 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
4
Comments matching a bug
3
Comments not matching
1
Cost of this PR
$1.773

Published comments (4)

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

All-clients permission ignored when specific client resource exists — Granting a scope only through the all-clients permission is ignored for any client that has its own resource, so callers are incorrectly denied access. Evaluate the all-clients resource in addition to the specific resource, or fall back per scope, when the specific resource does not grant the requested scope.

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

getClientsWithPermission returns typed resource name instead of client IDs — Callers filtering clients by the returned set will match no client or treat "Clients" as a client id when a global all-clients permission exists. Skip the typed resource or expand it into actual client ids so the set contains only client identifiers.

highbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/AdminPermissions.java:89-91

Skip unsupported V2 setPermissionsEnabled call on client removal — Client removal with ADMIN_FINE_GRAINED_AUTHZ enabled throws UnsupportedOperationException because ClientPermissionsV2.setPermissionsEnabled is unsupported. Skip the call when the V2 feature is enabled, and verify the role and group branches do not have the same issue.

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

removeDefaultClientScope permission test masked by getDefaultClientScopes call — The test passes even when removeDefaultClientScope authorization is broken because getDefaultClientScopes throws first. Fetch default client scopes with a privileged client before the try block so only removeDefaultClientScope is exercised inside it.

Gold bugs found (3)

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