Skip to content

Commit 371be34

Browse files
committed
Add signer type to native s3 filesystem
1 parent ae3282b commit 371be34

File tree

6 files changed

+54
-4
lines changed

6 files changed

+54
-4
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ support:
3434
- S3 storage class to use while writing data. Defaults to `STANDARD`. Other allowed
3535
values are: `STANDARD_IA`, `INTELLIGENT_TIERING`, `REDUCED_REDUNDANCY`, `ONEZONE_IA`,
3636
`GLACIER`, `DEEP_ARCHIVE`, `OUTPOSTS`, `GLACIER_IR`, `SNOW`, `EXPRESS_ONEZONE`.
37+
* - `s3.signer-type`
38+
- Specifies the AWS signer to use for S3 requests. Supported values are:
39+
`AwsS3V4Signer`, `Aws4Signer`, `AsyncAws4Signer`, `Aws4UnsignedPayloadSigner`,
40+
`EventStreamAws4SignerE`.
3741
* - `s3.exclusive-create`
3842
- Whether conditional write is supported by the S3-compatible storage. Defaults to `true`.
3943
* - `s3.canned-acl`
@@ -386,13 +390,15 @@ the following edits to your catalog configuration:
386390
* - `hive.s3.path-style-access`
387391
- `s3.path-style-access`
388392
-
393+
* - `hive.s3.signer-type`
394+
- `s3.signer-type`
395+
-
389396
:::
390397

391398
1. Remove the following legacy configuration properties if they exist in your
392399
catalog configuration:
393400

394401
* `hive.s3.storage-class`
395-
* `hive.s3.signer-type`
396402
* `hive.s3.signer-class`
397403
* `hive.s3.staging-directory`
398404
* `hive.s3.pin-client-to-current-region`

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import jakarta.validation.constraints.Min;
2828
import jakarta.validation.constraints.NotNull;
2929
import jakarta.validation.constraints.Size;
30+
import software.amazon.awssdk.core.signer.Signer;
3031
import software.amazon.awssdk.retries.api.RetryStrategy;
3132
import software.amazon.awssdk.services.s3.model.ObjectCannedACL;
3233
import software.amazon.awssdk.services.s3.model.StorageClass;
@@ -79,6 +80,27 @@ public static StorageClass toStorageClass(StorageClassType storageClass)
7980
}
8081
}
8182

83+
public enum SignerType
84+
{
85+
AwsS3V4Signer,
86+
Aws4Signer,
87+
AsyncAws4Signer,
88+
Aws4UnsignedPayloadSigner,
89+
EventStreamAws4Signer;
90+
91+
@SuppressWarnings("deprecation")
92+
public static Signer getAwsSignerInstance(SignerType signerType)
93+
{
94+
return switch (signerType) {
95+
case AwsS3V4Signer -> software.amazon.awssdk.auth.signer.AwsS3V4Signer.create();
96+
case Aws4Signer -> software.amazon.awssdk.auth.signer.Aws4Signer.create();
97+
case AsyncAws4Signer -> software.amazon.awssdk.auth.signer.AsyncAws4Signer.create();
98+
case Aws4UnsignedPayloadSigner -> software.amazon.awssdk.auth.signer.Aws4UnsignedPayloadSigner.create();
99+
case EventStreamAws4Signer -> software.amazon.awssdk.auth.signer.EventStreamAws4Signer.create();
100+
};
101+
}
102+
}
103+
82104
public enum ObjectCannedAcl
83105
{
84106
NONE,
@@ -135,6 +157,7 @@ public static RetryStrategy getRetryStrategy(RetryMode retryMode)
135157
private String sseCustomerKey;
136158
private boolean useWebIdentityTokenCredentialsProvider;
137159
private DataSize streamingPartSize = DataSize.of(32, MEGABYTE);
160+
private SignerType signerType;
138161
private boolean requesterPays;
139162
private Integer maxConnections = 500;
140163
private Duration connectionTtl;
@@ -395,6 +418,18 @@ public boolean isSseWithCustomerKeyConfigValid()
395418
return true;
396419
}
397420

421+
public Optional<SignerType> getSignerType()
422+
{
423+
return Optional.ofNullable(signerType);
424+
}
425+
426+
@Config("s3.signer-type")
427+
public S3FileSystemConfig setSignerType(SignerType signerType)
428+
{
429+
this.signerType = signerType;
430+
return this;
431+
}
432+
398433
@NotNull
399434
@MinDataSize("5MB")
400435
@MaxDataSize("256MB")

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@
5151
import static com.google.common.base.Preconditions.checkState;
5252
import static io.airlift.concurrent.Threads.daemonThreadsNamed;
5353
import static io.trino.filesystem.s3.S3FileSystemConfig.RetryMode.getRetryStrategy;
54+
import static io.trino.filesystem.s3.S3FileSystemConfig.SignerType.getAwsSignerInstance;
5455
import static java.lang.Math.toIntExact;
5556
import static java.util.Objects.requireNonNull;
5657
import static java.util.concurrent.Executors.newCachedThreadPool;
5758
import static software.amazon.awssdk.core.checksums.ResponseChecksumValidation.WHEN_REQUIRED;
59+
import static software.amazon.awssdk.core.client.config.SdkAdvancedClientOption.SIGNER;
5860

