Kimi K3.1 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 Haiku 5.5.

Gold bugs found
6 of 8
Comments published
11
Comments matching a bug
6
Comments not matching
5
Cost of this PR
$3.364

Published comments (11)

mediumbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:215-220

Missing Clients resource breaks permissions for existing admin-permissions clients — An existing admin-permissions client created before this PR has no `Clients` resource because `AdminPermissionsSchema.init` returns when that client already exists, so `getResourceTypeResource` returns null and `findByResource` dereferences `resource.getId()`. Backfill the new resource and scopes for existing realms and handle a missing aggregate resource before querying policies.

mediumbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:147-150

V2 canExchangeTo throws on every cross-client token exchange — `AdminPermissions.management(...).clients()` resolves to this V2 implementation whenever V2 is enabled, and `AbstractTokenExchangeProvider` calls `canExchangeTo` for every exchange to a different target client. The unconditional exception turns such token-exchange attempts into server errors; implement V2 evaluation or deny/delegate without throwing.

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

When V2 is enabled without V1, this guard skips `ClientRemovedEvent` cleanup, leaving the new… — Add V2 resource and policy cleanup independently of the V1-only listener.

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

Per-client resources created by `AdminPermissionsSchema.getOrCreateResource` never have `type`… — Store `Clients` as their type, including for existing resources, or query using the actual resource storage scheme.

mediumbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:139-141

All-clients grants add "Clients" as a client ID and trigger an NPE — The built-in all-clients resource also has type `Clients`, so a matching all-clients permission adds the literal name `Clients` as a client ID; `AvailableRoleMappingResource` then dereferences `realm.getClientById("Clients")` and throws a null-pointer exception. Exclude the aggregate resource and expand an all-clients grant to actual client IDs.

mediumbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:86-88

canView() ignores the all-clients manage permission — An administrator granted only the all-clients `manage` scope still gets `canView() == false`, so `ClientsResource.getClients` rejects the request at `requireList()` unless the administrator also has an unrelated query role. Include `hasPermission(AdminPermissionsSchema.MANAGE)` in this check, matching the manage-implies-view behavior of `canView(ClientModel)` and `canView(ClientScopeModel)`.

mediumbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:214-224

All-clients grants are skipped when a client-specific resource exists — The all-clients permission is considered only when the client has no resource of its own. If a client has any client-specific permission (for example CONFIGURE), resource is non-null and an all-clients MANAGE or VIEW grant is never evaluated, so valid global grants stop applying to that client.

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

CONFIGURE test does not check permissions on a different client — This test grants CONFIGURE only on `myclient`, but every post-grant operation still targets `myclient`; the later denied operations only distinguish CONFIGURE from MANAGE. If `canConfigure` ignored the supplied client and applied that permission to every client, the entire test would still pass.

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

OnlyOneClient test does not check that other clients stay forbidden — The “OnlyOneClient” role-mapping test never verifies that another client remains inaccessible after these grants. An implementation that ignores the client argument when evaluating MAP_ROLES/MAP_ROLES_COMPOSITE would still fail the pre-grant checks and pass both post-grant calls.

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

View-all-clients test accepts an incomplete client list — `not(empty())` does not verify the claimed ability to list and view all clients: the test would still pass if the all-clients VIEW permission exposed only `myclient`, since the subsequent protocol-mapper check also uses only that client. Compare the returned client IDs with the complete set obtained through the privileged realm admin (or at least assert access to multiple otherwise-unpermissioned clients).

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

V2 setPermissionsEnabled breaks client removal cleanup — This override conflicts with the changed `AdminPermissions` client-removal listener. That listener calls `management(...).clients().setPermissionsEnabled(client, false)` on every `ClientRemovedEvent`; with V2 enabled, `clients()` returns this class, so the call always throws `UnsupportedOperationException` and can cause client deletion to fail. **Also found in:** - `services/src/main/java/org/keycloak/services/resources/admin/permissions/AdminPermissions.java:89-92` - `services/src/main/java/org/keycloak/services/resources/admin/permissions/AdminPermissions.java:89-91`

Gold bugs found (6)

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

Gold bugs missed (2)

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.