66 lines
2.5 KiB
Bash
Executable File
66 lines
2.5 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
project_root=$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd)
|
|
cd "$project_root"
|
|
|
|
api_containers=$(docker compose ps -q api)
|
|
if [ -z "$api_containers" ]; then
|
|
printf "%s\n" "no running API containers found" >&2
|
|
exit 1
|
|
fi
|
|
for container_id in $api_containers; do
|
|
docker exec "$container_id" sh -ec '
|
|
test ! -e /run/secrets/minio_root_user
|
|
test ! -e /run/secrets/minio_root_password
|
|
! env | grep -Eq "^MINIO_ROOT_(USER|PASSWORD)="
|
|
'
|
|
done
|
|
|
|
docker compose run --rm --entrypoint /bin/sh minio-bootstrap -ec '
|
|
root_user="$(cat /run/secrets/minio_root_user)"
|
|
root_password="$(cat /run/secrets/minio_root_password)"
|
|
api_user="$(cat /run/secrets/s3_api_access_key)"
|
|
api_password="$(cat /run/secrets/s3_api_secret_key)"
|
|
bucket="messenger-attachments"
|
|
probe_key="policy-probe/object.txt"
|
|
|
|
mc alias set admin http://minio:9000 "$root_user" "$root_password" --api S3v4 >/dev/null
|
|
mc alias set limited http://minio:9000 "$api_user" "$api_password" --api S3v4 >/dev/null
|
|
|
|
cleanup() {
|
|
mc rm --force "admin/${bucket}/staging/${probe_key}" >/dev/null 2>&1 || true
|
|
mc rm --force "admin/${bucket}/attachments/${probe_key}" >/dev/null 2>&1 || true
|
|
mc rb --force "admin/forbidden-policy-probe" >/dev/null 2>&1 || true
|
|
}
|
|
trap cleanup EXIT INT TERM
|
|
|
|
printf private-probe | mc pipe "limited/${bucket}/staging/${probe_key}" >/dev/null
|
|
if mc cat "limited/${bucket}/staging/${probe_key}" >/dev/null 2>&1; then
|
|
printf "%s\n" "API credentials unexpectedly read the staging prefix" >&2
|
|
exit 1
|
|
fi
|
|
|
|
printf ready-object | mc pipe "admin/${bucket}/attachments/${probe_key}" >/dev/null
|
|
mc cat "limited/${bucket}/attachments/${probe_key}" >/dev/null
|
|
if printf overwrite | mc pipe "limited/${bucket}/attachments/${probe_key}" >/dev/null 2>&1; then
|
|
printf "%s\n" "API credentials unexpectedly wrote the attachments prefix" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if mc mb "limited/forbidden-policy-probe" >/dev/null 2>&1; then
|
|
printf "%s\n" "limited API credentials unexpectedly created another bucket" >&2
|
|
exit 1
|
|
fi
|
|
if wget -qO- "http://minio:9000/${bucket}/attachments/${probe_key}" >/dev/null 2>&1; then
|
|
printf "%s\n" "anonymous HTTP GET unexpectedly read a private object" >&2
|
|
exit 1
|
|
fi
|
|
|
|
mc rm --force "admin/${bucket}/staging/${probe_key}" >/dev/null
|
|
mc rm --force "admin/${bucket}/attachments/${probe_key}" >/dev/null
|
|
trap - EXIT INT TERM
|
|
printf "%s\n" "PASS: API has no MinIO root credentials; staging is write-only, attachments are read-only, bucket creation and anonymous GET are denied."
|
|
'
|
|
|