GLM-5.3 · 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 Haiku 5.5.

Gold bugs found
3 of 8
Comments published
4
Comments matching a bug
3
Comments not matching
1
Cost of this PR
$1.854

Published comments (4)

highbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/MgmtPermissionsV2.java:63-68

`MgmtPermissionsV2.clients()` breaks callers via `ClientPermissionsV2` V1 stubs — When both `ADMIN_FINE_GRAINED_AUTHZ` and its V2 are enabled, every client deletion fails: the `ClientRemovedEvent` handler in `AdminPermissions` calls `setPermissionsEnabled`, which `ClientPermissionsV2` stubs with `UnsupportedOperationException`; `ClientResource`'s V1 endpoints and `canExchangeTo` break likewise. Keep V1 semantics for these methods or gate the V1 callers on `!ADMIN_FINE_GRAINED_AUTHZ_V2`.

highbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:136-144

getClientsWithPermission: 'Clients' in result and per-client grants omitted — With a type-level grant, the result contains the literal `Clients` name, not a client ID, so `AvailableRoleMappingResource` NPEs on the null `getClientById` result; per-client resources, created typeless by `AdminPermissionsSchema.getOrCreateResource`, stay invisible to `findByType` and get omitted — a V1 regression. Skip the type resource and include per-client grants.

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

NPE when Clients type resource is missing in hasPermission(ClientModel, String) — Realms initialized before this change never get the `Clients` type resource, so `getResourceTypeResource` returns null and `policyStore.findByResource` NPEs; every client permission evaluation 500s for callers without realm-admin roles, though the sibling type-level method null-checks. Guard `resource == null`, and add a store migration creating missing type resources and scopes. **Also found in:** - `server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java:63-68`

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

Client-removal cleanup skipped when only ADMIN_FINE_GRAINED_AUTHZ_V2 is enabled — Since `ADMIN_FINE_GRAINED_AUTHZ_V2` is an independent feature, clients deleted under it permanently orphan their resources and referencing permissions; `getClientsWithPermission` then policy-evaluates every orphan on each restricted client listing, growing cost unboundedly. Handle `ClientRemovedEvent` for V2 by deleting the removed client's resource and referencing permissions.

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.
mediumClaims getResourceTypeResource can return null in ClientPermissionsV2.hasPermission, causing a NullPointerException in findByResource.

Gold bugs missed (5)

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