我有一个用例,可以在该组织的所有其他帐户中使用 A 的秘密。我已为组织提供了秘密许可,并使用 kms key 加密了秘密。我在整个组织中拥有一个角色,允许访问此秘密。
使用 AWS CLI 从 B 获取密钥时,效果很好。但是在使用 python boto3 获取秘密时,我的访问被拒绝。
错误:
botocore.exceptions.ClientError:调用 GetSecretValue 操作时发生错误 (AccessDeniedException):用户:arn:aws:sts:::assumed-role// 无权对资源执行:secretsmanager:GetSecretValue:因为没有身份 -基于策略允许 Secretsmanager:GetSecretValue 操作
AWS cli 列出机密如下:
$ aws secretsmanager get-secret-value --secret-id arn:aws:secretsmanager:eu-central-1:291854329851:secret:D011358-f9gGzq --region eu-central-1
{
"ARN": "arn:aws:secretsmanager:eu-central-1:<acc number>:secret:Cuser-f9gGzq",
"Name": "Cuser",
"VersionId": "c4537bdf-3aff-4e13-b355-36890834a407",
"SecretString": "{\"C user\":\"password"}",
"VersionStages": [
"AWSCURRENT"
],
"CreatedDate": 1690539987.039
}
秘密许可如下:
{
"Version" : "2012-10-17",
"Statement" : [ {
"Sid" : "AllowUseOfTheKey",
"Effect" : "Allow",
"Principal" : {
"AWS" : "*"
},
"Action" : "secretsmanager:GetSecretValue",
"Resource" : "*",
"Condition" : {
"StringEquals" : {
"aws:PrincipalOrgID" : "orgid"
}
}
} ]
}
有什么建议吗?
我假设秘密位于帐户 A 中,并且您正在尝试访问它,即从组织中的其他帐户调用
GetSecretValue
。在这种情况下,由于资源(即密钥)位于不同的账户中,因此基于资源的策略是不够的,您必须通过 IAM 角色的权限策略授予 secretsmanager:GetSecretValue
权限。