我将ec2实例角色应用于我的服务器,但我希望自己首先在本地切换到这些角色,以测试权限
我试着切换到一个,但是我得到了一个错误:
aws sts assume-role --role-arn arn:aws:iam::1234567890:role/myrole --role-session abc
An error occurred (AccessDenied) when calling the AssumeRole operation: User: arn:aws:iam::1234567890:user/meeee is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::1234567890:role/myrole我是一个帐户管理员。我是否需要修改信任策略或其他允许用户承担ec2实例角色的内容?
发布于 2020-04-13 18:27:56
要允许您的帐户承担服务角色,您需要编辑该角色并在Principal中添加您的帐户。为此:
在IAM -> Roles -> Your Service Role中,转到Trust relationship选项卡并单击Edit trust relationship。你的信任关系会是这样的:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}您需要添加类似于以下内容的AWS帐户:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com",
"AWS": "arn:aws:iam::<your AWS account number>:root"
},
"Action": "sts:AssumeRole"
}
]
}然后,您将能够通过sts获得凭据。
另一种获得想要的结果的方法是使用策略模拟器
在角色的Permissions选项卡中,单击策略左侧的箭头,它将显示一个指向Simulate policy的按钮:

不可能将IAM用作Principal。
请注意,组不是真正的标识,因为它不能在基于资源或信任策略中标识为主体。它只是一次将策略附加到多个用户的一种方式。
https://serverfault.com/questions/1012115
复制相似问题