-
Notifications
You must be signed in to change notification settings - Fork 156
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
Feature configuration to modify storage credential lifetime #408
base: main
Are you sure you want to change the base?
Changes from all commits
d901f07
8d8d34f
2bf82b4
87ec396
7450a3b
d889e0f
f276656
e4207ce
0f45625
b60dd2c
bc0762e
c99db2b
6e27eec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,9 +21,14 @@ | |
import java.util.List; | ||
import java.util.Optional; | ||
import org.apache.polaris.core.admin.model.StorageConfigInfo; | ||
import org.apache.polaris.core.context.CallContext; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class PolarisConfiguration<T> { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(PolarisConfiguration.class); | ||
|
||
public final String key; | ||
public final String description; | ||
public final T defaultValue; | ||
|
@@ -89,6 +94,25 @@ public PolarisConfiguration<T> build() { | |
} | ||
} | ||
|
||
/** | ||
* Returns the value of a `PolarisConfiguration`, or the default if it cannot be loaded. This | ||
* method does not need to be used when a `CallContext` is already available | ||
*/ | ||
public static <T> T loadConfig(PolarisConfiguration<T> configuration) { | ||
var callContext = CallContext.getCurrentContext(); | ||
if (callContext == null) { | ||
LOGGER.warn( | ||
String.format( | ||
"Unable to load current call context; using %s = %s", | ||
configuration.key, configuration.defaultValue)); | ||
return configuration.defaultValue; | ||
} | ||
return callContext | ||
.getPolarisCallContext() | ||
.getConfigurationStore() | ||
.getConfiguration(callContext.getPolarisCallContext(), configuration); | ||
} | ||
|
||
public static <T> Builder<T> builder() { | ||
return new Builder<>(); | ||
} | ||
|
@@ -199,4 +223,22 @@ public static <T> Builder<T> builder() { | |
"If set to true, allows tables to be dropped with the purge parameter set to true.") | ||
.defaultValue(true) | ||
.build(); | ||
|
||
public static final PolarisConfiguration<Integer> STORAGE_CREDENTIAL_DURATION_SECONDS = | ||
PolarisConfiguration.<Integer>builder() | ||
.key("STORAGE_CREDENTIAL_DURATION_SECONDS") | ||
.description( | ||
"The duration of time that vended storage credentials are valid for. Support for" | ||
+ " longer (or shorter) durations is dependent on the storage provider.") | ||
Comment on lines
+230
to
+232
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor suggestion: adding a comment that GCS isn't supported yet? |
||
.defaultValue(60 * 60) // 1 hour | ||
.build(); | ||
|
||
public static final PolarisConfiguration<Integer> STORAGE_CREDENTIAL_CACHE_DURATION_SECONDS = | ||
PolarisConfiguration.<Integer>builder() | ||
.key("STORAGE_CREDENTIAL_CACHE_DURATION_SECONDS") | ||
.description( | ||
"How long to store storage credentials in the local cache. This should be less than " | ||
+ STORAGE_CREDENTIAL_DURATION_SECONDS.key) | ||
.defaultValue(30 * 60) // 30 minutes | ||
.build(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,8 +22,10 @@ | |
import java.util.EnumMap; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
import org.apache.polaris.core.PolarisConfiguration; | ||
import org.apache.polaris.core.PolarisDiagnostics; | ||
import org.apache.polaris.core.storage.InMemoryStorageIntegration; | ||
import org.apache.polaris.core.storage.PolarisCredentialProperty; | ||
|
@@ -69,13 +71,21 @@ public EnumMap<PolarisCredentialProperty, String> getSubscopedCreds( | |
allowedReadLocations, | ||
allowedWriteLocations) | ||
.toJson()) | ||
.durationSeconds( | ||
PolarisConfiguration.loadConfig( | ||
PolarisConfiguration.STORAGE_CREDENTIAL_DURATION_SECONDS)) | ||
Comment on lines
+74
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor suggestion: we could keep them in one line like the following if we import the static field/method.
|
||
.build()); | ||
EnumMap<PolarisCredentialProperty, String> credentialMap = | ||
new EnumMap<>(PolarisCredentialProperty.class); | ||
credentialMap.put(PolarisCredentialProperty.AWS_KEY_ID, response.credentials().accessKeyId()); | ||
credentialMap.put( | ||
PolarisCredentialProperty.AWS_SECRET_KEY, response.credentials().secretAccessKey()); | ||
credentialMap.put(PolarisCredentialProperty.AWS_TOKEN, response.credentials().sessionToken()); | ||
Optional.ofNullable(response.credentials().expiration()) | ||
.ifPresent( | ||
i -> | ||
credentialMap.put( | ||
PolarisCredentialProperty.EXPIRATION_TIME, String.valueOf(i.toEpochMilli()))); | ||
return credentialMap; | ||
} | ||
|
||
|
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.
+1 on this method. There are a lot of other places can reuse this as well, like here https://github.com/polaris-catalog/polaris/blob/main/polaris-service/src/main/java/org/apache/polaris/service/catalog/BasePolarisCatalog.java#L1029-L1029. We can consolidate them in a followup PR.