add level 3
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
Матвей
2026-11-07 22:00:19 +03:00
parent 7b6c10cde9
commit 9cb708335d
14 changed files with 482 additions and 22 deletions
+26
View File
@@ -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')