Renamed test_buckets
This commit is contained in:
parent
74da180a07
commit
1d8cfbfc07
@ -9,7 +9,7 @@ RUN pip install --no-cache-dir -r /tmp/requirements.txt \
|
||||
USER appuser
|
||||
WORKDIR /home/appuser/work
|
||||
|
||||
COPY --chown=appuser:appuser test_script.py /home/appuser/work/test_script.py
|
||||
COPY --chown=appuser:appuser test_script.py /home/appuser/work/test_buckets.py
|
||||
|
||||
EXPOSE 8888
|
||||
|
||||
|
||||
37
images/jupyter/test_buckets.py
Normal file
37
images/jupyter/test_buckets.py
Normal file
@ -0,0 +1,37 @@
|
||||
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