我们有使用 AWS PHP SDK 版本 1 AmazonSTS()->get_federation_token() 的现有代码。升级到 SDK 版本 3 后,使用相同凭据、资源和策略的相同调用将返回 403 未授权错误。
版本和地区似乎相同。政策 json 是相同的。用于进行调用的用户凭据是相同的(如果我切换回 SDK v1,它们仍然有效)。我设置了调试选项,但它似乎没有提供任何其他信息,说明为什么同一用户未被授权对同一联合用户执行相同的功能 getFederationToken。
有效的旧代码:
$client = new AmazonSTS();
$policy = new stdClass();
$policy->Statement = [
'Sid' => 'randomstatementid' . time(),
'Action' => ['s3:*'],
'Effect' => 'Allow',
'Resource' => 'aws:s3:::' . $AWS_BUCKET . '*'
];
// Fetch the session credentials.
$response = $client->get_federation_token('User1',array(
'Policy' => json_encode($policy),
'DurationSeconds' => $NUMSECS
));
返回 403 错误的新代码:
$client = new Aws\Sts\StsClient([
'region' => 'us-east-1',
'version' => '2011-06-15',
]);
$policy = new stdClass();
$policy->Statement = [
'Sid' => 'randomstatementid' . time(),
'Action' => ['s3:*'],
'Effect' => 'Allow',
'Resource' => 'aws:s3:::' . $AWS_BUCKET . '*'
];
try {
$response = $client->getFederationToken([
'Name' => 'User1',
'Policy' => json_encode($policy),
'DurationSeconds' => $NUMSECS,
]);
} catch (Exception $e) {
var_dump($e);
die();
}
第一个示例返回联合用户 User1 的临时凭证。第二个示例返回 403 forbidden 错误(我隐藏了实际帐户 ID):
<Error>
<Type>Sender</Type>
<Code>AccessDenied</Code>
<Message>User: arn:aws:iam::[account id]:user/portal is not authorized to perform: sts:GetFederationToken on resource: arn:aws:sts::[account id]:federated-user/User1</Message>
</Error>
原来我正在查看错误的凭据。我在脚本中找到了硬编码的正确凭据:(
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句