amazon-web-services - 如何更改 CloudFormation 模板以更正 s3 容器上的 Access Denied ListObjectV2 操作
问题描述
我有一个云形成模板,我正在尝试创建一个托管策略,我可以在其中控制对文件夹中对象的访问。我曾经有过这样的工作,但我更改了模板中的某些内容,需要第二双眼睛来希望指出一个错字或我的权限设置错误。
CF (yaml) 定义如下所示:
- Sid: ExternalLISTReturns
Effect: Allow
Action:
- s3:ListBucket
Condition:
ForAnyValue:StringEquals:
s3:prefix: "folder1/returns/*"
Resource: !Join
- 's3:prefix'
- - !Ref S3ContainerName
- Sid: ExternalLISTUploads
Effect: Allow
Action:
- s3:ListBucket
Condition:
ForAnyValue:StringEquals:
s3:prefix: "folder1/uploads/*"
Resource: !Join
- 's3:prefix'
- - !Ref S3ContainerName
打包和部署后,JSON 定义在策略管理器中如下所示:
{
"Version": "2012-10-17",
"Statement": [
{
"Condition": {
"ForAnyValue:StringEquals": {
"s3:prefix": "folder1/returns/*"
}
},
"Action": [
"s3:ListBucket"
],
"Resource": "arn:aws:s3:::mydeployedbucket",
"Effect": "Allow",
"Sid": "ExternalLISTReturns"
},
{
"Condition": {
"ForAnyValue:StringEquals": {
"s3:prefix": "folder1/uploads/*"
}
},
"Action": [
"s3:ListBucket"
],
"Resource": "arn:aws:s3:::mydeployedbucket",
"Effect": "Allow",
"Sid": "ExternalLISTUploads"
}
]
}
该政策看起来有效,但是当我尝试使用 cli 列出项目时
aws s3 ls s3://mydeployedbucket/folder1/uploads --profile testaccount
我收到错误
An error occurred (AccessDenied) when calling the ListObjectsV2 operation: Access Denied
有什么东西会因为缺少或需要而跳出来吗?目的是只允许列出带有前缀的对象folder1/uploads
或folder1/returns
与此策略关联的用户
解决方案
所以在挖掘了更多之后,我发现问题在于我如何为 LIST Buckets 声明我的资源。我最初将资源定义为对象而不是存储桶。我还发现我可以StringLike
在条件定义中使用。StringEquals
也有效,但我不必明确声明ForAnyValue:
我更新了 CF 模板,因此 LIST 权限如下所示:
- Sid: ExternalLISTUploads
Effect: Allow
Action:
- s3:ListBucket
Condition:
StringLike:
s3:prefix: "folder1/uploads/*"
Resource: !Join
- ''
- - !Ref S3ContainerName
推荐阅读
- python - 使用 matplotib 小部件水平滚动热图时出现初始帧和结束帧的问题
- typescript - 在本地链接一个 Vue 应用程序和一个 Vue lib --> d.ts 问题;
- flutter - Flutter中如何根据平台编译源码?
- javascript - 解析云代码作业功能优化
- javascript - Cordova -> face-api-js [错误] 加载资源失败:在此服务器上找不到请求的 URL。(空,第 0 行)
- sql - 转换 PostgreSQL 中的时间戳数组(不在表中)
- r - 创建具有最大值的新列
- react-native - 如何验证 AsyncStorage 在 react-native 中是否可用
- python - .plot() 保留旧图并每次在其上绘制新图
- html - TikZJax 生成的 svg 中的一些数学符号渲染不正确