This commit is contained in:
2026-11-10 19:24:33 +03:00
parent c594b88a46
commit b55b230533
23 changed files with 1200 additions and 73 deletions
+7 -2
View File
@@ -36,7 +36,8 @@ defaults
timeout connect 1s
timeout client 30s
timeout server 10s
timeout http-request 10s
# Body arrival for a 10 MiB attachment; JSON posts finish well under this.
timeout http-request 30s
timeout http-keep-alive 5s
timeout queue 2s
timeout check 1s
@@ -55,7 +56,7 @@ frontend public
acl safe_request_id req.hdr(X-Request-Id) -m reg ^[A-Za-z0-9._:-]{1,128}$
http-request set-var(txn.reqid) req.hdr(X-Request-Id) if upload_too_large safe_request_id
http-request set-var(txn.reqid) str(lb) if upload_too_large !safe_request_id
http-request return status 413 content-type application/json lf-string "{\"error\":{\"code\":\"payload_too_large\",\"message\":\"Файл больше 10 МиБ\",\"request_id\":\"%[var(txn.reqid)]\"}}" hdr X-Request-Id %[var(txn.reqid)] if upload_too_large
http-request return status 413 content-type application/json lf-string "{\"error\":{\"code\":\"payload_too_large\",\"message\":\"Файл больше 10 МиБ\",\"request_id\":\"%[var(txn.reqid)]\"}}" hdr X-Request-Id %[var(txn.reqid)] hdr X-Instance-Id %[str(lb)] if upload_too_large
# Message POST carries a mandatory Idempotency-Key, so replaying it on another replica is safe.
# Other POSTs (users, chats, sessions) are retried only when the connection was never established.
@@ -67,6 +68,10 @@ frontend public
backend api
# Round robin, no stickiness: any replica serves any session from PostgreSQL.
# Attachment PUT to S3 can outlast the default 10 s server timeout under concurrent load.
acl attachment_upload method POST
acl attachment_upload_path path_reg ^/api/v1/chats/[^/]+/attachments$
http-request set-timeout server 30s if attachment_upload attachment_upload_path
balance roundrobin
option httpchk
http-check send meth GET uri /health/ready ver HTTP/1.1 hdr Host lb
+7 -3
View File
@@ -70,7 +70,7 @@ cat > "$policy_file" <<EOF
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:GetBucketLocation", "s3:ListBucket"],
"Action": ["s3:GetBucketLocation", "s3:ListBucket", "s3:ListBucketMultipartUploads"],
"Resource": ["arn:aws:s3:::${bucket}"]
},
{
@@ -88,9 +88,13 @@ cat > "$policy_file" <<EOF
}
EOF
if ! mc admin policy info local "$policy_name" >/dev/null 2>&1; then
mc admin policy create local "$policy_name" "$policy_file" >/dev/null
# Recreate the canned policy on every run so added actions (multipart list) apply.
if mc admin user info local "$access_key" >/dev/null 2>&1; then
mc admin policy detach local "$policy_name" --user "$access_key" >/dev/null 2>&1 || true
fi
mc admin policy remove local "$policy_name" >/dev/null 2>&1 || \
mc admin policy rm local "$policy_name" >/dev/null 2>&1 || true
mc admin policy create local "$policy_name" "$policy_file" >/dev/null
if ! mc admin user info local "$access_key" >/dev/null 2>&1; then
mc admin user add local "$access_key" "$secret_key" >/dev/null
+41
View File
@@ -0,0 +1,41 @@
#!/bin/sh
# In-network proof that the bucket is private and API credentials cannot see other buckets.
# Run via: docker compose --env-file .env --profile ops run --rm check-private-bucket
set -eu
bucket=${S3_BUCKET:?S3_BUCKET is required}
endpoint=${MINIO_ENDPOINT:-http://minio:9000}
read_secret() {
tr -d '\r\n' < "$1"
}
root_user=$(read_secret /run/secrets/minio_root_user)
root_password=$(read_secret /run/secrets/minio_root_password)
access_key=$(read_secret /run/secrets/s3_access_key_id)
secret_key=$(read_secret /run/secrets/s3_secret_access_key)
mc alias set local "$endpoint" "$root_user" "$root_password" >/dev/null
# MINIO_BROWSER=off: nothing should answer on the console port.
if curl -sf --connect-timeout 2 "http://minio:9001/" >/dev/null 2>&1; then
echo "MinIO console answered on :9001" >&2
exit 1
fi
probe_key=".bootstrap/private-check"
printf 'probe' | mc pipe "local/${bucket}/${probe_key}" >/dev/null
code=$(curl -s -o /dev/null -w '%{http_code}' "${endpoint}/${bucket}/${probe_key}")
mc rm --force "local/${bucket}/${probe_key}" >/dev/null
if [ "$code" != "403" ]; then
echo "unauthenticated GET returned ${code}, expected 403" >&2
exit 1
fi
mc alias set api "$endpoint" "$access_key" "$secret_key" >/dev/null
if mc ls "api/not-this-bucket" >/dev/null 2>&1; then
echo "API credentials can list a different bucket" >&2
exit 1
fi
echo "PASS: bucket ${bucket} is private; unauthenticated GET is 403; API user cannot list another bucket; console is closed"