或者也可以指定允许使用代入角色的某个iam role,替换"arn:aws:iam::<my-account-id>:role/aws-service-role/*"为可信的角色ARN。
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "EnforceIdentityPerimeter",
"Effect": "Deny",
"Principal": {
"AWS": "*"
},
"Action": [
"sts:AssumeRole",
"sts:AssumeRoleWithWebIdentity"
],
"Condition": {
"StringNotEqualsIfExists": {
"aws:PrincipalOrgID": "<my-org-id>",
"aws:PrincipalAccount": [
"<third-party-account-a>",
"<third-party-account-b>"
]
},
"BoolIfExists": {
"aws:PrincipalIsAWSService": "false"
}
}
},
{
"Sid": "EnforceNetworkPerimeter",
"Effect": "Deny",
"Principal": {
"AWS": "*"
},
"Action": [
"sts:AssumeRole",
"sts:AssumeRoleWithSAML",
"sts:AssumeRoleWithWebIdentity"
],
"Condition": {
"NotIpAddressIfExists": {
"aws:SourceIp": "<my-corporate-cidr>"
},
"StringNotEqualsIfExists": {
"aws:SourceVpc": "<my-vpc>",
"aws:PrincipalTag/network-perimeter-exception": "true",
"aws:PrincipalAccount": [
"<third-party-account-a>",
"<third-party-account-b>"
]
},
"BoolIfExists": {
"aws:PrincipalIsAWSService": "false",
"aws:ViaAWSService": "false"
},
"ArnNotLikeIfExists": {
"aws:PrincipalArn": "arn:aws:iam::<my-account-id>:role/aws-service-role/*"
}
}
}
]
}