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

api: add get_bucket_policy and set_bucket_policy. #385

Merged
merged 1 commit into from
Jul 29, 2016

Conversation

balamurugana
Copy link
Member

Fixes ##377

@harshavardhana
Copy link
Member

what else is needed here @balamurugana ?

@harshavardhana
Copy link
Member

what else is needed here @balamurugana ?

Checking again what else is pending here to get this merged @balamurugana ?

@balamurugana
Copy link
Member Author

balamurugana commented Jul 27, 2016

There is an issue which delete policy. Fixing now.

Fixed in the latest refresh.

@balamurugana
Copy link
Member Author

balamurugana commented Jul 27, 2016

When running below sequence, there is a left over s3:ListBucket statement.

$ mc.set_bucket_policy(Policy.READ_ONLY, BUCKET, 'hello')
$ mc.set_bucket_policy(Policy.READ_WRITE, BUCKET, 'world')
$ mc.set_bucket_policy(Policy.READ_WRITE, BUCKET)
$ mc.set_bucket_policy(Policy.NONE, BUCKET)

Fixing it now.

Fixed in latest refresh.

@balamurugana
Copy link
Member Author

Below policy JSON is set.

mc.set_bucket_policy(Policy.READ_ONLY, "mybucket", "hello")
{"Statement": [{"Action": "s3:GetBucketLocation",
                 "Effect": "Allow",
                 "Principal": {"AWS": "*"},
                 "Resource": "arn:aws:s3:::mybucket",
                 "Sid": ""},
                {"Action": "s3:ListBucket",
                 "Condition": {"StringEquals": {"s3:prefix": "hello"}},
                 "Effect": "Allow",
                 "Principal": {"AWS": "*"},
                 "Resource": "arn:aws:s3:::mybucket",
                 "Sid": ""},
                {"Action": "s3:GetObject",
                 "Effect": "Allow",
                 "Principal": {"AWS": "*"},
                 "Resource": "arn:aws:s3:::mybucket/hello*",
                 "Sid": ""}],
 "Version": "2012-10-17"}
mc.set_bucket_policy(Policy.READ_WRITE, "mybucket", "world")
{"Statement": [{"Action": "s3:GetBucketLocation",
                 "Effect": "Allow",
                 "Principal": {"AWS": "*"},
                 "Resource": "arn:aws:s3:::mybucket",
                 "Sid": ""},
                {"Action": "s3:GetObject",
                 "Effect": "Allow",
                 "Principal": {"AWS": "*"},
                 "Resource": "arn:aws:s3:::mybucket/hello*",
                 "Sid": ""},
                {"Action": "s3:ListBucket",
                 "Condition": {"StringEquals": {"s3:prefix": ["world", "hello"]}},
                 "Effect": "Allow",
                 "Principal": {"AWS": "*"},
                 "Resource": "arn:aws:s3:::mybucket",
                 "Sid": ""},
                {"Action": "s3:ListBucketMultipartUploads",
                 "Effect": "Allow",
                 "Principal": {"AWS": "*"},
                 "Resource": "arn:aws:s3:::mybucket",
                 "Sid": ""},
                {"Action": ["s3:ListMultipartUploadParts",
                             "s3:GetObject",
                             "s3:AbortMultipartUpload",
                             "s3:DeleteObject",
                             "s3:PutObject"],
                 "Effect": "Allow",
                 "Principal": {"AWS": "*"},
                 "Resource": "arn:aws:s3:::mybucket/world*",
                 "Sid": ""}],
 "Version": "2012-10-17"}
mc.set_bucket_policy(Policy.READ_WRITE, "mybucket")
{"Statement": [{"Action": "s3:GetBucketLocation",
                 "Effect": "Allow",
                 "Principal": {"AWS": "*"},
                 "Resource": "arn:aws:s3:::mybucket",
                 "Sid": ""},
                {"Action": "s3:GetObject",
                 "Effect": "Allow",
                 "Principal": {"AWS": "*"},
                 "Resource": "arn:aws:s3:::mybucket/hello*",
                 "Sid": ""},
                {"Action": "s3:ListBucketMultipartUploads",
                 "Effect": "Allow",
                 "Principal": {"AWS": "*"},
                 "Resource": "arn:aws:s3:::mybucket",
                 "Sid": ""},
                {"Action": ["s3:ListMultipartUploadParts",
                             "s3:GetObject",
                             "s3:AbortMultipartUpload",
                             "s3:DeleteObject",
                             "s3:PutObject"],
                 "Effect": "Allow",
                 "Principal": {"AWS": "*"},
                 "Resource": "arn:aws:s3:::mybucket/world*",
                 "Sid": ""},
                {"Action": "s3:ListBucket",
                 "Condition": {"StringEquals": {"s3:prefix": ["world", "hello"]}},
                 "Effect": "Allow",
                 "Principal": {"AWS": "*"},
                 "Resource": "arn:aws:s3:::mybucket",
                 "Sid": ""},
                {"Action": "s3:ListBucket",
                 "Effect": "Allow",
                 "Principal": {"AWS": "*"},
                 "Resource": "arn:aws:s3:::mybucket",
                 "Sid": ""},
                {"Action": ["s3:ListMultipartUploadParts",
                             "s3:GetObject",
                             "s3:AbortMultipartUpload",
                             "s3:DeleteObject",
                             "s3:PutObject"],
                 "Effect": "Allow",
                 "Principal": {"AWS": "*"},
                 "Resource": "arn:aws:s3:::mybucket/*",
                 "Sid": ""}],
 "Version": "2012-10-17"}


policy_dict = self._get_bucket_policy(bucket_name)
if policy_access == policy.Policy.NONE and not policy_dict:
return
Copy link
Member

Choose a reason for hiding this comment

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

We need to return an error here..We raise an exception. NoSuchBucketPolicy

@harshavardhana
Copy link
Member

@balamurugana can you add examples, update README.md and API.md as well.

@balamurugana
Copy link
Member Author

@balamurugana can you add examples, update README.md and API.md as well.

Done in latest refresh.

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.

2 participants