Files
k3s/009-基础设施/002-s3/set-bucket-policy.sh
2026-02-05 00:11:05 +08:00

26 lines
796 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
# 自动为新创建的存储桶设置 download公开只读策略
# 配置 mc 客户端
mc alias set myminio http://localhost:9000 ${MINIO_ROOT_USER} ${MINIO_ROOT_PASSWORD}
# 持续监控并设置新桶的策略
while true; do
# 获取所有存储桶
BUCKETS=$(mc ls myminio 2>/dev/null | awk '{print $NF}' | sed 's/\///')
for BUCKET in $BUCKETS; do
# 检查当前策略
CURRENT_POLICY=$(mc anonymous get myminio/${BUCKET} 2>/dev/null | grep -o "download\|upload\|public" || echo "none")
# 如果策略为 none私有则设置为 download
if [ "$CURRENT_POLICY" = "none" ]; then
echo "Setting download policy for bucket: ${BUCKET}"
mc anonymous set download myminio/${BUCKET}
fi
done
# 每 30 秒检查一次
sleep 30
done