Skip to content

startup, welcome, and cli handling of bootstrap-admin user#30054

Merged
vmuzikar merged 3 commits into
keycloak:mainfrom
shawkins:iss29324
Jul 3, 2024
Merged

startup, welcome, and cli handling of bootstrap-admin user#30054
vmuzikar merged 3 commits into
keycloak:mainfrom
shawkins:iss29324

Conversation

@shawkins

@shawkins shawkins commented May 31, 2024

Copy link
Copy Markdown
Contributor

Addresses #29324, #30002, #30003, and the non-ui parts of #30010.

The old hanlding of env variables KEYCLOAK_ADMIN and KEYCLOAK_ADMIN_PASSWORD were left in place so that we can decouple this pr from the operator work. We can come back and deprecate or remove that as a cleanup.

The only thing that looks a little of on the cli is the help for no-prompt - it shows it as taking a value even if I specify arity 0. Not sure that's worth addressing.

The actual handling for temporary / expriation will be deferred to the other issues.

cc @vmuzikar

@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

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.oauth.TokenIntrospectionTest#testUnsupportedToken

Keycloak CI - Base IT (6)

java.lang.NullPointerException: Cannot invoke "com.fasterxml.jackson.databind.JsonNode.asBoolean()" because the return value of "com.fasterxml.jackson.databind.JsonNode.get(String)" is null
	at org.keycloak.testsuite.oauth.TokenIntrospectionTest.testUnsupportedToken(TokenIntrospectionTest.java:313)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
...

Report flaky test

@shawkins

shawkins commented Jun 6, 2024

Copy link
Copy Markdown
Contributor Author

@vmuzikar this is roughly what we talked about. I wasn't sure if we even need to have an env option for bootstrap-admin user username - we can have just the direct --username input, just --username:env, or allow either. I left it initially as just the direct --username input under the assumption that it's much less of a security concern that it appears on the cli.

Also do we want a password confirmation prompt?

@vmuzikar

vmuzikar commented Jun 6, 2024

Copy link
Copy Markdown
Contributor

we can have just the direct --username input, just --username:env, or allow either

It'd allow either. Plus, if someone doesn't specify neither, they will be prompted.

Also do we want a password confirmation prompt?

Sounds like a good idea.

@shawkins

shawkins commented Jun 6, 2024

Copy link
Copy Markdown
Contributor Author

It'd allow either. Plus, if someone doesn't specify neither, they will be prompted.

Ok, this now supports either --username or --username:env

Sounds like a good idea.

Added a confirmation prompt as well.

I still have not removed the old env / sys handling - that will come later. The expiration logic was left in place, it's just hidden.

@shawkins

Copy link
Copy Markdown
Contributor Author

@vmuzikar adding bootstrap-admin service account handling as well.

Some additional thoughts / questions:

  • if the user specifies both the env variable for the admin user and service, should we create both or just prefer one?
  • it could further simplify things if we dropped accepting the password / client secret at all from the cli - and instead just use a generated one that we can show on the console or put into a temp file.

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

@shawkins Thank you for the PR and sorry for the late review. I think the changes are a good start.

Added some comments.

Noticed also help is a bit misbehaving with list of commands:

kc.sh bootstrap-admin --help

...

Commands:

  service  Add an admin user with a password
  service  Add an admin user with a password
  • if the user specifies both the env variable for the admin user and service, should we create both or just prefer one?

As a user, I'd expected both.

  • it could further simplify things if we dropped accepting the password / client secret at all from the cli - and instead just use a generated one that we can show on the console or put into a temp file.

CLI is required for automated scenarios without using env vars, e.g. the test framework.

Comment thread .gitignore Outdated
Comment thread quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/Picocli.java Outdated
Comment thread quarkus/config-api/src/main/java/org/keycloak/config/BootstrapAdminOptions.java Outdated
Comment thread services/src/main/java/org/keycloak/services/managers/ApplianceBootstrap.java Outdated
@shawkins

Copy link
Copy Markdown
Contributor Author

@shawkins Thank you for the PR and sorry for the late review. I think the changes are a good start.

