Лаба 4: SeaweedFS S3-хранилище и вложения (оценка 4)

Переиспользован стек lab3 (LB/2 реплики/Postgres/Redis/идемпотентность).
Добавлены: S3-хранилище байтов вложений (SeaweedFS вместо MinIO — публичные
MinIO-образы недоступны без авторизации), метаданные attachments в Postgres,
проверка изображений по содержимому с защитой от decompression bomb,
ограниченные S3-credentials, скрипт сверки orphan-объектов. make test/
test-persistence/test-failover/validate зелёные для обеих реплик; собраны
доказательства по превышению размера, MIME-спуфингу, чужим attachment_id,
приватности bucket, конкурентным загрузкам и orphan-очистке — см. REPORT.md.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-10-30 00:59:13 +03:00
co-authored by Claude Sonnet 5
parent ec540a1a72
commit 38268f63f8
23 changed files with 1584 additions and 16 deletions
+48
View File
@@ -0,0 +1,48 @@
token=1ZC9D9imXzZUpIvaW8qOmVdr33YVdMPicZRAWqsgGoU chat=2d72b0c1-df2c-4113-a32f-1fb75bee58fc
--- oversized (11MB) ---
<html>
<head><title>413 Request Entity Too Large</title></head>
<body>
<center><h1>413 Request Entity Too Large</h1></center>
<hr><center>nginx/1.27.2</center>
</body>
</html>
http_code: 413
--- corrupted PNG bytes ---
{"error":{"code":"unsupported_media_type","message":"cannot identify image file <_io.BytesIO object at 0x7cb8783334c0>","request_id":"2bd8f7228a8d4abe8931f9895b47ee3d"}}
http_code: 415
--- oversized (11MB) after fix ---
--- oversized (11MB) after nginx fix, chat=837a45cf-4efb-4eac-9b22-cac92f2f028f ---
<html>
<head><title>413 Request Entity Too Large</title></head>
<body>
<center><h1>413 Request Entity Too Large</h1></center>
<hr><center>nginx/1.27.2</center>
</body>
</html>
http_code: 413
--- oversized (11MB) after real nginx reload, chat=c195690d-349d-42b1-a0ee-64aed48624fc ---
{"error":{"code":"payload_too_large","message":"upload exceeds 10485760 bytes","request_id":"05012b5eb87244f5b148cbe6d0514322"}}
http_code: 413
--- MIME spoof: real JPEG declared as image/png, chat=3b6a90a4-389d-4de7-94bf-eafa440d429d ---
{"id":"becd3307-d724-49ea-8489-0fd433ac48db","chat_id":"3b6a90a4-389d-4de7-94bf-eafa440d429d","owner_id":"d0d5bf95-89b5-4b76-a3fe-50f7dc0ddf09","filename":"spoof.png","content_type":"image/png","size_bytes":111817,"sha256":"99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75","status":"ready","variants":[],"error_code":null,"created_at":"2026-10-29T21:53:55.349174Z","updated_at":"2026-10-29T21:53:55.349174Z"}
http_code: 201
--- real MIME spoof: genuine JPEG bytes, declared Content-Type: image/png, chat=65cb5873-b196-4b26-9e00-1fabec6b9fb7 ---
{"error":{"code":"unsupported_media_type","message":"declared content type does not match actual image format","request_id":"087fa41902454f72983f865a488fe0b7"}}
http_code: 415
--- foreign attachment_id: attach chatA's attachment (628e92e9-c127-48f8-b7b5-c5fc91907503) to a message in chatB ---
{"error":{"code":"not_found","message":"one or more attachment_ids are not available in this chat","request_id":"306a37f74afe49b2aedb3cfb7fedcb82"}}
http_code: 404
--- direct unauthenticated S3 access check (must NOT be exposed to host) ---
host->seaweedfs:8333 directly: 000 (curl exit 7)
host->seaweedfs:8333 directly: 000
exit=7
--- 15 concurrent uploads (sample.png, ~112KB each) -- all 201, memory before/after ---
before:
mtusi2026lab4-api1-1 73.41MiB / 256MiB
mtusi2026lab4-api2-1 69.55MiB / 256MiB
after:
mtusi2026lab4-api1-1 75.21MiB / 256MiB
mtusi2026lab4-api2-1 68.92MiB / 256MiB
+7
View File
@@ -0,0 +1,7 @@
1 orphaned object(s) older than 0 minutes with no DB row.
attachments/orphan-demo-key
Dry-run: nothing deleted. Re-run with --delete to remove them.
--- now with --delete ---
1 orphaned object(s) older than 0 minutes with no DB row.
attachments/orphan-demo-key
Deleted 1 orphan(s).