【发布时间】:2019-09-16 18:13:35
【问题描述】:
我正在尝试使用运行 python3 (kivy) 的独立应用程序检索 AWS Secret(这是 boto3 配置)。
客户端使用 boto3 并且使用硬编码的凭据可以正常工作。
我正在尝试在 boto3 中使用 get_credentials_for_identity 获得信誉。
我创建了一个联合身份池并为其分配了一个访问 Secrets Manager 的策略:
{
"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)
给我错误的AccessKeyId 和SecretKey,我什至找不到它提供的那些。我想我要的是持有此identity 的 IAM 的访问密钥/秘密,但我需要访问 secrets manager 的 IAM 角色的访问密钥/秘密,因此我可以将它们输入 boto3 和检索信用/秘密。
user pool 我也需要同样的设置,但一旦我意识到我在做的愚蠢,我就可以配置它。
【问题讨论】:
-
您获得的凭证很可能是使用 IAM 角色为会话生成的临时凭证。问题是,您是否尝试过在 boto3 中使用检索到的凭据来获取机密?。
-
是的!这就是我获取
invalid token error的地方 - 我使用具有secretsmanager权限的身份池获取_credentials_for_identity 我将这些通过我的SecretsManager并获得无效令牌
标签: python amazon-web-services boto3 amazon-cognito aws-secrets-manager