使用启用了 IAM Identity Center 的命名配置文件 您所在的位置:网站首页 xaml文件读取config 使用启用了 IAM Identity Center 的命名配置文件

使用启用了 IAM Identity Center 的命名配置文件

2023-03-21 22:19| 来源: 网络整理| 查看: 265

Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)。 使用启用了 IAM Identity Center 的命名配置文件

本主题介绍如何使用 Amazon CLI 通过 Amazon IAM Identity Center (successor to Amazon Single Sign-On)(IAM Identity Center)对用户进行身份验证,以获取用于运行 Amazon CLI 命令的凭证。

注意

您的凭证是临时还是自动刷新,这取决于您之前如何对配置文件进行配置。

主题

先决条件登录和获取凭证使用支持 IAM Identity Center 的配置文件运行命令退出您的 IAM Identity Center 会话 先决条件

您配置了 IAM Identity Center 配置文件。有关更多信息,请参阅 Amazon IAM Identity Center (successor to Amazon Single Sign-On) 的具有自动身份验证刷新功能的令牌提供程序配置 和 Amazon IAM Identity Center (successor to Amazon Single Sign-On) 的旧版不可刷新配置。

登录和获取凭证 注意

登录过程可能会提示您允许 Amazon CLI 访问您的数据。由于 Amazon CLI 基于 SDK for Python 而构建,因此权限消息可能包含 botocore 名称的变体。

配置命名配置文件后,您可以调用它以从 Amazon 请求凭证。您必须检索和缓存一组凭证,然后才能运行 Amazon CLI 服务命令。要获取这些凭证,请运行以下命令。

$ aws sso login --profile my-dev-profile

Amazon CLI 打开原定设置浏览器并验证您的 IAM Identity Center 登录。

SSO authorization page has automatically been opened in your default browser. Follow the instructions in the browser to complete this authorization request. Successfully logged into Start URL: https://my-sso-portal.awsapps.com/start

如果您当前未登录 IAM Identity Center,则必须提供您的 IAM Identity Center 凭证。

如果 Amazon CLI 无法打开浏览器,则系统会提示您自行打开浏览器并输入指定的代码。

$ aws sso login --profile my-dev-profile Using a browser, open the following URL: https://device.sso.us-west-2.amazonaws.com/ and enter the following code: QCFK-N451

Amazon CLI 将您的原定设置浏览器打开(或您手动将选择的浏览器打开)到指定页面,然后输入提供的代码。然后,网页会提示您输入 IAM Identity Center 凭证。

缓存 IAM Identity Center 会话凭证。如果这些凭证是临时性的,则会包括过期时间戳,并且在凭证过期后,Amazon CLI 会请求您再次登录 IAM Identity Center。

如果您的 IAM Identity Center 凭证有效,则 Amazon CLI 使用它们安全地检索在配置文件中指定的用于 IAM 角色的 Amazon 凭证。

Welcome, you have successfully signed-in to the AWS-CLI.

在使用 aws sso login 命令的 --sso-session 参数登录时,您还可以指定使用哪个 sso-session 配置文件。

$ aws sso login --sso-session my-dev-session Attempting to automatically open the SSO authorization page in your default browser. If the browser does not open or you wish to use a different device to authorize this request, open the following URL: https://device.sso.us-west-2.amazonaws.com/ and enter the following code: QCFK-N451 Successfully logged into Start URL: https://cli-reinvent.awsapps.com/start 使用支持 IAM Identity Center 的配置文件运行命令

您可以使用这些凭证通过关联的命名配置文件来调用 Amazon CLI 命令。以下示例显示该命令是在作为指定账户一部分的代入角色下运行的。

$ aws sts get-caller-identity --profile my-dev-profile { "UserId": "AROA12345678901234567:[email protected]", "Account": "123456789011", "Arn": "arn:aws:sts::123456789011:assumed-role/AWSPeregrine_readOnly_12321abc454d123/[email protected]" }

只要您登录 IAM Identity Center 并且这些缓存的凭证未过期,Amazon CLI 就会在需要时自动续订过期的 Amazon 凭证。但是,如果您的 IAM Identity Center 凭证过期,则必须通过再次登录您的 IAM Identity Center 账户来显式续订它们。

$ aws s3 ls --profile my-sso-profile Your short-term credentials have expired. Please sign-in to renew your credentials SSO authorization page has automatically been opened in your default browser. Follow the instructions in the browser to complete this authorization request.

您可以创建多个支持 IAM Identity Center 的命名配置文件,每个配置文件指向不同的 Amazon 账户或角色。您还可以一次对多个配置文件使用该 aws sso login 命令。如果其中任何一个配置文件共享同一个 IAM Identity Center 用户账户,则您必须只登录到该 IAM Identity Center 用户账户一次,然后它们都将共享一组 IAM Identity Center 缓存凭证。

# The following command retrieves temporary credentials for the Amazon account and role # specified in one named profile. If you are not yet signed in to IAM Identity Center or your # cached credentials have expired, it opens your browser and prompts you for your # IAM Identity Center user name and password. It then retrieves Amazon temporary credentials for # the IAM role associated with this profile. $ aws sso login --profile my-first-sso-profile # The next command retrieves a different set of temporary credentials for the Amazon # account and role specified in the second named profile. It does not overwrite or # in any way compromise the first profile's credentials. If this profile specifies the # same Amazon access portal, then it uses the SSO credentials that you retrieved in the # previous command. The Amazon CLI then retrieves Amazon temporary credentials for the # IAM role associated with the second profile. You don't have to sign in to # IAM Identity Center again. $ aws sso login --profile my-second-sso-profile # The following command lists the Amazon EC2 instances accessible to the role # identified in the first profile. $ aws ec2 describe-instances --profile my-first-sso-profile # The following command lists the Amazon EC2 instances accessible to the role # identified in the second profile. $ aws ec2 describe-instances --profile my-second-sso-profile 退出您的 IAM Identity Center 会话

完成使用支持 IAM Identity Center 的配置文件后,您可以选择不执行任何操作,而让 Amazon 临时凭证和您的 IAM Identity Center 凭证过期。但是,您也可以选择运行以下命令来立即删除 SSO 凭证缓存文件夹中的所有缓存凭证和基于 IAM Identity Center 凭证的所有 Amazon 临时凭证。这使得这些凭证不可用于将来的任何命令。

$ aws sso logout Successfully signed out of all SSO profiles.

如果稍后要使用支持 IAM Identity Center 的配置文件之一来运行命令,则必须再次运行 aws sso login 命令(请参阅上一节)并指定要使用的配置文件。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有