#!/bin/sh set -eu export MC_CONFIG_DIR=/tmp/mc mkdir -p "$MC_CONFIG_DIR/certs/CAs" cp /trust/ca.crt "$MC_CONFIG_DIR/certs/CAs/lab.crt" mc alias set admin https://minio:9000 "$(cat /bootstrap/admin/S3_ACCESS_KEY)" "$(cat /bootstrap/admin/S3_SECRET_KEY)" >/dev/null mc ready admin >/dev/null mc mb --ignore-existing admin/attachments >/dev/null mc anonymous set none admin/attachments >/dev/null if [ "${1:-}" = worker ]; then old=$(cat /retired/S3_ACCESS_KEY) mc admin user rm admin "$old" >/dev/null set -- worker else set -- api worker operator fi for role do mc admin policy create admin "attachments-$role" "/policies/s3-$role.json" >/dev/null key=$(cat "/bootstrap/$role/S3_ACCESS_KEY") mc admin user add admin "$key" "$(cat "/bootstrap/$role/S3_SECRET_KEY")" >/dev/null mc admin policy attach admin "attachments-$role" --user "$key" >/dev/null done printf '%s\n' 'Private bucket and scoped S3 accounts configured.'