Implement lab4 S3 attachments
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
read_secret() {
|
||||
tr -d '\r\n' < "/run/secrets/$1"
|
||||
}
|
||||
|
||||
ROOT_ACCESS=$(read_secret s3_root_access)
|
||||
ROOT_SECRET=$(read_secret s3_root_secret)
|
||||
API_ACCESS=$(read_secret s3_access_key_id)
|
||||
API_SECRET=$(read_secret s3_secret_access_key)
|
||||
|
||||
# Bound bootstrap wait: fail with diagnostic rather than stall forever.
|
||||
count=0
|
||||
until output=$(timeout 4 mc alias set local http://s3:9000 "$ROOT_ACCESS" "$ROOT_SECRET" 2>&1) && output=$(timeout 4 mc admin info local 2>&1); do
|
||||
count=$((count + 1))
|
||||
if [ "$count" -ge 12 ]; then
|
||||
echo "ERROR: MinIO did not become reachable after 12 attempts; inspect docker compose logs s3" >&2
|
||||
if [ -n "$output" ]; then printf '%s\n' "$output" >&2; fi
|
||||
exit 1
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
|
||||
mc mb --ignore-existing local/messenger-attachments
|
||||
mc anonymous set none local/messenger-attachments
|
||||
# Repeatable bootstrap: policy may exist already after restarts.
|
||||
mc admin policy create local messenger-app /etc/bootstrap/s3-policy.json
|
||||
mc admin user add local "$API_ACCESS" "$API_SECRET"
|
||||
if ! mc admin policy attach local messenger-app --user "$API_ACCESS"; then
|
||||
mc admin policy entities local messenger-app --user "$API_ACCESS" --json | grep -Fq "\"$API_ACCESS\""
|
||||
fi
|
||||
mc anonymous get local/messenger-attachments
|
||||
mc alias set api http://s3:9000 "$API_ACCESS" "$API_SECRET" >/dev/null
|
||||
mc ls api/messenger-attachments >/dev/null
|
||||
printf 'S3 bootstrap completed (private bucket, limited API identity).\n'
|
||||
@@ -0,0 +1,26 @@
|
||||
worker_processes auto;
|
||||
events { worker_connections 1024; }
|
||||
http {
|
||||
resolver 127.0.0.11 valid=1s ipv6=off;
|
||||
upstream messenger_api {
|
||||
zone messenger_api 64k;
|
||||
server api1:8080 resolve max_fails=1 fail_timeout=2s;
|
||||
server api2:8080 resolve max_fails=1 fail_timeout=2s;
|
||||
}
|
||||
server {
|
||||
listen 8080;
|
||||
client_max_body_size 11m;
|
||||
location / {
|
||||
proxy_pass http://messenger_api;
|
||||
proxy_http_version 1.1;
|
||||
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 1s;
|
||||
proxy_read_timeout 35s;
|
||||
proxy_send_timeout 35s;
|
||||
proxy_next_upstream error timeout http_502 http_503;
|
||||
proxy_next_upstream_tries 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["s3:ListBucket"],"Resource":["arn:aws:s3:::messenger-attachments"]},{"Effect":"Allow","Action":["s3:GetObject","s3:PutObject","s3:DeleteObject"],"Resource":["arn:aws:s3:::messenger-attachments/originals/*"]}]}
|
||||
Reference in New Issue
Block a user