Skip to content

Commit c4fe067

Browse files
committed
Auto-bootstrap: add verbose logging
Log explicit messages around auto-bootstrapping and unnecessary/left-over secrets that are (still) available.
1 parent 50767a0 commit c4fe067

File tree

2 files changed

+65
-7
lines changed

2 files changed

+65
-7
lines changed

polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,6 @@ public synchronized Map<String, PrincipalSecretsResult> bootstrapRealms(
118118
PrincipalSecretsResult secretsResult =
119119
bootstrapServiceAndCreatePolarisPrincipalForRealm(
120120
realmContext, metaStoreManagerMap.get(realmContext.getRealmIdentifier()));
121-
122-
if (rootCredentialsSet.credentials().containsKey(realm)) {
123-
LOGGER.info("Bootstrapped realm {} using preset credentials.", realm);
124-
}
125-
126121
results.put(realmContext.getRealmIdentifier(), secretsResult);
127122
}
128123
}

quarkus/service/src/main/java/org/apache/polaris/service/quarkus/config/QuarkusProducers.java

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import jakarta.ws.rs.container.ContainerRequestContext;
3333
import jakarta.ws.rs.core.Context;
3434
import java.time.Clock;
35+
import java.util.stream.Collectors;
3536
import org.apache.polaris.core.PolarisCallContext;
3637
import org.apache.polaris.core.PolarisDefaultDiagServiceImpl;
3738
import org.apache.polaris.core.PolarisDiagnostics;
@@ -68,8 +69,11 @@
6869
import org.eclipse.microprofile.config.inject.ConfigProperty;
6970
import org.eclipse.microprofile.context.ManagedExecutor;
7071
import org.eclipse.microprofile.context.ThreadContext;
72+
import org.slf4j.Logger;
73+
import org.slf4j.LoggerFactory;
7174

7275
public class QuarkusProducers {
76+
private static final Logger LOGGER = LoggerFactory.getLogger(QuarkusProducers.class);
7377

7478
@Produces
7579
@ApplicationScoped // cannot be singleton because it is mocked in tests
@@ -159,9 +163,68 @@ public void maybeBootstrap(
159163
MetaStoreManagerFactory factory,
160164
QuarkusPersistenceConfiguration config,
161165
RealmContextConfiguration realmContextConfiguration) {
166+
var rootCredentialsSet = RootCredentialsSet.fromEnvironment();
167+
var rootCredentials = rootCredentialsSet.credentials();
162168
if (config.isAutoBootstrap()) {
163-
RootCredentialsSet rootCredentialsSet = RootCredentialsSet.fromEnvironment();
164-
factory.bootstrapRealms(realmContextConfiguration.realms(), rootCredentialsSet);
169+
var realmIds = realmContextConfiguration.realms();
170+
171+
LOGGER.info(
172+
"Bootstrapping realm(s) {}, if necessary, from root credentials set provided via the environment variable {} or Java system property {} ...",
173+
realmIds.stream().map(r -> "'" + r + "'").collect(Collectors.joining(", ")),
174+
RootCredentialsSet.ENVIRONMENT_VARIABLE,
175+
RootCredentialsSet.SYSTEM_PROPERTY);
176+
177+
var result = factory.bootstrapRealms(realmIds, rootCredentialsSet);
178+
179+
result.forEach(
180+
(realm, secrets) -> {
181+
var principalSecrets = secrets.getPrincipalSecrets();
182+
183+
var log =
184+
LOGGER
185+
.atInfo()
186+
.addArgument(realm)
187+
.addArgument(RootCredentialsSet.ENVIRONMENT_VARIABLE)
188+
.addArgument(RootCredentialsSet.SYSTEM_PROPERTY);
189+
if (rootCredentials.containsKey(realm)) {
190+
log.log(
191+
"Realm '{}' automatically bootstrapped, credentials taken from root credentials set provided via the environment variable {} or Java system property {}, not printed to stdout.");
192+
} else {
193+
log.log(
194+
"Realm '{}' automatically bootstrapped, credentials were not present in root credentials set provided via the environment variable {} or Java system property {}, see separate message printed to stdout.");
195+
String msg =
196+
String.format(
197+
"realm: %1s root principal credentials: %2s:%3s",
198+
realm,
199+
principalSecrets.getPrincipalClientId(),
200+
principalSecrets.getMainSecret());
201+
System.out.println(msg);
202+
}
203+
});
204+
205+
var unusedRealmSecrets =
206+
realmIds.stream()
207+
.filter(rootCredentials::containsKey)
208+
.filter(r -> !result.containsKey(r))
209+
.map(r -> "'" + r + "'")
210+
.collect(Collectors.joining(", "));
211+
if (!unusedRealmSecrets.isEmpty()) {
212+
// This is intentionally an error to highlight the importance of the situation.
213+
LOGGER.error(
214+
"The realms {} are already fully bootstrapped but the secrets are still available via the environment variable {} or Java system property {}. "
215+
+ "Remove this security sensitive information from the environment / Java system properties!",
216+
unusedRealmSecrets,
217+
RootCredentialsSet.ENVIRONMENT_VARIABLE,
218+
RootCredentialsSet.SYSTEM_PROPERTY);
219+
}
220+
} else if (!rootCredentials.isEmpty()) {
221+
// This is intentionally an error to highlight the importance of the situation.
222+
LOGGER.error(
223+
"Secrets for the realms {} are available via the environment variable {} or Java system property {}. "
224+
+ "Remove this security sensitive information from the environment / Java system properties!",
225+
rootCredentials.keySet(),
226+
RootCredentialsSet.ENVIRONMENT_VARIABLE,
227+
RootCredentialsSet.SYSTEM_PROPERTY);
165228
}
166229
}
167230

0 commit comments

Comments
 (0)