繁体   English   中英

如何使用AWS Cognito-身份池检索正确的凭证以在boto3客户端上访问AWS SecretsManger

[英]How can I retrieve correct credentials to access AWS SecretsManger on a boto3 client using AWS Cognito - Indentity Pool

我正在尝试使用运行python3(kivy)的独立应用程序检索AWS Secret(这是boto3配置)。

客户端使用boto3并使用硬编码的凭据正常工作。

我正在尝试在boto3中使用get_credentials_for_identity获得信誉。

我创建了一个联合身份池,并为其分配了一个策略以访问秘密管理器:

{
    "Version": "2012-10-17",
    "Statement": {
        "Effect": "Allow",
        "Action": "secretsmanager:GetSecretValue",
        "Resource": "<arn-of-the-secret-the-app-needs-to-access>"
    }
}

我还使用通用的Cognito角色完成了同样的操作。 (知道这不是问题,但我敢肯定,我们所有人在尝试解决问题时都会犯傻)。

client = boto3.client('cognito-identity', region_name='eu-west-1')
response = client.get_credentials_for_identity(
    #identity taken from fedenration/identity pools;app with cognito access
    IdentityId='eu-west-1:6###...',
)
creds_dic = response['Credentials']
awsaccesskey = creds_dic['AccessKeyId']
awsseckey = creds_dic['SecretKey']
print(response)
print(awsseckey)
print(awsaccesskey)

给我提供了我什至找不到的错误AccessKeyIdSecretKey 我想我正在要求持有该identity的IAM的访问密钥/秘密,但是我需要IAM角色的访问密钥/秘密,该角色正在访问secrets manager因此我可以将其输入boto3并检索凭据/秘密。

我也需要为user pool设置相同的功能,但是一旦意识到自己的愚蠢性就可以对其进行配置。

Cognito会生成由AWS STS出售的新凭证。 您将无法将这些凭据与现有的IAM生成的凭据进行匹配。 要访问AWS Secrets Manager API,请确保您的Cognito身份池的Authenticated Role具有足够的权限。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM