-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a flag to control whether credentials are printed during bootstrapping #461
Open
eric-maynard
wants to merge
18
commits into
apache:main
Choose a base branch
from
eric-maynard:no-brick-metastore
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
65c3012
initial commit
eric-maynard d9a1698
autolint
eric-maynard 7b1e258
rebase
eric-maynard 312453b
autolint
eric-maynard 6e14558
check in; not working
eric-maynard 4a3b1fd
autolint
eric-maynard ffcdf49
rename
eric-maynard 910bb2a
rework tests
eric-maynard 208b8cd
autolint
eric-maynard 3b32662
stable
eric-maynard a7a4e67
autolint
eric-maynard f922055
resolve conflicts
eric-maynard d0aeeee
annotation change
eric-maynard fd49022
another annotation fix
eric-maynard 6ee09b4
merge conflict fix
eric-maynard fbd11a1
autolint
eric-maynard 96885d0
doc note
eric-maynard df1d642
style
eric-maynard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
.../java/org/apache/polaris/core/persistence/secrets/BootstrapPrincipalSecretsGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* 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 org.apache.polaris.core.entity.PolarisPrincipalSecrets; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.jetbrains.annotations.VisibleForTesting; | ||
|
||
/** | ||
* A {@link PrincipalSecretsGenerator} implementation used for bootstrapping that uses an {@link | ||
* EnvVariablePrincipalSecretsGenerator} if possible and falls back to a {@link | ||
* RandomPrincipalSecretsGenerator} otherwise | ||
*/ | ||
public class BootstrapPrincipalSecretsGenerator extends PrincipalSecretsGenerator { | ||
|
||
public BootstrapPrincipalSecretsGenerator(@Nullable String realmName) { | ||
super(realmName); | ||
} | ||
|
||
@VisibleForTesting | ||
protected PrincipalSecretsGenerator buildEnvVariablePrincipalSecretsGenerator(String realmName) { | ||
return new EnvVariablePrincipalSecretsGenerator(realmName); | ||
} | ||
|
||
@VisibleForTesting | ||
protected PrincipalSecretsGenerator getDelegate(@NotNull String principalName) { | ||
var envVarGenerator = buildEnvVariablePrincipalSecretsGenerator(principalName); | ||
if (!envVarGenerator.systemGeneratedSecrets(principalName)) { | ||
return new RandomPrincipalSecretsGenerator(realmName); | ||
} else { | ||
return envVarGenerator; | ||
} | ||
} | ||
|
||
@Override | ||
public PolarisPrincipalSecrets produceSecrets(@NotNull String principalName, long principalId) { | ||
PrincipalSecretsGenerator delegate = getDelegate(principalName); | ||
return delegate.produceSecrets(principalName, principalId); | ||
} | ||
|
||
@Override | ||
public boolean systemGeneratedSecrets(@NotNull String principalName) { | ||
PrincipalSecretsGenerator delegate = getDelegate(principalName); | ||
return delegate.systemGeneratedSecrets(principalName); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...ava/org/apache/polaris/core/persistence/secrets/EnvVariablePrincipalSecretsGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* 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 org.apache.polaris.core.entity.PolarisPrincipalSecrets; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.jetbrains.annotations.VisibleForTesting; | ||
|
||
public class EnvVariablePrincipalSecretsGenerator extends PrincipalSecretsGenerator { | ||
|
||
public EnvVariablePrincipalSecretsGenerator(@Nullable String realmName) { | ||
super(realmName); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
public PolarisPrincipalSecrets produceSecrets(@NotNull String principalName, long principalId) { | ||
String clientIdKey = clientIdEnvironmentVariable(realmName, principalName); | ||
String clientSecretKey = clientSecretEnvironmentVariable(realmName, principalName); | ||
|
||
String clientId = getEnvironmentVariable(clientIdKey); | ||
String clientSecret = getEnvironmentVariable(clientSecretKey); | ||
if (clientId == null || clientSecret == null) { | ||
return null; | ||
} else { | ||
return new PolarisPrincipalSecrets(principalId, clientId, clientSecret, null); | ||
} | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
public boolean systemGeneratedSecrets(@NotNull String principalName) { | ||
String clientIdKey = clientIdEnvironmentVariable(realmName, principalName); | ||
String clientSecretKey = clientSecretEnvironmentVariable(realmName, principalName); | ||
return getEnvironmentVariable(clientIdKey) != null | ||
&& getEnvironmentVariable(clientSecretKey) != null; | ||
} | ||
|
||
/** Load a single environment variable */ | ||
@VisibleForTesting | ||
String getEnvironmentVariable(String key) { | ||
return System.getenv(key); | ||
} | ||
|
||
/** Build the key for the env variable used to store client ID */ | ||
private static String clientIdEnvironmentVariable(String realmName, String principalName) { | ||
return String.format("POLARIS_BOOTSTRAP_%s_%s_CLIENT_ID", realmName, principalName); | ||
} | ||
|
||
/** Build the key for the env variable used to store client secret */ | ||
private static String clientSecretEnvironmentVariable(String realmName, String principalName) { | ||
return String.format("POLARIS_BOOTSTRAP_%s_%s_CLIENT_SECRET", realmName, principalName); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 aprint-credentials
config flag and the constructed secrets generator can react accordingly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.