8000 Add a export-realm role that allows exporting a realm configuration dump without having full manage-realm rights by malexmave · Pull Request #44799 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Add a export-realm role that allows exporting a realm configuration dump without having full manage-realm rights - #44799

Open
malexmave wants to merge 1 commit into
keycloak:mainfrom
malexmave:feature/export-realm-role
Open

malexmave wants to merge 1 commit into
keycloak:mainfrom
malexmave:feature/export-realm-role

Conversation

@malexmave
@malexmave malexmave commented Dec 10, 2025 •
Copy link
Copy Markdown

Closes #44797

This PR implements part of the work required to add a new export-realm role, as discussed in #44797.

Current status:

  • Add the new realm role
  • Allow it to use the partial-export endpoint
  • Test it manually using a REST call against the API
  • Implement test cases - done in PermissionsTest.java. PartialExportTest.java currently does not test any roles, so I have not adapted it.
  • Implement a migration to add the role to existing realms during an upgrade - I had to pick a Keycloak version for that, so I picked the next minor release. Feel free to adjust it if it does not fit.
  • Update documentation - I have also added an entry to the release notes, feel free to remove it if you feel this does not warrant one.
  • Update API docs - not necessary, as they don't mention required roles, it seems.
  • Transfer migration code to the 26.7 migration.
  • Make the role usable when assigned to a user (fix UI)
  • Add information string describing what the role does in the UI
  • Add information to the project documentation about the purpose of the role

Feel free to add anything else I have forgotten in the checklist.

Ping @ahus1 @srose - and thanks for your help in getting this far :).

AI disclosure: I used AI (Claude Code) to orient myself within the code base and find the right places for test cases. I wrote the functional code myself. The test cases (four lines of code) and the migration were generated by Claude Opus 4.6 and reviewed by me. (edit: further disclosures in the thread below)

@malexmave
malexmave force-pushed the feature/export-realm-role branch from 9701da9 to 7febb85 Compare December 10, 2025 09:51
@malexmave
malexmave force-pushed the feature/export-realm-role branch 4 times, most recently from 91a8ab8 to e04dec7 Compare April 21, 2026 19:09
@malexmave
malexmave marked this pull request as ready for review April 21, 2026 19:31
@malexmave
malexmave requested a review from a team as a code owner April 21, 2026 19:31
@malexmave
Copy link
Copy Markdown
Author

@srose Thanks for the reminder to get this done at KC Dev Day :). Finally got around to finishing the PR. I tested everything except the migration, as I currently cannot get the build to complete on my machine once again. But since I (and Claude) basically lifted the code wholesale from the previous migration which did pretty much the exact same thing, I would expect it to work as well.

@malexmave
Copy link
Copy Markdown
Author

I just realized that 26.7.0 is not yet released, so I could also adapt the PR to put the new role into the same migration and add it to the changelog. It would also fit the theme quite well, as 26.7.0 also adds a bunch new roles. Let me know if I should change it - I'm holding off on it since I don't know if you are already in code freeze.

@ahus1 ahus1 self-assigned this Apr 22, 2026
ahus1
ahus1 previously requested changes Apr 22, 2026
@ahus1 ahus1 left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this PR.

The code-freeze is still ~1.5 months in the future, so please adjust the PR so that its changes are part of 26.7.

Nitpick: Update

and https://github.com/keycloak/keycloak/blob/13560136cf5987f373684a7a11312a10fe0417c3/js/apps/admin-ui/maven-resources/theme/keycloak.v2/admin/messages/messages_en.properties with a role description, so the admin UI and account UI can show the new role. The new message key would be role_query-users

I tried to use the new permission with the Admin UI, and I found that with just the "export realm" permission, I wasn't able to navigate to the "Realm Setting" menu entry. Once I added "view realm" permissions, the drop-down action "partial export" was disabled.

This is what I would expect: When I have the "export-realm" role, I can navigate in the Admin UI to the "Realm settings" menu entry, and I can trigger the action "Partial export".
About the different tabs in the "Realm settings": Ideally they would be hidden.

Thanks again for the PR, and sorry that I didn't provide an earlier feedback.

@malexmave
Copy link
Copy Markdown
Author

I will make the changes to the migration and add the documentation strings soon, thanks for the heads up.

I tried to use the new permission with the Admin UI, and I found that with just the "export realm" permission, I wasn't able to navigate to the "Realm Setting" menu entry. Once I added "view realm" permissions, the drop-down action "partial export" was disabled.

This is what I would expect: When I have the "export-realm" role, I can navigate in the Admin UI to the "Realm settings" menu entry, and I can trigger the action "Partial export".
About the different tabs in the "Realm settings": Ideally they would be hidden.

Thats actually a good point. I primarily designed the role for programmatic (API) access, and didn't really think about the implications for the UI. Do you think changing the UI would be a good idea? I felt that not being able to log into the admin console and see things would actually be a perk for the primary use case I forsee (programmatically downloading a config dump using a service account to do things like updating a Confluence page, running kcwarden, or similar things), but I realize now that this may be inconsistent with how you like to do things.

@ahus1
ahus1 commented Apr 22, 2026
Copy link
Copy Markdown
Member

