accessPolicy: Implement Put, Get, Delete access policy.
This patch implements Get,Put,Delete bucket policies
Supporting - http://docs.aws.amazon.com/AmazonS3/latest/dev/access-policy-language-overview.html
Currently supports following actions.
"*": true,
"s3:*": true,
"s3:GetObject": true,
"s3:ListBucket": true,
"s3:PutObject": true,
"s3:CreateBucket": true,
"s3:GetBucketLocation": true,
"s3:DeleteBucket": true,
"s3:DeleteObject": true,
"s3:AbortMultipartUpload": true,
"s3:ListBucketMultipartUploads": true,
"s3:ListMultipartUploadParts": true,
following conditions for "StringEquals" and "StringNotEquals"
"s3:prefix", "s3:max-keys"
2016-02-04 01:46:56 +01:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 2015, 2016 Minio, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2016-08-19 01:23:42 +02:00
|
|
|
package cmd
|
accessPolicy: Implement Put, Get, Delete access policy.
This patch implements Get,Put,Delete bucket policies
Supporting - http://docs.aws.amazon.com/AmazonS3/latest/dev/access-policy-language-overview.html
Currently supports following actions.
"*": true,
"s3:*": true,
"s3:GetObject": true,
"s3:ListBucket": true,
"s3:PutObject": true,
"s3:CreateBucket": true,
"s3:GetBucketLocation": true,
"s3:DeleteBucket": true,
"s3:DeleteObject": true,
"s3:AbortMultipartUpload": true,
"s3:ListBucketMultipartUploads": true,
"s3:ListMultipartUploadParts": true,
following conditions for "StringEquals" and "StringNotEquals"
"s3:prefix", "s3:max-keys"
2016-02-04 01:46:56 +01:00
|
|
|
|
|
|
|
import (
|
2016-07-29 05:49:08 +02:00
|
|
|
"bytes"
|
2016-10-13 18:19:04 +02:00
|
|
|
"encoding/json"
|
2016-08-11 05:10:48 +02:00
|
|
|
"io"
|
|
|
|
"path"
|
2016-09-26 23:28:35 +02:00
|
|
|
"sync"
|
accessPolicy: Implement Put, Get, Delete access policy.
This patch implements Get,Put,Delete bucket policies
Supporting - http://docs.aws.amazon.com/AmazonS3/latest/dev/access-policy-language-overview.html
Currently supports following actions.
"*": true,
"s3:*": true,
"s3:GetObject": true,
"s3:ListBucket": true,
"s3:PutObject": true,
"s3:CreateBucket": true,
"s3:GetBucketLocation": true,
"s3:DeleteBucket": true,
"s3:DeleteObject": true,
"s3:AbortMultipartUpload": true,
"s3:ListBucketMultipartUploads": true,
"s3:ListMultipartUploadParts": true,
following conditions for "StringEquals" and "StringNotEquals"
"s3:prefix", "s3:max-keys"
2016-02-04 01:46:56 +01:00
|
|
|
)
|
|
|
|
|
2016-09-26 23:28:35 +02:00
|
|
|
// Variable represents bucket policies in memory.
|
|
|
|
var globalBucketPolicies *bucketPolicies
|
|
|
|
|
|
|
|
// Global bucket policies list, policies are enforced on each bucket looking
|
|
|
|
// through the policies here.
|
|
|
|
type bucketPolicies struct {
|
|
|
|
rwMutex *sync.RWMutex
|
|
|
|
|
|
|
|
// Collection of 'bucket' policies.
|
|
|
|
bucketPolicyConfigs map[string]*bucketPolicy
|
|
|
|
}
|
|
|
|
|
2016-10-13 18:19:04 +02:00
|
|
|
// Represent a policy change
|
|
|
|
type policyChange struct {
|
|
|
|
// isRemove is true if the policy change is to delete the
|
|
|
|
// policy on a bucket.
|
|
|
|
IsRemove bool
|
|
|
|
|
|
|
|
// represents the new policy for the bucket
|
|
|
|
BktPolicy *bucketPolicy
|
|
|
|
}
|
|
|
|
|
2016-09-26 23:28:35 +02:00
|
|
|
// Fetch bucket policy for a given bucket.
|
|
|
|
func (bp bucketPolicies) GetBucketPolicy(bucket string) *bucketPolicy {
|
|
|
|
bp.rwMutex.RLock()
|
|
|
|
defer bp.rwMutex.RUnlock()
|
|
|
|
return bp.bucketPolicyConfigs[bucket]
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set a new bucket policy for a bucket, this operation will overwrite
|
2016-10-13 18:19:04 +02:00
|
|
|
// any previous bucket policies for the bucket.
|
|
|
|
func (bp *bucketPolicies) SetBucketPolicy(bucket string, pCh policyChange) error {
|
2016-09-26 23:28:35 +02:00
|
|
|
bp.rwMutex.Lock()
|
|
|
|
defer bp.rwMutex.Unlock()
|
2016-10-13 18:19:04 +02:00
|
|
|
|
|
|
|
if pCh.IsRemove {
|
|
|
|
delete(bp.bucketPolicyConfigs, bucket)
|
|
|
|
} else {
|
|
|
|
if pCh.BktPolicy == nil {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
|
|
|
bp.bucketPolicyConfigs[bucket] = pCh.BktPolicy
|
2016-09-26 23:28:35 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loads all bucket policies from persistent layer.
|
|
|
|
func loadAllBucketPolicies(objAPI ObjectLayer) (policies map[string]*bucketPolicy, err error) {
|
|
|
|
// List buckets to proceed loading all notification configuration.
|
|
|
|
buckets, err := objAPI.ListBuckets()
|
|
|
|
errorIf(err, "Unable to list buckets.")
|
|
|
|
err = errorCause(err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
policies = make(map[string]*bucketPolicy)
|
|
|
|
var pErrs []error
|
|
|
|
// Loads bucket policy.
|
|
|
|
for _, bucket := range buckets {
|
|
|
|
policy, pErr := readBucketPolicy(bucket.Name, objAPI)
|
|
|
|
if pErr != nil {
|
|
|
|
switch pErr.(type) {
|
|
|
|
case BucketPolicyNotFound:
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
pErrs = append(pErrs, pErr)
|
|
|
|
// Continue to load other bucket policies if possible.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
policies[bucket.Name] = policy
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look for any errors occurred while reading bucket policies.
|
|
|
|
for _, pErr := range pErrs {
|
|
|
|
if pErr != nil {
|
|
|
|
return policies, pErr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Success.
|
|
|
|
return policies, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Intialize all bucket policies.
|
|
|
|
func initBucketPolicies(objAPI ObjectLayer) error {
|
|
|
|
if objAPI == nil {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read all bucket policies.
|
|
|
|
policies, err := loadAllBucketPolicies(objAPI)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Populate global bucket collection.
|
|
|
|
globalBucketPolicies = &bucketPolicies{
|
|
|
|
rwMutex: &sync.RWMutex{},
|
|
|
|
bucketPolicyConfigs: policies,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Success.
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-08-11 05:10:48 +02:00
|
|
|
// getOldBucketsConfigPath - get old buckets config path. (Only used for migrating old bucket policies)
|
2016-07-29 05:49:08 +02:00
|
|
|
func getOldBucketsConfigPath() (string, error) {
|
accessPolicy: Implement Put, Get, Delete access policy.
This patch implements Get,Put,Delete bucket policies
Supporting - http://docs.aws.amazon.com/AmazonS3/latest/dev/access-policy-language-overview.html
Currently supports following actions.
"*": true,
"s3:*": true,
"s3:GetObject": true,
"s3:ListBucket": true,
"s3:PutObject": true,
"s3:CreateBucket": true,
"s3:GetBucketLocation": true,
"s3:DeleteBucket": true,
"s3:DeleteObject": true,
"s3:AbortMultipartUpload": true,
"s3:ListBucketMultipartUploads": true,
"s3:ListMultipartUploadParts": true,
following conditions for "StringEquals" and "StringNotEquals"
"s3:prefix", "s3:max-keys"
2016-02-04 01:46:56 +01:00
|
|
|
configPath, err := getConfigPath()
|
|
|
|
if err != nil {
|
2016-04-29 23:24:10 +02:00
|
|
|
return "", err
|
accessPolicy: Implement Put, Get, Delete access policy.
This patch implements Get,Put,Delete bucket policies
Supporting - http://docs.aws.amazon.com/AmazonS3/latest/dev/access-policy-language-overview.html
Currently supports following actions.
"*": true,
"s3:*": true,
"s3:GetObject": true,
"s3:ListBucket": true,
"s3:PutObject": true,
"s3:CreateBucket": true,
"s3:GetBucketLocation": true,
"s3:DeleteBucket": true,
"s3:DeleteObject": true,
"s3:AbortMultipartUpload": true,
"s3:ListBucketMultipartUploads": true,
"s3:ListMultipartUploadParts": true,
following conditions for "StringEquals" and "StringNotEquals"
"s3:prefix", "s3:max-keys"
2016-02-04 01:46:56 +01:00
|
|
|
}
|
2016-08-11 05:10:48 +02:00
|
|
|
return path.Join(configPath, "buckets"), nil
|
accessPolicy: Implement Put, Get, Delete access policy.
This patch implements Get,Put,Delete bucket policies
Supporting - http://docs.aws.amazon.com/AmazonS3/latest/dev/access-policy-language-overview.html
Currently supports following actions.
"*": true,
"s3:*": true,
"s3:GetObject": true,
"s3:ListBucket": true,
"s3:PutObject": true,
"s3:CreateBucket": true,
"s3:GetBucketLocation": true,
"s3:DeleteBucket": true,
"s3:DeleteObject": true,
"s3:AbortMultipartUpload": true,
"s3:ListBucketMultipartUploads": true,
"s3:ListMultipartUploadParts": true,
following conditions for "StringEquals" and "StringNotEquals"
"s3:prefix", "s3:max-keys"
2016-02-04 01:46:56 +01:00
|
|
|
}
|
|
|
|
|
2016-08-30 19:04:50 +02:00
|
|
|
// readBucketPolicyJSON - reads bucket policy for an input bucket, returns BucketPolicyNotFound
|
|
|
|
// if bucket policy is not found.
|
|
|
|
func readBucketPolicyJSON(bucket string, objAPI ObjectLayer) (bucketPolicyReader io.Reader, err error) {
|
2016-09-22 01:38:50 +02:00
|
|
|
// Verify if bucket actually exists
|
2016-09-23 08:47:48 +02:00
|
|
|
if err = isBucketExist(bucket, objAPI); err != nil {
|
|
|
|
return nil, err
|
accessPolicy: Implement Put, Get, Delete access policy.
This patch implements Get,Put,Delete bucket policies
Supporting - http://docs.aws.amazon.com/AmazonS3/latest/dev/access-policy-language-overview.html
Currently supports following actions.
"*": true,
"s3:*": true,
"s3:GetObject": true,
"s3:ListBucket": true,
"s3:PutObject": true,
"s3:CreateBucket": true,
"s3:GetBucketLocation": true,
"s3:DeleteBucket": true,
"s3:DeleteObject": true,
"s3:AbortMultipartUpload": true,
"s3:ListBucketMultipartUploads": true,
"s3:ListMultipartUploadParts": true,
following conditions for "StringEquals" and "StringNotEquals"
"s3:prefix", "s3:max-keys"
2016-02-04 01:46:56 +01:00
|
|
|
}
|
2016-09-22 01:38:50 +02:00
|
|
|
|
2016-07-29 05:49:08 +02:00
|
|
|
policyPath := pathJoin(bucketConfigPrefix, bucket, policyJSON)
|
2016-08-09 20:33:45 +02:00
|
|
|
objInfo, err := objAPI.GetObjectInfo(minioMetaBucket, policyPath)
|
2016-08-25 18:39:01 +02:00
|
|
|
err = errorCause(err)
|
accessPolicy: Implement Put, Get, Delete access policy.
This patch implements Get,Put,Delete bucket policies
Supporting - http://docs.aws.amazon.com/AmazonS3/latest/dev/access-policy-language-overview.html
Currently supports following actions.
"*": true,
"s3:*": true,
"s3:GetObject": true,
"s3:ListBucket": true,
"s3:PutObject": true,
"s3:CreateBucket": true,
"s3:GetBucketLocation": true,
"s3:DeleteBucket": true,
"s3:DeleteObject": true,
"s3:AbortMultipartUpload": true,
"s3:ListBucketMultipartUploads": true,
"s3:ListMultipartUploadParts": true,
following conditions for "StringEquals" and "StringNotEquals"
"s3:prefix", "s3:max-keys"
2016-02-04 01:46:56 +01:00
|
|
|
if err != nil {
|
2016-07-29 05:49:08 +02:00
|
|
|
if _, ok := err.(ObjectNotFound); ok {
|
|
|
|
return nil, BucketPolicyNotFound{Bucket: bucket}
|
|
|
|
}
|
2016-09-06 22:30:05 +02:00
|
|
|
errorIf(err, "Unable to load policy for the bucket %s.", bucket)
|
2016-04-29 23:24:10 +02:00
|
|
|
return nil, err
|
accessPolicy: Implement Put, Get, Delete access policy.
This patch implements Get,Put,Delete bucket policies
Supporting - http://docs.aws.amazon.com/AmazonS3/latest/dev/access-policy-language-overview.html
Currently supports following actions.
"*": true,
"s3:*": true,
"s3:GetObject": true,
"s3:ListBucket": true,
"s3:PutObject": true,
"s3:CreateBucket": true,
"s3:GetBucketLocation": true,
"s3:DeleteBucket": true,
"s3:DeleteObject": true,
"s3:AbortMultipartUpload": true,
"s3:ListBucketMultipartUploads": true,
"s3:ListMultipartUploadParts": true,
following conditions for "StringEquals" and "StringNotEquals"
"s3:prefix", "s3:max-keys"
2016-02-04 01:46:56 +01:00
|
|
|
}
|
2016-07-29 05:49:08 +02:00
|
|
|
var buffer bytes.Buffer
|
2016-08-09 20:33:45 +02:00
|
|
|
err = objAPI.GetObject(minioMetaBucket, policyPath, 0, objInfo.Size, &buffer)
|
2016-08-25 18:39:01 +02:00
|
|
|
err = errorCause(err)
|
2016-07-29 05:49:08 +02:00
|
|
|
if err != nil {
|
|
|
|
if _, ok := err.(ObjectNotFound); ok {
|
2016-04-29 23:24:10 +02:00
|
|
|
return nil, BucketPolicyNotFound{Bucket: bucket}
|
accessPolicy: Implement Put, Get, Delete access policy.
This patch implements Get,Put,Delete bucket policies
Supporting - http://docs.aws.amazon.com/AmazonS3/latest/dev/access-policy-language-overview.html
Currently supports following actions.
"*": true,
"s3:*": true,
"s3:GetObject": true,
"s3:ListBucket": true,
"s3:PutObject": true,
"s3:CreateBucket": true,
"s3:GetBucketLocation": true,
"s3:DeleteBucket": true,
"s3:DeleteObject": true,
"s3:AbortMultipartUpload": true,
"s3:ListBucketMultipartUploads": true,
"s3:ListMultipartUploadParts": true,
following conditions for "StringEquals" and "StringNotEquals"
"s3:prefix", "s3:max-keys"
2016-02-04 01:46:56 +01:00
|
|
|
}
|
2016-09-06 22:30:05 +02:00
|
|
|
errorIf(err, "Unable to load policy for the bucket %s.", bucket)
|
2016-04-29 23:24:10 +02:00
|
|
|
return nil, err
|
accessPolicy: Implement Put, Get, Delete access policy.
This patch implements Get,Put,Delete bucket policies
Supporting - http://docs.aws.amazon.com/AmazonS3/latest/dev/access-policy-language-overview.html
Currently supports following actions.
"*": true,
"s3:*": true,
"s3:GetObject": true,
"s3:ListBucket": true,
"s3:PutObject": true,
"s3:CreateBucket": true,
"s3:GetBucketLocation": true,
"s3:DeleteBucket": true,
"s3:DeleteObject": true,
"s3:AbortMultipartUpload": true,
"s3:ListBucketMultipartUploads": true,
"s3:ListMultipartUploadParts": true,
following conditions for "StringEquals" and "StringNotEquals"
"s3:prefix", "s3:max-keys"
2016-02-04 01:46:56 +01:00
|
|
|
}
|
2016-08-30 19:04:50 +02:00
|
|
|
|
|
|
|
return &buffer, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// readBucketPolicy - reads bucket policy for an input bucket, returns BucketPolicyNotFound
|
|
|
|
// if bucket policy is not found. This function also parses the bucket policy into an object.
|
|
|
|
func readBucketPolicy(bucket string, objAPI ObjectLayer) (*bucketPolicy, error) {
|
|
|
|
// Read bucket policy JSON.
|
|
|
|
bucketPolicyReader, err := readBucketPolicyJSON(bucket, objAPI)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-08-11 05:10:48 +02:00
|
|
|
// Parse the saved policy.
|
|
|
|
var policy = &bucketPolicy{}
|
2016-08-30 19:04:50 +02:00
|
|
|
err = parseBucketPolicy(bucketPolicyReader, policy)
|
2016-08-11 05:10:48 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
return policy, nil
|
accessPolicy: Implement Put, Get, Delete access policy.
This patch implements Get,Put,Delete bucket policies
Supporting - http://docs.aws.amazon.com/AmazonS3/latest/dev/access-policy-language-overview.html
Currently supports following actions.
"*": true,
"s3:*": true,
"s3:GetObject": true,
"s3:ListBucket": true,
"s3:PutObject": true,
"s3:CreateBucket": true,
"s3:GetBucketLocation": true,
"s3:DeleteBucket": true,
"s3:DeleteObject": true,
"s3:AbortMultipartUpload": true,
"s3:ListBucketMultipartUploads": true,
"s3:ListMultipartUploadParts": true,
following conditions for "StringEquals" and "StringNotEquals"
"s3:prefix", "s3:max-keys"
2016-02-04 01:46:56 +01:00
|
|
|
}
|
|
|
|
|
2016-08-11 05:10:48 +02:00
|
|
|
// removeBucketPolicy - removes any previously written bucket policy. Returns BucketPolicyNotFound
|
|
|
|
// if no policies are found.
|
2016-08-09 20:33:45 +02:00
|
|
|
func removeBucketPolicy(bucket string, objAPI ObjectLayer) error {
|
2016-09-22 01:38:50 +02:00
|
|
|
// Verify if bucket actually exists
|
|
|
|
if err := isBucketExist(bucket, objAPI); err != nil {
|
|
|
|
return err
|
accessPolicy: Implement Put, Get, Delete access policy.
This patch implements Get,Put,Delete bucket policies
Supporting - http://docs.aws.amazon.com/AmazonS3/latest/dev/access-policy-language-overview.html
Currently supports following actions.
"*": true,
"s3:*": true,
"s3:GetObject": true,
"s3:ListBucket": true,
"s3:PutObject": true,
"s3:CreateBucket": true,
"s3:GetBucketLocation": true,
"s3:DeleteBucket": true,
"s3:DeleteObject": true,
"s3:AbortMultipartUpload": true,
"s3:ListBucketMultipartUploads": true,
"s3:ListMultipartUploadParts": true,
following conditions for "StringEquals" and "StringNotEquals"
"s3:prefix", "s3:max-keys"
2016-02-04 01:46:56 +01:00
|
|
|
}
|
2016-09-22 01:38:50 +02:00
|
|
|
|
2016-07-29 05:49:08 +02:00
|
|
|
policyPath := pathJoin(bucketConfigPrefix, bucket, policyJSON)
|
2016-08-09 20:33:45 +02:00
|
|
|
if err := objAPI.DeleteObject(minioMetaBucket, policyPath); err != nil {
|
2016-08-25 18:39:01 +02:00
|
|
|
errorIf(err, "Unable to remove bucket-policy on bucket %s.", bucket)
|
|
|
|
err = errorCause(err)
|
2016-07-29 05:49:08 +02:00
|
|
|
if _, ok := err.(ObjectNotFound); ok {
|
2016-04-29 23:24:10 +02:00
|
|
|
return BucketPolicyNotFound{Bucket: bucket}
|
accessPolicy: Implement Put, Get, Delete access policy.
This patch implements Get,Put,Delete bucket policies
Supporting - http://docs.aws.amazon.com/AmazonS3/latest/dev/access-policy-language-overview.html
Currently supports following actions.
"*": true,
"s3:*": true,
"s3:GetObject": true,
"s3:ListBucket": true,
"s3:PutObject": true,
"s3:CreateBucket": true,
"s3:GetBucketLocation": true,
"s3:DeleteBucket": true,
"s3:DeleteObject": true,
"s3:AbortMultipartUpload": true,
"s3:ListBucketMultipartUploads": true,
"s3:ListMultipartUploadParts": true,
following conditions for "StringEquals" and "StringNotEquals"
"s3:prefix", "s3:max-keys"
2016-02-04 01:46:56 +01:00
|
|
|
}
|
2016-04-29 23:24:10 +02:00
|
|
|
return err
|
accessPolicy: Implement Put, Get, Delete access policy.
This patch implements Get,Put,Delete bucket policies
Supporting - http://docs.aws.amazon.com/AmazonS3/latest/dev/access-policy-language-overview.html
Currently supports following actions.
"*": true,
"s3:*": true,
"s3:GetObject": true,
"s3:ListBucket": true,
"s3:PutObject": true,
"s3:CreateBucket": true,
"s3:GetBucketLocation": true,
"s3:DeleteBucket": true,
"s3:DeleteObject": true,
"s3:AbortMultipartUpload": true,
"s3:ListBucketMultipartUploads": true,
"s3:ListMultipartUploadParts": true,
following conditions for "StringEquals" and "StringNotEquals"
"s3:prefix", "s3:max-keys"
2016-02-04 01:46:56 +01:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-10-13 18:19:04 +02:00
|
|
|
// writeBucketPolicy - save a bucket policy that is assumed to be
|
|
|
|
// validated.
|
|
|
|
func writeBucketPolicy(bucket string, objAPI ObjectLayer, bpy *bucketPolicy) error {
|
2016-09-22 01:38:50 +02:00
|
|
|
// Verify if bucket actually exists
|
|
|
|
if err := isBucketExist(bucket, objAPI); err != nil {
|
|
|
|
return err
|
accessPolicy: Implement Put, Get, Delete access policy.
This patch implements Get,Put,Delete bucket policies
Supporting - http://docs.aws.amazon.com/AmazonS3/latest/dev/access-policy-language-overview.html
Currently supports following actions.
"*": true,
"s3:*": true,
"s3:GetObject": true,
"s3:ListBucket": true,
"s3:PutObject": true,
"s3:CreateBucket": true,
"s3:GetBucketLocation": true,
"s3:DeleteBucket": true,
"s3:DeleteObject": true,
"s3:AbortMultipartUpload": true,
"s3:ListBucketMultipartUploads": true,
"s3:ListMultipartUploadParts": true,
following conditions for "StringEquals" and "StringNotEquals"
"s3:prefix", "s3:max-keys"
2016-02-04 01:46:56 +01:00
|
|
|
}
|
|
|
|
|
2016-10-13 18:19:04 +02:00
|
|
|
buf, err := json.Marshal(bpy)
|
|
|
|
if err != nil {
|
|
|
|
errorIf(err, "Unable to marshal bucket policy '%v' to JSON", *bpy)
|
|
|
|
return err
|
|
|
|
}
|
2016-07-29 05:49:08 +02:00
|
|
|
policyPath := pathJoin(bucketConfigPrefix, bucket, policyJSON)
|
2016-10-13 18:19:04 +02:00
|
|
|
if _, err := objAPI.PutObject(minioMetaBucket, policyPath, int64(len(buf)), bytes.NewReader(buf), nil, ""); err != nil {
|
2016-08-25 18:39:01 +02:00
|
|
|
errorIf(err, "Unable to set policy for the bucket %s", bucket)
|
|
|
|
return errorCause(err)
|
|
|
|
}
|
|
|
|
return nil
|
accessPolicy: Implement Put, Get, Delete access policy.
This patch implements Get,Put,Delete bucket policies
Supporting - http://docs.aws.amazon.com/AmazonS3/latest/dev/access-policy-language-overview.html
Currently supports following actions.
"*": true,
"s3:*": true,
"s3:GetObject": true,
"s3:ListBucket": true,
"s3:PutObject": true,
"s3:CreateBucket": true,
"s3:GetBucketLocation": true,
"s3:DeleteBucket": true,
"s3:DeleteObject": true,
"s3:AbortMultipartUpload": true,
"s3:ListBucketMultipartUploads": true,
"s3:ListMultipartUploadParts": true,
following conditions for "StringEquals" and "StringNotEquals"
"s3:prefix", "s3:max-keys"
2016-02-04 01:46:56 +01:00
|
|
|
}
|