Skip to content

Commit 3c5e82a

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

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

docs/src/main/sphinx/object-storage/file-system-s3.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ support:
110110
Trino on Amazon EKS and using [IAM roles for service accounts
111111
(IRSA)](https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html)
112112
Defaults to `false`.
113+
* - `s3.web-identity-token-credentials-prefetch-time`
114+
- Configure the amount of time, relative to STS token expiration, that the
115+
cached credentials are considered close to stale and should be updated.
116+
Prefetch updates will occur between the specified time and the stale time
117+
of the provider. Prefetch updates are asynchronous.
118+
Defaults to `5m`.
119+
* - `s3.web-identity-token-credentials-stale-time`
120+
- Configure the amount of time, relative to STS token expiration, that the
121+
cached credentials are considered stale and must be updated. All threads
122+
using S3 client will block until the value is updated.
123+
Defaults to `1m`.
113124
* - `s3.application-id`
114125
- Specify the application identifier appended to the `User-Agent` header
115126
for all requests sent to S3. Defaults to `Trino`.

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 Duration webIdentityTokenCredentialsPrefetchTime = Duration.valueOf("5m");
163+
private Duration webIdentityTokenCredentialsStaleTime = Duration.valueOf("1m");
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 Duration getWebIdentityTokenCredentialsPrefetchTime()
403+
{
404+
return webIdentityTokenCredentialsPrefetchTime;
405+
}
406+
407+
@Config("s3.web-identity-token-credentials-prefetch-time")
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(Duration webIdentityTokenCredentialsPrefetchTime)
410+
{
411+
this.webIdentityTokenCredentialsPrefetchTime = webIdentityTokenCredentialsPrefetchTime;
412+
return this;
413+
}
414+
415+
public Duration getWebIdentityTokenCredentialsStaleTime()
416+
{
417+
return webIdentityTokenCredentialsStaleTime;
418+
}
419+
420+
@Config("s3.web-identity-token-credentials-stale-time")
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 setWebIdentityTokenCredentialsStaleTime(Duration webIdentityTokenCredentialsStaleTime)
423+
{
424+
this.webIdentityTokenCredentialsStaleTime = webIdentityTokenCredentialsStaleTime;
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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package io.trino.filesystem.s3;
1515

1616
import com.google.inject.Inject;
17+
import io.airlift.units.Duration;
1718
import io.opentelemetry.api.OpenTelemetry;
1819
import io.opentelemetry.instrumentation.awssdk.v2_2.AwsSdkTelemetry;
1920
import io.trino.filesystem.Location;
@@ -162,6 +163,8 @@ private static S3ClientFactory s3ClientFactory(SdkHttpClient httpClient, OpenTel
162163
Optional<String> staticEndpoint = Optional.ofNullable(config.getEndpoint());
163164
boolean pathStyleAccess = config.isPathStyleAccess();
164165
boolean useWebIdentityTokenCredentialsProvider = config.isUseWebIdentityTokenCredentialsProvider();
166+
Duration webIdentityTokenCredentialsPrefetchTime = config.getWebIdentityTokenCredentialsPrefetchTime();
167+
Duration webIdentityTokenCredentialsStaleTime = config.getWebIdentityTokenCredentialsStaleTime();
165168
Optional<String> staticIamRole = Optional.ofNullable(config.getIamRole());
166169
String staticRoleSessionName = config.getRoleSessionName();
167170
String externalId = config.getExternalId();
@@ -192,6 +195,8 @@ private static S3ClientFactory s3ClientFactory(SdkHttpClient httpClient, OpenTel
192195
if (useWebIdentityTokenCredentialsProvider) {
193196
s3.credentialsProvider(WebIdentityTokenFileCredentialsProvider.builder()
194197
.asyncCredentialUpdateEnabled(true)
198+
.prefetchTime(webIdentityTokenCredentialsPrefetchTime.toJavaTime())
199+
.staleTime(webIdentityTokenCredentialsStaleTime.toJavaTime())
195200
.build());
196201
}
197202
else if (iamRole.isPresent()) {
@@ -219,6 +224,8 @@ private static S3Presigner s3PreSigner(SdkHttpClient httpClient, OpenTelemetry o
219224
Optional<String> staticEndpoint = Optional.ofNullable(config.getEndpoint());
220225
boolean pathStyleAccess = config.isPathStyleAccess();
221226
boolean useWebIdentityTokenCredentialsProvider = config.isUseWebIdentityTokenCredentialsProvider();
227+
Duration webIdentityTokenCredentialsPrefetchTime = config.getWebIdentityTokenCredentialsPrefetchTime();
228+
Duration webIdentityTokenCredentialsStaleTime = config.getWebIdentityTokenCredentialsStaleTime();
222229
Optional<String> staticIamRole = Optional.ofNullable(config.getIamRole());
223230
String staticRoleSessionName = config.getRoleSessionName();
224231
String externalId = config.getExternalId();
@@ -236,6 +243,8 @@ private static S3Presigner s3PreSigner(SdkHttpClient httpClient, OpenTelemetry o
236243
if (useWebIdentityTokenCredentialsProvider) {
237244
s3.credentialsProvider(WebIdentityTokenFileCredentialsProvider.builder()
238245
.asyncCredentialUpdateEnabled(true)
246+
.prefetchTime(webIdentityTokenCredentialsPrefetchTime.toJavaTime())
247+
.staleTime(webIdentityTokenCredentialsStaleTime.toJavaTime())
239248
.build());
240249
}
241250
else if (staticIamRole.isPresent()) {

lib/trino-filesystem-s3/src/test/java/io/trino/filesystem/s3/TestS3FileSystemConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public void testDefaults()
6060
.setMaxErrorRetries(20)
6161
.setSseKmsKeyId(null)
6262
.setUseWebIdentityTokenCredentialsProvider(false)
63+
.setWebIdentityTokenCredentialsPrefetchTimeSeconds(new Duration(5, MINUTES))
64+
.setWebIdentityTokenCredentialsStaleTime(new Duration(1, MINUTES))
6365
.setSseCustomerKey(null)
6466
.setStreamingPartSize(DataSize.of(32, MEGABYTE))
6567
.setRequesterPays(false)
@@ -102,6 +104,8 @@ public void testExplicitPropertyMappings()
102104
.put("s3.sse.kms-key-id", "mykey")
103105
.put("s3.sse.customer-key", "customerKey")
104106
.put("s3.use-web-identity-token-credentials-provider", "true")
107+
.put("s3.web-identity-token-credentials-prefetch-time", "10m")
108+
.put("s3.web-identity-token-credentials-stale-time", "5m")
105109
.put("s3.streaming.part-size", "42MB")
106110
.put("s3.requester-pays", "true")
107111
.put("s3.max-connections", "42")
@@ -140,6 +144,8 @@ public void testExplicitPropertyMappings()
140144
.setSseType(S3SseType.KMS)
141145
.setSseKmsKeyId("mykey")
142146
.setUseWebIdentityTokenCredentialsProvider(true)
147+
.setWebIdentityTokenCredentialsPrefetchTimeSeconds(new Duration(10, MINUTES))
148+
.setWebIdentityTokenCredentialsStaleTime(new Duration(5, MINUTES))
143149
.setSseCustomerKey("customerKey")
144150
.setRequesterPays(true)
145151
.setMaxConnections(42)

0 commit comments

Comments
 (0)