You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polaris.apache.org by di...@apache.org on 2026/09/18 15:06:49 UTC

(polaris) branch main updated: Fix bootstrap silently creating realms with an unreachable root principal (#5526)

This is an automated email from the ASF dual-hosted git repository.

dimas-b pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git


The following commit(s) were added to refs/heads/main by this push:
     new c90944ea04 Fix bootstrap silently creating realms with an unreachable root principal (#5526)
c90944ea04 is described below

commit c90944ea04db9b0c2fe954a178af0634e39b9c6b
Author: Ayush Saxena <ay...@apache.org>
AuthorDate: Fri Sep 18 20:36:44 2026 +0530

    Fix bootstrap silently creating realms with an unreachable root principal (#5526)
    
    bootstrap required --credential or --print-credentials only when no
    credentials at all were supplied. A non-empty but incomplete list passed
    that check, so any realm not named in it was bootstrapped with a
    generated secret that is never printed. PrincipalSecretsGenerator falls
    back to RANDOM_SECRETS for a realm absent from the credentials map, and
    the command still reported the realm successfully bootstrapped.
    
    Nothing validates that the realm named in a --credential triplet is one
    of the requested realms either, so a misspelled realm name produced the
    same result.
    
    Such a realm cannot be used or recovered: its root principal is the only
    principal, no other credential can be minted without it, and re-running
    bootstrap is a no-op for an existing realm. The guard now covers every
    requested realm and names the ones that are missing credentials.
---
 CHANGELOG.md                                       |  7 +++++++
 .../apache/polaris/admintool/BootstrapCommand.java | 17 +++++++++++------
 .../polaris/admintool/BootstrapCommandTest.java    |  2 +-
 .../admintool/BootstrapCommandTestBase.java        | 22 ++++++++++++++++++++++
 site/content/in-dev/unreleased/admin-tool.md       |  7 +++++++
 5 files changed, 48 insertions(+), 7 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9524359cb9..e4a8aa1cf9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -137,6 +137,13 @@ request adding CHANGELOG notes for breaking (!) changes and possibly other secti
 - OPA authorizer HTTP client creation no longer silently falls back to a default client when
   truststore or SSL setup fails. Misconfiguration (for example a bad truststore path) now fails
   startup instead of continuing with system trust and no configured response timeout.
+- `bootstrap` no longer creates realms whose root principal is unreachable. Credentials were
+  required only when none at all were supplied, so an invocation naming credentials for just
+  some of its realms bootstrapped the rest with randomly generated secrets that were never
+  printed, and reported them successfully bootstrapped. Every `--realm` must now have a
+  matching `--credential` unless `--print-credentials` is given; otherwise the command names
+  the realms that are missing credentials and exits without bootstrapping anything.
+  `--credentials-file` is unaffected.
 - GCS credential vending no longer fails with HTTP 500 when a table's location or `write.data.path`
   / `write.metadata.path` points at a bucket root without a trailing slash (e.g. `gs://bucket`).
   Such a location parses to an empty path and previously triggered a `StringIndexOutOfBoundsException`
diff --git a/runtime/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java b/runtime/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java
index 24bf385aad..4fbb8e133d 100644
--- a/runtime/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java
+++ b/runtime/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java
@@ -103,14 +103,19 @@ public class BootstrapCommand extends BaseMetaStoreCommand {
                 ? RootCredentialsSet.EMPTY
                 : RootCredentialsSet.fromList(
                     inputOptions.rootCredentialsOptions.stdinOptions.credentials);
-        if (inputOptions.rootCredentialsOptions.stdinOptions.credentials == null
-            || inputOptions.rootCredentialsOptions.stdinOptions.credentials.isEmpty()) {
-          if (!inputOptions.rootCredentialsOptions.stdinOptions.printCredentials) {
+        if (!inputOptions.rootCredentialsOptions.stdinOptions.printCredentials) {
+          List<String> realmsWithoutCredentials =
+              inputOptions.rootCredentialsOptions.stdinOptions.realms.stream()
+                  .filter(realm -> !rootCredentialsSet.credentials().containsKey(realm))
+                  .toList();
+          if (!realmsWithoutCredentials.isEmpty()) {
             spec.commandLine()
                 .getErr()
-                .println(
-                    "Specify either `--credentials` or `--print-credentials` to ensure"
-                        + " the root user is accessible after bootstrapping.");
+                .printf(
+                    "No credentials were supplied for realm(s) %s. Specify `--credential` for"
+                        + " every realm, or `--print-credentials`, to ensure the root user is"
+                        + " accessible after bootstrapping.%n",
+                    realmsWithoutCredentials);
             return EXIT_CODE_BOOTSTRAP_ERROR;
           }
         }
diff --git a/runtime/admin/src/test/java/org/apache/polaris/admintool/BootstrapCommandTest.java b/runtime/admin/src/test/java/org/apache/polaris/admintool/BootstrapCommandTest.java
index b242b999ec..c7eb7510c3 100644
--- a/runtime/admin/src/test/java/org/apache/polaris/admintool/BootstrapCommandTest.java
+++ b/runtime/admin/src/test/java/org/apache/polaris/admintool/BootstrapCommandTest.java
@@ -78,7 +78,7 @@ class BootstrapCommandTest {
     int exitCode = commandLine.execute("-r", "realm1");
 
     assertThat(exitCode).isEqualTo(BaseCommand.EXIT_CODE_BOOTSTRAP_ERROR);
-    assertThat(err.toString()).contains("--credentials").contains("--print-credentials");
+    assertThat(err.toString()).contains("--credential").contains("--print-credentials");
   }
 
   @Test
diff --git a/runtime/admin/src/test/java/org/apache/polaris/admintool/BootstrapCommandTestBase.java b/runtime/admin/src/test/java/org/apache/polaris/admintool/BootstrapCommandTestBase.java
index 45a401c4f6..be65a41a7d 100644
--- a/runtime/admin/src/test/java/org/apache/polaris/admintool/BootstrapCommandTestBase.java
+++ b/runtime/admin/src/test/java/org/apache/polaris/admintool/BootstrapCommandTestBase.java
@@ -101,6 +101,28 @@ public abstract class BootstrapCommandTestBase {
     assertThat(result.getOutput()).contains("realm: realm1 root principal credentials: ");
   }
 
+  @Test
+  public void testRealmWithoutCredentialsIsRefused(QuarkusMainLauncher launcher) {
+    LaunchResult result =
+        launcher.launch(
+            "bootstrap", "-r", "realm1", "-r", "realm2", "-c", "realm1,client1d,s3cr3t");
+    assertThat(result.exitCode()).isNotEqualTo(0);
+    assertThat(result.getErrorOutput()).contains("No credentials were supplied for realm(s)");
+    assertThat(result.getErrorOutput()).contains("realm2");
+    assertThat(result.getOutput()).doesNotContain("successfully bootstrapped");
+  }
+
+  @Test
+  public void testMisspelledCredentialRealmIsRefused(QuarkusMainLauncher launcher) {
+    LaunchResult result =
+        launcher.launch("bootstrap", "-r", "realm1", "-c", "realm2,client1d,s3cr3t");
+    assertThat(result.exitCode()).isNotEqualTo(0);
+    assertThat(result.getErrorOutput())
+        .contains("No credentials were supplied for realm(s)")
+        .contains("realm1");
+    assertThat(result.getOutput()).doesNotContain("successfully bootstrapped");
+  }
+
   private static Path copyResource(Path temp, String resource) throws IOException {
     URL source = Objects.requireNonNull(BootstrapCommandTestBase.class.getResource(resource));
     Path dest = temp.resolve(resource);
diff --git a/site/content/in-dev/unreleased/admin-tool.md b/site/content/in-dev/unreleased/admin-tool.md
index 14592ac4c4..cd5ceb3359 100644
--- a/site/content/in-dev/unreleased/admin-tool.md
+++ b/site/content/in-dev/unreleased/admin-tool.md
@@ -123,6 +123,13 @@ File Input Options:
                               bootstrap.
 ```
 
+Every realm passed with `--realm` must have a matching `--credential`, unless
+`--print-credentials` is given. Without one of the two, that realm's root principal would be
+created with a randomly generated secret that is never shown, leaving the realm unusable; the
+command lists the realms that are missing credentials and exits without bootstrapping
+anything. This does not apply to `--credentials-file`, where the realms to bootstrap are taken
+from the file's own entries.
+
 For example, to bootstrap the `realm1` realm and create its root principal credential with the
 client ID `admin` and client secret `admin`, you can run the following commands: