This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
"""Check allowed and denied S3 prefixes using the current service identity."""
|
||||
import json
|
||||
import http.client
|
||||
import urllib.parse
|
||||
from botocore.auth import S3SigV4Auth
|
||||
from botocore.awsrequest import AWSRequest
|
||||
from botocore.credentials import Credentials
|
||||
import os
|
||||
import ssl
|
||||
import urllib.request
|
||||
@@ -38,3 +43,24 @@ else:
|
||||
finally:
|
||||
client.close()
|
||||
print(f'PASS {role}: allowed staging write; forbidden prefix denied')
|
||||
|
||||
# Repeated Authorization fields must fail even for an otherwise allowed read.
|
||||
endpoint = urllib.parse.urlsplit(os.environ['S3_ENDPOINT'])
|
||||
path = '/' + bucket + '/' + allowed
|
||||
req = AWSRequest(method='GET', url=os.environ['S3_ENDPOINT'] + path)
|
||||
S3SigV4Auth(Credentials(values['S3_ACCESS_KEY_ID'], values['S3_SECRET_ACCESS_KEY']),
|
||||
's3', 'us-east-1').add_auth(req)
|
||||
conn = http.client.HTTPSConnection(endpoint.hostname, endpoint.port,
|
||||
context=ssl.create_default_context(cafile=os.environ['AWS_CA_BUNDLE']), timeout=10)
|
||||
try:
|
||||
conn.putrequest('GET', path)
|
||||
for key, value in req.headers.items():
|
||||
conn.putheader(key, value)
|
||||
conn.putheader('Authorization', req.headers['Authorization'])
|
||||
conn.endheaders()
|
||||
response = conn.getresponse()
|
||||
assert response.status == 403, 'duplicate Authorization not denied'
|
||||
response.read()
|
||||
finally:
|
||||
conn.close()
|
||||
print(f'PASS {role}: duplicate Authorization denied')
|
||||
|
||||
Reference in New Issue
Block a user