8000 Make bootstrap admins temporary conditionally by slaskawi · Pull Request #40309 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Make bootstrap admins temporary conditionally - #40309

Closed
slaskawi wants to merge 1 commit into
keycloak:mainfrom
slaskawi:40305-temporary-admin-switch
Closed

slaskawi wants to merge 1 commit into
keycloak:mainfrom
slaskawi:40305-temporary-admin-switch

Conversation

@slaskawi
@slaskawi slaskawi commented Jun 6, 2025
Copy link
Copy Markdown
Contributor

This Pull Request introduces a flag to make the Bootstrap Admin temporary or permanent.

Closes #40305

@shawkins shawkins left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @slaskawi, just a couple of things that could be addressed.

@slaskawi
slaskawi force-pushed the 40305-temporary-admin-switch branch 2 times, most recently from f7a10aa to 1796d79 Compare June 10, 2025 10:18
@slaskawi
Copy link
Copy Markdown
Contributor Author

@shawkins Comments addressed and this PR is ready for the next round.

Highlight of the changes:

  • Removed the "temporary" word from the the bootstrap admin help messages
  • Introduced a different logging message indicating the created admin is not a temporary account
  • Fixed missing assertions in tests that I found when working on this PR
  • Renamed methods as suggested in the previous review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems like it needs more refinement. The screen shown to the user says temporary in several places - do you plan on updating the template as well?

Also behavior doesn't match the behavior of the other properties. If I set the admin username env variable, that does not become the default in the form.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also behavior doesn't match the behavior of the other properties. If I set the admin username env variable, that does not become the default in the form.

At the moment, this works on two levels - it can be set via an Environment Property (KC_BOOTSTRAP_ADMIN_IS_TEMPORARY) or in the theme.properties file. The latter gives a chance of override this in a custom theme. At the moment, the theme override takes the priority over the environment variable to give custom theme authors more flexibility.

I'm open for a discussion if you'd like me to change the mechanism how this works.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I adjusted the theme for these changes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see that it works on two levels, but I'm not sure that either is needed - in particular the usage of the environment variable since it's not consistent behavior.

The creation of the initial admin via the localhost welcome page also seems like it won't come into play with for most production usage.

Why not just have a checkbox in the form for the initial admin to choose? Are you thinking that that anyone who may has themed this page will want to control the one time operation without leaving it up to the initial admin and/or won't want to update their template to add a checkbox?

cc @vmuzikar

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

From the Defense Unicorns UDS perspective, we would mostly need the Welcome Page approach. The platform is wired in such a way, the initial Platform Administrators use Port Forward (via zarf connect command) and create the initial Keycloak Administrator account this way. We treat this account as a final (and not temporary) one.

Looking from this perspective, having a checkbox whether the Administrator account is temporary or not may appear weird to our users. Therefore, we'd still need to apply a custom theme and pretend this checkbox is always "checked" for us. Not the best option for us but we can deal with it.

Since Keycloak has many entry points to create the initial Admin Account (command line, environment variables, initial Realm import and Welcome Page), I tried to deliver a solution for each of them. This way the code is "symmetric". I'm slightly concerns that otherwise this feature would look like "half-baked". But I'll leave the final call to both of you @vmuzikar and @shawkins - how would you like me to approach this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

in particular the usage of the environment variable since it's not consistent behavior

Exactly.

Additionally, I do not believe a theme prop is something that should affect this, it's not its responsibility, IMHO.

I'm ok with having the ability to set the temporary flag via the Welcome Screen, though. However, we should use a systematic approach: fully leverage the bootstrap-admin-temporary option, i.e. it would accept the env var, the CLI option, etc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Adjusted

@slaskawi
slaskawi force-pushed the 40305-temporary-admin-switch branch from 1796d79 to bd19a46 Compare June 16, 2025 10:37
@slaskawi
slaskawi requested a review from a team as a code owner June 16, 2025 10:37
@slaskawi
Copy link
Copy Markdown
Contributor Author

@shawkins The comments have been addressed and the change is ready for the next round.

The major changes are in Welcome Page theme. It now doesn't print information about temporary user if the kcBootstrapAdminIsTemporary setting is set to false.

I'm still considering writing a unit test for it but this PR is also fine without it (this is a bit niche feature).

@slaskawi
slaskawi force-pushed the 40305-temporary-admin-switch branch 3 times, most recently from 53c2973 to 64143b8 Compare June 17, 2025 09:36
@slaskawi
Copy link
Copy Markdown
Contributor Author

Comments addressed and this PR is ready for the next round.

Here's the list of changes:

  • Added WelcomeResourceTest unit test cover the most important part of the WelcomeResource
  • Renamed the createsTemporaryAdminUser method to isAdminUserTemporary
  • Fixed the docs

@vmuzikar vmuzikar left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@slaskawi Thank you for the contribution!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

in particular the usage of the environment variable since it's not consistent behavior

Exactly.

Additionally, I do not believe a theme prop is something that should affect this, it's not its responsibility, IMHO.

I'm ok with having the ability to set the temporary flag via the Welcome Screen, though. However, we should use a systematic approach: fully leverage the bootstrap-admin-temporary option, i.e. it would accept the env var, the CLI option, etc.