5961
final class S3FileSystemLoader
6062
implements Function<Location, TrinoFileSystemFactory>
@@ -277,7 +279,7 @@ private static StsClient createStsClient(S3FileSystemConfig config, Optional<Aws
277279

278280
private static ClientOverrideConfiguration createOverrideConfiguration(OpenTelemetry openTelemetry, S3FileSystemConfig config, MetricPublisher metricPublisher)
279281
{
280-
return ClientOverrideConfiguration.builder()
282+
ClientOverrideConfiguration.Builder builder = ClientOverrideConfiguration.builder()
281283
.addExecutionInterceptor(AwsSdkTelemetry.builder(openTelemetry)
282284
.setCaptureExperimentalSpanAttributes(true)
283285
.setRecordIndividualHttpError(true)
@@ -286,8 +288,9 @@ private static ClientOverrideConfiguration createOverrideConfiguration(OpenTelem
286288
.maxAttempts(config.getMaxErrorRetries())
287289
.build())
288290
.appId(config.getApplicationId())
289-
.addMetricPublisher(metricPublisher)
290-
.build();
291+
.addMetricPublisher(metricPublisher);
292+
config.getSignerType().ifPresent(signer -> builder.putAdvancedOption(SIGNER, getAwsSignerInstance(signer)));
293+
return builder.build();
291294
}
292295

293296
private static SdkHttpClient createHttpClient(S3FileSystemConfig config)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ protected S3FileSystemFactory createS3FileSystemFactory()
8989
.setRegion(region)
9090
.setEndpoint(endpoint)
9191
.setSupportsExclusiveCreate(true)
92+
.setSignerType(S3FileSystemConfig.SignerType.AwsS3V4Signer)
9293
.setStreamingPartSize(DataSize.valueOf("5.5MB")), new S3FileSystemStats());
9394
}
9495

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import static io.airlift.units.DataSize.Unit.MEGABYTE;
3333
import static io.trino.filesystem.s3.S3FileSystemConfig.RetryMode.LEGACY;
3434
import static io.trino.filesystem.s3.S3FileSystemConfig.RetryMode.STANDARD;
35+
import static io.trino.filesystem.s3.S3FileSystemConfig.SignerType.Aws4Signer;
3536
import static io.trino.filesystem.s3.S3FileSystemConfig.StorageClassType.STANDARD_IA;
3637
import static java.util.concurrent.TimeUnit.MINUTES;
3738

@@ -52,6 +53,7 @@ public void testDefaults()
5253
.setStsEndpoint(null)
5354
.setStsRegion(null)
5455
.setStorageClass(StorageClassType.STANDARD)
56+
.setSignerType(null)
5557
.setCannedAcl(ObjectCannedAcl.NONE)
5658
.setSseType(S3SseType.NONE)
5759
.setRetryMode(LEGACY)
@@ -93,6 +95,7 @@ public void testExplicitPropertyMappings()
9395
.put("s3.sts.endpoint", "sts.example.com")
9496
.put("s3.sts.region", "us-west-2")
9597
.put("s3.storage-class", "STANDARD_IA")
98+
.put("s3.signer-type", "Aws4Signer")
9699
.put("s3.canned-acl", "BUCKET_OWNER_FULL_CONTROL")
97100
.put("s3.retry-mode", "STANDARD")
98101
.put("s3.max-error-retries", "12")
@@ -131,6 +134,7 @@ public void testExplicitPropertyMappings()
131134
.setStsEndpoint("sts.example.com")
132135
.setStsRegion("us-west-2")
133136
.setStorageClass(STANDARD_IA)
137+
.setSignerType(Aws4Signer)
134138
.setCannedAcl(ObjectCannedAcl.BUCKET_OWNER_FULL_CONTROL)
135139
.setStreamingPartSize(DataSize.of(42, MEGABYTE))
136140
.setRetryMode(STANDARD)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ protected S3FileSystemFactory createS3FileSystemFactory()
7878
.setRegion(Region.US_EAST_1.id())
7979
.setPathStyleAccess(true)
8080
.setStreamingPartSize(DataSize.valueOf("5.5MB"))
81+
.setSignerType(S3FileSystemConfig.SignerType.AwsS3V4Signer)
8182
.setSupportsExclusiveCreate(false), new S3FileSystemStats());
8283
}
8384

0 commit comments

Comments
 (0)