aws-sdk-net: AWS S3 SDK: Error when calling GetPreSignedURL for certain regions
Describe the bug
Hello!
I am using the S3 SDK to for non-Amazon endpoints specifically Wasabi. When generating presigned URL for certain regions, it fails with the message:
The maximum expiry period for a presigned url using AWS4 signing is 604800 seconds
The regions that fails are: https://s3.us-east-2.wasabisys.com https://s3.us-central-1.wasabisys.com
But it works okay for: https://s3.us-west-1.wasabisys.com https://s3.us-east-1.wasabisys.com
The below xUnit test should work as is with no changes.
Thank you kindly!
Expected Behavior
Expect the presigned URL to be generated correctly.
Current Behavior
Message:
System.ArgumentException : The maximum expiry period for a presigned url using AWS4 signing is 604800 seconds
Stack Trace:
AmazonS3Client.Marshall(IClientConfig config, GetPreSignedUrlRequest getPreSignedUrlRequest, String accessKey, String token, SignatureVersion signatureVersion)
AmazonS3Client.GetPreSignedURLInternal(GetPreSignedUrlRequest request, Boolean useSigV2Fallback)
AmazonS3Client.GetPreSignedURL(GetPreSignedUrlRequest request)
S3VolumeOperationShould.PresignedShould(String serviceURL) line 267
Reproduction Steps
[Theory]
[InlineData("https://s3.us-west-1.wasabisys.com")] // pass
[InlineData("https://s3.us-east-1.wasabisys.com")] // pass
[InlineData("https://s3.us-east-2.wasabisys.com")] // error
[InlineData("https://s3.us-central-1.wasabisys.com")] // error
public void PresignedShould(string serviceURL)
{
var client = new AmazonS3Client(
"Settings.AuthKeyId",
"Settings.AuthKey",
new AmazonS3Config { ServiceURL = serviceURL });
client.GetPreSignedURL(new GetPreSignedUrlRequest
{
BucketName = "bucket",
Expires = DateTime.UtcNow.AddDays(10),
Verb = HttpVerb.GET
});
}
Possible Solution
No response
Additional Information/Context
No response
AWS .NET SDK and/or Package version used
3.7.9.54, 3.7.108.
Targeted .NET Platform
.NET 6
Operating System and version
Windows & Ubuntu
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (8 by maintainers)
I have no idea if this will work for Wasabi but worth a try. When you construct the the
AmazonS3Configobject try always setting theAuthenticationRegiontous-east-1even when theServiceUrlis to some other region. That should trick the SDK into using SigV2 which doesn’t include the region as part of the signing. Not sure what Wasabi will do in this case but you can see if it unblocks you.Keep in mind this unsupported behavior but maybe it will unblock you.
@jerome-zenfolio Boto working for
us-east-2andus-central-1is by accident not design. I would bet if you went across the 12 AWS SDKs you would get a collection of behavior for specifying a non-AWS endpoint and then using an expiration greater then the SigV4 max. In fact most of the newer SDKs only support SigV4 with no SigV2 fallback.The .NET SDK, which is assuming an AWS endpoint, looks at the service URL to determine the AWS region the request is being sent to. The parse logic for the host name is assuming the service url is
<service>.<region>.<host-suffix>Which the Wasabi host name follow so forhttps://s3.us-east-2.wasabisys.com/the .NET SDK determine the request is being sent to theus-east-2AWS region which is a SigV4 only S3 region. Forhttps://s3.us-central-1.wasabisys.com/there is no AWS region calledus-central-1so the SDK is assuming you are attempting to use a new region and all new regions are SigV4 only regions so it defaults to that.SigV4 has the restriction that signature can not last any longer then 7 days so in your case when the SDK determines it needs to use SigV4 for the signature it fails since you are using 10 days. Can you use 7 instead of 10 days for your expiration?
The SDK’s logic for determine regions and signing is very complicated with a lot of built up legacy decisions with how AWS regions have changed over the years and how SDKs are supposed to resolve endpoints and signing regions. I’m very leery of adding more complications to the code for a scenario that shouldn’t be valid since it violates SigV4 requirements.