Skip to content

Commit 8ef4343

Browse files
committed
Support prefetch & stale time for S3 web identity provider
1 parent 3600ee4 commit 8ef4343

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

lib/trino-filesystem-s3/src/main/java/io/trino/filesystem/s3/S3FileSystemConfig.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ public static RetryStrategy getRetryStrategy(RetryMode retryMode)
159159
private String sseKmsKeyId;
160160
private String sseCustomerKey;
161161
private boolean useWebIdentityTokenCredentialsProvider;
162+
private int webIdentityTokenCredentialsPrefetchTimeSeconds = 300;
163+
private int webIdentityTokenCredentialsStaleTimeSeconds = 60;
162164
private SignerType signerType;
163165
private DataSize streamingPartSize = DataSize.of(32, MEGABYTE);
164166
private boolean requesterPays;
@@ -397,6 +399,32 @@ public S3FileSystemConfig setUseWebIdentityTokenCredentialsProvider(boolean useW
397399
return this;
398400
}
399401

402+
public int getWebIdentityTokenCredentialsPrefetchTimeSeconds()
403+
{
404+
return webIdentityTokenCredentialsPrefetchTimeSeconds;
405+
}
406+
407+
@Config("s3.web-identity-token-credentials-prefetch-time-seconds")
408+
@ConfigDescription("Configure the amount of time, relative to STS token expiration, that the cached credentials are considered close to stale and should be updated. Prefetch updates will occur between the specified time and the stale time of the provider. Prefetch updates are asynchronous.")
409+
public S3FileSystemConfig setWebIdentityTokenCredentialsPrefetchTimeSeconds(int webIdentityTokenCredentialsPrefetchTimeSeconds)
410+
{
411+
this.webIdentityTokenCredentialsPrefetchTimeSeconds = webIdentityTokenCredentialsPrefetchTimeSeconds;
412+
return this;
413+
}
414+
415+
public int getWebIdentityTokenCredentialsStaleTimeSeconds()
416+
{
417+
return webIdentityTokenCredentialsStaleTimeSeconds;
418+
}
419+
420+
@Config("s3.web-identity-token-credentials-stale-time-seconds")
421+
@ConfigDescription("Configure the amount of time, relative to STS token expiration, that the cached credentials are considered stale and must be updated. All threads using S3 client will block until the value is updated.")
422+
public S3FileSystemConfig setWebIdentityTokenCredentialsStaleTimeSeconds(int webIdentityTokenCredentialsStaleTimeSeconds)
423+
{
424+
this.webIdentityTokenCredentialsStaleTimeSeconds = webIdentityTokenCredentialsStaleTimeSeconds;
425+
return this;
426+
}
427+
400428
public String getSseCustomerKey()
401429
{
402430
return sseCustomerKey;

lib/trino-filesystem-s3/src/main/java/io/trino/filesystem/s3/S3FileSystemLoader.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
import software.amazon.awssdk.services.sts.auth.StsAssumeRoleCredentialsProvider;
4242

4343
import java.net.URI;
44+
import java.time.Duration;
45+
import java.time.temporal.ChronoUnit;
4446
import java.util.Map;
4547
import java.util.Optional;
4648
import java.util.concurrent.ConcurrentHashMap;
@@ -162,6 +164,8 @@ private static S3ClientFactory s3ClientFactory(SdkHttpClient httpClient, OpenTel
162164
Optional<String> staticEndpoint = Optional.ofNullable(config.getEndpoint());
163165
boolean pathStyleAccess = config.isPathStyleAccess();
164166
boolean useWebIdentityTokenCredentialsProvider = config.isUseWebIdentityTokenCredentialsProvider();
167+
Duration webIdentityTokenCredentialsPrefetchTime = Duration.of(config.getWebIdentityTokenCredentialsPrefetchTimeSeconds(), ChronoUnit.SECONDS);
168+
Duration webIdentityTokenCredentialsStaleTime = Duration.of(config.getWebIdentityTokenCredentialsStaleTimeSeconds(), ChronoUnit.SECONDS);
165169
Optional<String> staticIamRole = Optional.ofNullable(config.getIamRole());
166170
String staticRoleSessionName = config.getRoleSessionName();
167171
String externalId = config.getExternalId();
@@ -192,6 +196,8 @@ private static S3ClientFactory s3ClientFactory(SdkHttpClient httpClient, OpenTel
192196
if (useWebIdentityTokenCredentialsProvider) {
193197
s3.credentialsProvider(WebIdentityTokenFileCredentialsProvider.builder()
194198
.asyncCredentialUpdateEnabled(true)
199+
.prefetchTime(webIdentityTokenCredentialsPrefetchTime)
200+
.staleTime(webIdentityTokenCredentialsStaleTime)
195201
.build());
196202
}
197203
else if (iamRole.isPresent()) {
@@ -219,6 +225,8 @@ private static S3Presigner s3PreSigner(SdkHttpClient httpClient, OpenTelemetry o
219225
Optional<String> staticEndpoint = Optional.ofNullable(config.getEndpoint());
220226
boolean pathStyleAccess = config.isPathStyleAccess();
221227
boolean useWebIdentityTokenCredentialsProvider = config.isUseWebIdentityTokenCredentialsProvider();
228+
Duration webIdentityTokenCredentialsPrefetchTime = Duration.of(config.getWebIdentityTokenCredentialsPrefetchTimeSeconds(), ChronoUnit.SECONDS);
229+
Duration webIdentityTokenCredentialsStaleTime = Duration.of(config.getWebIdentityTokenCredentialsStaleTimeSeconds(), ChronoUnit.SECONDS);
222230
Optional<String> staticIamRole = Optional.ofNullable(config.getIamRole());
223231
String staticRoleSessionName = config.getRoleSessionName();
224232
String externalId = config.getExternalId();
@@ -236,6 +244,8 @@ private static S3Presigner s3PreSigner(SdkHttpClient httpClient, OpenTelemetry o
236244
if (useWebIdentityTokenCredentialsProvider) {
237245
s3.credentialsProvider(WebIdentityTokenFileCredentialsProvider.builder()
238246
.asyncCredentialUpdateEnabled(true)
247+
.prefetchTime(webIdentityTokenCredentialsPrefetchTime)
248+
.staleTime(webIdentityTokenCredentialsStaleTime)
239249
.build());
240250
}
241251
else if (staticIamRole.isPresent()) {

0 commit comments

Comments
 (0)