gpt4 book ai didi

php - AWS AssumeRole - 用户无权执行 : sts:AssumeRole on resource

转载 作者:IT王子 更新时间:2023-10-29 00:00:39 28 4
gpt4 key购买 nike

我试图在我的 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');

但是,我不断收到以下错误:

User arn:aws:iam::123456789012:user/TVMUser is not authorized to perform: sts:AssumeRole on resource: 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":[
{
"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"
}
]
}

现在有没有人在我的 AWS 政策声明和 AWS 上的设置中缺少什么,所以我没有收到以下错误?

User arn:aws:iam::123456789012:user/TVMUser is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::123456789012:role/createPic

我错过了什么吗?

最佳答案

您还需要编辑角色的信任关系以允许帐户(即使相同)担任该角色。

  1. 在控制台中打开您要担任的角色
  2. 点击“信任关系”标签
  3. 点击“编辑关系”
  4. 为您要添加的帐户添加声明(通常您只会在“受信任的实体”中拥有 ec2 服务),例如
{
"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”委托(delegate)人,ec2.amazonaws.com 服务已经存在。

完成之后,我能够毫无问题地担任该角色。我花了几个小时才弄清楚这一点,希望对某人有所帮助。

关于php - AWS AssumeRole - 用户无权执行 : sts:AssumeRole on resource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21956794/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com