@slaskawi
slaskawi force-pushed the 40305-temporary-admin-switch branch 2 times, most recently from 7267163 to c34582e Compare July 16, 2025 08:13
@slaskawi
Copy link
Copy Markdown
Contributor Author

@vmuzikar @shawkins Thanks for the comments. I've pushed another update, here are the highlights:

  • Removed the environment variable handling in WelcomeResource as suggested
  • Unified approach with bootstrap parameters
  • Updated the documentation

@slaskawi
slaskawi force-pushed the 40305-temporary-admin-switch branch from c34582e to 18c8fbc Compare July 16, 2025 11:55
@vmuzikar
vmuzikar self-requested a review July 17, 2025 17:05
@slaskawi
slaskawi force-pushed the 40305-temporary-admin-switch branch 2 times, most recently from ffbf7fa to 1345388 Compare July 21, 2025 06:55
@keycloak-github-bot keycloak-github-bot Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@keycloak-github-bot
< 10BC8 /svg> Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.cluster.SessionFailoverClusterTest#sessionFailover

Keycloak CI - Clustering IT

java.lang.RuntimeException: java.lang.IllegalStateException: Keycloak unexpectedly died :(
	at org.keycloak.testsuite.arquillian.containers.KeycloakQuarkusServerDeployableContainer.start(KeycloakQuarkusServerDeployableContainer.java:71)
	at org.jboss.arquillian.container.impl.ContainerImpl.start(ContainerImpl.java:185)
	at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController$8.perform(ContainerLifecycleController.java:137)
	at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController$8.perform(ContainerLifecycleController.java:133)
...

Report flaky test

@vmuzikar vmuzikar left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@slaskawi Thank you for the updates.

@slaskawi
Copy link
Copy Markdown
Contributor Author

Is it truly necessary for the is-temporary option to influnce the WelcomeResource?
The alternative to this static variable to map the is-temporary option to an spi key and use Config.scope
We mused about providing the root configuration to Config via something like #39123 but it didn't move forward.

For the UDS Platform, having this functionality in WelcomeResource is vital. Putting this into Config seems a bit artificial as this is not really an SPI and there's only 1 implementation that probably won't be overridden. Maybe I'll just add a link to #39123 in the comment so that we can retrofit it later once we have better options.

Signed-off-by: Sebastian Łaskawiec <sebastian.laskawiec@defenseunicorns.com>
@slaskawi
slaskawi force-pushed the 40305-temporary-admin-switch branch from bdba7ea to 4fff581 Compare July 23, 2025 10:30
@slaskawi
Copy link
Copy Markdown
Contributor Author

@vmuzikar @shawkins I've addressed your comments and this PR should be ready for the next round of reviews.

@vmuzikar
vmuzikar commented Jul 23, 2025 •
Copy link
Copy Markdown
Contributor

Putting this into Config seems a bit artificial as this is not really an SPI and there's only 1 implementation that probably won't be overridden.

It might feel artificial but it's currently the way of doing that. We don't want to create a direct dependency of core KC codebase on Quarkus dist config, hence the abstraction in form of SPI config layer.

But it's not a real blocker for me.


Both `bootstrap-admin user` and `bootstrap-admin service` commands support the `--is-temporary` parameter. This parameter allows you to treat the created admin account as a permanent one, meaning it will not be marked as temporary and will not be subject to the temporary account restrictions.

A temporary admin account can also be created with the Welcome Screen that is displayed at the first start of {project_name}. In this case, the temporary account behavior is controlled by the `--bootstrap-admin-temporary` parameter. If the variable or setting is not defined, the account will be created as a temporary one.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The --bootstrap-admin-temporary also work with the --bootstrap-admin-* options used for creating admin user/svc account at startup, no? Not just with the Welcome Screen.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@vmuzikar that wouldn't be consistent with the bootstrap admin commands existing handling. The commands do not consult the bootstrap-admin=* options. Someone could be setting bootstrap-admin-* options in keycloak.conf for example, and we don't want that influencing the bootstrap admin command unintentionally.

So --bootstrap-admin-temporary should just affect the initial admin creation / Welcome Screen.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So --bootstrap-admin-temporary should just affect the initial admin creation / Welcome Screen.

Yes, that's what I meant. Sorry, I was probably not clear before.

I meant that --bootstrap-admin-temporary should also affect when you create an admin user/service account at startup, not just the Welcome Screen. And that this behaviour should be documented.

@stianst
stianst commented Jul 24, 2025
Copy link
Copy Markdown
Contributor

I disagree with this approach; we don't have a mechanism to auto-delete the admin account at this point, so this option is complete unnecessary. If/when we do some form of auto removal of the admin account it should include a consideration of the scenarios where someone doesn't want to delete the account, but rather configure it properly.

I propose a completely different approach to the temporary admin account (never been a big fan of this in the first place). See #41382

@stianst stianst left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not in favour of adding this option, see my comment

@slaskawi
Copy link
Copy Markdown
Contributor Author

Closing this one in favor of working on #41388

@slaskawi slaskawi closed this Jul 24, 2025
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.

Introduce a switch by avoid printing information about temporary bootstrap admin

4 participants

0