Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ public synchronized Map<String, PrincipalSecretsResult> bootstrapRealms(
PrincipalSecretsResult secretsResult =
bootstrapServiceAndCreatePolarisPrincipalForRealm(
realmContext, metaStoreManagerMap.get(realmContext.getRealmIdentifier()));

if (rootCredentialsSet.credentials().containsKey(realm)) {
LOGGER.info("Bootstrapped realm {} using preset credentials.", realm);
}

results.put(realmContext.getRealmIdentifier(), secretsResult);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.apache.polaris.core.persistence.MetaStoreManagerFactory;
import org.apache.polaris.core.persistence.PolarisEntityManager;
import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
import org.apache.polaris.core.persistence.bootstrap.RootCredentialsSet;
import org.apache.polaris.core.storage.cache.StorageCredentialCache;
import org.apache.polaris.service.auth.ActiveRolesProvider;
import org.apache.polaris.service.auth.Authenticator;
Expand All @@ -55,7 +56,6 @@
import org.apache.polaris.service.context.RealmContextConfiguration;
import org.apache.polaris.service.context.RealmContextFilter;
import org.apache.polaris.service.context.RealmContextResolver;
import org.apache.polaris.service.persistence.InMemoryPolarisMetaStoreManagerFactory;
import org.apache.polaris.service.quarkus.auth.QuarkusAuthenticationConfiguration;
import org.apache.polaris.service.quarkus.catalog.io.QuarkusFileIOConfiguration;
import org.apache.polaris.service.quarkus.context.QuarkusRealmContextConfiguration;
Expand Down Expand Up @@ -154,12 +154,14 @@ public MetaStoreManagerFactory metaStoreManagerFactory(
* Eagerly initialize the in-memory default realm on startup, so that users can check the
* credentials printed to stdout immediately.
*/
public void maybeInitializeInMemoryRealm(
public void maybeBootstrap(
@Observes StartupEvent event,
MetaStoreManagerFactory factory,
QuarkusPersistenceConfiguration config,
RealmContextConfiguration realmContextConfiguration) {
if (factory instanceof InMemoryPolarisMetaStoreManagerFactory) {
((InMemoryPolarisMetaStoreManagerFactory) factory).onStartup(realmContextConfiguration);
if (config.isAutoBootstrap()) {
RootCredentialsSet rootCredentialsSet = RootCredentialsSet.fromEnvironment();
factory.bootstrapRealms(realmContextConfiguration.realms(), rootCredentialsSet);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import io.quarkus.runtime.annotations.StaticInitSafe;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;
import java.util.Set;

@StaticInitSafe
@ConfigMapping(prefix = "polaris.persistence")
Expand All @@ -30,4 +32,11 @@ public interface QuarkusPersistenceConfiguration {
* org.apache.polaris.core.persistence.MetaStoreManagerFactory} identifier.
*/
String type();

@WithDefault("in-memory")
Set<String> autoBootstrapTypes();

default boolean isAutoBootstrap() {
return autoBootstrapTypes().contains(type());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.persistence.LocalPolarisMetaStoreManagerFactory;
import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
import org.apache.polaris.core.persistence.bootstrap.RootCredentials;
import org.apache.polaris.core.persistence.bootstrap.RootCredentialsSet;
import org.apache.polaris.core.persistence.dao.entity.PrincipalSecretsResult;
import org.apache.polaris.core.persistence.transactional.TransactionalPersistence;
import org.apache.polaris.core.persistence.transactional.TreeMapMetaStore;
import org.apache.polaris.core.persistence.transactional.TreeMapTransactionalPersistenceImpl;
import org.apache.polaris.core.storage.PolarisStorageIntegrationProvider;
import org.apache.polaris.service.context.RealmContextConfiguration;

@ApplicationScoped
@Identifier("in-memory")
Expand All @@ -59,10 +59,6 @@ public InMemoryPolarisMetaStoreManagerFactory(
this.storageIntegration = storageIntegration;
}

public void onStartup(RealmContextConfiguration realmContextConfiguration) {
bootstrapRealmsAndPrintCredentials(realmContextConfiguration.realms());
}

@Override
protected TreeMapMetaStore createBackingStore(@Nonnull PolarisDiagnostics diagnostics) {
return new TreeMapMetaStore(diagnostics);
Expand Down Expand Up @@ -100,10 +96,22 @@ public synchronized Supplier<TransactionalPersistence> getOrCreateSessionSupplie

private void bootstrapRealmsAndPrintCredentials(List<String> realms) {
RootCredentialsSet rootCredentialsSet = RootCredentialsSet.fromEnvironment();
Map<String, PrincipalSecretsResult> results = this.bootstrapRealms(realms, rootCredentialsSet);
this.bootstrapRealms(realms, rootCredentialsSet);
bootstrappedRealms.addAll(realms);
}

@Override
public Map<String, PrincipalSecretsResult> bootstrapRealms(
Iterable<String> realms, RootCredentialsSet rootCredentialsSet) {
Map<String, PrincipalSecretsResult> results = super.bootstrapRealms(realms, rootCredentialsSet);

Map<String, RootCredentials> presetCredentials = rootCredentialsSet.credentials();
for (String realmId : realms) {
if (presetCredentials.containsKey(realmId)) {
// Credentials provided in the runtime env... no need to print
Copy link
Contributor

Choose a reason for hiding this comment

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

personally I think this is fine, but this is a small behavior change and could potentially have impact on tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll wait another day in case someone else has a concern.

continue;
}

PrincipalSecretsResult principalSecrets = results.get(realmId);

String msg =
Expand All @@ -114,5 +122,7 @@ private void bootstrapRealmsAndPrintCredentials(List<String> realms) {
principalSecrets.getPrincipalSecrets().getMainSecret());
System.out.println(msg);
}

return results;
}
}