Skip to content

Commit 89d9c71

Browse files
authored
ST469 - apps/augmentedreality - improve minio config, use allowed_buckets for configuration (#33)
1 parent 6be2399 commit 89d9c71

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

adhocracy-plus/config/settings/local.py.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ GEOS_LIBRARY_PATH = "/opt/homebrew/Cellar/geos/3.13.1/lib/libgeos_c.dylib"
88
MINIO_DATA = {
99
"endpoint": "",
1010
"region": "eu-central-1",
11-
"bucket": "",
11+
"allowed_buckets": [""],
1212
"accessKey": "",
1313
"secretKey": ""
1414
}

changelog/469.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Changed
2+
3+
- Replace `bucket_name` with `allowed_buckets` in minio config, verifies bucket_name requested by frontend

util/minio_client.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class MinIOClient:
1313
def client(self):
1414
if all(
1515
attr in settings.MINIO_DATA
16-
for attr in ["endpoint", "accessKey", "secretKey"]
16+
for attr in ["endpoint", "accessKey", "secretKey", "allowed_buckets"]
1717
):
1818
return Minio(
1919
settings.MINIO_DATA.get("endpoint"),
@@ -30,10 +30,16 @@ def client(self):
3030
def get_presigned_url(self, mesh_id, expires=timedelta(hours=1)):
3131
try:
3232
parts = mesh_id.split("/", 1)
33-
object_name = parts[1]
34-
return self.client.presigned_get_object(
35-
settings.MINIO_DATA.get("bucket"), object_name, expires=expires
36-
)
33+
bucket_name = parts[0]
34+
allowed_buckets = settings.MINIO_DATA.get("allowed_buckets")
35+
if bucket_name in allowed_buckets:
36+
object_name = parts[1]
37+
return self.client.presigned_get_object(
38+
bucket_name, object_name, expires=expires
39+
)
40+
else:
41+
logger.error(f"Access to bucket {bucket_name} is not allowed.")
42+
return None
3743
except Exception as e:
3844
logger.error(f"Failed to generate presigned URL for {mesh_id}: {str(e)}")
3945
return None

0 commit comments

Comments
 (0)