Make admin tool bootstrap idempotent for already-bootstrapped realms#4996
Conversation
|
FYI: @obelix74 , @tokoko , @cccs-cat001 |
cccs-cat001
left a comment
There was a problem hiding this comment.
I've been wanting this for months now! Great change :)
I'd say the code should not assume that 😅 Only the first bootstrap should emit auto-generated credentials. If that's what you mean by follow-up then, let's do that :) My personal preference is to avoid generating user-owned secrets in Polaris completely. Right now the admin use has both options: 1) provide a secret or 2) let Polaris generate it. Ideally, the schema setup should be idempotent. The "root" user set up should be separate (e.g. via Terraform). With external IdP the root user does not even have to exist, but that requires more work to follow #4356 All in all, +1 to follow-up improvements, but I'm afraid it's a long road 😅 |
|
@sepandr : Some of the commits mention Claude as a formal co-author. It is fine to use AI to make contributions, but a human has to assume authorship, I think. Cf. #4106 (comment) |
Bootstrapping a realm that already has a root principal used to throw IllegalArgumentException, which BootstrapCommand mapped to the generic EXIT_CODE_BOOTSTRAP_ERROR. Automated deployments (e.g. Kubernetes Jobs or ArgoCD hooks) that run bootstrap on every deploy therefore failed on any redeploy, and callers could not distinguish the benign case from real failures except by matching the error-message text. AuthBootstrapUtil.createPolarisPrincipalForRealm now returns a PrincipalSecretsResult with ENTITY_ALREADY_EXISTS instead of throwing, PolarisMetaStoreManager.bootstrapPolarisService propagates that result, and BootstrapCommand reports "Realm 'x' is already bootstrapped; skipping." while keeping exit code 0. Existing credentials are never returned or altered; realms that are not yet bootstrapped are still bootstrapped normally. Fixes apache#4995
…tion message - testBootstrapAgainIsNoOp now asserts ReturnStatus.ENTITY_ALREADY_EXISTS directly instead of isSuccess() + alreadyExists() - BootstrapCommand reports 'Bootstrap completed (N realm(s) already bootstrapped).' when realms were skipped, keeping 'Bootstrap completed successfully.' for full bootstraps
d316f18 to
c60a606
Compare
|
Thanks for the pointer @dimas-b — you're right. I've rewritten the branch to drop the |
There was a problem hiding this comment.
We may accidentally make this function not suitable for any callers other than bootstrapping. I understand bootstrapping is the only use case now, should we change the method name to make it explicitly only for bootstrapping?
There was a problem hiding this comment.
The class name is specific to bootstrapping. Renaming to avoid confusion is also fine. @flyrain : Would you like to propose a PR for that?
|
Can we wait until all comments are resolved? |
@flyrain : I enabled auto-merge (as noted above) based on the previous approvals and the 2 day review period. I believe you could have disabled the auto-merge. |
Got it. I guess auto merge will naturally ignore new comments. I'd suggest using it with caution. |
Running the admin tool's
bootstrapagainst a realm that is already bootstrapped currently throwsIllegalArgumentException("It appears this metastore manager has already been bootstrapped…") and exits with the genericEXIT_CODE_BOOTSTRAP_ERROR(3) — the same code as every real failure. That makes automated deployments (Kubernetes Jobs, ArgoCD hook Jobs that run bootstrap on every deploy) fail on any redeploy, with no reliable way to distinguish the benign case short of matching the error text, and Kubernetes offers no "treat exit N as success" escape hatch. See #4995 for full context.This change makes re-bootstrap a graceful no-op:
AuthBootstrapUtil.createPolarisPrincipalForRealmreturns aPrincipalSecretsResultwithReturnStatus.ENTITY_ALREADY_EXISTSinstead of throwing when the root principal already exists (same for the duplicated check inLocalPolarisMetaStoreManagerFactory).PolarisMetaStoreManager.bootstrapPolarisServicepropagates that result (javadoc updated).BootstrapCommandprintsRealm '<realm>' is already bootstrapped; skipping.for such realms and keeps exit code 0; all other failures still exit 3.--print-credentialsnever prints anything for skipped realms — existing credentials are never returned or altered, and realms in the same invocation that are not yet bootstrapped are still bootstrapped normally.Testing: new
testBootstrapAgainIsNoOpinBasePolarisMetaStoreManagerTest(runs for both TreeMap metastore variants) asserts the second bootstrap reportsalreadyExists()and the realm stays fully intact; existing bootstrap/purge CLI tests pass unchanged (:polaris-core:test,:polaris-admin:testin-memory variants run locally; an admin-CLI-level double-bootstrap test isn't possible yet because consecutive launches don't reuse the dev-services container — see the existing TODO inRelationalJdbcBootstrapCommandTest). Also verified behaviorally against a live 1.5.0 deployment (relational-jdbc on PostgreSQL 16) where re-running bootstrap on an existing realm currently fails.AI assistance disclosure: this PR was developed with the assistance of Claude (Anthropic's coding assistant), per the Guidelines for AI-assisted Contributions. I have reviewed, tested, and understand all of the changes, and assume full authorship of and responsibility for the contribution.
Checklist
CHANGELOG.md(if needed)site/content/in-dev/unreleased(if needed)