Skip to content

Commit

Permalink
PublicAccessBlock: test access deny via bucket policy
Browse files Browse the repository at this point in the history
Make sure 403 is returned when access is denied via s3:GetBucketPublicAccessBlock action on GetBucketPublicAccessBlock

Refs: ceph/ceph#55652
Signed-off-by: Seena Fallah <seenafallah@gmail.com>
(cherry picked from commit 3af4231)
  • Loading branch information
clwluvw authored and cbodley committed Mar 8, 2024
1 parent 43dff59 commit 4054d4b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions s3tests_boto3/functional/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ def to_json(self):

return json.dumps(policy_dict)

def make_json_policy(action, resource, principal={"AWS": "*"}, conditions=None):
def make_json_policy(action, resource, principal={"AWS": "*"}, effect="Allow", conditions=None):
"""
Helper function to make single statement policies
"""
s = Statement(action, resource, principal, condition=conditions)
s = Statement(action, resource, principal, effect=effect, condition=conditions)
p = Policy()
return p.add_statement(s).to_json()
28 changes: 28 additions & 0 deletions s3tests_boto3/functional/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -12607,6 +12607,34 @@ def test_get_undefined_public_block():

assert response_code == 'NoSuchPublicAccessBlockConfiguration'

def test_get_public_block_deny_bucket_policy():
bucket_name = get_new_bucket()
client = get_client()

access_conf = {'BlockPublicAcls': True,
'IgnorePublicAcls': True,
'BlockPublicPolicy': True,
'RestrictPublicBuckets': False}
client.put_public_access_block(Bucket=bucket_name, PublicAccessBlockConfiguration=access_conf)

# make sure we can get the public access block
resp = client.get_public_access_block(Bucket=bucket_name)
assert resp['PublicAccessBlockConfiguration']['BlockPublicAcls'] == access_conf['BlockPublicAcls']
assert resp['PublicAccessBlockConfiguration']['BlockPublicPolicy'] == access_conf['BlockPublicPolicy']
assert resp['PublicAccessBlockConfiguration']['IgnorePublicAcls'] == access_conf['IgnorePublicAcls']
assert resp['PublicAccessBlockConfiguration']['RestrictPublicBuckets'] == access_conf['RestrictPublicBuckets']

# make bucket policy to deny access
resource = _make_arn_resource(bucket_name)
policy_document = make_json_policy("s3:GetBucketPublicAccessBlock",
resource, effect="Deny")
client.put_bucket_policy(Bucket=bucket_name, Policy=policy_document)

# check if the access is denied
e = assert_raises(ClientError, client.get_public_access_block, Bucket=bucket_name)
status, error_code = _get_status_and_error_code(e.response)
assert status == 403

def test_put_public_block():
#client = get_svc_client(svc='s3control', client_config=Config(s3={'addressing_style': 'path'}))
bucket_name = get_new_bucket()
Expand Down

0 comments on commit 4054d4b

Please sign in to comment.