You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@polaris.apache.org by "eric-maynard (via GitHub)" <gi...@apache.org> on 2024/11/21 03:28:15 UTC

[PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

eric-maynard opened a new pull request, #461:
URL: https://github.com/apache/polaris/pull/461

   # Description
   
   This adds a new flag, `BOOTSTRAP_PRINT_CREDENTIALS`, that controls whether the bootstrap command prints root credentials to stdout.
   
   If it's disabled, and environment variables were not provided to set the root credentials, bootstrapping will fail.
   
   Fixes #450
   
   ## Type of change
   
   Please delete options that are not relevant.
   
   - [ ] Bug fix (non-breaking change which fixes an issue)
   - [ ] Documentation update
   - [x] New feature (non-breaking change which adds functionality)
   - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
   - [ ] This change requires a documentation update
   
   # How Has This Been Tested?
   
   Credentials are now printed during bootstrap when it's enabled:
   ```
   realm: default-realm root principal credentials: 2b98107557bcce20:f74281319ac8519ef30cbced6563223b
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "sfc-gh-emaynard (via GitHub)" <gi...@apache.org>.
sfc-gh-emaynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1976061345


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/bootstrap/RootCredentialsSet.java:
##########
@@ -74,6 +76,54 @@ static RootCredentialsSet fromString(@Nullable String credentialsString) {
         : EMPTY;
   }
 
+  /**
+   * Parse a JSON object of credentials. Example: { "realm1": { "client-id": "client1",
+   * "client-secret": "secret1" }, "realm2": { "client-id": "client2", "client-secret": "secret2",
+   * "extra-field": "extra-value" } }

Review Comment:
   While I agree that a shared method would be ideal, I don't see how we can keep this principal-check logic in `fromJson` but remove it from `fromUrl` while sharing a meaningful amount of code across the two methods. If it's okay with you though, I'm happy just to push this logic down into `fromUrl` and then share the code that way.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1861147455


##########
polaris-core/src/test/java/org/apache/polaris/core/persistence/secrets/PrincipalSecretsGeneratorTest.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.polaris.core.persistence.secrets;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.doReturn;
+
+import org.apache.polaris.core.entity.PolarisPrincipalSecrets;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+class PrincipalSecretsGeneratorTest {
+
+  @Test
+  void testRandomSecrets() {
+    RandomPrincipalSecretsGenerator rpsg = new RandomPrincipalSecretsGenerator("realm");
+    PolarisPrincipalSecrets s = rpsg.produceSecrets("name1", 123);
+    assertThat(s).isNotNull();
+    assertThat(s.getPrincipalId()).isEqualTo(123);
+    assertThat(s.getPrincipalClientId()).isNotNull();
+    assertThat(s.getMainSecret()).isNotNull();
+    assertThat(s.getSecondarySecret()).isNotNull();
+  }
+
+  @Test
+  void testRandomSecretsNullRealm() {
+    RandomPrincipalSecretsGenerator rpsg = new RandomPrincipalSecretsGenerator(null);
+    PolarisPrincipalSecrets s = rpsg.produceSecrets("name1", 123);
+    assertThat(s).isNotNull();
+    assertThat(s.getPrincipalId()).isEqualTo(123);
+    assertThat(s.getPrincipalClientId()).isNotNull();
+    assertThat(s.getMainSecret()).isNotNull();
+    assertThat(s.getSecondarySecret()).isNotNull();
+  }
+
+  @Test
+  void testEnvVariableSecrets() {
+    EnvVariablePrincipalSecretsGenerator psg =
+        Mockito.spy(new EnvVariablePrincipalSecretsGenerator("REALM"));
+
+    String clientIdKey = "POLARIS_BOOTSTRAP_REALM_PRINCIPAL_CLIENT_ID";
+    String clientSecretKey = "POLARIS_BOOTSTRAP_REALM_PRINCIPAL_CLIENT_SECRET";
+
+    doReturn("test-id").when(psg).getEnvironmentVariable(clientIdKey);

Review Comment:
   I think it would be nicer to allow `EnvVariablePrincipalSecretsGenerator` to take an explicit `Map` (or a `Function<String, String>`) as a constructor argument. The the "environment" part cab be just a static factory method like `EnvVariablePrincipalSecretsGenerator.fromEnv()`.
   
   Testing the static method would not really be necessary because it would be a one-line redirect to `System.env()`, but it would allow for nicer design that is testable without `Mockito`.
   
   Just my 2 cents :)



##########
polaris-core/src/test/java/org/apache/polaris/core/persistence/secrets/PrincipalSecretsGeneratorTest.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.polaris.core.persistence.secrets;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.doReturn;
+
+import org.apache.polaris.core.entity.PolarisPrincipalSecrets;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+class PrincipalSecretsGeneratorTest {
+
+  @Test
+  void testRandomSecrets() {
+    RandomPrincipalSecretsGenerator rpsg = new RandomPrincipalSecretsGenerator("realm");
+    PolarisPrincipalSecrets s = rpsg.produceSecrets("name1", 123);
+    assertThat(s).isNotNull();
+    assertThat(s.getPrincipalId()).isEqualTo(123);
+    assertThat(s.getPrincipalClientId()).isNotNull();
+    assertThat(s.getMainSecret()).isNotNull();
+    assertThat(s.getSecondarySecret()).isNotNull();
+  }
+
+  @Test
+  void testRandomSecretsNullRealm() {
+    RandomPrincipalSecretsGenerator rpsg = new RandomPrincipalSecretsGenerator(null);
+    PolarisPrincipalSecrets s = rpsg.produceSecrets("name1", 123);
+    assertThat(s).isNotNull();
+    assertThat(s.getPrincipalId()).isEqualTo(123);
+    assertThat(s.getPrincipalClientId()).isNotNull();
+    assertThat(s.getMainSecret()).isNotNull();
+    assertThat(s.getSecondarySecret()).isNotNull();
+  }
+
+  @Test
+  void testEnvVariableSecrets() {
+    EnvVariablePrincipalSecretsGenerator psg =
+        Mockito.spy(new EnvVariablePrincipalSecretsGenerator("REALM"));
+
+    String clientIdKey = "POLARIS_BOOTSTRAP_REALM_PRINCIPAL_CLIENT_ID";
+    String clientSecretKey = "POLARIS_BOOTSTRAP_REALM_PRINCIPAL_CLIENT_SECRET";
+
+    doReturn("test-id").when(psg).getEnvironmentVariable(clientIdKey);
+    doReturn("test-secret").when(psg).getEnvironmentVariable(clientSecretKey);
+
+    // Invoke the method
+    PolarisPrincipalSecrets secrets = psg.produceSecrets("PRINCIPAL", 123);
+
+    // Verify the result
+    Assertions.assertNotNull(secrets);
+    Assertions.assertEquals(123, secrets.getPrincipalId());
+    Assertions.assertEquals("test-id", secrets.getPrincipalClientId());
+    Assertions.assertEquals("test-secret", secrets.getMainSecret());
+  }
+
+  @Test
+  void testBoostrapGeneratorDelegationToRandomPrincipalSecrets() {
+    EnvVariablePrincipalSecretsGenerator mockedEnvVariablePrincipalSecretsGenerator =
+        Mockito.spy(new EnvVariablePrincipalSecretsGenerator("REALM"));
+
+    String clientIdKey = "POLARIS_BOOTSTRAP_REALM_PRINCIPAL_CLIENT_ID";
+    String clientSecretKey = "POLARIS_BOOTSTRAP_REALM_PRINCIPAL_CLIENT_SECRET";
+
+    doReturn("test-id")
+        .when(mockedEnvVariablePrincipalSecretsGenerator)
+        .getEnvironmentVariable(clientIdKey);
+    doReturn("test-secret")
+        .when(mockedEnvVariablePrincipalSecretsGenerator)
+        .getEnvironmentVariable(clientSecretKey);
+
+    class ExposingPrincipalSecretsGenerator extends BootstrapPrincipalSecretsGenerator {
+      public ExposingPrincipalSecretsGenerator(@Nullable String realmName) {
+        super(realmName);
+      }
+
+      @Override
+      protected PrincipalSecretsGenerator buildEnvVariablePrincipalSecretsGenerator(

Review Comment:
   same here: I think we could have a simple factory that bind to `System.env()` in runtime, but use explicit constructor parameters in tests... This will remove reliance on `Mockito`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2528134004

   I think it is generally not a good idea to store retrievable secrets in the metastore. If we want that functionality it would probably be preferable to integrate with well-known secret manages (e.g. k8s secrets, cloud-specific secret managers, Vault, etc.).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "collado-mike (via GitHub)" <gi...@apache.org>.
collado-mike commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2529935071

   My thoughts here are complex. On the one hand, I agree that we should never print credentials to the _service_ log. On the other hand, users need a way of bootstrapping their Polaris service and storing their secrets. 
   
   This is one reason why we made the `bootstrap` command a separate command from the `server` command. Bootstrapping is always an explicit action taken by the user - presumably in an environment that is distinct from the actual runtime of the service (e.g., on a user desktop or in a terraform command or something). Thus, the output of the `bootstrap` command shouldn't be stored in the user's production log store. 
   
   My hope for the `PolarisSecretsManager` is to use it to front a real secrets manager, like Vault or K8s or something. That being the case, randomly generated secrets would be the norm, so I don't think we should print secrets by default just because they were randomly generated. But if the user passes a flag `--printSecrets` or something, then the user can explicitly tell the command that they need the secrets to be printed so they can write them down on a sticky note or whatever (I'm kidding).
   
   I don't think the user should _need_ a separate secrets store, like Vault or whatever, in order to be able to use Polaris at all. If the RDBMS persistence impl is enough for them to store hashed secrets and they can manage their principal secrets in some other way, we should support that. So for the user who has no separate secrets store and only stores hashes of the secret in Postgres, how do we get the user their secrets? 
   
   Either we can require the user to pass in secrets as an argument to bootstrapping or we can randomly generate secrets and print them out for the user. It seems that we _can_ support randomly generated credentials when we _do_ have a separate secrets store, but I don't really like the idea of the secrets manager having to declare that its secrets are retrievable by the end user. So if we require the user to pass in the secrets as an argument, then I think we should _always_ require the secrets as an argument. And if we don't always take the secrets as an argument, then we need to pass randomly generated secrets back to the user in some way - printing seems obvious. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "snazy (via GitHub)" <gi...@apache.org>.
snazy commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2531300792

   I'm quite open (and probably brutal) here: logging or storing plain/clear text credentials is a severe security issue that justifies a CVE. The process of creating credentials must really be a command that only allows the user to grab the secrets - but only once - not stored anywhere - not explicitly or implicitly (or ephemerally), accessible by other tools (database, logging system/files, etc). If the user does not grab the generated secrets, bummer. If the bootstrap process cannot ensure this, then the bootstrap process _has_ to be changed. Security is a very sensitive topic - and and absolute necessity for the production readiness of Apache Polaris!
   
   Generally, I do not think that Apache Polaris should get into the business of handling identities or secrets, but rather interface w/ systems that are purely there for these kinds of things. The currently built-in secrets handling should IMHO entirely go away.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1852668537


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java:
##########
@@ -181,6 +196,19 @@ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm
       throw new IllegalArgumentException(overrideMessage);
     }
 
+    // TODO rebase onto #422, call a method like PrincipalSecretsGenerator.hasEnvironmentVariables

Review Comment:
   idea: maybe pass a flag down to `PrincipalSecretsGenerator` to _not_ use random secrets if `printCredentials` is `false`? Then the `PrincipalSecretsGenerator` can simply throw if the specific realm/user combination is missing env. vars. WDYT?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1930975445


##########
quarkus/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java:
##########
@@ -38,20 +39,37 @@ public class BootstrapCommand extends BaseCommand {
   List<String> realms;
 
   @CommandLine.Option(
-      names = {"-c", "--credential"},
-      paramLabel = "<realm,clientId,clientSecret>",

Review Comment:
   I'm suggesting to delegate the choice of which way to go to the user.
   
   Option 1:
   `bootstrap --realm r1 --client-id c1 --client-secret s1`
   [... do something else ...]
   `bootstrap --realm r2 --client-id c2 --client-secret s2`
   etc....
   
   Option 2:
   `bootstrap --json '{...}'` - here all realm IDs and client ID/secret pairs are in the JSON.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1978021995


##########
quarkus/admin/src/test/java/org/apache/polaris/admintool/BootstrapCommandTest.java:
##########
@@ -132,6 +132,45 @@ public void testBootstrapFromInvalidFile(QuarkusMainLauncher launcher) {
         .contains("Bootstrap encountered errors during operation.");
   }
 
+  @Test
+  @Launch(
+      value = {"bootstrap", "-r", "realm1", "-c", "realm1,client1d,s3cr3t", "--print-credentials"})
+  public void testPrintCredentials(LaunchResult result) {
+    assertThat(result.getOutput()).contains("Bootstrap completed successfully.");
+    assertThat(result.getOutput()).contains("realm: realm1 root principal credentials: client1d:");

Review Comment:
   TIL. I think this PR is good to merge then, and we'll follow-up on #801



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1964866296


##########
polaris-core/src/main/java/org/apache/polaris/core/entity/PolarisEntityConstants.java:
##########
@@ -21,6 +21,10 @@
 public class PolarisEntityConstants {
 
   public static final String ENTITY_BASE_LOCATION = "location";
+
+  // the name of the root principal we create at bootstrap time
+  public static final String ROOT_PRINCIPAL_NAME = "root";

Review Comment:
   Good catch, this is a merge conflict



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1927943529


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisCredentialsBootstrap.java:
##########
@@ -63,6 +66,39 @@ public static PolarisCredentialsBootstrap fromString(@Nullable String credential
         : EMPTY;
   }
 
+  /**
+   * Parse a JSON array of credentials. Example: """ [ {"realm": "a", "principal": "root",
+   * "clientId": "abc123", "clientSecret": "xyz987"}, {"realm": "b", "principal": "boot",
+   * "clientId": "boot-id", "clientSecret": "boot-secret"}, ] """
+   */
+  public static PolarisCredentialsBootstrap fromJson(String json) {

Review Comment:
   Could you add a test for this method?



##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisCredentialsBootstrap.java:
##########
@@ -63,6 +66,39 @@ public static PolarisCredentialsBootstrap fromString(@Nullable String credential
         : EMPTY;
   }
 
+  /**
+   * Parse a JSON array of credentials. Example: """ [ {"realm": "a", "principal": "root",
+   * "clientId": "abc123", "clientSecret": "xyz987"}, {"realm": "b", "principal": "boot",
+   * "clientId": "boot-id", "clientSecret": "boot-secret"}, ] """
+   */
+  public static PolarisCredentialsBootstrap fromJson(String json) {
+    ObjectMapper objectMapper = new ObjectMapper();
+    try {
+      List<Map<String, String>> credentialsList =
+          objectMapper.readValue(json, new TypeReference<List<Map<String, String>>>() {});
+      List<String> formattedList = new ArrayList<>();
+      for (Map<String, String> entry : credentialsList) {
+        String realm = entry.get("realm");
+        String principal = entry.get("principal");
+        String clientId = entry.get("clientId");
+        String clientSecret = entry.get("clientSecret");
+        if (realm == null || principal == null || clientId == null || clientSecret == null) {
+          throw new IllegalArgumentException("Invalid JSON format for credentials: " + json);
+        }
+        if (!principal.equals(PolarisEntityConstants.ROOT_PRINCIPAL_NAME)) {
+          throw new IllegalArgumentException(
+              String.format(
+                  "Invalid principal %s. Expected %s.",
+                  principal, PolarisEntityConstants.ROOT_PRINCIPAL_NAME));
+        }
+        formattedList.add(String.join(",", realm, principal, clientId, clientSecret));
+      }
+      return fromList(formattedList);

Review Comment:
   Re-parsing from a generated list looks too complex to me. Why not create a `PolarisCredentialsBootstrap` object directly?



##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisCredentialsBootstrap.java:
##########
@@ -63,6 +66,39 @@ public static PolarisCredentialsBootstrap fromString(@Nullable String credential
         : EMPTY;
   }
 
+  /**
+   * Parse a JSON array of credentials. Example: """ [ {"realm": "a", "principal": "root",
+   * "clientId": "abc123", "clientSecret": "xyz987"}, {"realm": "b", "principal": "boot",
+   * "clientId": "boot-id", "clientSecret": "boot-secret"}, ] """
+   */
+  public static PolarisCredentialsBootstrap fromJson(String json) {
+    ObjectMapper objectMapper = new ObjectMapper();
+    try {
+      List<Map<String, String>> credentialsList =
+          objectMapper.readValue(json, new TypeReference<List<Map<String, String>>>() {});
+      List<String> formattedList = new ArrayList<>();
+      for (Map<String, String> entry : credentialsList) {
+        String realm = entry.get("realm");
+        String principal = entry.get("principal");
+        String clientId = entry.get("clientId");
+        String clientSecret = entry.get("clientSecret");
+        if (realm == null || principal == null || clientId == null || clientSecret == null) {
+          throw new IllegalArgumentException("Invalid JSON format for credentials: " + json);
+        }
+        if (!principal.equals(PolarisEntityConstants.ROOT_PRINCIPAL_NAME)) {
+          throw new IllegalArgumentException(
+              String.format(
+                  "Invalid principal %s. Expected %s.",
+                  principal, PolarisEntityConstants.ROOT_PRINCIPAL_NAME));
+        }
+        formattedList.add(String.join(",", realm, principal, clientId, clientSecret));
+      }
+      return fromList(formattedList);
+    } catch (Exception e) {
+      throw new IllegalArgumentException("Failed to parse JSON: " + json, e);

Review Comment:
   nit: an exception here may not be related to JSON parsing. I'd simply say "unable to determine bootstrap credentials"... or something like that.



##########
quarkus/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java:
##########
@@ -38,20 +39,37 @@ public class BootstrapCommand extends BaseCommand {
   List<String> realms;
 
   @CommandLine.Option(
-      names = {"-c", "--credential"},
-      paramLabel = "<realm,clientId,clientSecret>",
+      names = {"-c", "--credentials"},
+      description = "Principal credentials to bootstrap. Must be a valid JSON array e.g. " +
+          "[{\"realm\": \"my-realm\", \"principal\": \"root\", \"clientId\": \"polaris\", \"clientSecret\": \"p4ssw0rd\"}]")
+  String credentials;
+
+  @CommandLine.Option(
+      names = {"-p", "--print-credentials"},
       description =
-          "Root principal credentials to bootstrap. Must be of the form 'realm,clientId,clientSecret'.")
-  List<String> credentials;
+          "Print root credentials to stdout")

Review Comment:
   Also, could you add a test case for this to `BootstrapCommandTest`?



##########
quarkus/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java:
##########
@@ -38,20 +39,37 @@ public class BootstrapCommand extends BaseCommand {
   List<String> realms;
 
   @CommandLine.Option(
-      names = {"-c", "--credential"},
-      paramLabel = "<realm,clientId,clientSecret>",
+      names = {"-c", "--credentials"},
+      description = "Principal credentials to bootstrap. Must be a valid JSON array e.g. " +
+          "[{\"realm\": \"my-realm\", \"principal\": \"root\", \"clientId\": \"polaris\", \"clientSecret\": \"p4ssw0rd\"}]")
+  String credentials;
+
+  @CommandLine.Option(
+      names = {"-p", "--print-credentials"},
       description =
-          "Root principal credentials to bootstrap. Must be of the form 'realm,clientId,clientSecret'.")
-  List<String> credentials;
+          "Print root credentials to stdout")
+  boolean printCredentials;
 
   @Override
   public Integer call() {
     warnOnInMemory();
 
+    if (credentials == null || credentials.isEmpty()) {
+      if (!printCredentials) {
+        throw new IllegalArgumentException("Specify either `--credentials` or `--print-credentials` to ensure" +

Review Comment:
   It's a simple error message. Stack trace is not valuable. `spec.commandLine().getErr().println(...)` might be more user-friendly.



##########
quarkus/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java:
##########
@@ -38,20 +39,37 @@ public class BootstrapCommand extends BaseCommand {
   List<String> realms;
 
   @CommandLine.Option(
-      names = {"-c", "--credential"},
-      paramLabel = "<realm,clientId,clientSecret>",

Review Comment:
   while I agree that supporting well-formed JSON is valuable, I believe the value is realized mostly in automated use case. This old option, however, is easier to use for humans, IMHO... Why not keep both options available for users to choose what it convenient for them?
   
   For example: `--json` for JSON, and `--client-id`, `--client-secret` for plain strings?



##########
quarkus/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java:
##########
@@ -38,20 +39,37 @@ public class BootstrapCommand extends BaseCommand {
   List<String> realms;
 
   @CommandLine.Option(
-      names = {"-c", "--credential"},
-      paramLabel = "<realm,clientId,clientSecret>",
+      names = {"-c", "--credentials"},
+      description = "Principal credentials to bootstrap. Must be a valid JSON array e.g. " +
+          "[{\"realm\": \"my-realm\", \"principal\": \"root\", \"clientId\": \"polaris\", \"clientSecret\": \"p4ssw0rd\"}]")
+  String credentials;
+
+  @CommandLine.Option(
+      names = {"-p", "--print-credentials"},
       description =
-          "Root principal credentials to bootstrap. Must be of the form 'realm,clientId,clientSecret'.")
-  List<String> credentials;
+          "Print root credentials to stdout")

Review Comment:
   This option implies that credentials are generated, right? Could you mention that in the description?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1930991709


##########
quarkus/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java:
##########
@@ -38,20 +39,37 @@ public class BootstrapCommand extends BaseCommand {
   List<String> realms;
 
   @CommandLine.Option(
-      names = {"-c", "--credential"},
-      paramLabel = "<realm,clientId,clientSecret>",

Review Comment:
   FYI, I'm working on #878... I'm leaning towards a file in the following syntax:
   
   ```json
   {
     "credentials" : {
       "realm1" : {
         "client-id" : "client1",
         "client-secret" : "secret1"
       },
       "realm2" : {
         "client-id": "client2",
         "client-secret": "secret2"
       }
     }
   }
   ```
   
   YAML will also be supported:
   
   ```yaml
   credentials:
     realm1:
       client-id: client1
       client-secret: secret1
     realm2:
       client-id: client2
       client-secret: secret2
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1966386578


##########
quarkus/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java:
##########
@@ -43,20 +45,17 @@ static class InputOptions {
     FileInputOptions fileOptions;
 
     static class StandardInputOptions {
-
       @CommandLine.Option(
-          names = {"-r", "--realm"},
-          paramLabel = "<realm>",
-          required = true,
-          description = "The name of a realm to bootstrap.")
-      List<String> realms;
+          names = {"-c", "--credentials"},
+          description =
+              "Principal credentials to bootstrap. If provided, must be a valid JSON array e.g. "
+                  + "[{\"realm\": \"my-realm\", \"principal\": \"root\", \"clientId\": \"polaris\", \"clientSecret\": \"p4ssw0rd\"}]")
+      String credentials;
 
       @CommandLine.Option(
-          names = {"-c", "--credential"},
-          paramLabel = "<realm,clientId,clientSecret>",

Review Comment:
   I believe the existing `-c` option is adequate for bootstrapping current Polaris Server and it is convenient for users.
   
   I think we should keep it, but I'm open to altering its format as long as it is human-writable in shells without too much quoting.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1860358591


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/secrets/PrincipalSecretsGenerator.java:
##########
@@ -38,48 +37,48 @@
  *   <li>{@code POLARIS_BOOTSTRAP_<REALM-NAME>_<PRINCIPAL-NAME>_CLIENT_SECRET}
  * </ul>
  *
- * For example: {@code POLARIS_BOOTSTRAP_DEFAULT-REALM_ROOT_CLIENT_ID} and {@code
- * POLARIS_BOOTSTRAP_DEFAULT-REALM_ROOT_CLIENT_SECRET}.
+ * For example: {@code POLARIS_BOOTSTRAP_default-realm_root_CLIENT_ID} and {@code
+ * POLARIS_BOOTSTRAP_default-realm_root_CLIENT_SECRET}.
  */
-@FunctionalInterface
-public interface PrincipalSecretsGenerator {
+public abstract class PrincipalSecretsGenerator {
 
-  /**
-   * A secret generator that produces cryptographically random client ID and client secret values.
-   */
-  PrincipalSecretsGenerator RANDOM_SECRETS = (name, id) -> new PolarisPrincipalSecrets(id);
+  protected final String realmName;
+
+  public PrincipalSecretsGenerator() {
+    this.realmName = null;
+  }
+
+  public PrincipalSecretsGenerator(@Nullable String realmName) {
+    this.realmName = realmName;
+  }
 
   /**
    * Produces a new {@link PolarisPrincipalSecrets} object for the given principal ID. The returned
-   * secrets may or may not be random, depending on context. In bootstrapping contexts, the returned
-   * secrets can be predefined. After bootstrapping, the returned secrets can be expected to be
-   * cryptographically random.
+   * secrets may or may not be random, depending on context. The returned secrets can be predefined.
    *
    * @param principalName the name of the related principal. This parameter is a hint for
    *     pre-defined secrets lookup during bootstrapping it is not included in the returned data.
    * @param principalId the ID of the related principal. This ID is part of the returned data.
    * @return a new {@link PolarisPrincipalSecrets} instance for the specified principal.
    */
-  PolarisPrincipalSecrets produceSecrets(@NotNull String principalName, long principalId);
-
-  static PrincipalSecretsGenerator bootstrap(String realmName) {
-    return bootstrap(realmName, System.getenv()::get);
-  }
+  public abstract PolarisPrincipalSecrets produceSecrets(
+      @NotNull String principalName, long principalId);
 
-  static PrincipalSecretsGenerator bootstrap(String realmName, Function<String, String> config) {
-    return (principalName, principalId) -> {
-      String propId = String.format("POLARIS_BOOTSTRAP_%s_%s_CLIENT_ID", realmName, principalName);
-      String propSecret =
-          String.format("POLARIS_BOOTSTRAP_%s_%s_CLIENT_SECRET", realmName, principalName);
+  /**
+   * @param principalName the name of the related principal. This parameter is a hint for
+   *     pre-defined secrets lookup during bootstrapping it is not included in the returned data.
+   * @return true if the secrets generated by this {@link PrincipalSecretsGenerator} are
+   *     Polaris-generated as opposed to being provided by the user or another system.
+   */
+  public abstract boolean systemGeneratedSecrets(@NotNull String principalName);
 
-      String clientId = config.apply(propId.toUpperCase(Locale.ROOT));
-      String secret = config.apply(propSecret.toUpperCase(Locale.ROOT));
-      // use config values at most once (do not interfere with secret rotation)
-      if (clientId != null && secret != null) {
-        return new PolarisPrincipalSecrets(principalId, clientId, secret, secret);
-      } else {
-        return RANDOM_SECRETS.produceSecrets(principalName, principalId);
-      }
-    };
+  /**
+   * Build a PrincipalSecretsGenerator for bootstrapping
+   *
+   * @param realmName the name of the realm
+   * @return A {@link PrincipalSecretsGenerator} that can generate secrets through `produceSecrets`
+   */
+  public static PrincipalSecretsGenerator bootstrap(String realmName) {
+    return new DefaultPrincipalSecretsGenerator(realmName);

Review Comment:
   Good point. It's just a wrapper, so I was not sure what to call it. Since it's only used during bootstrap, let me change to `BootstrapPrincipalSecretsGenerator` for now



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2527033463

   > It seems odd that Polaris determines whether bootstrapping has failed based on a configuration controlling whether credentials are printed. 
   
   The issue at hand is that currently credentials are unrecoverable after bootstrapping, which needs to be fixed ASAP.
   
   > IIUC, https://github.com/apache/polaris/pull/438 removed plain text secrets from the metastore, meaning these secrets cannot be retrieved unless they are printed in the console. Would it be more reasonable to always print the credentials if they are generated by Polaris? This ensures the secrets remain accessible when needed without relying on an external configuration.
   
   @collado-mike expressed concern about an approach like this some time ago. I think a configuration, or perhaps better a CLI argument to the `bootstrap` command, is a good compromise in that it allows a secure behavior by default (e.g. no secrets to stdout) but also gives people an "out" in case they want to use polaris-generated credentials with a metastore that doesn't support retrieving credentials.
   
   This last point is also very important to consider: some metastore implementations could allow secrets to be retrieved, in which case it's okay to bootstrap without printing credentials. The issue at hand is that after #438 EclipseLink does not allow this.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2533211071

   With respect to the apparent security issues, I can only echo @collado-mike's comment -- the stdout of the bootstrap command is ***not*** the Polaris log. As such, this is neither `logging [n]or storing plain/clear text credentials` in @snazy's words.
   
   Moreover, I question whether doing such a thing _iff_ the user sets a parameter called `BOOTSTRAP_PRINT_CREDENTIALS` really does qualify as a security "issue".


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "collado-mike (via GitHub)" <gi...@apache.org>.
collado-mike commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2533431900

   > Generally, I do not think that Apache Polaris should get into the business of handling identities or secrets, but rather interface w/ systems that are purely there for these kinds of things. The currently built-in secrets handling should IMHO entirely go away.
   
   While I appreciate the security focus, I think the reality is that we are going to have to be able to manage secrets in Polaris as a standalone application for a long time (forever?). External secrets management systems like Vault or external identity providers like Okta are fantastic and I definitely promote their usage, but the reality is that some installations will simply not want/need the overhead of managing an external service. I think our approach should be that core features work out of the box with nothing more than a database (even that might be a local file), but that we allow extension points to add more and more layers of security and functionality. My proposal for Federated Principals and Roles is an example of this - basic identity management works, but if you want to be _really_ secure, delegate identity and group membership to an external service that's tailor made for that.
   
   I 100% agree with the approach that we should expose secrets once and never again. This is a core tenet of the service and the reason why there are no secrets retrieval APIs. It's why @eric-maynard's changes to store only secret hashes works.
   
   But there has to be _once_. That means that during bootstrapping, we need the ability to return the root credentials to the user who bootstrapped. Never again will we return those credentials be accessible, but we have to be able to return them somewhere. 
   
   I see a few approaches for this:
   1. Remove the `bootstrap` method from the `PolarisMetaStoreManager` and bootstrap directly from the `BootstrapCommand` class, as @dimas-b suggests. I actually think this is very elegant and allows the `BootstrapCommand` itself to determine what to do with the secrets (print or not depending on the argument)
   2. Keep the `bootstrap` method, but change the response to return a `Map<String, PrincipalSecrets>` so that the `BootstrapCommand` can determine what to do with the secrets
   3. Add a `PrincipalSecretsConsumer` of some kind that takes the generated secrets and does something with them. This can be configured on the CLI to print or to store in a file or whatever
   
   Personally, I like 1. It's clean and simple and there's no opportunity to misuse it. The tests and the in-memory startup will need to change, but I think that's a cost worth paying.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard merged PR #461:
URL: https://github.com/apache/polaris/pull/461


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1860879997


##########
polaris-core/src/test/java/org/apache/polaris/core/persistence/PrincipalSecretsGeneratorTest.java:
##########
@@ -18,41 +18,34 @@
  */
 package org.apache.polaris.core.persistence;
 
-import static org.apache.polaris.core.persistence.PrincipalSecretsGenerator.bootstrap;
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.util.Map;
-import org.apache.polaris.core.entity.PolarisPrincipalSecrets;
-import org.junit.jupiter.api.Test;
-
 class PrincipalSecretsGeneratorTest {
-
-  @Test
-  void testRandomSecrets() {
-    PolarisPrincipalSecrets s = bootstrap("test", (name) -> null).produceSecrets("name1", 123);
-    assertThat(s).isNotNull();
-    assertThat(s.getPrincipalId()).isEqualTo(123);
-    assertThat(s.getPrincipalClientId()).isNotNull();
-    assertThat(s.getMainSecret()).isNotNull();
-    assertThat(s.getSecondarySecret()).isNotNull();
-  }
-
-  @Test
-  void testSecretOverride() {
-    PrincipalSecretsGenerator gen =
-        bootstrap(
-            "test-Realm",
-            Map.of(
-                    "POLARIS_BOOTSTRAP_TEST-REALM_USER1_CLIENT_ID",
-                    "client1",
-                    "POLARIS_BOOTSTRAP_TEST-REALM_USER1_CLIENT_SECRET",
-                    "sec2")
-                ::get);
-    PolarisPrincipalSecrets s = gen.produceSecrets("user1", 123);
-    assertThat(s).isNotNull();
-    assertThat(s.getPrincipalId()).isEqualTo(123);
-    assertThat(s.getPrincipalClientId()).isEqualTo("client1");
-    assertThat(s.getMainSecret()).isEqualTo("sec2");
-    assertThat(s.getSecondarySecret()).isEqualTo("sec2");
-  }
+  //
+  //  @Test
+  //  void testRandomSecrets() {

Review Comment:
   Did you mean to move test code into new classes matching new implementations?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1861211075


##########
polaris-core/src/test/java/org/apache/polaris/core/persistence/secrets/PrincipalSecretsGeneratorTest.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.polaris.core.persistence.secrets;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.doReturn;
+
+import org.apache.polaris.core.entity.PolarisPrincipalSecrets;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+class PrincipalSecretsGeneratorTest {
+
+  @Test
+  void testRandomSecrets() {
+    RandomPrincipalSecretsGenerator rpsg = new RandomPrincipalSecretsGenerator("realm");
+    PolarisPrincipalSecrets s = rpsg.produceSecrets("name1", 123);
+    assertThat(s).isNotNull();
+    assertThat(s.getPrincipalId()).isEqualTo(123);
+    assertThat(s.getPrincipalClientId()).isNotNull();
+    assertThat(s.getMainSecret()).isNotNull();
+    assertThat(s.getSecondarySecret()).isNotNull();
+  }
+
+  @Test
+  void testRandomSecretsNullRealm() {
+    RandomPrincipalSecretsGenerator rpsg = new RandomPrincipalSecretsGenerator(null);
+    PolarisPrincipalSecrets s = rpsg.produceSecrets("name1", 123);
+    assertThat(s).isNotNull();
+    assertThat(s.getPrincipalId()).isEqualTo(123);
+    assertThat(s.getPrincipalClientId()).isNotNull();
+    assertThat(s.getMainSecret()).isNotNull();
+    assertThat(s.getSecondarySecret()).isNotNull();
+  }
+
+  @Test
+  void testEnvVariableSecrets() {
+    EnvVariablePrincipalSecretsGenerator psg =
+        Mockito.spy(new EnvVariablePrincipalSecretsGenerator("REALM"));
+
+    String clientIdKey = "POLARIS_BOOTSTRAP_REALM_PRINCIPAL_CLIENT_ID";
+    String clientSecretKey = "POLARIS_BOOTSTRAP_REALM_PRINCIPAL_CLIENT_SECRET";
+
+    doReturn("test-id").when(psg).getEnvironmentVariable(clientIdKey);

Review Comment:
   I like this idea, but my concern is that `EnvVariablePrincipalSecretsGenerator` essentially becomes `MapPrincipalSecretsGenerator` with that approach. I would rather not place the burden on its callers to do the `fromEnv` / `getEnv`; this seems like the exact responsibility we would like `EnvVariablePrincipalSecretsGenerator` to take on.
   
   For example: if we later add command-line options to `bootstrap` that allow you to provide credentials, would we use the  `EnvVariablePrincipalSecretsGenerator` for that? If it takes a map, we could.
   
   Taking this further, we could even pass in a map with random secrets to `EnvVariablePrincipalSecretsGenerator`! 
   
   And so its role, as well as that of `RandomPrincipalSecretsGenerator`, can quickly become quite unclear



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1976099290


##########
quarkus/admin/src/test/java/org/apache/polaris/admintool/BootstrapCommandTest.java:
##########
@@ -132,6 +132,45 @@ public void testBootstrapFromInvalidFile(QuarkusMainLauncher launcher) {
         .contains("Bootstrap encountered errors during operation.");
   }
 
+  @Test
+  @Launch(
+      value = {"bootstrap", "-r", "realm1", "-c", "realm1,client1d,s3cr3t", "--print-credentials"})
+  public void testPrintCredentials(LaunchResult result) {
+    assertThat(result.getOutput()).contains("Bootstrap completed successfully.");
+    assertThat(result.getOutput()).contains("realm: realm1 root principal credentials: client1d:");

Review Comment:
   Why not assert that `s3cr3t` is printed?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1977997630


##########
quarkus/admin/src/test/java/org/apache/polaris/admintool/BootstrapCommandTest.java:
##########
@@ -132,6 +132,45 @@ public void testBootstrapFromInvalidFile(QuarkusMainLauncher launcher) {
         .contains("Bootstrap encountered errors during operation.");
   }
 
+  @Test
+  @Launch(
+      value = {"bootstrap", "-r", "realm1", "-c", "realm1,client1d,s3cr3t", "--print-credentials"})
+  public void testPrintCredentials(LaunchResult result) {
+    assertThat(result.getOutput()).contains("Bootstrap completed successfully.");
+    assertThat(result.getOutput()).contains("realm: realm1 root principal credentials: client1d:");

Review Comment:
   It's actually _not_ printed -- maybe it should be. Because of #801 the secret supplied becomes the secondary secret while the primary secret is printed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1977999040


##########
quarkus/admin/src/test/java/org/apache/polaris/admintool/BootstrapCommandTest.java:
##########
@@ -132,6 +132,45 @@ public void testBootstrapFromInvalidFile(QuarkusMainLauncher launcher) {
         .contains("Bootstrap encountered errors during operation.");
   }
 
+  @Test
+  @Launch(
+      value = {"bootstrap", "-r", "realm1", "-c", "realm1,client1d,s3cr3t", "--print-credentials"})
+  public void testPrintCredentials(LaunchResult result) {
+    assertThat(result.getOutput()).contains("Bootstrap completed successfully.");
+    assertThat(result.getOutput()).contains("realm: realm1 root principal credentials: client1d:");

Review Comment:
   I would rather we just solve #801 rather than add special logic around printing the secondary secret here



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1936527885


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisCredentialsBootstrap.java:
##########
@@ -63,6 +66,42 @@ public static PolarisCredentialsBootstrap fromString(@Nullable String credential
         : EMPTY;
   }
 
+  /**
+   * Parse a JSON array of credentials. Example: """ [ {"realm": "a", "principal": "root",
+   * "clientId": "abc123", "clientSecret": "xyz987"}, {"realm": "b", "principal": "boot",
+   * "clientId": "boot-id", "clientSecret": "boot-secret"}, ] """
+   */
+  public static PolarisCredentialsBootstrap fromJson(String json) {
+    ObjectMapper objectMapper = new ObjectMapper();
+    List<Map<String, String>> credentialsList = new ArrayList<>();
+    try {
+      credentialsList = objectMapper.readValue(json, new TypeReference<>() {});
+    } catch (Exception e) {
+      throw new IllegalArgumentException("Could not parse credentials JSON: " + json, e);
+    }
+    Map<String, Map.Entry<String, String>> credentials = new HashMap<>();
+    for (Map<String, String> entry : credentialsList) {
+      String realm = entry.get("realm");
+      String principal = entry.get("principal");
+      String clientId = entry.get("clientId");
+      String clientSecret = entry.get("clientSecret");
+      if (realm == null || principal == null || clientId == null || clientSecret == null) {
+        throw new IllegalArgumentException("Failed to find credentials in: " + json);
+      } else if (!principal.equals(PolarisEntityConstants.ROOT_PRINCIPAL_NAME)) {
+        throw new IllegalArgumentException(
+            String.format(
+                "Invalid principal %s. Expected %s.",

Review Comment:
   I think, in this case it would be fine to accept JSON with extra fields. However, in that case, the parsing code should probably not attempt to validate (or even interpret) the fields it does not use.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1859287670


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/secrets/PrincipalSecretsGenerator.java:
##########
@@ -38,48 +37,48 @@
  *   <li>{@code POLARIS_BOOTSTRAP_<REALM-NAME>_<PRINCIPAL-NAME>_CLIENT_SECRET}
  * </ul>
  *
- * For example: {@code POLARIS_BOOTSTRAP_DEFAULT-REALM_ROOT_CLIENT_ID} and {@code
- * POLARIS_BOOTSTRAP_DEFAULT-REALM_ROOT_CLIENT_SECRET}.
+ * For example: {@code POLARIS_BOOTSTRAP_default-realm_root_CLIENT_ID} and {@code
+ * POLARIS_BOOTSTRAP_default-realm_root_CLIENT_SECRET}.
  */
-@FunctionalInterface
-public interface PrincipalSecretsGenerator {
+public abstract class PrincipalSecretsGenerator {
 
-  /**
-   * A secret generator that produces cryptographically random client ID and client secret values.
-   */
-  PrincipalSecretsGenerator RANDOM_SECRETS = (name, id) -> new PolarisPrincipalSecrets(id);
+  protected final String realmName;
+
+  public PrincipalSecretsGenerator() {
+    this.realmName = null;
+  }
+
+  public PrincipalSecretsGenerator(@Nullable String realmName) {
+    this.realmName = realmName;
+  }
 
   /**
    * Produces a new {@link PolarisPrincipalSecrets} object for the given principal ID. The returned
-   * secrets may or may not be random, depending on context. In bootstrapping contexts, the returned
-   * secrets can be predefined. After bootstrapping, the returned secrets can be expected to be
-   * cryptographically random.
+   * secrets may or may not be random, depending on context. The returned secrets can be predefined.
    *
    * @param principalName the name of the related principal. This parameter is a hint for
    *     pre-defined secrets lookup during bootstrapping it is not included in the returned data.
    * @param principalId the ID of the related principal. This ID is part of the returned data.
    * @return a new {@link PolarisPrincipalSecrets} instance for the specified principal.
    */
-  PolarisPrincipalSecrets produceSecrets(@NotNull String principalName, long principalId);
-
-  static PrincipalSecretsGenerator bootstrap(String realmName) {
-    return bootstrap(realmName, System.getenv()::get);
-  }
+  public abstract PolarisPrincipalSecrets produceSecrets(
+      @NotNull String principalName, long principalId);
 
-  static PrincipalSecretsGenerator bootstrap(String realmName, Function<String, String> config) {
-    return (principalName, principalId) -> {
-      String propId = String.format("POLARIS_BOOTSTRAP_%s_%s_CLIENT_ID", realmName, principalName);
-      String propSecret =
-          String.format("POLARIS_BOOTSTRAP_%s_%s_CLIENT_SECRET", realmName, principalName);
+  /**
+   * @param principalName the name of the related principal. This parameter is a hint for
+   *     pre-defined secrets lookup during bootstrapping it is not included in the returned data.
+   * @return true if the secrets generated by this {@link PrincipalSecretsGenerator} are
+   *     Polaris-generated as opposed to being provided by the user or another system.
+   */
+  public abstract boolean systemGeneratedSecrets(@NotNull String principalName);
 
-      String clientId = config.apply(propId.toUpperCase(Locale.ROOT));
-      String secret = config.apply(propSecret.toUpperCase(Locale.ROOT));
-      // use config values at most once (do not interfere with secret rotation)
-      if (clientId != null && secret != null) {
-        return new PolarisPrincipalSecrets(principalId, clientId, secret, secret);
-      } else {
-        return RANDOM_SECRETS.produceSecrets(principalName, principalId);
-      }
-    };
+  /**
+   * Build a PrincipalSecretsGenerator for bootstrapping
+   *
+   * @param realmName the name of the realm
+   * @return A {@link PrincipalSecretsGenerator} that can generate secrets through `produceSecrets`
+   */
+  public static PrincipalSecretsGenerator bootstrap(String realmName) {
+    return new DefaultPrincipalSecretsGenerator(realmName);

Review Comment:
   nit: maybe rename `DefaultPrincipalSecretsGenerator` -> `BootstrapPrincipalSecretsGenerator`?.. it is not actually default in `LocalPolarisMetaStoreManagerFactory`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1861211701


##########
polaris-core/src/test/java/org/apache/polaris/core/persistence/secrets/PrincipalSecretsGeneratorTest.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.polaris.core.persistence.secrets;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.doReturn;
+
+import org.apache.polaris.core.entity.PolarisPrincipalSecrets;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+class PrincipalSecretsGeneratorTest {
+
+  @Test
+  void testRandomSecrets() {
+    RandomPrincipalSecretsGenerator rpsg = new RandomPrincipalSecretsGenerator("realm");
+    PolarisPrincipalSecrets s = rpsg.produceSecrets("name1", 123);
+    assertThat(s).isNotNull();
+    assertThat(s.getPrincipalId()).isEqualTo(123);
+    assertThat(s.getPrincipalClientId()).isNotNull();
+    assertThat(s.getMainSecret()).isNotNull();
+    assertThat(s.getSecondarySecret()).isNotNull();
+  }
+
+  @Test
+  void testRandomSecretsNullRealm() {
+    RandomPrincipalSecretsGenerator rpsg = new RandomPrincipalSecretsGenerator(null);
+    PolarisPrincipalSecrets s = rpsg.produceSecrets("name1", 123);
+    assertThat(s).isNotNull();
+    assertThat(s.getPrincipalId()).isEqualTo(123);
+    assertThat(s.getPrincipalClientId()).isNotNull();
+    assertThat(s.getMainSecret()).isNotNull();
+    assertThat(s.getSecondarySecret()).isNotNull();
+  }
+
+  @Test
+  void testEnvVariableSecrets() {
+    EnvVariablePrincipalSecretsGenerator psg =
+        Mockito.spy(new EnvVariablePrincipalSecretsGenerator("REALM"));
+
+    String clientIdKey = "POLARIS_BOOTSTRAP_REALM_PRINCIPAL_CLIENT_ID";
+    String clientSecretKey = "POLARIS_BOOTSTRAP_REALM_PRINCIPAL_CLIENT_SECRET";
+
+    doReturn("test-id").when(psg).getEnvironmentVariable(clientIdKey);
+    doReturn("test-secret").when(psg).getEnvironmentVariable(clientSecretKey);
+
+    // Invoke the method
+    PolarisPrincipalSecrets secrets = psg.produceSecrets("PRINCIPAL", 123);
+
+    // Verify the result
+    Assertions.assertNotNull(secrets);
+    Assertions.assertEquals(123, secrets.getPrincipalId());
+    Assertions.assertEquals("test-id", secrets.getPrincipalClientId());
+    Assertions.assertEquals("test-secret", secrets.getMainSecret());
+  }
+
+  @Test
+  void testBoostrapGeneratorDelegationToRandomPrincipalSecrets() {
+    EnvVariablePrincipalSecretsGenerator mockedEnvVariablePrincipalSecretsGenerator =
+        Mockito.spy(new EnvVariablePrincipalSecretsGenerator("REALM"));
+
+    String clientIdKey = "POLARIS_BOOTSTRAP_REALM_PRINCIPAL_CLIENT_ID";
+    String clientSecretKey = "POLARIS_BOOTSTRAP_REALM_PRINCIPAL_CLIENT_SECRET";
+
+    doReturn("test-id")
+        .when(mockedEnvVariablePrincipalSecretsGenerator)
+        .getEnvironmentVariable(clientIdKey);
+    doReturn("test-secret")
+        .when(mockedEnvVariablePrincipalSecretsGenerator)
+        .getEnvironmentVariable(clientSecretKey);
+
+    class ExposingPrincipalSecretsGenerator extends BootstrapPrincipalSecretsGenerator {
+      public ExposingPrincipalSecretsGenerator(@Nullable String realmName) {
+        super(realmName);
+      }
+
+      @Override
+      protected PrincipalSecretsGenerator buildEnvVariablePrincipalSecretsGenerator(

Review Comment:
   In this case what I think we really want is DI 😔



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1964844654


##########
polaris-core/src/main/java/org/apache/polaris/core/entity/PolarisEntityConstants.java:
##########
@@ -21,6 +21,10 @@
 public class PolarisEntityConstants {
 
   public static final String ENTITY_BASE_LOCATION = "location";
+
+  // the name of the root principal we create at bootstrap time
+  public static final String ROOT_PRINCIPAL_NAME = "root";

Review Comment:
   nit: is this change necessary?



##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/bootstrap/RootCredentialsSet.java:
##########
@@ -74,6 +76,54 @@ static RootCredentialsSet fromString(@Nullable String credentialsString) {
         : EMPTY;
   }
 
+  /**
+   * Parse a JSON object of credentials. Example: { "realm1": { "client-id": "client1",
+   * "client-secret": "secret1" }, "realm2": { "client-id": "client2", "client-secret": "secret2",
+   * "extra-field": "extra-value" } }

Review Comment:
   `fromUrl()` is already able to parse this kind of JSON... Why add a new parsing method? Why not reuse that code?



##########
quarkus/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java:
##########
@@ -43,20 +45,17 @@ static class InputOptions {
     FileInputOptions fileOptions;
 
     static class StandardInputOptions {
-
       @CommandLine.Option(
-          names = {"-r", "--realm"},
-          paramLabel = "<realm>",
-          required = true,
-          description = "The name of a realm to bootstrap.")
-      List<String> realms;
+          names = {"-c", "--credentials"},
+          description =
+              "Principal credentials to bootstrap. If provided, must be a valid JSON array e.g. "
+                  + "[{\"realm\": \"my-realm\", \"principal\": \"root\", \"clientId\": \"polaris\", \"clientSecret\": \"p4ssw0rd\"}]")
+      String credentials;
 
       @CommandLine.Option(
-          names = {"-c", "--credential"},
-          paramLabel = "<realm,clientId,clientSecret>",

Review Comment:
   What is the reason for removing the option for the user to specify plain text credentials as command line args?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1852669846


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java:
##########
@@ -181,6 +196,19 @@ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm
       throw new IllegalArgumentException(overrideMessage);
     }
 
+    // TODO rebase onto #422, call a method like PrincipalSecretsGenerator.hasEnvironmentVariables
+    boolean environmentVariableCredentials = false;
+    if (!this.printCredentials(polarisContext) && !environmentVariableCredentials) {
+      String failureMessage =
+          String.format(
+              "It appears that environment variables were not provided for root credentials, and that printing "
+                  + "the root credentials is disabled via %s. If bootstrapping were to proceed, there would be no way "
+                  + "to recover the root credentials",
+              PolarisConfiguration.BOOTSTRAP_PRINT_CREDENTIALS.key);
+      LOGGER.error("\n\n {} \n\n", failureMessage);
+      throw new IllegalArgumentException(failureMessage);

Review Comment:
   Good idea :+1: 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1852673738


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java:
##########
@@ -181,6 +196,19 @@ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm
       throw new IllegalArgumentException(overrideMessage);
     }
 
+    // TODO rebase onto #422, call a method like PrincipalSecretsGenerator.hasEnvironmentVariables

Review Comment:
   I like that idea. If there is a good pathway from the bootstrap command down to the `PrincipalSecretsGenerator` then I think that works as well. It should hopefully be more clear when #422 merges.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1930989230


##########
quarkus/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java:
##########
@@ -38,20 +39,37 @@ public class BootstrapCommand extends BaseCommand {
   List<String> realms;
 
   @CommandLine.Option(
-      names = {"-c", "--credential"},
-      paramLabel = "<realm,clientId,clientSecret>",

Review Comment:
   Just to clarify: Option 1 only bootstraps one realm at a time, correct? I think I can live with that.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1931087539


##########
quarkus/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java:
##########
@@ -38,20 +39,37 @@ public class BootstrapCommand extends BaseCommand {
   List<String> realms;
 
   @CommandLine.Option(
-      names = {"-c", "--credential"},
-      paramLabel = "<realm,clientId,clientSecret>",

Review Comment:
   `--print-credentials` is just a CLI option. I do no think it should be inside JSON.
   
   As for `--json` being unclean, how about:
   
   Option 1: `bootstrap --realm ... [ --client-id ... --client-secret ...]` (as above)
   Option 2: `bootstrap --realm-json <json>`, where `<json>` is from from @adutra 's example
   Option 3: `bootstrap --realm-yaml ...` - same as JSON, but in YAML format



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "flyrain (via GitHub)" <gi...@apache.org>.
flyrain commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2526935265

   It seems odd that Polaris determines whether bootstrapping has failed based on a configuration controlling whether credentials are printed. IIUC, #438 removed plain text secrets from the metastore, meaning these secrets cannot be retrieved unless they are printed in the console. Would it be more reasonable to always print the credentials if they are generated by Polaris? This ensures the secrets remain accessible when needed without relying on an external configuration.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "flyrain (via GitHub)" <gi...@apache.org>.
flyrain commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1873865689


##########
extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreSessionImpl.java:
##########
@@ -66,8 +66,16 @@
 import org.apache.polaris.core.exceptions.AlreadyExistsException;
 import org.apache.polaris.core.persistence.PolarisMetaStoreManagerImpl;
 import org.apache.polaris.core.persistence.PolarisMetaStoreSession;
-import org.apache.polaris.core.persistence.PrincipalSecretsGenerator;
 import org.apache.polaris.core.persistence.RetryOnConcurrencyException;
+<<<<<<< HEAD
+import org.apache.polaris.core.persistence.models.ModelEntity;
+import org.apache.polaris.core.persistence.models.ModelEntityActive;
+import org.apache.polaris.core.persistence.models.ModelEntityChangeTracking;
+import org.apache.polaris.core.persistence.models.ModelGrantRecord;
+import org.apache.polaris.core.persistence.models.ModelPrincipalSecrets;
+import org.apache.polaris.core.persistence.secrets.PrincipalSecretsGenerator;
+=======
+>>>>>>> c7ec45fa799bffa8526fbc758cb4a5d07815be9e

Review Comment:
   A bit cleanup here?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2666608052

   @adutra so on this note:
   
   > a. To bootstrap realms in this case, the only option right now is to use the admin tool.
   
   
   This was true before (insofar as you call the Dropwizard bootstrap command the "admin tool"), but you could also just call `bootstrap` with no args. Where did that behavior go?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "sfc-gh-emaynard (via GitHub)" <gi...@apache.org>.
sfc-gh-emaynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1976061345


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/bootstrap/RootCredentialsSet.java:
##########
@@ -74,6 +76,54 @@ static RootCredentialsSet fromString(@Nullable String credentialsString) {
         : EMPTY;
   }
 
+  /**
+   * Parse a JSON object of credentials. Example: { "realm1": { "client-id": "client1",
+   * "client-secret": "secret1" }, "realm2": { "client-id": "client2", "client-secret": "secret2",
+   * "extra-field": "extra-value" } }

Review Comment:
   While I agree that a shared method would be ideal, I don't see how we can keep this principal-check logic in `fromJson` but remove it from `fromUrl` while sharing a meaningful amount of code across the two methods. If it's okay with you though, I'm happy just to push this logic down into `fromUrl` and then share the code that way.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1977997630


##########
quarkus/admin/src/test/java/org/apache/polaris/admintool/BootstrapCommandTest.java:
##########
@@ -132,6 +132,45 @@ public void testBootstrapFromInvalidFile(QuarkusMainLauncher launcher) {
         .contains("Bootstrap encountered errors during operation.");
   }
 
+  @Test
+  @Launch(
+      value = {"bootstrap", "-r", "realm1", "-c", "realm1,client1d,s3cr3t", "--print-credentials"})
+  public void testPrintCredentials(LaunchResult result) {
+    assertThat(result.getOutput()).contains("Bootstrap completed successfully.");
+    assertThat(result.getOutput()).contains("realm: realm1 root principal credentials: client1d:");

Review Comment:
   It's actually _not_ printed -- maybe it should be. Because of PR#801 the secret supplied becomes the secondary secret while the primary secret is printed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2498865881

   Hey @dimas-b, do you mind taking a look now that #422 has merged?
   
   I think the integration is easy enough with some slight refactoring to `PrincipalSecretsGenerator`. I left the current behavior wrt. using env variables even when printing is enabled, since if that's what the user decides to explicitly configure we can respect it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1857405610


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/PrincipalSecretsGenerator.java:
##########
@@ -82,4 +86,28 @@ static PrincipalSecretsGenerator bootstrap(String realmName, Function<String, St
       }
     };
   }
+
+  /** Return true if environment variables for client ID & secret are set */
+  static boolean hasCredentialVariables(String realmName, String principalName) {

Review Comment:
   Exposing this `static` method does not look nice to be from the encapsulation point of view. I'd prefer to keep credential generation logic inside `PrincipalSecretsGenerator` instances.
   
   We already have the `bootstrap` flag in `LocalPolarisMetaStoreManagerFactory` that controls secret generation under a synchronization lock. WDYT about converting it into something like `PrincipalSecretsGenerator generatorFallback` and making `PrincipalSecretsGenerator.bootstrap()` take an explicit fallback parameter (which is currently always `RANDOM_SECRETS`)? `LocalPolarisMetaStoreManagerFactory` would use `RANDOM_SECRETS` as the fallback by default, but during bootstrapping, we could have a custom impl. that produces random secrets if printing is enabled, but throws an exception if fallback if requested, but printing is disabled.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "flyrain (via GitHub)" <gi...@apache.org>.
flyrain commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2533072727

   > If printing is super controversial then we can always just require the env variables for now.
   
   +1 to this approach. We could introduce an additional step before starting the Polaris instance to handle secret generation and environment variable setup. This step could take one of the following forms:
   1. Manual Process: Generate the secrets manually and set the environment variables accordingly.
   2. Integrated Bootstrap: Automate the secret generation and environment variable setup as part of the bootstrap process.
   
   Additionally, users is responsible for ensuring anything generated during this step, such as logs or extra files, is not leaked to unsecured locations to maintain security.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2533195728

   This is all valuable discussion, but I am worried we are going in circles a bit.
   
   For now, does someone else want to take a crack at a minimal change to fix the experience of using EclipseLink?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1928063989


##########
quarkus/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java:
##########
@@ -38,20 +39,37 @@ public class BootstrapCommand extends BaseCommand {
   List<String> realms;
 
   @CommandLine.Option(
-      names = {"-c", "--credential"},
-      paramLabel = "<realm,clientId,clientSecret>",

Review Comment:
   > This old option, however, is easier to use for humans, IMHO...
   
   I really do not think that is the case for the current format.
   
   As for supporting both the old and the new format (and maybe field-specific args like you suggest), I think we're best off just having one way to do the same thing here. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1930969734


##########
quarkus/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java:
##########
@@ -38,20 +39,37 @@ public class BootstrapCommand extends BaseCommand {
   List<String> realms;
 
   @CommandLine.Option(
-      names = {"-c", "--credential"},
-      paramLabel = "<realm,clientId,clientSecret>",

Review Comment:
   But with `--client-id` etc., how does multi-realm support work?
   
   Since bootstrap is a one-time operation, I feel OK with a "heavier" invocation so long as it is very human-readable.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1930972489


##########
quarkus/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java:
##########
@@ -38,20 +39,37 @@ public class BootstrapCommand extends BaseCommand {
   List<String> realms;
 
   @CommandLine.Option(
-      names = {"-c", "--credential"},
-      paramLabel = "<realm,clientId,clientSecret>",
+      names = {"-c", "--credentials"},
+      description = "Principal credentials to bootstrap. Must be a valid JSON array e.g. " +
+          "[{\"realm\": \"my-realm\", \"principal\": \"root\", \"clientId\": \"polaris\", \"clientSecret\": \"p4ssw0rd\"}]")
+  String credentials;
+
+  @CommandLine.Option(
+      names = {"-p", "--print-credentials"},
       description =
-          "Root principal credentials to bootstrap. Must be of the form 'realm,clientId,clientSecret'.")
-  List<String> credentials;
+          "Print root credentials to stdout")

Review Comment:
   Currently, it also prints user-provided credentials



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1931022721


##########
quarkus/admin/src/test/java/org/apache/polaris/admintool/BootstrapCommandTest.java:
##########
@@ -32,16 +34,35 @@ class BootstrapCommandTest {
   @Launch(
       value = {
         "bootstrap",
-        "-r",
-        "realm1",
-        "-r",
-        "realm2",
         "-c",
-        "realm1,root,s3cr3t",
-        "-c",
-        "realm2,root,s3cr3t"
+        "[{\"realm\":\"realm1\",\"principal\":\"root\",\"clientId\":\"root\",\"clientSecret\":\"s3cr3t\"}]"
       })
   public void testBootstrap(LaunchResult result) {
     assertThat(result.getOutput()).contains("Bootstrap completed successfully.");
   }
+
+  @Test
+  @Launch(
+      value = {
+          "bootstrap",
+          "-c",
+          "[{\"realm\":\"realm1\",\"principal\":\"root\",\"clientId\":\"root\",\"clientSecret\":\"s3cr3t\"}]",
+          "--print-credentials"
+      })
+  public void testPrintCredentials(LaunchResult result) {
+    String output = result.getOutput();
+    assertThat(output).contains("Bootstrap completed successfully.");
+    assertThat(output).contains("root:");

Review Comment:
   This looks like:
   ```
   realm: realm1 root principal credentials: root:c15196133e4348d64c7f478dca57e99e
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "snazy (via GitHub)" <gi...@apache.org>.
snazy commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1931065961


##########
quarkus/admin/src/test/java/org/apache/polaris/admintool/BootstrapCommandTest.java:
##########
@@ -32,16 +34,35 @@ class BootstrapCommandTest {
   @Launch(
       value = {
         "bootstrap",
-        "-r",
-        "realm1",
-        "-r",
-        "realm2",
         "-c",
-        "realm1,root,s3cr3t",
-        "-c",
-        "realm2,root,s3cr3t"
+        "[{\"realm\":\"realm1\",\"principal\":\"root\",\"clientId\":\"root\",\"clientSecret\":\"s3cr3t\"}]"
       })
   public void testBootstrap(LaunchResult result) {
     assertThat(result.getOutput()).contains("Bootstrap completed successfully.");
   }
+
+  @Test
+  @Launch(
+      value = {
+          "bootstrap",
+          "-c",
+          "[{\"realm\":\"realm1\",\"principal\":\"root\",\"clientId\":\"root\",\"clientSecret\":\"s3cr3t\"}]",

Review Comment:
   I don't think users will get the JSON syntax on the command line right in every circumstance. The previous approach at least allowed to use quotes around arguments, if even necessary, w/o the need to think about the JSON syntax.
   
   Automated tooling would have to deal with escaping of special characters.
   `"` and `\` and `*` are possible in secrets - but escaping those for JSON and then for the the command line is quite tricky to get right.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1964867562


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/bootstrap/RootCredentialsSet.java:
##########
@@ -74,6 +76,54 @@ static RootCredentialsSet fromString(@Nullable String credentialsString) {
         : EMPTY;
   }
 
+  /**
+   * Parse a JSON object of credentials. Example: { "realm1": { "client-id": "client1",
+   * "client-secret": "secret1" }, "realm2": { "client-id": "client2", "client-secret": "secret2",
+   * "extra-field": "extra-value" } }

Review Comment:
   Agreed, but I wanted to showcase the behavior around `principal` that was discussed above; it's not clear to me how to add that logic into `fromUrl`. If there's an easy way, happy to just make that change now



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1860373265


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java:
##########
@@ -95,10 +97,26 @@ public synchronized Map<String, PrincipalSecretsResult> bootstrapRealms(List<Str
         RealmContext realmContext = () -> realm;
         if (!metaStoreManagerMap.containsKey(realmContext.getRealmIdentifier())) {
           initializeForRealm(realmContext);
+          // While bootstrapping we need to act as a fake privileged context since the real
+          // CallContext hasn't even been resolved yet.
+          PolarisCallContext polarisContext =
+              new PolarisCallContext(
+                  sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(), diagServices);
           PrincipalSecretsResult secretsResult =
               bootstrapServiceAndCreatePolarisPrincipalForRealm(
-                  realmContext, metaStoreManagerMap.get(realmContext.getRealmIdentifier()));
+                  realmContext,
+                  metaStoreManagerMap.get(realmContext.getRealmIdentifier()),
+                  polarisContext);
           results.put(realmContext.getRealmIdentifier(), secretsResult);
+          if (this.printCredentials(polarisContext)) {
+            String msg =
+                String.format(
+                    "realm: %1s root principal credentials: %2s:%3s",
+                    realmContext.getRealmIdentifier(),
+                    secretsResult.getPrincipalSecrets().getPrincipalClientId(),
+                    secretsResult.getPrincipalSecrets().getMainSecret());
+            System.out.println(msg);
+          }

Review Comment:
   It seems like the `PrincipalSecretsGenerator` is doing exactly what the name suggests: generating secrets.
   
   Whatever is done with those secrets -- persisting them, using them, printing them -- is outside the purview of the generator itself.
   
   You are right that the `MetaStoreManager` doesn't need to know anything about printing either (it doesn't in this PR) and clearly this should be outside the purview of the metastore itself.
   
   And so we landed on the factory. I would be happy to take this bootstrapping logic and excise it to somewhere more idiomatic if that is a concern. But right now the bootstrapping logic lives here (e.g. the `purge` check) and this seems like the most appropriate place that doesn't change the responsibility of either the metastore or generator classes.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "collado-mike (via GitHub)" <gi...@apache.org>.
collado-mike commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1858924693


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java:
##########
@@ -95,10 +97,26 @@ public synchronized Map<String, PrincipalSecretsResult> bootstrapRealms(List<Str
         RealmContext realmContext = () -> realm;
         if (!metaStoreManagerMap.containsKey(realmContext.getRealmIdentifier())) {
           initializeForRealm(realmContext);
+          // While bootstrapping we need to act as a fake privileged context since the real
+          // CallContext hasn't even been resolved yet.
+          PolarisCallContext polarisContext =
+              new PolarisCallContext(
+                  sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(), diagServices);
           PrincipalSecretsResult secretsResult =
               bootstrapServiceAndCreatePolarisPrincipalForRealm(
-                  realmContext, metaStoreManagerMap.get(realmContext.getRealmIdentifier()));
+                  realmContext,
+                  metaStoreManagerMap.get(realmContext.getRealmIdentifier()),
+                  polarisContext);
           results.put(realmContext.getRealmIdentifier(), secretsResult);
+          if (this.printCredentials(polarisContext)) {
+            String msg =
+                String.format(
+                    "realm: %1s root principal credentials: %2s:%3s",
+                    realmContext.getRealmIdentifier(),
+                    secretsResult.getPrincipalSecrets().getPrincipalClientId(),
+                    secretsResult.getPrincipalSecrets().getMainSecret());
+            System.out.println(msg);
+          }

Review Comment:
   I think this logic belongs to the secrets generator. The MetaStoreManager doesn't need to know anything about whether the secrets generated are provided by the user or if they've been generated randomly. So why would it be concerned with printing the credentials? The secrets generator knows if the secrets were provided explicitly or if they were randomly generated. 
   
   I think the `bootstrap` command should take a `print-credentials` config flag and the constructed secrets generator can react accordingly.



##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java:
##########
@@ -196,6 +211,20 @@ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm
       throw new IllegalArgumentException(overrideMessage);
     }
 
+    boolean environmentVariableCredentials =
+        PrincipalSecretsGenerator.hasCredentialVariables(
+            realmContext.getRealmIdentifier(), PolarisEntityConstants.getRootPrincipalName());
+    if (!this.printCredentials(polarisContext) && !environmentVariableCredentials) {
+      String failureMessage =
+          String.format(
+              "It appears that environment variables were not provided for root credentials, and that printing "
+                  + "the root credentials is disabled via %s. If bootstrapping were to proceed, there would be no way "
+                  + "to recover the root credentials",
+              PolarisConfiguration.BOOTSTRAP_PRINT_CREDENTIALS.key);
+      LOGGER.error("\n\n {} \n\n", failureMessage);

Review Comment:
   Similar here - why is the metastore aware of whether the secrets were provided by environment variables? What if there are other impls of secrets generators that don't rely on env variables? E.g., we could have one that calls AWS SecretsManager to dynamically generate and store the secrets without any env variables. Should this code throw an exception?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1860876048


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/secrets/PrincipalSecretsGenerator.java:
##########
@@ -38,48 +37,48 @@
  *   <li>{@code POLARIS_BOOTSTRAP_<REALM-NAME>_<PRINCIPAL-NAME>_CLIENT_SECRET}
  * </ul>
  *
- * For example: {@code POLARIS_BOOTSTRAP_DEFAULT-REALM_ROOT_CLIENT_ID} and {@code
- * POLARIS_BOOTSTRAP_DEFAULT-REALM_ROOT_CLIENT_SECRET}.
+ * For example: {@code POLARIS_BOOTSTRAP_default-realm_root_CLIENT_ID} and {@code
+ * POLARIS_BOOTSTRAP_default-realm_root_CLIENT_SECRET}.
  */
-@FunctionalInterface
-public interface PrincipalSecretsGenerator {
+public abstract class PrincipalSecretsGenerator {
 
-  /**
-   * A secret generator that produces cryptographically random client ID and client secret values.
-   */
-  PrincipalSecretsGenerator RANDOM_SECRETS = (name, id) -> new PolarisPrincipalSecrets(id);
+  protected final String realmName;
+
+  public PrincipalSecretsGenerator() {
+    this.realmName = null;
+  }
+
+  public PrincipalSecretsGenerator(@Nullable String realmName) {
+    this.realmName = realmName;
+  }
 
   /**
    * Produces a new {@link PolarisPrincipalSecrets} object for the given principal ID. The returned
-   * secrets may or may not be random, depending on context. In bootstrapping contexts, the returned
-   * secrets can be predefined. After bootstrapping, the returned secrets can be expected to be
-   * cryptographically random.
+   * secrets may or may not be random, depending on context. The returned secrets can be predefined.
    *
    * @param principalName the name of the related principal. This parameter is a hint for
    *     pre-defined secrets lookup during bootstrapping it is not included in the returned data.
    * @param principalId the ID of the related principal. This ID is part of the returned data.
    * @return a new {@link PolarisPrincipalSecrets} instance for the specified principal.
    */
-  PolarisPrincipalSecrets produceSecrets(@NotNull String principalName, long principalId);
-
-  static PrincipalSecretsGenerator bootstrap(String realmName) {
-    return bootstrap(realmName, System.getenv()::get);
-  }
+  public abstract PolarisPrincipalSecrets produceSecrets(
+      @NotNull String principalName, long principalId);
 
-  static PrincipalSecretsGenerator bootstrap(String realmName, Function<String, String> config) {
-    return (principalName, principalId) -> {
-      String propId = String.format("POLARIS_BOOTSTRAP_%s_%s_CLIENT_ID", realmName, principalName);
-      String propSecret =
-          String.format("POLARIS_BOOTSTRAP_%s_%s_CLIENT_SECRET", realmName, principalName);
+  /**
+   * @param principalName the name of the related principal. This parameter is a hint for
+   *     pre-defined secrets lookup during bootstrapping it is not included in the returned data.
+   * @return true if the secrets generated by this {@link PrincipalSecretsGenerator} are
+   *     Polaris-generated as opposed to being provided by the user or another system.
+   */
+  public abstract boolean systemGeneratedSecrets(@NotNull String principalName);
 
-      String clientId = config.apply(propId.toUpperCase(Locale.ROOT));

Review Comment:
   Mixed case env. variable look odd, but technically we can support them. I do not mind ;)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "snazy (via GitHub)" <gi...@apache.org>.
snazy commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2528279987

   > I think it is generally not a good idea to store retrievable secrets in the metastore.
   
   Completely agree with this. I'd extend this even to not put any credentials into a server log at all, because that information is not just "ephemeral on a console window", but logs can easily go into 3rd party systems, which would then make those _clear text_ credentials easily accessible.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2533094193

   Conceptually, bootstrapping may not even be the right term here :) This is not about helping the server to start and run, but about defining some prerequisite persisted objects (the root principal, specifically).
   
   How about removing "bootstrap" methods from `MetaStoreManagerFactory` and performing the associated initialization in a new `initialize` CLI command? The command will have options for printing generated secrets to the console (not log) or (preferably) to a local file.
   
   For the in-memory case, we could probably execute `initialize` inside the `main` application method, so in-memory servers will have to provide initialization parameters to the `server` command.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1931089470


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisCredentialsBootstrap.java:
##########
@@ -63,6 +66,42 @@ public static PolarisCredentialsBootstrap fromString(@Nullable String credential
         : EMPTY;
   }
 
+  /**
+   * Parse a JSON array of credentials. Example: """ [ {"realm": "a", "principal": "root",
+   * "clientId": "abc123", "clientSecret": "xyz987"}, {"realm": "b", "principal": "boot",
+   * "clientId": "boot-id", "clientSecret": "boot-secret"}, ] """
+   */
+  public static PolarisCredentialsBootstrap fromJson(String json) {
+    ObjectMapper objectMapper = new ObjectMapper();
+    List<Map<String, String>> credentialsList = new ArrayList<>();
+    try {
+      credentialsList = objectMapper.readValue(json, new TypeReference<>() {});
+    } catch (Exception e) {
+      throw new IllegalArgumentException("Could not parse credentials JSON: " + json, e);
+    }
+    Map<String, Map.Entry<String, String>> credentials = new HashMap<>();
+    for (Map<String, String> entry : credentialsList) {
+      String realm = entry.get("realm");
+      String principal = entry.get("principal");
+      String clientId = entry.get("clientId");
+      String clientSecret = entry.get("clientSecret");
+      if (realm == null || principal == null || clientId == null || clientSecret == null) {
+        throw new IllegalArgumentException("Failed to find credentials in: " + json);
+      } else if (!principal.equals(PolarisEntityConstants.ROOT_PRINCIPAL_NAME)) {
+        throw new IllegalArgumentException(
+            String.format(
+                "Invalid principal %s. Expected %s.",

Review Comment:
   Do we need the `principal` entry in the JSON at all?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2610913033

   @eric-maynard : GH still shows a conflict on this PR... Would you mind resolving it before the next review round?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1976062296


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/bootstrap/RootCredentialsSet.java:
##########
@@ -74,6 +76,54 @@ static RootCredentialsSet fromString(@Nullable String credentialsString) {
         : EMPTY;
   }
 
+  /**
+   * Parse a JSON object of credentials. Example: { "realm1": { "client-id": "client1",
+   * "client-secret": "secret1" }, "realm2": { "client-id": "client2", "client-secret": "secret2",
+   * "extra-field": "extra-value" } }

Review Comment:
   While I agree that a shared method would be ideal, I don't see how we can keep this principal-check logic in `fromJson` but remove it from `fromUrl` while sharing a meaningful amount of code across the two methods. If it's okay with you though, I'm happy just to push this logic down into `fromUrl` and then share the code that way.
   
   Otherwise, we can also remove this check altogether if you think it shouldn't be there, or we can keep the divergent parsing logic. I don't have a strong opinion here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1978021995


##########
quarkus/admin/src/test/java/org/apache/polaris/admintool/BootstrapCommandTest.java:
##########
@@ -132,6 +132,45 @@ public void testBootstrapFromInvalidFile(QuarkusMainLauncher launcher) {
         .contains("Bootstrap encountered errors during operation.");
   }
 
+  @Test
+  @Launch(
+      value = {"bootstrap", "-r", "realm1", "-c", "realm1,client1d,s3cr3t", "--print-credentials"})
+  public void testPrintCredentials(LaunchResult result) {
+    assertThat(result.getOutput()).contains("Bootstrap completed successfully.");
+    assertThat(result.getOutput()).contains("realm: realm1 root principal credentials: client1d:");

Review Comment:
   TIL. I think this PR is good to merge, then and we'll follow-up on #801



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1958702475


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisCredentialsBootstrap.java:
##########
@@ -63,6 +66,42 @@ public static PolarisCredentialsBootstrap fromString(@Nullable String credential
         : EMPTY;
   }
 
+  /**
+   * Parse a JSON array of credentials. Example: """ [ {"realm": "a", "principal": "root",
+   * "clientId": "abc123", "clientSecret": "xyz987"}, {"realm": "b", "principal": "boot",
+   * "clientId": "boot-id", "clientSecret": "boot-secret"}, ] """
+   */
+  public static PolarisCredentialsBootstrap fromJson(String json) {
+    ObjectMapper objectMapper = new ObjectMapper();
+    List<Map<String, String>> credentialsList = new ArrayList<>();
+    try {
+      credentialsList = objectMapper.readValue(json, new TypeReference<>() {});
+    } catch (Exception e) {
+      throw new IllegalArgumentException("Could not parse credentials JSON: " + json, e);
+    }
+    Map<String, Map.Entry<String, String>> credentials = new HashMap<>();
+    for (Map<String, String> entry : credentialsList) {
+      String realm = entry.get("realm");
+      String principal = entry.get("principal");
+      String clientId = entry.get("clientId");
+      String clientSecret = entry.get("clientSecret");
+      if (realm == null || principal == null || clientId == null || clientSecret == null) {
+        throw new IllegalArgumentException("Failed to find credentials in: " + json);
+      } else if (!principal.equals(PolarisEntityConstants.ROOT_PRINCIPAL_NAME)) {
+        throw new IllegalArgumentException(
+            String.format(
+                "Invalid principal %s. Expected %s.",

Review Comment:
   I agree that extra fields are okay, but specifically I wanted to check for `principal` so as to not mislead people into thinking `principal` is a field that works. It must be `root` and I thought being explicit about that would be helpful.
   
   Hopefully in the future we can lift this restriction and then we can simply remove that check without having to change the input syntax.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1858978770


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/PrincipalSecretsGenerator.java:
##########
@@ -82,4 +86,28 @@ static PrincipalSecretsGenerator bootstrap(String realmName, Function<String, St
       }
     };
   }
+
+  /** Return true if environment variables for client ID & secret are set */
+  static boolean hasCredentialVariables(String realmName, String principalName) {

Review Comment:
   The issue is that the check against `POLARIS_BOOTSTRAP_%s_%s_CLIENT_SECRET` was buried inside `bootstrap`. One potential fix could be to sort of refactor `PrincipalSecretsGenerator` so that we have multiple implementations / providers and we could then use the type of the `PrincipalSecretsGenerator` to determine whether the credentials are user-provided or generated.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1860357874


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/secrets/PrincipalSecretsGenerator.java:
##########
@@ -38,48 +37,48 @@
  *   <li>{@code POLARIS_BOOTSTRAP_<REALM-NAME>_<PRINCIPAL-NAME>_CLIENT_SECRET}
  * </ul>
  *
- * For example: {@code POLARIS_BOOTSTRAP_DEFAULT-REALM_ROOT_CLIENT_ID} and {@code
- * POLARIS_BOOTSTRAP_DEFAULT-REALM_ROOT_CLIENT_SECRET}.
+ * For example: {@code POLARIS_BOOTSTRAP_default-realm_root_CLIENT_ID} and {@code
+ * POLARIS_BOOTSTRAP_default-realm_root_CLIENT_SECRET}.
  */
-@FunctionalInterface
-public interface PrincipalSecretsGenerator {
+public abstract class PrincipalSecretsGenerator {
 
-  /**
-   * A secret generator that produces cryptographically random client ID and client secret values.
-   */
-  PrincipalSecretsGenerator RANDOM_SECRETS = (name, id) -> new PolarisPrincipalSecrets(id);
+  protected final String realmName;
+
+  public PrincipalSecretsGenerator() {
+    this.realmName = null;
+  }
+
+  public PrincipalSecretsGenerator(@Nullable String realmName) {
+    this.realmName = realmName;
+  }
 
   /**
    * Produces a new {@link PolarisPrincipalSecrets} object for the given principal ID. The returned
-   * secrets may or may not be random, depending on context. In bootstrapping contexts, the returned
-   * secrets can be predefined. After bootstrapping, the returned secrets can be expected to be
-   * cryptographically random.
+   * secrets may or may not be random, depending on context. The returned secrets can be predefined.
    *
    * @param principalName the name of the related principal. This parameter is a hint for
    *     pre-defined secrets lookup during bootstrapping it is not included in the returned data.
    * @param principalId the ID of the related principal. This ID is part of the returned data.
    * @return a new {@link PolarisPrincipalSecrets} instance for the specified principal.
    */
-  PolarisPrincipalSecrets produceSecrets(@NotNull String principalName, long principalId);
-
-  static PrincipalSecretsGenerator bootstrap(String realmName) {
-    return bootstrap(realmName, System.getenv()::get);
-  }
+  public abstract PolarisPrincipalSecrets produceSecrets(
+      @NotNull String principalName, long principalId);
 
-  static PrincipalSecretsGenerator bootstrap(String realmName, Function<String, String> config) {
-    return (principalName, principalId) -> {
-      String propId = String.format("POLARIS_BOOTSTRAP_%s_%s_CLIENT_ID", realmName, principalName);
-      String propSecret =
-          String.format("POLARIS_BOOTSTRAP_%s_%s_CLIENT_SECRET", realmName, principalName);
+  /**
+   * @param principalName the name of the related principal. This parameter is a hint for
+   *     pre-defined secrets lookup during bootstrapping it is not included in the returned data.
+   * @return true if the secrets generated by this {@link PrincipalSecretsGenerator} are
+   *     Polaris-generated as opposed to being provided by the user or another system.
+   */
+  public abstract boolean systemGeneratedSecrets(@NotNull String principalName);
 
-      String clientId = config.apply(propId.toUpperCase(Locale.ROOT));

Review Comment:
   Yeah, I actually think this is wrong isn't it? It seems like you can have both a `dimas` and a `DIMAS` user, so how would you differentiate them in the env variables?
   
   This is assuming we now allow the use of env variables for non-root users.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "flyrain (via GitHub)" <gi...@apache.org>.
flyrain commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2533207796

   I'd not be too worried about the name(`bootstrap`) at this moment. A quick fix to resolve the issue without security issues would be prefered.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2528949731

   Agreed as well. But for the time being we need to make the EclipseLink metastore work again. This is significantly better than both the current state and where we were before #438.
   
   I added a note to the relevant doc clarifying that we don't recommend using this in production, where users should provide secure credentials through environment variables.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2530377833

   So it looks like the approach proposed in this PR (while I keep my non-binding approval) appears to be not robust enough.
   
   I'd like to propose to move the printing of generated credentials to the `bootstrap` CLI command and also add an option to write them to a file on the local filesystem.
   
   For that matter, I think even the generation of random secrets should be delegated to the `bootstrap` command and removed from core. Them, core services will receive secrets the same way whether the user provided self-managed secrets or asked the `bootstrap` command to generate them. Integration with secret managers is deferred. WDYT?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1930992953


##########
quarkus/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java:
##########
@@ -38,20 +39,37 @@ public class BootstrapCommand extends BaseCommand {
   List<String> realms;
 
   @CommandLine.Option(
-      names = {"-c", "--credential"},
-      paramLabel = "<realm,clientId,clientSecret>",

Review Comment:
   One last comment, sorry... I think the admin tool should require the user to enter credentials for each realm to bootstrap. In real life, it makes little sense to bootstrap with random credentials. Wdyt? At the least the file syntax for now requires the credentials to be specified.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1960323739


##########
quarkus/admin/src/test/java/org/apache/polaris/admintool/BootstrapCommandTest.java:
##########
@@ -32,16 +34,35 @@ class BootstrapCommandTest {
   @Launch(
       value = {
         "bootstrap",
-        "-r",
-        "realm1",
-        "-r",
-        "realm2",
         "-c",
-        "realm1,root,s3cr3t",
-        "-c",
-        "realm2,root,s3cr3t"
+        "[{\"realm\":\"realm1\",\"principal\":\"root\",\"clientId\":\"root\",\"clientSecret\":\"s3cr3t\"}]"
       })
   public void testBootstrap(LaunchResult result) {
     assertThat(result.getOutput()).contains("Bootstrap completed successfully.");
   }
+
+  @Test
+  @Launch(
+      value = {
+          "bootstrap",
+          "-c",
+          "[{\"realm\":\"realm1\",\"principal\":\"root\",\"clientId\":\"root\",\"clientSecret\":\"s3cr3t\"}]",

Review Comment:
   The new JSON format exactly matches the format used in the `-f` argument, so hopefully that makes this less treacherous for users



##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisCredentialsBootstrap.java:
##########
@@ -63,6 +66,42 @@ public static PolarisCredentialsBootstrap fromString(@Nullable String credential
         : EMPTY;
   }
 
+  /**
+   * Parse a JSON array of credentials. Example: """ [ {"realm": "a", "principal": "root",
+   * "clientId": "abc123", "clientSecret": "xyz987"}, {"realm": "b", "principal": "boot",
+   * "clientId": "boot-id", "clientSecret": "boot-secret"}, ] """
+   */
+  public static PolarisCredentialsBootstrap fromJson(String json) {
+    ObjectMapper objectMapper = new ObjectMapper();
+    List<Map<String, String>> credentialsList = new ArrayList<>();
+    try {
+      credentialsList = objectMapper.readValue(json, new TypeReference<>() {});
+    } catch (Exception e) {
+      throw new IllegalArgumentException("Could not parse credentials JSON: " + json, e);
+    }
+    Map<String, Map.Entry<String, String>> credentials = new HashMap<>();
+    for (Map<String, String> entry : credentialsList) {
+      String realm = entry.get("realm");
+      String principal = entry.get("principal");
+      String clientId = entry.get("clientId");
+      String clientSecret = entry.get("clientSecret");
+      if (realm == null || principal == null || clientId == null || clientSecret == null) {
+        throw new IllegalArgumentException("Failed to find credentials in: " + json);
+      } else if (!principal.equals(PolarisEntityConstants.ROOT_PRINCIPAL_NAME)) {
+        throw new IllegalArgumentException(
+            String.format(
+                "Invalid principal %s. Expected %s.",

Review Comment:
   Added a test to cover this behavior



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2610962345

   Bulk-resolved some comments as this is a rewrite. PTAL @dimas-b, @collado-mike, @flyrain 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "sfc-gh-emaynard (via GitHub)" <gi...@apache.org>.
sfc-gh-emaynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1931080017


##########
quarkus/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java:
##########
@@ -38,20 +39,37 @@ public class BootstrapCommand extends BaseCommand {
   List<String> realms;
 
   @CommandLine.Option(
-      names = {"-c", "--credential"},
-      paramLabel = "<realm,clientId,clientSecret>",
+      names = {"-c", "--credentials"},
+      description = "Principal credentials to bootstrap. Must be a valid JSON array e.g. " +
+          "[{\"realm\": \"my-realm\", \"principal\": \"root\", \"clientId\": \"polaris\", \"clientSecret\": \"p4ssw0rd\"}]")
+  String credentials;
+
+  @CommandLine.Option(
+      names = {"-p", "--print-credentials"},
       description =
-          "Root principal credentials to bootstrap. Must be of the form 'realm,clientId,clientSecret'.")
-  List<String> credentials;
+          "Print root credentials to stdout")

Review Comment:
   > It may not be obvious to all users that Polaris will generate client ID/secret if they are not explicitly provided.
   
   Oh, this is a good point. I'll add a note on this, though I'm not sure the `print-credentials` flag is the right place for that.
   
   Ultimately, I want to keep the behavior of the flags "simple", so having `print-credentials` just "print credentials" with no qualifiers appeals to me. Also, FWIW, it does not print out exactly the same clientId:clientSecret tuple you pass in



##########
quarkus/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java:
##########
@@ -38,20 +39,37 @@ public class BootstrapCommand extends BaseCommand {
   List<String> realms;
 
   @CommandLine.Option(
-      names = {"-c", "--credential"},
-      paramLabel = "<realm,clientId,clientSecret>",
+      names = {"-c", "--credentials"},
+      description = "Principal credentials to bootstrap. Must be a valid JSON array e.g. " +
+          "[{\"realm\": \"my-realm\", \"principal\": \"root\", \"clientId\": \"polaris\", \"clientSecret\": \"p4ssw0rd\"}]")
+  String credentials;
+
+  @CommandLine.Option(
+      names = {"-p", "--print-credentials"},
       description =
-          "Root principal credentials to bootstrap. Must be of the form 'realm,clientId,clientSecret'.")
-  List<String> credentials;
+          "Print root credentials to stdout")

Review Comment:
   > It may not be obvious to all users that Polaris will generate client ID/secret if they are not explicitly provided.
   
   Oh, this is a good point. I'll add a note on this, though I'm not sure the `print-credentials` flag is the right place for that.
   
   Ultimately, I want to keep the behavior of the flags "simple", so having `print-credentials` just "print credentials" with no qualifiers appeals to me. Also, FWIW, it does not print out exactly the same clientId:clientSecret tuple you pass in



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2682018046

   > bootstrap with no args. Where did that behavior go? Is it gone? Should it be gone?
   
   I missed that I confess. What the `bootstrap` command without args used to do? Bootstrap the configured default realm with random credentials? 
   
   If so, we might have a small problem because the notion of "default realm" is tied to the actual implementation of `RealmContextResolver`. If someone is using a different resolver, there might not be any "default realm".


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2691645014

   For now, let me refactor out the controversial syntax changes, so we can look at just the changes necessary to prevent bricking the metastore.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1968252193


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/bootstrap/RootCredentialsSet.java:
##########
@@ -74,6 +76,54 @@ static RootCredentialsSet fromString(@Nullable String credentialsString) {
         : EMPTY;
   }
 
+  /**
+   * Parse a JSON object of credentials. Example: { "realm1": { "client-id": "client1",
+   * "client-secret": "secret1" }, "realm2": { "client-id": "client2", "client-secret": "secret2",
+   * "extra-field": "extra-value" } }

Review Comment:
   How about extracting a `private` shared method from `fromUrl` that would take a `JsonFactory` and an `InputStream`? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1859285434


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/secrets/PrincipalSecretsGenerator.java:
##########
@@ -38,48 +37,48 @@
  *   <li>{@code POLARIS_BOOTSTRAP_<REALM-NAME>_<PRINCIPAL-NAME>_CLIENT_SECRET}
  * </ul>
  *
- * For example: {@code POLARIS_BOOTSTRAP_DEFAULT-REALM_ROOT_CLIENT_ID} and {@code
- * POLARIS_BOOTSTRAP_DEFAULT-REALM_ROOT_CLIENT_SECRET}.
+ * For example: {@code POLARIS_BOOTSTRAP_default-realm_root_CLIENT_ID} and {@code
+ * POLARIS_BOOTSTRAP_default-realm_root_CLIENT_SECRET}.
  */
-@FunctionalInterface
-public interface PrincipalSecretsGenerator {
+public abstract class PrincipalSecretsGenerator {
 
-  /**
-   * A secret generator that produces cryptographically random client ID and client secret values.
-   */
-  PrincipalSecretsGenerator RANDOM_SECRETS = (name, id) -> new PolarisPrincipalSecrets(id);
+  protected final String realmName;
+
+  public PrincipalSecretsGenerator() {
+    this.realmName = null;
+  }
+
+  public PrincipalSecretsGenerator(@Nullable String realmName) {
+    this.realmName = realmName;
+  }
 
   /**
    * Produces a new {@link PolarisPrincipalSecrets} object for the given principal ID. The returned
-   * secrets may or may not be random, depending on context. In bootstrapping contexts, the returned
-   * secrets can be predefined. After bootstrapping, the returned secrets can be expected to be
-   * cryptographically random.
+   * secrets may or may not be random, depending on context. The returned secrets can be predefined.
    *
    * @param principalName the name of the related principal. This parameter is a hint for
    *     pre-defined secrets lookup during bootstrapping it is not included in the returned data.
    * @param principalId the ID of the related principal. This ID is part of the returned data.
    * @return a new {@link PolarisPrincipalSecrets} instance for the specified principal.
    */
-  PolarisPrincipalSecrets produceSecrets(@NotNull String principalName, long principalId);
-
-  static PrincipalSecretsGenerator bootstrap(String realmName) {
-    return bootstrap(realmName, System.getenv()::get);
-  }
+  public abstract PolarisPrincipalSecrets produceSecrets(
+      @NotNull String principalName, long principalId);
 
-  static PrincipalSecretsGenerator bootstrap(String realmName, Function<String, String> config) {
-    return (principalName, principalId) -> {
-      String propId = String.format("POLARIS_BOOTSTRAP_%s_%s_CLIENT_ID", realmName, principalName);
-      String propSecret =
-          String.format("POLARIS_BOOTSTRAP_%s_%s_CLIENT_SECRET", realmName, principalName);
+  /**
+   * @param principalName the name of the related principal. This parameter is a hint for
+   *     pre-defined secrets lookup during bootstrapping it is not included in the returned data.
+   * @return true if the secrets generated by this {@link PrincipalSecretsGenerator} are
+   *     Polaris-generated as opposed to being provided by the user or another system.
+   */
+  public abstract boolean systemGeneratedSecrets(@NotNull String principalName);
 
-      String clientId = config.apply(propId.toUpperCase(Locale.ROOT));

Review Comment:
   Did we lose uppercasing in the new code?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1860386984


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java:
##########
@@ -95,10 +97,26 @@ public synchronized Map<String, PrincipalSecretsResult> bootstrapRealms(List<Str
         RealmContext realmContext = () -> realm;
         if (!metaStoreManagerMap.containsKey(realmContext.getRealmIdentifier())) {
           initializeForRealm(realmContext);
+          // While bootstrapping we need to act as a fake privileged context since the real
+          // CallContext hasn't even been resolved yet.
+          PolarisCallContext polarisContext =
+              new PolarisCallContext(
+                  sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(), diagServices);
           PrincipalSecretsResult secretsResult =
               bootstrapServiceAndCreatePolarisPrincipalForRealm(
-                  realmContext, metaStoreManagerMap.get(realmContext.getRealmIdentifier()));
+                  realmContext,
+                  metaStoreManagerMap.get(realmContext.getRealmIdentifier()),
+                  polarisContext);
           results.put(realmContext.getRealmIdentifier(), secretsResult);
+          if (this.printCredentials(polarisContext)) {
+            String msg =
+                String.format(
+                    "realm: %1s root principal credentials: %2s:%3s",
+                    realmContext.getRealmIdentifier(),
+                    secretsResult.getPrincipalSecrets().getPrincipalClientId(),
+                    secretsResult.getPrincipalSecrets().getMainSecret());
+            System.out.println(msg);
+          }

Review Comment:
   Looking again, is your objection specifically to the protected method `printCredentials`?
   
   That only exists to support the legacy behavior of the in-memory metastore always printing credentials, and if possible I would very much be in favor of removing that. 
   
   However it feels like pushing that logic down into an existing method (whether `secretsGenerator`, `createMetaStoreSession`, or elsewhere) could be a bit hacky if it winds up somewhere it doesn't belong.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1861348656


##########
polaris-core/src/test/java/org/apache/polaris/core/persistence/secrets/PrincipalSecretsGeneratorTest.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.polaris.core.persistence.secrets;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.doReturn;
+
+import org.apache.polaris.core.entity.PolarisPrincipalSecrets;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+class PrincipalSecretsGeneratorTest {
+
+  @Test
+  void testRandomSecrets() {
+    RandomPrincipalSecretsGenerator rpsg = new RandomPrincipalSecretsGenerator("realm");
+    PolarisPrincipalSecrets s = rpsg.produceSecrets("name1", 123);
+    assertThat(s).isNotNull();
+    assertThat(s.getPrincipalId()).isEqualTo(123);
+    assertThat(s.getPrincipalClientId()).isNotNull();
+    assertThat(s.getMainSecret()).isNotNull();
+    assertThat(s.getSecondarySecret()).isNotNull();
+  }
+
+  @Test
+  void testRandomSecretsNullRealm() {
+    RandomPrincipalSecretsGenerator rpsg = new RandomPrincipalSecretsGenerator(null);
+    PolarisPrincipalSecrets s = rpsg.produceSecrets("name1", 123);
+    assertThat(s).isNotNull();
+    assertThat(s.getPrincipalId()).isEqualTo(123);
+    assertThat(s.getPrincipalClientId()).isNotNull();
+    assertThat(s.getMainSecret()).isNotNull();
+    assertThat(s.getSecondarySecret()).isNotNull();
+  }
+
+  @Test
+  void testEnvVariableSecrets() {
+    EnvVariablePrincipalSecretsGenerator psg =
+        Mockito.spy(new EnvVariablePrincipalSecretsGenerator("REALM"));
+
+    String clientIdKey = "POLARIS_BOOTSTRAP_REALM_PRINCIPAL_CLIENT_ID";
+    String clientSecretKey = "POLARIS_BOOTSTRAP_REALM_PRINCIPAL_CLIENT_SECRET";
+
+    doReturn("test-id").when(psg).getEnvironmentVariable(clientIdKey);

Review Comment:
   Fair enough. I'm fine with the current code in this PR.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1861211075


##########
polaris-core/src/test/java/org/apache/polaris/core/persistence/secrets/PrincipalSecretsGeneratorTest.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.polaris.core.persistence.secrets;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.doReturn;
+
+import org.apache.polaris.core.entity.PolarisPrincipalSecrets;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+class PrincipalSecretsGeneratorTest {
+
+  @Test
+  void testRandomSecrets() {
+    RandomPrincipalSecretsGenerator rpsg = new RandomPrincipalSecretsGenerator("realm");
+    PolarisPrincipalSecrets s = rpsg.produceSecrets("name1", 123);
+    assertThat(s).isNotNull();
+    assertThat(s.getPrincipalId()).isEqualTo(123);
+    assertThat(s.getPrincipalClientId()).isNotNull();
+    assertThat(s.getMainSecret()).isNotNull();
+    assertThat(s.getSecondarySecret()).isNotNull();
+  }
+
+  @Test
+  void testRandomSecretsNullRealm() {
+    RandomPrincipalSecretsGenerator rpsg = new RandomPrincipalSecretsGenerator(null);
+    PolarisPrincipalSecrets s = rpsg.produceSecrets("name1", 123);
+    assertThat(s).isNotNull();
+    assertThat(s.getPrincipalId()).isEqualTo(123);
+    assertThat(s.getPrincipalClientId()).isNotNull();
+    assertThat(s.getMainSecret()).isNotNull();
+    assertThat(s.getSecondarySecret()).isNotNull();
+  }
+
+  @Test
+  void testEnvVariableSecrets() {
+    EnvVariablePrincipalSecretsGenerator psg =
+        Mockito.spy(new EnvVariablePrincipalSecretsGenerator("REALM"));
+
+    String clientIdKey = "POLARIS_BOOTSTRAP_REALM_PRINCIPAL_CLIENT_ID";
+    String clientSecretKey = "POLARIS_BOOTSTRAP_REALM_PRINCIPAL_CLIENT_SECRET";
+
+    doReturn("test-id").when(psg).getEnvironmentVariable(clientIdKey);

Review Comment:
   I like this idea, but my concern is that `EnvVariablePrincipalSecretsGenerator` essentially becomes `MapPrincipalSecretsGenerator` with that approach. I would rather not place the burden on its callers to do the `fromEnv` / `getEnv`; this seems like the exact responsibility we would like `EnvVariablePrincipalSecretsGenerator` to take on.
   
   Indeed, if we later add command-line options to `bootstrap` that allow you to provide credentials, would we use the  `EnvVariablePrincipalSecretsGenerator` for that? If it takes a map, we could



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2529017004

   I added a note in the most recent commit to clarify, but the best thing
   users can do is provide secrets through env variables. The credential
   printing is there as a workaround (the in-memory metastore always does
   this) for testing or development.
   
   The important thing is we don’t let users brick the metastore. If printing
   is super controversial then we can always just require the env variables
   for now.
   
   On Mon, Dec 9, 2024 at 10:22 AM Yufei Gu ***@***.***> wrote:
   
   > Agreed to not log the secrets, but I also feel the urgency of fixing
   > EclipseLink. How about writing the secrets into a separated file? Here are
   > benefits:
   >
   >    1. A file can be potentially integrated with third-party secret
   >    managers in the future.
   >    2. Avoid putting secrets in logs
   >    3. No configuration item needed, alway persist the secrets file in
   >    case of auto-generation.
   >
   > —
   > Reply to this email directly, view it on GitHub
   > <https://github.com/apache/polaris/pull/461#issuecomment-2529006729>, or
   > unsubscribe
   > <https://github.com/notifications/unsubscribe-auth/AFRE3SAZOHDY4HHUR56KOTD2EXNU5AVCNFSM6AAAAABSF72CZGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMRZGAYDMNZSHE>
   > .
   > You are receiving this because you authored the thread.Message ID:
   > ***@***.***>
   >
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add a flag to control whether credentials are printed during bootstrapping [polaris]

Posted by "flyrain (via GitHub)" <gi...@apache.org>.
flyrain commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2529006729

   Agreed to not log the secrets, but I also feel the urgency of fixing EclipseLink. How about writing the secrets into a separated file? Here are benefits:
   1. A file can be potentially integrated with third-party secret managers in the future.
   2. Avoid putting secrets in logs
   3. No configuration item needed, alway persist the secrets file in case of auto-generation.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1930999725


##########
quarkus/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java:
##########
@@ -38,20 +39,37 @@ public class BootstrapCommand extends BaseCommand {
   List<String> realms;
 
   @CommandLine.Option(
-      names = {"-c", "--credential"},
-      paramLabel = "<realm,clientId,clientSecret>",

Review Comment:
   `bootstrap --json` feels a little unclear to me; e.g. should the `--print-credentials` option also go inside that JSON? It seems to imply that we are bootstrapping in JSON "mode" or providing all options into a JSON. While in fact, the JSON is just a set of `credentials`.
   
   Since we call it `credentials`, I think having a second way to do the exact same thing could be confusing, i.e. having both a `credentials` option and a `client-id` option.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1931065581


##########
quarkus/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java:
##########
@@ -38,20 +39,37 @@ public class BootstrapCommand extends BaseCommand {
   List<String> realms;
 
   @CommandLine.Option(
-      names = {"-c", "--credential"},
-      paramLabel = "<realm,clientId,clientSecret>",
+      names = {"-c", "--credentials"},
+      description = "Principal credentials to bootstrap. Must be a valid JSON array e.g. " +
+          "[{\"realm\": \"my-realm\", \"principal\": \"root\", \"clientId\": \"polaris\", \"clientSecret\": \"p4ssw0rd\"}]")
+  String credentials;
+
+  @CommandLine.Option(
+      names = {"-p", "--print-credentials"},
       description =
-          "Root principal credentials to bootstrap. Must be of the form 'realm,clientId,clientSecret'.")
-  List<String> credentials;
+          "Print root credentials to stdout")

Review Comment:
   Right, but I guess the intended use case is to print generated credentials (mostly). It would be nice to inform users about that. It may not be obvious to all users that Polaris will generate client ID/secret if they are not explicitly provided.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1931080534


##########
quarkus/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java:
##########
@@ -38,20 +39,37 @@ public class BootstrapCommand extends BaseCommand {
   List<String> realms;
 
   @CommandLine.Option(
-      names = {"-c", "--credential"},
-      paramLabel = "<realm,clientId,clientSecret>",
+      names = {"-c", "--credentials"},
+      description = "Principal credentials to bootstrap. Must be a valid JSON array e.g. " +
+          "[{\"realm\": \"my-realm\", \"principal\": \"root\", \"clientId\": \"polaris\", \"clientSecret\": \"p4ssw0rd\"}]")
+  String credentials;
+
+  @CommandLine.Option(
+      names = {"-p", "--print-credentials"},
       description =
-          "Root principal credentials to bootstrap. Must be of the form 'realm,clientId,clientSecret'.")
-  List<String> credentials;
+          "Print root credentials to stdout")

Review Comment:
   It may not be obvious to all users that Polaris will generate client ID/secret if they are not explicitly provided.
   
   Oh, this is a good point. I'll add a note on this, though I'm not sure the print-credentials flag is the right place for that.
   
   Ultimately, I want to keep the behavior of the flags "simple", so having print-credentials just "print credentials" with no qualifiers appeals to me. Also, FWIW, it does not print out exactly the same clientId:clientSecret tuple you pass in. See the note in `BootstrapCommandTest`.



##########
quarkus/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java:
##########
@@ -38,20 +39,37 @@ public class BootstrapCommand extends BaseCommand {
   List<String> realms;
 
   @CommandLine.Option(
-      names = {"-c", "--credential"},
-      paramLabel = "<realm,clientId,clientSecret>",
+      names = {"-c", "--credentials"},
+      description = "Principal credentials to bootstrap. Must be a valid JSON array e.g. " +
+          "[{\"realm\": \"my-realm\", \"principal\": \"root\", \"clientId\": \"polaris\", \"clientSecret\": \"p4ssw0rd\"}]")
+  String credentials;
+
+  @CommandLine.Option(
+      names = {"-p", "--print-credentials"},
       description =
-          "Root principal credentials to bootstrap. Must be of the form 'realm,clientId,clientSecret'.")
-  List<String> credentials;
+          "Print root credentials to stdout")

Review Comment:
   > It may not be obvious to all users that Polaris will generate client ID/secret if they are not explicitly provided.
   
   Oh, this is a good point. I'll add a note on this, though I'm not sure the print-credentials flag is the right place for that.
   
   Ultimately, I want to keep the behavior of the flags "simple", so having print-credentials just "print credentials" with no qualifiers appeals to me. Also, FWIW, it does not print out exactly the same clientId:clientSecret tuple you pass in. See the note in `BootstrapCommandTest`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "sfc-gh-ygu (via GitHub)" <gi...@apache.org>.
sfc-gh-ygu commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1958850438


##########
quarkus/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java:
##########
@@ -18,19 +18,42 @@
  */
 package org.apache.polaris.admintool;
 
+<<<<<<< HEAD

Review Comment:
   Can we remove these lines generated by rebasing? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2664434746

   @adutra is it correct that after #605 we no longer have the ability to bootstrap to the default realm like before?
   
   That is, realm always must be specified now?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2665221448

   > @adutra is it correct that after #605 we no longer have the ability to bootstrap to the default realm like before?
   > 
   > That is, realm always must be specified now?
   
   As of today:
   
   1. If using the in-memory metastore, all realms listed in `polaris.realm-context.realms` are bootstrapped automatically.
     a. The environment variable `POLARIS_BOOTSTRAP_CREDENTIALS` or the system property `polaris.bootstrap.credentials` can be used to provide root credentials.
   3. If using other metastores, no realm is automatically bootstrapped.
     a. To bootstrap realms in this case, the only option right now is to use the admin tool.
     b. With the admin tool, root credentials can be provided as command arguments, or in a json/yaml file.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1936155692


##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisCredentialsBootstrap.java:
##########
@@ -63,6 +66,42 @@ public static PolarisCredentialsBootstrap fromString(@Nullable String credential
         : EMPTY;
   }
 
+  /**
+   * Parse a JSON array of credentials. Example: """ [ {"realm": "a", "principal": "root",
+   * "clientId": "abc123", "clientSecret": "xyz987"}, {"realm": "b", "principal": "boot",
+   * "clientId": "boot-id", "clientSecret": "boot-secret"}, ] """
+   */
+  public static PolarisCredentialsBootstrap fromJson(String json) {
+    ObjectMapper objectMapper = new ObjectMapper();
+    List<Map<String, String>> credentialsList = new ArrayList<>();
+    try {
+      credentialsList = objectMapper.readValue(json, new TypeReference<>() {});
+    } catch (Exception e) {
+      throw new IllegalArgumentException("Could not parse credentials JSON: " + json, e);
+    }
+    Map<String, Map.Entry<String, String>> credentials = new HashMap<>();
+    for (Map<String, String> entry : credentialsList) {
+      String realm = entry.get("realm");
+      String principal = entry.get("principal");
+      String clientId = entry.get("clientId");
+      String clientSecret = entry.get("clientSecret");
+      if (realm == null || principal == null || clientId == null || clientSecret == null) {
+        throw new IllegalArgumentException("Failed to find credentials in: " + json);
+      } else if (!principal.equals(PolarisEntityConstants.ROOT_PRINCIPAL_NAME)) {
+        throw new IllegalArgumentException(
+            String.format(
+                "Invalid principal %s. Expected %s.",

Review Comment:
   I can see how it's confusing, but I was imagining this as a sort of serialization of a `PolarisCredentials[Bootstrap]`... given that, including all the fields felt correct. We could also make `principal` optional.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1964864442


##########
quarkus/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java:
##########
@@ -43,20 +45,17 @@ static class InputOptions {
     FileInputOptions fileOptions;
 
     static class StandardInputOptions {
-
       @CommandLine.Option(
-          names = {"-r", "--realm"},
-          paramLabel = "<realm>",
-          required = true,
-          description = "The name of a realm to bootstrap.")
-      List<String> realms;
+          names = {"-c", "--credentials"},
+          description =
+              "Principal credentials to bootstrap. If provided, must be a valid JSON array e.g. "
+                  + "[{\"realm\": \"my-realm\", \"principal\": \"root\", \"clientId\": \"polaris\", \"clientSecret\": \"p4ssw0rd\"}]")
+      String credentials;
 
       @CommandLine.Option(
-          names = {"-c", "--credential"},
-          paramLabel = "<realm,clientId,clientSecret>",

Review Comment:
   Refer to my comments and -1 on #633 for more context, but essentially I don't think this format captures the full range of ways you might wish to bootstrap. I also don't think we really want two syntaxes for bootstrapping.
   
   With that being said, I'd like to understand why the [pre-Quarkus bootstrap behavior](https://github.com/apache/polaris/pull/461#issuecomment-2666608052) is now gone, since being able to bootstrap a realm without specifying credentials is a core part of why this heavier syntax makes sense.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Prevent the bootstrap command from leaving root credentials unrecoverable [polaris]

Posted by "eric-maynard (via GitHub)" <gi...@apache.org>.
eric-maynard commented on PR #461:
URL: https://github.com/apache/polaris/pull/461#issuecomment-2683252398

   > I missed that I confess. What the bootstrap command without args used to do? Bootstrap the configured default realm with random credentials?
   
   Yeah that is exactly right. I suppose if there is no default realm, failing to bootstrap with no realm might be correct.
   
   The silver lining is, with this behavior gone this PR is less urgent. It is still possible to bootstrap a realm with random credentials though, and we should still make sure those credentials are either printed or recoverable.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org