With last commit
This commit is contained in:
parent
1d8cfbfc07
commit
6945db40e1
@ -1,37 +0,0 @@
|
||||
import os
|
||||
import boto3
|
||||
|
||||
s3 = boto3.client(
|
||||
's3',
|
||||
endpoint_url=os.environ['S3_ENDPOINT'],
|
||||
aws_access_key_id=os.environ['MINIO_ACCESS_KEY_ID'],
|
||||
aws_secret_access_key=os.environ['MINIO_SECRET_ACCESS_KEY']
|
||||
)
|
||||
|
||||
ref_bucket = os.environ['BUCKET_REF']
|
||||
work_bucket = os.environ['BUCKET_WORK']
|
||||
|
||||
# 1. READ FROM REFERENCE BUCKET (Should PASS)
|
||||
response = s3.list_objects_v2(Bucket=ref_bucket)
|
||||
data = s3.get_object(Bucket=ref_bucket, Key="hello.txt")['Body'].read()
|
||||
print("SUCCESS: List items in ref bucket:", response['KeyCount'], data.decode())
|
||||
|
||||
# 2. WRITE TO REFERENCE BUCKET (Should FAIL with 403 Forbidden)
|
||||
try:
|
||||
s3.put_object(Bucket=ref_bucket, Key="test.txt", Body=b"forbidden write")
|
||||
print("ERROR: Write succeeded when it should be forbidden!")
|
||||
except Exception as e:
|
||||
print("SUCCESS: Write to reference bucket blocked:", e)
|
||||
|
||||
# 3. WRITE & READ WORK BUCKET (Should PASS)
|
||||
s3.put_object(Bucket=work_bucket, Key="data.txt", Body=b"hello tenant")
|
||||
data = s3.get_object(Bucket=work_bucket, Key="data.txt")['Body'].read()
|
||||
print("SUCCESS: Read back from work bucket:", data.decode())
|
||||
|
||||
# 4. ACCESS OTHER TENANT BUCKET (Should FAIL with Access Denied)
|
||||
try:
|
||||
s3.list_objects_v2(Bucket="work-tenant-b")
|
||||
print("ERROR: Accessed tenant-b bucket!")
|
||||
except Exception as e:
|
||||
print("SUCCESS: Access to tenant-b blocked:", e)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user