我试图在我的PHP程序中使用AWS sts调用AssumeRole函数,因为我想创建临时凭证以允许用户为AWS桶创建对象。
以下是我称之为PHP的功能:
$sts = StsClient::factory(array(
'key' => 'XXXXXXXXXXXXXX',
'secret' => 'XXXXXXXXXXXXXXXX',
'token.ttd' => $timetodie
));
$bucket = "mybucket";
$result1 = $sts->assumeRole(array(
'RoleArn' => 'arn:aws:iam::123456789012:role/createPic',
'RoleSessionName' => 'mytest',
'Policy' => json_encode(array(
'Statement' => array(
array(
'Sid' => 'Deny attributes',
'Action' => array(
's3:deleteObject',
's3:deleteBucket'
),
'Effect' => 'Deny',
'Resource' => array(
"arn:aws:s3:::{$bucket}",
"arn:aws:s3:::{$bucket}/AWSLogs/*"
),
'Principal' => array(
'AWS' => "*"
)
)
)
)
),
'DurationSeconds' => 3600,
// 'ExternalId' => 'string',
));
$credentials = $result1->get('Credentials');
但是,我一直收到以下错误:
用户arn:aws:iam :: 123456789012:用户/ TVMUser无权执行:资源上的sts:AssumeRole:arn:aws:iam :: 123456789012:role / createPic
以下是我的AWS控制台上用户TVMUser的权限政策:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect":"Allow",
"Action":"ec2:RunInstances",
"Resource":"*"
},
{
"Effect":"Allow",
"Action":"iam:PassRole",
"Resource":"arn:aws:iam::791758789361:user/TVMUser"
},
{
"Effect":"Allow",
"Action":"sts:AssumeRole",
"Resource":"arn:aws:iam::791758789361:role/createPic"
}
]
}
以下是我对角色createPic的角色政策:
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:Get*",
"s3:List*",
"s3:Put*",
],
"Effect": "Allow",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "arn:aws:iam::123456789012:role/createPic"
}
]
}
现在有人在我的AWS政策声明和AWS上设置我所遗漏的内容,因此我没有收到错误:用户arn:aws:iam :: 123456789012:用户/ TVMUser无权执行:sts:AssumeRole资源:arn:aws:iam :: 123456789012:role / createPic?
我错过了什么吗?
答案 0 :(得分:43)
您还需要编辑角色的信任关系,以允许该帐户(即使它是相同的)承担该角色。
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Action": "sts:AssumeRole"
},
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789012:role/some-role"
},
"Action": "sts:AssumeRole"
}
]
}
在这个例子中,我不得不添加" AWS"有正确帐号的校长,ec2.amazonaws.com服务已经在那里。
在我完成之后,我能够毫无问题地承担这个角色。花了几个小时来解决这个问题,希望能帮助别人。
答案 1 :(得分:2)
我遇到了同样的错误,花了好几个小时尝试使用权限和信任关系修复它......但这不是我的问题。
我正在关注this tutorial,并按指定在美国西部(俄勒冈州)部署了群集。
为了使其有效,我需要为此区域here激活STS。
答案 2 :(得分:0)
也许你应该分配你的sts区域和端点:
$sts = StsClient::factory(array(
//...
'region' => 'us-west-2',
'endpoint' => 'https://sts.us-west-2.amazonaws.com',
));