Files
mtusi2026lab6/infra/s3/init.sh
T
Artyom 12db77133f Forward the lab 5 foundation while preserving lab 6 telemetry
Source: immutable lab5 snapshot f88e9ba43cdfd7eb6a5a7ae5feb4247b4e820071; forward the allowed diff from 64d5c67. Carry SQLAlchemy, Alembic, reliability fixes, versioned jobs, infrastructure and student tests without changing protected coursework files.

Validation: make check, validate, lint; 515 student tests passed with one Linux-only skip; public smoke with telemetry enabled and repeat migration passed. Stop the owned stack and retain volumes. Preserve the existing OTel work in progress; grade implementation remains a separate phase.
2026-11-06 12:29:35 +03:00

26 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
set -eu
secret() { tr -d '\r\n' < "/run/secrets/$1"; }
bucket="${S3_BUCKET:-messenger-attachments}"
endpoint="${S3_ENDPOINT:-http://s3:9000}"
policy="${S3_API_POLICY:-messenger-api}"
reconciler="${S3_RECONCILER_POLICY:-messenger-reconciler}"
RC_HOST_root="${endpoint%%://*}://$(secret s3_root_user):$(secret s3_root_password)@${endpoint#*://}"
export RC_HOST_root
grant() {
sed "s/messenger-attachments/$bucket/g" "/s3/$2" > "/tmp/$2"
rc admin policy create root "$1" "/tmp/$2" >/dev/null
rc admin user add root "$(secret "$3")" "$(secret "$4")" >/dev/null
rc admin policy attach root "$1" --user "$(secret "$3")" >/dev/null
rc admin user info root "$(secret "$3")" --json | grep -q "\"$1\""
}
rc ready root --timeout 10 >/dev/null
rc bucket create --ignore-existing "root/$bucket" >/dev/null
rc bucket anonymous set private "root/$bucket" >/dev/null
grant "$policy" api-policy.json s3_access_key_id s3_secret_access_key
grant "$reconciler" reconciler-policy.json s3_reconciler_access_key_id s3_reconciler_secret_access_key
grant messenger-worker worker-policy.json s3_worker_access_key_id s3_worker_secret_access_key
rc bucket lifecycle rule import "root/$bucket" /s3/lifecycle.json >/dev/null
rc bucket anonymous get "root/$bucket" --json | grep -q '"permission": *"private"'
echo "s3-init: bucket=$bucket anonymous=private policies=$policy,$reconciler lifecycle=abort-incomplete-uploads"