From 7eb7f65e48e2e59c2dacd7e2777b69a07de7d8d2 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 2 Apr 2021 09:34:15 -0700 Subject: [PATCH] add policy conditions support for signatureVersion and authType (#11947) https://docs.aws.amazon.com/AmazonS3/latest/API/bucket-policy-s3-sigv4-conditions.html fixes #11944 --- cmd/bucket-policy.go | 41 ++++++++++++++++++++++-------- pkg/bucket/policy/condition/key.go | 10 ++++++++ 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/cmd/bucket-policy.go b/cmd/bucket-policy.go index f359b8057..fe80bbca9 100644 --- a/cmd/bucket-policy.go +++ b/cmd/bucket-policy.go @@ -83,17 +83,38 @@ func getConditionValues(r *http.Request, lc string, username string, claims map[ } } + authType := getRequestAuthType(r) + var signatureVersion string + switch authType { + case authTypeSignedV2, authTypePresignedV2: + signatureVersion = signV2Algorithm + case authTypeSigned, authTypePresigned, authTypeStreamingSigned, authTypePostPolicy: + signatureVersion = signV4Algorithm + } + + var authtype string + switch authType { + case authTypePresignedV2, authTypePresigned: + authtype = "REST-QUERY-STRING" + case authTypeSignedV2, authTypeSigned, authTypeStreamingSigned: + authtype = "REST-HEADER" + case authTypePostPolicy: + authtype = "POST" + } + args := map[string][]string{ - "CurrentTime": {currTime.Format(time.RFC3339)}, - "EpochTime": {strconv.FormatInt(currTime.Unix(), 10)}, - "SecureTransport": {strconv.FormatBool(r.TLS != nil)}, - "SourceIp": {handlers.GetSourceIP(r)}, - "UserAgent": {r.UserAgent()}, - "Referer": {r.Referer()}, - "principaltype": {principalType}, - "userid": {username}, - "username": {username}, - "versionid": {vid}, + "CurrentTime": {currTime.Format(time.RFC3339)}, + "EpochTime": {strconv.FormatInt(currTime.Unix(), 10)}, + "SecureTransport": {strconv.FormatBool(r.TLS != nil)}, + "SourceIp": {handlers.GetSourceIP(r)}, + "UserAgent": {r.UserAgent()}, + "Referer": {r.Referer()}, + "principaltype": {principalType}, + "userid": {username}, + "username": {username}, + "versionid": {vid}, + "signatureversion": {signatureVersion}, + "authType": {authtype}, } if lc != "" { diff --git a/pkg/bucket/policy/condition/key.go b/pkg/bucket/policy/condition/key.go index 2538e3cb0..6d66ee74b 100644 --- a/pkg/bucket/policy/condition/key.go +++ b/pkg/bucket/policy/condition/key.go @@ -110,10 +110,18 @@ const ( // AWSUsername - user friendly name, in MinIO this value is same as your user Access Key. AWSUsername Key = "aws:username" + + // S3SignatureVersion - identifies the version of AWS Signature that you want to support for authenticated requests. + S3SignatureVersion = "s3:signatureversion" + + // S3AuthType - optionally use this condition key to restrict incoming requests to use a specific authentication method. + S3AuthType = "s3:authType" ) // AllSupportedKeys - is list of all all supported keys. var AllSupportedKeys = append([]Key{ + S3SignatureVersion, + S3AuthType, S3XAmzCopySource, S3XAmzServerSideEncryption, S3XAmzServerSideEncryptionCustomerAlgorithm, @@ -144,6 +152,8 @@ var AllSupportedKeys = append([]Key{ // CommonKeys - is list of all common condition keys. var CommonKeys = append([]Key{ + S3SignatureVersion, + S3AuthType, S3XAmzContentSha256, S3LocationConstraint, AWSReferer,