如何使用 AWS CLI 为 IAM Identity Center 用户获取临时凭证?

1 分钟阅读
0

我想为 AWS IAM Identity Center(AWS Single Sign-On 的后继者)用户获取临时凭证。

简短描述

配置命名配置文件以使用 IAM Identity Center$ cd ~/.aws/sso/cache 目录中创建 JSON 文件。JSON 文件包含一个 JSON Web 令牌(JWT),后者用于通过 get-role-credentials API 调用获取临时安全凭证。如 JSON 文件中的 expiresAt 时间戳所述,该访问令牌的有效时长为 8 小时。过期令牌必须使用 get-role-credentials API 调用重新进行身份验证。

解决方法

您可以使用 AWS 命令行界面(AWS CLI)为 IAM Identity Center 用户获取临时凭证。

**注意:**如果在运行 AWS CLI 命令时收到错误,请确保您使用的是最新的 AWS CLI 版本

打开 JSON 文件并复制访问令牌:

$ cat 535a8450b05870c9045c8a7b95870.json

{"startUrl": "https://my-sso-portal.awsapps.com/start", "region": "us-east-1", "accessToken": "eyJlbmMiOiJBM….”, "expiresAt": "2020-06-17T10:02:08UTC"}

运行 AWS CLI 命令 get-role-credentials 为 IAM Identity Center 用户获取类似以下内容的凭证:

$ aws sso get-role-credentials --account-id 123456789012 --role-name <permission-set-name> --access-token eyJlbmMiOiJBM…. --region <enter_the_same_sso_region_same_in_the_JSON_file>

示例输出:

{
    "roleCredentials": {
        "accessKeyId": "ASIA*************”,
        "secretAccessKey": “**********************************”,
        "sessionToken": “****************************************”,
        "expiration": 1592362463000
    }
}

然后,请按照说明将凭证配置为环境变量


相关信息

如何使用 IAM Identity Center 权限集?

AWS 官方
AWS 官方已更新 3 年前