aws-sdk-go-v2: SignatureDoesNotMatch error when used with GCS
Describe the bug
I’m facing SignatureDoesNotMatch error when I use endpoint url as google cloud storage https://storage.googleapis.com.
I didn’t have this error when using aws-sdk-go.
Expected Behavior
To be able to send requests successfully just like in aws-sdk-go.
Current Behavior
I used a simple code where I try to ListBuckets with default settings. Following is the debug output and error:
SDK 2022/08/25 10:01:40 DEBUG Request Signature:
---[ CANONICAL STRING ]-----------------------------
GET
/
accept-encoding:identity
amz-sdk-invocation-id:159ecffe-dd09-43e5-8f3a-1c3a02e3da5b
amz-sdk-request:attempt=1; max=3
host:storage.googleapis.com
x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
x-amz-date:20220825T070140Z
accept-encoding;amz-sdk-invocation-id;amz-sdk-request;host;x-amz-content-sha256;x-amz-date
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
---[ STRING TO SIGN ]--------------------------------
AWS4-HMAC-SHA256
20220825T070140Z
20220825/auto/s3/aws4_request
97655a46f48a0bab4d36278d984931d1a4c1bc6fa8cdf77d4f3e70465a62fa6f
-----------------------------------------------------
SDK 2022/08/25 10:01:40 DEBUG Request
GET / HTTP/1.1
Host: storage.googleapis.com
User-Agent: aws-sdk-go-v2/1.16.7 os/macos lang/go/1.18.3 md/GOOS/darwin md/GOARCH/amd64 api/s3/1.27.1
Accept-Encoding: identity
Amz-Sdk-Invocation-Id: 159ecffe-dd09-43e5-8f3a-1c3a02e3da5b
Amz-Sdk-Request: attempt=1; max=3
Authorization: AWS4-HMAC-SHA256 Credential=GOOGXXXXCM3H4LRVOSWKUFX/20220825/auto/s3/aws4_request, SignedHeaders=accept-encoding;amz-sdk-invocation-id;amz-sdk-request;host;x-amz-content-sha256;x-amz-date, Signature=4613a0c21bfa65cbe2ca3895943c570dc14ae938d9059acb605bea8efc5aa81f
X-Amz-Content-Sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
X-Amz-Date: 20220825T070140Z
SDK 2022/08/25 10:01:40 DEBUG Response
HTTP/2.0 403 Forbidden
Content-Length: 859
Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
Cache-Control: private, max-age=0
Content-Type: application/xml; charset=UTF-8
Date: Thu, 25 Aug 2022 07:01:40 GMT
Expires: Thu, 25 Aug 2022 07:01:40 GMT
Server: UploadServer
X-Guploader-Uploadid: ADPycds0ijOgnsfw23HvSlSotY-STzCuGu6pj3GoXj49NNJeUCziHkT4sXz4vIcn_syis54UIon8h-O4KOcaR--G7Eq3lDhmrQmr
ListBuckets: operation error S3: ListBuckets, https response error StatusCode: 403, RequestID: , HostID: , api error SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.
Similarly, when I try to use aws-sdk-go, it is successful:
2022/08/25 10:12:18 DEBUG: Request Signature:
---[ CANONICAL STRING ]-----------------------------
GET
/
host:storage.googleapis.com
x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
x-amz-date:20220825T071218Z
host;x-amz-content-sha256;x-amz-date
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
---[ STRING TO SIGN ]--------------------------------
AWS4-HMAC-SHA256
20220825T071218Z
20220825/auto/s3/aws4_request
802442955334a38685a8630a467ad8c046e350beb19662a3f4d2fdb8b5120511
-----------------------------------------------------
2022/08/25 10:12:18 DEBUG: Request s3/ListBuckets Details:
---[ REQUEST POST-SIGN ]-----------------------------
GET / HTTP/1.1
Host: storage.googleapis.com
User-Agent: aws-sdk-go/1.40.25 (go1.18.3; darwin; amd64)
Authorization: AWS4-HMAC-SHA256 Credential=GOOGXXXXVCM3H4LRVOSWKUFX/20220825/auto/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=d211e86e8a77e5db71fcb99dc62f5c47ff6487a051169bf5fd787084800d8f13
X-Amz-Content-Sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
X-Amz-Date: 20220825T071218Z
Accept-Encoding: gzip
-----------------------------------------------------
2022/08/25 10:12:18 DEBUG: Response s3/ListBuckets Details:
---[ RESPONSE ]--------------------------------------
HTTP/2.0 200 OK
Content-Length: 251
Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
Cache-Control: private, max-age=0
Content-Type: application/xml; charset=UTF-8
Date: Thu, 25 Aug 2022 07:12:18 GMT
Expires: Thu, 25 Aug 2022 07:12:18 GMT
Server: UploadServer
X-Guploader-Uploadid: ADPycdsAazh0HYg9mOjQrtoUryuKndpaFtZeRbadNnaiaCccL-7DAshcQzVbFcXqGHG1iLwWMWHmzNY_FK8koXLQBvgxRYe-FfXR
-----------------------------------------------------
Buckets:bbs-test-bucket
Reproduction Steps
Below there are two gists, identically doing the same thing using aws-sdk-go and aws-sdk-go-v2 respectively.
Possible Solution
Some additional headers such as amz-sdk-request and amz-sdk-invocation-id are added to SignedHeaders in v2. Issue might be related to that, but I don’t have a possible solution in mind.
Additional Information/Context
GCS gives an example usage with aws-sdk-go here but there is no example with aws-sdk-go-v2.
AWS Go SDK V2 Module Versions Used
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/s3"
Compiler and Version used
go version go1.18.3 darwin/amd64
Operating System and version
macos monterey 12.4
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 16 (3 by maintainers)
Commits related to this issue
- allow GCS over S3, remove Accept-Encoding header from sign https://stackoverflow.com/a/74382598/1204665, https://github.com/aws/aws-sdk-go-v2/issues/1816, GCS over S3 have no 5Gb restriction, TestInte... — committed to Altinity/clickhouse-backup by Slach 3 years ago
- tusd: Use GCS upload backend when the endpoint matches. This works around tus/tusd#322, which in turn is caused by aws/aws-sdk-go-v2#1816. This requires separate authentication via service account k... — committed to alexmv/zulip by alexmv 2 years ago
- tusd: Use GCS upload backend when the endpoint matches. This works around tus/tusd#322, which in turn is caused by aws/aws-sdk-go-v2#1816. This requires separate authentication via service account k... — committed to alexmv/zulip by alexmv 2 years ago
- tusd: Use GCS upload backend when the endpoint matches. This works around tus/tusd#322, which in turn is caused by aws/aws-sdk-go-v2#1816. This requires separate authentication via service account k... — committed to alexmv/zulip by alexmv 2 years ago
- tusd: Use GCS upload backend when the endpoint matches. This works around tus/tusd#322, which in turn is caused by aws/aws-sdk-go-v2#1816. This requires separate authentication via service account k... — committed to alexmv/zulip by alexmv 2 years ago
- tusd: Use GCS upload backend when the endpoint matches. This works around tus/tusd#322, which in turn is caused by aws/aws-sdk-go-v2#1816. This requires separate authentication via service account k... — committed to alexmv/zulip by alexmv 2 years ago
- tusd: Use GCS upload backend when the endpoint matches. This works around tus/tusd#322, which in turn is caused by aws/aws-sdk-go-v2#1816. This requires separate authentication via service account k... — committed to zulip/zulip by alexmv 2 years ago
- tusd: Use GCS upload backend when the endpoint matches. This works around tus/tusd#322, which in turn is caused by aws/aws-sdk-go-v2#1816. This requires separate authentication via service account k... — committed to timabbott/zulip by alexmv 2 years ago
- tusd: Use GCS upload backend when the endpoint matches. This works around tus/tusd#322, which in turn is caused by aws/aws-sdk-go-v2#1816. This requires separate authentication via service account k... — committed to zulip/zulip by alexmv 2 years ago
- tusd: Use GCS upload backend when the endpoint matches. This works around tus/tusd#322, which in turn is caused by aws/aws-sdk-go-v2#1816. This requires separate authentication via service account k... — committed to theofficialvedantjoshi/zulip by alexmv 2 years ago
- tusd: Use GCS upload backend when the endpoint matches. This works around tus/tusd#322, which in turn is caused by aws/aws-sdk-go-v2#1816. This requires separate authentication via service account k... — committed to theofficialvedantjoshi/zulip by alexmv 2 years ago
I’m not sure whether it will be useful to others or if it is the best way to handle it, but based on the above stackoverflow question, here is my
ignoreSigningHeadersmiddleware:Usage pseudo-code:
Middleware:
I found a little hack way to achieve it. the idea is to use
go:linknameto access the internal variablev4.IgnoredHeadersand append a new itemaccept-encodingto it. @szabolcsgelencser hope it can be helpful.More safe way, https://stackoverflow.com/a/74382598/1204665, but with more code and could be less performance
Hi @szabolcsgelencser,
Unfortunately I couldn’t find a way to exclude accept-encoding without changing the source code of the sdk.