Kimi K3.1 Pro · 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
6 of 8
Comments published
9
Comments matching a bug
6
Comments not matching
3
Cost of this PR
$1.952

Published comments (9)

mediumbugserver-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java:67-73

Existing realms lack the Clients resource and scopes after upgrade — Add an upgrade or migration path that initializes the new resource and scopes on existing resource servers.

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

Client deletion skips V2 permission cleanup and breaks when V1 is also enabled — Client deletion has no working V2 cleanup path: with only V2 enabled this V1 guard skips the event and leaves per-client resources and policies behind, while enabling V1 and V2 makes `management(...).clients()` return the V2 evaluator whose `setPermissionsEnabled` throws `UnsupportedOperationException`. Implement V2 resource and policy cleanup independently of the legacy V1 `setPermissionsEnabled` path.

mediumsecurityservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:77-82

All-clients VIEW grant bypasses client-specific VIEW denials — A positive all-clients VIEW permission makes `canView()` return true before the client-specific resource is evaluated, so a negative per-client VIEW permission cannot deny access to that client. Evaluate the specific resource before accepting the global grant, preserving the override semantics used by `UserPermissionsV2`.

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

canView() ignores the global MANAGE permission — `canView()` checks only the global VIEW scope even though global MANAGE is treated as view elsewhere; an administrator with only all-clients MANAGE can fail `requireListClientScopes()` or receive an empty `/client-scopes` result while `canManageClientScopes()` is true. Include MANAGE in the global view decision or align `canViewClientScopes()` and `canListClientScopes()` with `canView(ClientScopeModel)`.

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

Client permission search skips untyped per-client resources — This search relies on resource type `Clients`, but `AdminPermissionsSchema.getOrCreateResource` never calls `setType` for per-client resources, so individual map-roles-composite grants produce no client IDs and `AvailableRoleMappingResource` omits their roles. Populate the resource type when creating client resources or query per-client resources without relying on a type they do not have.

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

Type-level Clients resource is returned as a client ID, causing an NPE — The all-clients schema resource itself has type and name `Clients`, so a global map-roles-composite grant makes this method return `Clients` as a client ID; `AvailableRoleMappingResource` then dereferences `realm.getClientById("Clients")` and throws a null-pointer exception. Exclude or expand the type-level resource instead of adding its name to the client ID set.

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

When any client-specific resource exists, `hasPermission` evaluates only that resource and never… — Evaluate the all-clients grant when the specific resource has no decision for the requested scope while retaining explicit client-specific denials.

mediumbugserver-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java:91-95

Client permission resources have no display name — Add Clients handling that returns the client ID for individual resources and an all-clients label for the type resource.

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

With `ADMIN_FINE_GRAINED_AUTHZ_V2` enabled, every token exchange to a different target client… — Implement the V2 evaluation using the authorized client and token context, or provide a non-throwing compatibility path until V2 token-exchange permissions are supported.

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

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