lab4: s3 attachments, private bucket, healthchecks, tests and report
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
"""Prove S3 is not public and API-scoped credentials cannot list other buckets."""
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
from botocore.exceptions import ClientError
|
||||
from .storage import s3, bucket
|
||||
import os
|
||||
import uuid
|
||||
|
||||
url = os.getenv("S3_ENDPOINT", "http://s3:8333").rstrip("/") + "/" + bucket + "/random-inaccessible-key"
|
||||
try:
|
||||
urllib.request.urlopen(url, timeout=4)
|
||||
except urllib.error.HTTPError as exc:
|
||||
assert exc.code in (401, 403), f"expected S3 denied, got {exc.code}"
|
||||
else:
|
||||
raise AssertionError("UNSAFE: direct unsigned S3 request succeeded")
|
||||
try:
|
||||
s3.create_bucket(Bucket="forbidden-probe-" + uuid.uuid4().hex[:16])
|
||||
except ClientError as exc:
|
||||
assert exc.response["Error"]["Code"] in ("AccessDenied", "403"), "unexpected S3 result"
|
||||
else:
|
||||
raise AssertionError("UNSAFE: API credentials have global create-bucket privileges")
|
||||
print("PASS: S3 requires authentication; API credentials restricted to own bucket")
|
||||
Reference in New Issue
Block a user