minio 权限策略配置
1.管理界面操作
2.代码操作
minio readwrite 访问策略:文章来源:https://www.toymoban.com/news/detail-613538.html
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": [
"*"
]
},
"Action": [
"s3:GetBucketLocation",
"s3:ListBucket",
"s3:ListBucketMultipartUploads"
],
"Resource": [
"arn:aws:s3:::bucketName"
]
},
{
"Effect": "Allow",
"Principal": {
"AWS": [
"*"
]
},
"Action": [
"s3:AbortMultipartUpload",
"s3:DeleteObject",
"s3:GetObject",
"s3:ListMultipartUploadParts",
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::bucketName/*"
]
}
]
}
初始化minio 权限策略
利用InitializingBean
在项目启动时候初始化 minio 创建buckets并设置策略文章来源地址https://www.toymoban.com/news/detail-613538.html
@Component
@Slf4j
public class InitSequenceBean implements InitializingBean {
@Resource
private MinioClient minioClient;
@Autowired
private MinioUtil minioUtil;
@Autowired
private MinioConfig prop;
@Override
public void afterPropertiesSet() {
String bucketName =prop.getBucketName();
try {
if (!minioUtil.bucketExists(bucketName)) {
minioUtil.makeBucket(bucketName);
String policyJson = "{\n" +
"\t\"Version\": \"2012-10-17\",\n" +
"\t\"Statement\": [{\n" +
"\t\t\"Effect\": \"Allow\",\n" +
"\t\t\"Principal\": {\n" +
"\t\t\t\"AWS\": [\"*\"]\n" +
"\t\t},\n" +
"\t\t\"Action\": [\"s3:GetBucketLocation\", \"s3:ListBucket\", \"s3:ListBucketMultipartUploads\"],\n" +
"\t\t\"Resource\": [\"arn:aws:s3:::" + bucketName + "\"]\n" +
"\t}, {\n" +
"\t\t\"Effect\": \"Allow\",\n" +
"\t\t\"Principal\": {\n" +
"\t\t\t\"AWS\": [\"*\"]\n" +
"\t\t},\n" +
"\t\t\"Action\": [\"s3:AbortMultipartUpload\", \"s3:DeleteObject\", \"s3:GetObject\", \"s3:ListMultipartUploadParts\", \"s3:PutObject\"],\n" +
"\t\t\"Resource\": [\"arn:aws:s3:::" + bucketName + "/*\"]\n" +
"\t}]\n" +
"}\n";
minioClient.setBucketPolicy(SetBucketPolicyArgs.builder().bucket(bucketName).config(policyJson).build());
log.info("buckets:【{}】,创建[readwrite]策略成功!", bucketName);
} else {
log.info("minio bucket->>>【{}】already exists", bucketName);
}
} catch (Exception e) {
log.debug("minio bucket->>>【{}】 created filed", bucketName);
e.printStackTrace();
}
}
}
到了这里,关于minio 权限策略配置的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!