在本节我们分别在Role的trust relationship
及Role Anywhere的Session Policy
中实现权限控制
进入之前创建的Role:
编辑Trust relationship
:
加一条condition限制,当aws:PrincipalTag/x509Subject/CN = workload-a.iamra.test
时,才允许被assume:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "rolesanywhere.amazonaws.com"
},
"Action": [
"sts:AssumeRole",
"sts:SetSourceIdentity",
"sts:TagSession"
],
"Condition": {
"StringEquals": {
"aws:PrincipalTag/x509Subject/CN": [
"workload-a.iamra.test"
]
}
}
}
]
}
保存后,分别执行访问S3的命令,此时workload-b
已被限制访问,只有workload-a
才有权限Assume Role:
进入Roles Anywhere页面:
编辑之前创建的Profile:
原来的Session Policy允许所有操作:
将其更新,只允许它访问SQS:
{
"Version":"2012-10-17",
"Statement":[
{
"Effect":"Allow",
"Action":"sqs:*",
"Resource":"*"
}
]
}
保存后,在命令行执行访问S3的命令,由于上面的Session Policy限制,所以此时访问也会报错:
测试完成后,将session policy
重新恢复:
{
"Version":"2012-10-17",
"Statement":[
{
"Effect":"Allow",
"Action":"*",
"Resource":"*"
}
]
}