feat: реализовать ЛР7 — TLS, mTLS, OpenBao и hardening
Skeleton contracts / contracts (pull_request) Blocked by required conditions

This commit is contained in:
ferraronp
2026-11-26 19:50:38 +03:00
parent 20afc2c790
commit ca7515601a
98 changed files with 6252 additions and 107 deletions
+40
View File
@@ -0,0 +1,40 @@
"""Verify bucket is private at S3 boundary (not merely hidden behind HTTP API)."""
import json
import os
import boto3
from botocore import UNSIGNED
from botocore.config import Config
from botocore.exceptions import ClientError
from .attachments import BUCKET, s3_client
def main():
client = s3_client()
client.head_bucket(Bucket=BUCKET) # restricted app identity works
unauth = boto3.client("s3", endpoint_url=os.environ["S3_ENDPOINT"],
region_name="us-east-1", config=Config(signature_version=UNSIGNED,
s3={"addressing_style":"path"}))
try:
unauth.list_objects_v2(Bucket=BUCKET, MaxKeys=1)
except ClientError as exc:
status = exc.response.get("ResponseMetadata", {}).get("HTTPStatusCode")
if status not in (401,403):
raise RuntimeError("Unexpected anonymous S3 response") from None
else:
raise RuntimeError("Private bucket leaked object list to anonymous caller")
listing = client.list_objects_v2(Bucket=BUCKET, MaxKeys=1)
keys = [entry["Key"] for entry in listing.get("Contents", [])]
if keys:
try:
unauth.get_object(Bucket=BUCKET, Key=keys[0])
except ClientError as exc:
status = exc.response.get("ResponseMetadata", {}).get("HTTPStatusCode")
if status not in (401, 403):
raise RuntimeError("Unexpected anonymous object GET response") from None
else:
raise RuntimeError("Private S3 object downloadable anonymously")
print(json.dumps({"private_bucket": True, "anonymous_listing": "denied",
"anonymous_object_get": "denied" if keys else "not_tested_empty_bucket"}))
if __name__ == "__main__":
main()