Skip to content
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

Merged
merged 1 commit into from
Feb 16, 2018

Conversation

vadmeste
Copy link
Member

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.

@vadmeste vadmeste changed the title [WIP] Sign V2: Fix signature calculation in virtual host style SignV2: Fix signature calculation in virtual host style Feb 13, 2018
@vadmeste vadmeste force-pushed the issue/920 branch 4 times, most recently from a0168a8 to 36b5062 Compare February 13, 2018 17:09
@kannappanr kannappanr requested review from krisis and poornas February 13, 2018 17:46
}
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 {
Copy link
Contributor

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

Copy link
Member Author

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.

@@ -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 {
Copy link
Contributor

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()

Copy link
Member Author

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.

if urlPath != encodeURL2Path(&http.Request{URL: u}) {
t.Fatal("Error")
expectedPath := "/" + bucketName + "/" + o.encodedObjName
if foundPath := encodeURL2Path(&http.Request{URL: u}, true); foundPath != expectedPath {
Copy link
Member

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.

Copy link
Member Author

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)
Copy link
Member

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.

Copy link
Member Author

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.
Copy link
Contributor

@poornas poornas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally -LGTM.

@vadmeste
Copy link
Member Author

ping @krisis

@nitisht nitisht merged commit 2d2b054 into minio:master Feb 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants