-
Notifications
You must be signed in to change notification settings - Fork 670
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
SignV2: Fix signature calculation in virtual host style #921
Conversation
a0168a8
to
36b5062
Compare
pkg/s3signer/request-signature-v2.go
Outdated
} | ||
path = s3utils.EncodePath(req.URL.Path) | ||
return | ||
} | ||
|
||
// PreSignV2 - presign the request in following style. | ||
// https://${S3_BUCKET}.s3.amazonaws.com/${S3_OBJECT}?AWSAccessKeyId=${S3_ACCESS_KEY}&Expires=${TIMESTAMP}&Signature=${SIGNATURE}. | ||
func PreSignV2(req http.Request, accessKeyID, secretAccessKey string, expires int64) *http.Request { | ||
func PreSignV2(req http.Request, accessKeyID, secretAccessKey string, expires int64, vhost bool) *http.Request { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might be better to rename vhost as isVirtualHostStyle - vhost is cryptic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might be better to rename vhost as isVirtualHostStyle - vhost is cryptic
Fixed.
pkg/s3signer/request-signature-v2.go
Outdated
@@ -132,7 +127,7 @@ func PostPresignSignatureV2(policyBase64, secretAccessKey string) string { | |||
// CanonicalizedProtocolHeaders = <described below> | |||
|
|||
// SignV2 sign the request before Do() (AWS Signature Version 2). | |||
func SignV2(req http.Request, accessKeyID, secretAccessKey string) *http.Request { | |||
func SignV2(req http.Request, accessKeyID, secretAccessKey string, vhost bool) *http.Request { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename vhost -> isVirtualHostStyle in this & preStringToSignV2() stringToSignV2() and writeCanonicalizedResource()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename vhost -> isVirtualHostStyle in this & preStringToSignV2() stringToSignV2() and writeCanonicalizedResource()
Fixed.
pkg/s3signer/utils_test.go
Outdated
if urlPath != encodeURL2Path(&http.Request{URL: u}) { | ||
t.Fatal("Error") | ||
expectedPath := "/" + bucketName + "/" + o.encodedObjName | ||
if foundPath := encodeURL2Path(&http.Request{URL: u}, true); foundPath != expectedPath { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should have tests for vhost
being both true
and false
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should have tests for vhost being both true and false.
yeah, done.
@@ -39,12 +39,12 @@ func TestSignatureCalculation(t *testing.T) { | |||
t.Fatal("Error: anonymous credentials should not have Signature query resource.") | |||
} | |||
|
|||
req = SignV2(*req, "", "") | |||
req = SignV2(*req, "", "", false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should add tests for vhost = true
too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should add tests for vhost = true too.
Done
In signature V2, the Resource Path that will be signed should have the form of /bucket/path/.. even in the case of vhost requests. The commit fixes the issue. The downside is to forbid automatic http redirection for V2 requests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally -LGTM.
ping @krisis |
In signature V2, the Resource Path that will be signed should have
the form of /bucket/path/.. even in the case of vhost requests. The
commit fixes the issue. The downside is to forbid automatic http
redirection for V2 requests.