feat: implement lab4 MinIO attachments

This commit is contained in:
EgorAnti
2026-11-11 20:40:09 +03:00
parent ec540a1a72
commit e06678b6a9
111 changed files with 5733 additions and 15 deletions
+20
View File
@@ -5,3 +5,23 @@
В REPORT.md сопоставьте роль → service name → версия/digest → health/readiness → volume → сеть/порт → способ передачи credentials. Приведите bootstrap (schema, bucket, broker topology, а с lab6 provisioning) и безопасное повторение этих команд.
Приложение строится из исходников. Не используйте заранее существующий образ преподавательского сервера вместо своей реализации. Restart hook перезапускает все соответствующие stores с volumes; failover hook останавливает только заданную API-реплику.
## MinIO в этом решении
- Сервер: `bitnamilegacy/minio:2025.4.22-debian-12-r1` с digest
`sha256:d7cd0e172c4cc0870f4bdc3142018e2a37be9acf04d68f386600daad427e0cab`.
- Bootstrap-клиент: `bitnamilegacy/minio-client:2025.4.16-debian-12-r0` с digest
`sha256:28e38f52642c06a2344fa974cf55786b4c52601b6b9b0676c68d40ee0876a5bc`.
- Bucket `messenger-attachments` создаёт одноразовый `minio-init`. Команда
`mc anonymous set none` явно оставляет bucket приватным.
- API не получает root credentials. Bootstrap создаёт отдельного пользователя и
назначает политику из `minio-api-policy.json`: только list/location bucket и
get/put/delete объектов под префиксом `attachments/`.
- Порт S3 и административная консоль наружу не публикуются. API обращается к
`http://minio:9000` в Compose или `http://hla-state_minio:9000` в Swarm.
- Байты лежат в named volume `minio-data`; PostgreSQL хранит только метаданные и
серверный object key. Клиентский filename никогда не используется как key.
Политика содержит placeholder `__S3_BUCKET__`; bootstrap подставляет фактическое
значение `S3_BUCKET` перед созданием policy. Повторный запуск безопасен: bucket,
user и policy переиспользуются, а private anonymous policy устанавливается снова.
+26
View File
@@ -0,0 +1,26 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::__S3_BUCKET__"
]
},
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject"
],
"Resource": [
"arn:aws:s3:::__S3_BUCKET__/attachments/*"
]
}
]
}
+86
View File
@@ -0,0 +1,86 @@
worker_processes auto;
worker_shutdown_timeout 10s;
events {
worker_connections 1024;
}
http {
# Let the application enforce the exact 10 MiB contract and return JSON.
client_max_body_size 11m;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log warn;
# Docker embedded DNS returns current Compose replicas. Nginx OSS 1.27.3+
# refreshes these addresses without a configuration reload.
resolver 127.0.0.11 valid=2s ipv6=off;
resolver_timeout 1s;
upstream api_backend {
zone api_backend 64k;
least_conn;
server api:8080 resolve max_fails=1 fail_timeout=2s;
keepalive 32;
}
server {
listen 80;
server_name _;
proxy_intercept_errors on;
error_page 502 503 504 = @no_ready_api;
location = /nginx-health {
access_log off;
default_type application/json;
return 200 '{"status":"ok"}';
}
# After both peers have refused traffic or become unreachable, Nginx
# would normally emit its own HTML 502. Keep the public API contract:
# no ready backend is a JSON 503 with the required tracing headers.
location @no_ready_api {
internal;
default_type application/json;
add_header X-Request-Id $request_id always;
add_header X-Instance-Id nginx always;
add_header Cache-Control "no-store" always;
return 503 '{"error":{"code":"unavailable","message":"No ready API backend","request_id":"$request_id"}}';
}
# Message POST is the only non-idempotent HTTP method that is safe to
# replay here: the API requires Idempotency-Key and commits the message
# together with its shared PostgreSQL idempotency record.
location ~ ^/api/v1/chats/[0-9a-fA-F-]+/messages$ {
proxy_pass http://api_backend;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_request_buffering on;
proxy_connect_timeout 500ms;
proxy_send_timeout 4s;
proxy_read_timeout 4s;
proxy_next_upstream error timeout http_502 http_503 http_504 non_idempotent;
proxy_next_upstream_tries 2;
}
location / {
proxy_pass http://api_backend;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 500ms;
proxy_send_timeout 4s;
proxy_read_timeout 4s;
# No sticky sessions. Failed/unready peers are retried elsewhere.
proxy_next_upstream error timeout http_502 http_503 http_504;
proxy_next_upstream_tries 2;
}
}
}