Added some comments.

Noticed also help is a bit misbehaving with list of commands:

kc.sh bootstrap-admin --help

...

Commands:

  service  Add an admin user with a password
  service  Add an admin user with a password

This appears to be due to our HelpFactory - it doesn't work well with multiple sub commands.

  • if the user specifies both the env variable for the admin user and service, should we create both or just prefer one?

As a user, I'd expected both.

Ok, I'll remove the TODO.

  • it could further simplify things if we dropped accepting the password / client secret at all from the cli - and instead just use a generated one that we can show on the console or put into a temp file.

CLI is required for automated scenarios without using env vars, e.g. the test framework.

Are we going to be testing the bootstrap-admin user and service cli in this way? I was thinking the cli options were only a hard requirement for the initial bootstrapping.

@shawkins shawkins force-pushed the iss29324 branch 4 times, most recently from bd66c44 to 2b1ec8a Compare June 12, 2024 20:03
@shawkins

Copy link
Copy Markdown
Contributor Author

The help should be fixed now. Also starting the operator support.

@vmuzikar

Copy link
Copy Markdown
Contributor

Are we going to be testing the bootstrap-admin user and service cli in this way? I was thinking the cli options were only a hard requirement for the initial bootstrapping.

Yes, the CLI options are a requirement for bootstrapping server in general for the new test framework.

Also starting the operator support.

Nice! I'd suggest splitting that to a separate PR. This PR is getting quite big. :)

@shawkins

Copy link
Copy Markdown
Contributor Author

Are we going to be testing the bootstrap-admin user and service cli in this way? I was thinking the cli options were only a hard requirement for the initial bootstrapping.

Yes, the CLI options are a requirement for bootstrapping server in general for the new test framework.

Discussed offline and there is still a desire to let users specify the recover password / client secret.

Also starting the operator support.

Nice! I'd suggest splitting that to a separate PR. This PR is getting quite big. :)

Yes, it will be separate once this one is out of draft.

@vmuzikar

Copy link
Copy Markdown
Contributor

@shawkins I think we can move forward with the PR, I don't have any additional comments at the moment.

@shawkins

Copy link
Copy Markdown
Contributor Author

I think we can move forward with the PR, I don't have any additional comments at the moment.

Ok, I'll add some service account tests, then remove the operator draft stuff before moving this out of draft.

@shawkins shawkins force-pushed the iss29324 branch 2 times, most recently from 0dd98af to dd1fd19 Compare June 21, 2024 13:58
@shawkins shawkins changed the title draft of startup, welcome, and cli handling of bootstrap-admin user startup, welcome, and cli handling of bootstrap-admin user Jun 21, 2024
@shawkins shawkins marked this pull request as ready for review June 21, 2024 13:59
@shawkins shawkins requested review from a team as code owners June 21, 2024 13:59
@mabartos

mabartos commented Jun 28, 2024

Copy link
Copy Markdown
Member

@mabartos This should be correct. The command basically starts the server and connects to DB etc. It's the same problem as with import/export commands.

@vmuzikar Ahh, you're right.

Comment thread services/src/main/java/org/keycloak/services/managers/ApplianceBootstrap.java Outdated
@shawkins

shawkins commented Jul 2, 2024

Copy link
Copy Markdown
Contributor Author

Using the service account is still failing.

Comment thread services/src/main/java/org/keycloak/services/managers/ApplianceBootstrap.java Outdated
@shawkins shawkins force-pushed the iss29324 branch 2 times, most recently from 8e737b6 to 2b2eff0 Compare July 3, 2024 01:51
Signed-off-by: Václav Muzikář <vmuzikar@redhat.com>
@vmuzikar

vmuzikar commented Jul 3, 2024

Copy link
Copy Markdown
Contributor

@shawkins Created shawkins#13. I broke a few tests by my previous PR.

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

Ok, tests are green, let's get this merged already. :)

@shawkins Thank you for your patience with these changes. Very nice work!

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.

Bootstrapping an admin user or service account at server startup Bootstrapping an admin service account using a dedicated command

4 participants