amazon-web-services - IAM CodeBuild 策略条件 - 委托人标签等于资源标签
问题描述
目标:
创建一个 IAM 角色策略,该策略仅在角色标签等于资源标签时才允许角色对 aws 资源执行定义的操作。
例如:
IAM 标签:
富=酒吧
CodeBuild 项目标签:
富=酒吧
IAM 角色策略:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"codebuild:List*",
"codebuild:DescribeTestCases",
"codebuild:DescribeCodeCoverages",
"codebuild:BatchGet*"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"aws:ResourceTag/foo": "${aws:PrincipalTag/foo}"
}
}
}
]
}
当用户担任该角色时,该用户将被拒绝访问与 AWS 控制台和 AWS CLI 中的角色codebuild:ListProjects
具有相同密钥对的项目。foo=bar
AWS 控制台错误:
User: arn:aws:sts::123456789:assumed-role/example-role/example-user is not authorized to perform: codebuild:ListProjects
使用以下命令的 AWS CLI 错误:aws codebuild list-projects --profile test
An error occurred (AccessDeniedException) when calling the ListProjects operation: User: arn:aws:sts::123456789:assumed-role/example-role/botocore-session-59458209 is not authorized to perform: codebuild:ListProjects
尝试:
#1
在策略条件中使用实际的密钥对值:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"codebuild:List*",
"codebuild:DescribeTestCases",
"codebuild:DescribeCodeCoverages",
"codebuild:BatchGet*"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"aws:ResourceTag/foo": "bar"
}
}
}
]
}
codebuild:ListProjects
在 aws 控制台上访问被拒绝错误的结果
#2
aws:PrincipalTag/foo
从(此处从臀部射击)移除 aws 键支架
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"codebuild:List*",
"codebuild:DescribeTestCases",
"codebuild:DescribeCodeCoverages",
"codebuild:BatchGet*"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"aws:ResourceTag/foo": "aws:PrincipalTag/foo"
}
}
}
]
}
#3
使用资源标签条件中的资源类型codebuild:ResourceTag/foo
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"codebuild:List*",
"codebuild:DescribeTestCases",
"codebuild:DescribeCodeCoverages",
"codebuild:BatchGet*"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"codebuild:ResourceTag/foo": "${aws:PrincipalTag/foo}"
}
}
}
]
}
aws控制台上的相同codebuild:ListProjects
访问被拒绝错误
解决方案
推荐阅读
- c# - 如何在课堂上从主窗口访问按钮/文本框.....
- ios - M1芯片上的Xcode构建失败
- javascript - 使用javascript动态添加div
- sql - 获取当年每个月的订阅者计数,即使计数为 0
- python - 如何用pdfplumber完成for循环?
- bash - 如何使用 awk 将混合/部分缺失的记录提取到定义的顺序
- reactjs - 如何使用 ReactJS 更新由一组对象组成的堆肥状态?
- javascript - 这个功能只工作一次有什么原因吗?
- performance - 如何找出服务器可以在 Jmeter 中处理的每秒最大并发请求数
- android-jetpack-compose - DatePicker 文本值更新到前一天而不是选择日期