#!/bin/sh # Idempotent private bucket and least-privilege API user. Root credentials stay in this init container. set -eu : "${MINIO_ROOT_USER:?}" : "${MINIO_ROOT_PASSWORD:?}" : "${S3_ACCESS_KEY_ID:?}" : "${S3_SECRET_ACCESS_KEY:?}" : "${S3_BUCKET:?}" export MC_CONFIG_DIR=/tmp/mc export MC_HOST_local="http://${MINIO_ROOT_USER}:${MINIO_ROOT_PASSWORD}@minio:9000" i=0 until mc mb --ignore-existing "local/${S3_BUCKET}" >/dev/null 2>&1; do i=$((i + 1)) if [ "$i" -gt 40 ]; then echo "bucket bootstrap failed" >&2 exit 1 fi sleep 1 done mc anonymous set none "local/${S3_BUCKET}" >/dev/null cat > /tmp/messenger-api-policy.json </dev/null 2>&1; then mc admin policy create local messenger-api /tmp/messenger-api-policy.json >/dev/null fi if ! mc admin user info local "${S3_ACCESS_KEY_ID}" >/dev/null 2>&1; then mc admin user add local "${S3_ACCESS_KEY_ID}" "${S3_SECRET_ACCESS_KEY}" >/dev/null fi mc admin policy attach local messenger-api --user "${S3_ACCESS_KEY_ID}" >/dev/null 2>&1 || true echo "bucket bootstrap ok"