feat: enable minio tls and scope bucket permissions

This commit is contained in:
2026-11-30 16:36:14 +03:00
parent 1d6b745015
commit 7162d4c518
4 changed files with 110 additions and 46 deletions
+29
View File
@@ -0,0 +1,29 @@
#!/bin/sh
set -eu
cd /run/tls
export MC_CONFIG_DIR=/tmp/mc
mkdir -p "$MC_CONFIG_DIR/certs/CAs"
cp ca.crt "$MC_CONFIG_DIR/certs/CAs/lab7.crt"
export MC_HOST_root="https://$(cat root_user):$(cat root_password)@s3:9000"
mc mb --ignore-existing "root/$S3_BUCKET"
mc anonymous set none "root/$S3_BUCKET" >/dev/null
policy() {
role="$1"
staging="$2"
final="$3"
cat > /tmp/policy.json <<EOF
{"Version":"2012-10-17","Statement":[
{"Effect":"Allow","Action":["s3:ListBucket","s3:GetBucketLocation"],"Resource":["arn:aws:s3:::$S3_BUCKET"]},
{"Effect":"Allow","Action":[$staging],"Resource":["arn:aws:s3:::$S3_BUCKET/staging/*"]},
{"Effect":"Allow","Action":[$final],"Resource":["arn:aws:s3:::$S3_BUCKET/attachments/*"]}
]}
EOF
mc admin policy create root "messenger-$role" /tmp/policy.json >/dev/null
mc admin user add root "messenger-$role" "$(cat "$role"_password)" >/dev/null
mc admin policy attach root "messenger-$role" --user "messenger-$role" >/dev/null
}
policy api '"s3:PutObject","s3:DeleteObject"' '"s3:GetObject"'
policy worker '"s3:GetObject","s3:DeleteObject"' '"s3:GetObject","s3:PutObject"'
policy reconciler '"s3:DeleteObject"' '"s3:DeleteObject"'
echo "Private bucket and role policies ready"