Skip to content

Import organizations before authorization settings during realm import - #55223

Draft
ig-suyas wants to merge 2 commits into
keycloak:mainfrom
ig-suyas:fix-55160-org-import-fgap
Draft

ig-suyas wants to merge 2 commits into
keycloak:mainfrom
ig-suyas:fix-55160-org-import-fgap

Conversation

@ig-suyas

Copy link
Copy Markdown

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]. In DefaultExportImportManager.importRealm, the authorization settings of the admin permissions client were imported before the organizations, which came last. When that permission is imported, AdminPermissionsSchema looks 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 after importRealm returns, 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) and ImportTest (6) also pass. In ExportImportTest, 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 (FileNotFoundException on a %20 path) before any import ran. They do not depend on this change, and CI should cover them.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Realm import fails when FGAP permissions reference a specific organization

1 participant