-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
URL encoding causes 403 SignatureDoesNotMatch on direct folder uploads #1583
Comments
Thanks for reaching out to us @damienstanton. The issue in differing functionality here that you're seeing is an artifact of the CLI's legacy implementation. The CLI hides some of the details of a S3 bucket and object. Based on the the example it looks like S3 does not natively the concept of founders. This is an artifact of the CLI's representation of folders due to the nature of using a CLI on a in a command shell. All objects in S3 are referenced by a In this case the example is adding a path to the bucket name. This is incorrect. Instead of prefixing the key. A prefix (aka sub folders in this example) can only exist in the A correct API request would be the following with the uploader := s3manager.NewUploader(sess)
_, err := uploader.Upload(&s3manager.UploadInput{
Bucket: aws.String("damienstanton-test"),
Key: aws.String("childpath/test.txt"),
Body: file,
}) |
Got it, this does describe the scenario we found and explains the unfortunate behavior of the CLI tool. I’ll close this issue as a change would have to come from the boto/cli side and not the Go SDK. Thanks 🙏 |
Thanks for the update @damienstanton. Let us know if you run into any additional issues or have feedback for the SDK. |
Versions:
AWS SDK:
1.8.44
Go:
1.9
Issue:
When uploading to a folder within a S3 bucket, the bucket name cannot be passed directly to the s3manager
UploadInput
type without a trailing slash.Given the bucket
damienstanton-test/childpath
as the destination, one expects the S3 path to be parsed as exactly such. But this does not occur.With debug logging on the session, we examine the canonical string and observe that instead of the usual
POST
and host# expected ---[ CANONICAL STRING ]----------------------------- POST /test.txt uploads= host:damienstanton-test/childpath.s3.amazonaws.com
the SDK seems to incorrectly parse the bucket and filename. We get this instead:
# actual ---[ CANONICAL STRING ]----------------------------- POST /damienstanton-test%2Fchildpath/test.txt uploads= host:s3.amazonaws.com
This throws a key-signing error:
Steps to reproduce:
A sanity check can be performed by comparing permissions on a bucket versus a folder within that bucket using the official AWS cli tool.
while
It seems we can assume that as far as S3 permissions are concerned,
<s3://bucketname/path>/
refers to a folder within the bucket, but the CLI tool can runcp
to the same path minus the slash.We have not tested this against buckets with multiple folders, nor could we find any relevant documentation on why the SDK parses the bucket string differently than the CLI. A fix may be to just ensure that the Go SDK parses the bucket URL in the same way the boto library does.
This can be reproduced in full via the following unit tests:
I will venture to guess that this could be related to #1385. We are aware that our version of the SDK is slightly old, but it seems URL encoding is still an open topic and since this particular issue caused upload failures in a live scenario, we believe it is worth discussing.
The text was updated successfully, but these errors were encountered: