Repository navigation
Conversation
Fine-grained admin permissions can reference a specific organization, which is resolved when the admin permissions client's authorization settings are imported. Organizations were imported last, so such a permission failed with "Resource [...] does not exist for type [Organizations]". Organizations are now imported right after users, and before the authorization settings. Closes keycloak#55160 Signed-off-by: Naitik Singh <teamopyonick@gmail.com>
Covers an organization with a linked identity provider and a managed member with a federated identity, referenced by a fine-grained admin permission, to make sure the new import order keeps these working. Closes keycloak#55160 Signed-off-by: Naitik Singh <teamopyonick@gmail.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the change to import organizations before authorization settings.
No open issues 🎉
What changed in this PR
Fixes #55160 by importing organizations before authorization settings, allowing realm imports to resolve organization-specific fine-grained admin permissions.
Changes:
- Moves organization import after users but before authorization settings, while preserving organization import for the deprecated null-callback path.
- Adds export/import regression tests for organization-specific permissions, including an organization linked to an identity provider with a managed member.
| File | Description |
|---|---|
tests/base/src/test/java/org/keycloak/tests/organization/authz/fgap/OrganizationFgapImportTest.java |
Adds round-trip tests for permission resource references, identity-provider links, and managed membership. |
model/storage-private/src/main/java/org/keycloak/storage/datastore/DefaultExportImportManager.java |
Reorders organization import so referenced organizations exist when permissions are imported. |
Review effort: Balanced
martin-kanis
left a comment
There was a problem hiding this comment.
@ig-suyas Thanks for the PR. The fix looks good, however I would appreciate some refactoring in the test.
Please see below.
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
|
||
| @KeycloakIntegrationTest | ||
| public class OrganizationFgapImportTest { |
There was a problem hiding this comment.
No need to create yet another class. You can put it into ExportImportFGAPV2Test and only testImportRealmWithPermissionForOrganizationLinkedToIdentityProvider that covers the fix well. No need to add testImportRealmWithPermissionForSpecificOrganization as well.
| assertThat(resources, contains(orgId)); | ||
| } | ||
|
|
||
| private String createOrg(String name) { |
There was a problem hiding this comment.
This helper method could be most likely removed and you can leverage
@InjectOrganization(lifecycle = LifeCycle.METHOD)
ManagedOrganization organization;
|
Thanks @martin-kanis , that makes sense. I'll move the test into ExportImportFGAPV2Test, keep only testImportRealmWithPermissionForOrganizationLinkedToIdentityProvider, remove OrganizationFgapImportTest, and use @InjectOrganization instead of the createOrg helper. I'll push the update shortly. |
Keep only the test for an organization linked to an identity provider, inject the organization with @InjectOrganization and remove OrganizationFgapImportTest. Signed-off-by: Naitik Singh <teamopyonick@gmail.com>
|
Done, pushed in 0072841.
Verified locally: ExportImportFGAPV2Test passes with the fix (4/4). Without the fix, the new test fails with |
Closes #55160
The bug: Importing a realm export fails if it has a fine-grained admin permission (FGAP v2) on one specific organization. The import stops with
Resource [<org-id>] does not exist for type [Organizations]. InDefaultExportImportManager.importRealm, the authorization settings of the admin permissions client were imported before the organizations, which came last. When that permission is imported,AdminPermissionsSchemalooks up the organization by ID, and it does not exist yet.The fix: Organizations are now imported right after users and before the authorization settings. They have to come after users because organization members are looked up by username. Nothing else moves. Nothing reacts to organization creation, so the earlier position does not change behavior. The deprecated path that skips user-dependent data (
userImport == null) still imports organizations, and its authorization settings are imported afterimportRealmreturns, as before.Testing: I added
OrganizationFgapImportTest. It creates an organization and a VIEW permission on that one organization, exports the realm on the server, deletes the realm, and imports the export again. Then it checks that the organization and the permission (with the organization as its resource) are there. Before the fix it fails with the exact error from the issue; with the fix it passes.OrganizationResourceTypeEvaluationTest(11),OrganizationTest(39) andImportTest(6) also pass. InExportImportTest, the directory and single-file export/import round trips pass. Six other tests in that class could not run on my Windows machine because the checkout path has a space, so their JSON fixtures were not found (FileNotFoundExceptionon a%20path) before any import ran. They do not depend on this change, and CI should cover them.