|
32 | 32 | import jakarta.ws.rs.container.ContainerRequestContext;
|
33 | 33 | import jakarta.ws.rs.core.Context;
|
34 | 34 | import java.time.Clock;
|
| 35 | +import java.util.stream.Collectors; |
35 | 36 | import org.apache.polaris.core.PolarisCallContext;
|
36 | 37 | import org.apache.polaris.core.PolarisDefaultDiagServiceImpl;
|
37 | 38 | import org.apache.polaris.core.PolarisDiagnostics;
|
|
68 | 69 | import org.eclipse.microprofile.config.inject.ConfigProperty;
|
69 | 70 | import org.eclipse.microprofile.context.ManagedExecutor;
|
70 | 71 | import org.eclipse.microprofile.context.ThreadContext;
|
| 72 | +import org.slf4j.Logger; |
| 73 | +import org.slf4j.LoggerFactory; |
71 | 74 |
|
72 | 75 | public class QuarkusProducers {
|
| 76 | + private static final Logger LOGGER = LoggerFactory.getLogger(QuarkusProducers.class); |
73 | 77 |
|
74 | 78 | @Produces
|
75 | 79 | @ApplicationScoped // cannot be singleton because it is mocked in tests
|
@@ -159,9 +163,68 @@ public void maybeBootstrap(
|
159 | 163 | MetaStoreManagerFactory factory,
|
160 | 164 | QuarkusPersistenceConfiguration config,
|
161 | 165 | RealmContextConfiguration realmContextConfiguration) {
|
| 166 | + var rootCredentialsSet = RootCredentialsSet.fromEnvironment(); |
| 167 | + var rootCredentials = rootCredentialsSet.credentials(); |
162 | 168 | 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); |
165 | 228 | }
|
166 | 229 | }
|
167 | 230 |
|
|
0 commit comments