Do you think changing the UI would be a good idea?

My approach was to do some explorative testing for this new feature. The first step is then to set up a user, and see if it can access the API endpoint.

As the PR doesn't contain any integration testing around this, and I didn't have the API endpoint at hand, this was the first thing I tried. And I assume an admin might want to do something similar when they set up that read-only user.

As basically all existing roles work with the Admin UI, I consider this part of it.

One more thing: I know we are very bad in describing what each role can do, and what its expected use is. Still, please add a paragraph to the docs about this new role.

@malexmave
Copy link
Copy Markdown
Author

One more thing: I know we are very bad in describing what each role can do, and what its expected use is. Still, please add a paragraph to the docs about this new role.

I could not find the place where the roles are actually documented - can you point me to the place in the docs where you think this would fit in?

@ahus1
ahus1 commented Apr 22, 2026
Copy link
Copy Markdown
Member

I could not find the place where the roles are actually documented - can you point me to the place in the docs where you think this would fit in?

I'd suggest adding it to the master-realm.adoc file where you listed the role. Maybe a colon : and a short description with one or two sentences after added role would suffice for this one. If you want to write more, consider another nested subsection below the Realm specific Roles section.

@malexmave
malexmave commented Apr 22, 2026 •
Copy link
Copy Markdown
Author

Ah, I didn't do that because then it would be the only one that has such a documentation. So, even though that would be inconsistent with the rest, I should add it anyway? I can do that, no problem, just making sure.

@ahus1
ahus1 commented Apr 22, 2026
Copy link
Copy Markdown
Member

So, even though that would be inconsistent with the rest, I should add it anyway? I can do that, no problem, just making sure.

Yes. Someone would need to make a start and lead by example.

@malexmave
Copy link
Copy Markdown
Author

✅ Fixed the UI

With view-realm and export-realm:
image

Without view-realm but with export-realm:
image

🤖 Disclosure: this code was written by Claude and reviewed and tested by me. However, since I am not familiar with the codebase, please take extra care in reviewing the .tsx files to see if it matches the expected code style. I (and Claude ;) could not find any relevant test cases that would have to be changed or added for this (there does not seem to be a pattern of testing with less privileged user accounts at the moment, and the endpoint checks are already tested by the existing tests added earlier). Let me know if I missed any.

✅ Moved migration code to 26.7 migration

✅ Added label and description to the roles

Still in progress: Will add the information about the role to the documentation in a bit, but wanted to get the functional improvements out the door so you can take another look :).

@malexmave
malexmave force-pushed the feature/export-realm-role branch from e04dec7 to 36a15be Compare April 22, 2026 13:42
@malexmave
malexmave requested a review from a team as a code owner April 22, 2026 13:42
@malexmave
malexmave force-pushed the feature/export-realm-role branch from 36a15be to bd1fb4b Compare April 22, 2026 13:56
@malexmave
Copy link
Copy Markdown
Author

I now also pushed the documentation update. I tried to create a description for each of the roles, to make the export-realm role stand out less. Let me know if that's okay or if you would prefer me to only give these descriptions for the new role.

AI Disclosure: I had Claude check what each of the roles was doing, challenging its assertions based on what I know myself about these roles. However, there may still be inaccuracies that I am not aware of.

@malexmave
Copy link
Copy Markdown
Author

Looks like I fixed the linter issues that made the pipeline go red, and the new red pipeline is just a flaky test that affects more than just my branch, so I won't try to fix that one :).

@malexmave
malexmave force-pushed the feature/export-realm-role branch from c45abfe to bbc8ecc Compare April 29, 2026 06:11
@malexmave
Copy link
Copy Markdown
Author

Updated to resolve the conflict against main.

@malexmave
Copy link
Copy Markdown
Author

Once again resolved conflicts against main.

@ahus1 the last run had an error in the integration tests against the account frontend. Since I didn't change anything about that, I assume that it was not related to my changes, so I didn't try to fix it. Let's see if it crops up again in these workflows.

From my side, the PR is ready for review and merge, if the pipeline doesn't fail again.

This commit implements a new role, 'realm-export', that gives access to the partialExport endpoint. See the linked issue and the pull request description for more details.

Closes keycloak#44797

Signed-off-by: Max Maass <max.maass@iteratec.com>
@ahus1
ahus1 force-pushed the feature/export-realm-role branch from be4235d to ef32916 Compare May 21, 2026 11:34
@ahus1
ahus1 dismissed their E081 stale review May 21, 2026 11:35

resolved

@ahus1
ahus1 commented May 21, 2026
Copy link
Copy Markdown
Member

@pedroigor - I had a look at this PR and it looks good to me. It is in your team's area, so it would be great to have feedback from you as well.

I'm happy to see that it adds docs for the different roles that was on our roadmap for quite a while!

@malexmave
Copy link
Copy Markdown
Author

For transparency: To avoid redundant work, I'll hold off on rebasing off main until we have agreement in principle that this should be merged - otherwise, I'll have to keep unnecessarily chasing commits. Just let me know once you need me to do this. :)

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.

Add an export-realm realm role that allows configuration exports without full write access to the realm

3 participants

0