This commit is contained in:
2026-11-10 19:24:33 +03:00
parent c594b88a46
commit b55b230533
23 changed files with 1200 additions and 73 deletions
+7 -3
View File
@@ -70,7 +70,7 @@ cat > "$policy_file" <<EOF
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:GetBucketLocation", "s3:ListBucket"],
"Action": ["s3:GetBucketLocation", "s3:ListBucket", "s3:ListBucketMultipartUploads"],
"Resource": ["arn:aws:s3:::${bucket}"]
},
{
@@ -88,9 +88,13 @@ cat > "$policy_file" <<EOF
}
EOF
if ! mc admin policy info local "$policy_name" >/dev/null 2>&1; then
mc admin policy create local "$policy_name" "$policy_file" >/dev/null
# Recreate the canned policy on every run so added actions (multipart list) apply.
if mc admin user info local "$access_key" >/dev/null 2>&1; then
mc admin policy detach local "$policy_name" --user "$access_key" >/dev/null 2>&1 || true
fi
mc admin policy remove local "$policy_name" >/dev/null 2>&1 || \
mc admin policy rm local "$policy_name" >/dev/null 2>&1 || true
mc admin policy create local "$policy_name" "$policy_file" >/dev/null
if ! mc admin user info local "$access_key" >/dev/null 2>&1; then
mc admin user add local "$access_key" "$secret_key" >/dev/null
+41
View File
@@ -0,0 +1,41 @@
#!/bin/sh
# In-network proof that the bucket is private and API credentials cannot see other buckets.
# Run via: docker compose --env-file .env --profile ops run --rm check-private-bucket
set -eu
bucket=${S3_BUCKET:?S3_BUCKET is required}
endpoint=${MINIO_ENDPOINT:-http://minio:9000}
read_secret() {
tr -d '\r\n' < "$1"
}
root_user=$(read_secret /run/secrets/minio_root_user)
root_password=$(read_secret /run/secrets/minio_root_password)
access_key=$(read_secret /run/secrets/s3_access_key_id)
secret_key=$(read_secret /run/secrets/s3_secret_access_key)
mc alias set local "$endpoint" "$root_user" "$root_password" >/dev/null
# MINIO_BROWSER=off: nothing should answer on the console port.
if curl -sf --connect-timeout 2 "http://minio:9001/" >/dev/null 2>&1; then
echo "MinIO console answered on :9001" >&2
exit 1
fi
probe_key=".bootstrap/private-check"
printf 'probe' | mc pipe "local/${bucket}/${probe_key}" >/dev/null
code=$(curl -s -o /dev/null -w '%{http_code}' "${endpoint}/${bucket}/${probe_key}")
mc rm --force "local/${bucket}/${probe_key}" >/dev/null
if [ "$code" != "403" ]; then
echo "unauthenticated GET returned ${code}, expected 403" >&2
exit 1
fi
mc alias set api "$endpoint" "$access_key" "$secret_key" >/dev/null
if mc ls "api/not-this-bucket" >/dev/null 2>&1; then
echo "API credentials can list a different bucket" >&2
exit 1
fi
echo "PASS: bucket ${bucket} is private; unauthenticated GET is 403; API user cannot list another bucket; console is closed"