本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
如何对管道使用 OIDC 身份验证 Amazon SAM
Amazon Serverless Application Model (Amazon SAM) 支持 Bitbucket、 GitHub Actions 以及 GitLab 持续集成和持续交付 (CI/CD) 平台的 OpenID Connect (OIDC) 用户身份验证。有了这种支持,您可以使用来自任何这些平台的授权 CI/CD 用户帐户来管理您的无服务器应用程序管道。否则,您需要创建和管理多个 Amazon Identity and Access Management (IAM) 用户来控制对 Amazon SAM 管道的访问权限。
使用管道设置 OIDC Amazon SAM
在sam pipeline bootstrap
配置过程中,请执行以下操作以在您的 Amazon SAM 管道中设置 OIDC。
-
当系统提示您选择身份提供商时,请选择 OIDC。
-
接下来,选择支持的 OIDC 提供商。
-
输入 OIDC 提供商 URL,以
https://
开头。注意
Amazon SAM 生成
AWS::IAM::OIDCProvider
资源类型时会引用此 URL。 -
接下来,按照提示输入访问所选平台所需的 CI/CD 平台信息。这些详细信息因平台而异,可能包括:
-
OIDC 客户端 ID。
-
代码存储库名称或通用唯一标识符 (UUID)。
-
与存储库关联的组或组织名称。
-
GitHub 代码仓库所属的组织。
-
GitHub 存储库名称。
-
部署将发生的分支。
-
-
Amazon SAM 显示输入的 OIDC 配置的摘要。输入某项设置的数字进行编辑,或按下 Enter 以继续。
-
当系统提示您确认创建支持输入的 OIDC 连接所需的资源时,按下 Y 以继续。
Amazon SAM 使用提供的配置生成一个承担管道执行角色的AWS::IAM::OIDCProvider
Amazon CloudFormation 资源。要了解有关此 Amazon CloudFormation 资源类型的更多信息,请参阅《Amazon CloudFormation 用户指南》中的 AWS::IAM::OIDCProvider。
注意
如果身份提供者 (IdP) 资源已存在于您的中 Amazon Web Services 账户,请 Amazon SAM 引用该资源,而不是创建新资源。
示例
以下是使用管道设置 OIDC 的 Amazon SAM 示例。
Select a permissions provider: 1 - IAM (default) 2 - OpenID Connect (OIDC) Choice (1, 2): 2 Select an OIDC provider: 1 - GitHub Actions 2 - GitLab 3 - Bitbucket Choice (1, 2, 3): 1 Enter the URL of the OIDC provider [https://token.actions.githubusercontent.com]: Enter the OIDC client ID (sometimes called audience) [sts.amazonaws.com]: Enter the GitHub organization that the code repository belongs to. If there is no organization enter your username instead: my-org Enter GitHub repository name: testing Enter the name of the branch that deployments will occur from [main]: [3] Reference application build resources Enter the pipeline execution role ARN if you have previously created one, or we will create one for you []: Enter the CloudFormation execution role ARN if you have previously created one, or we will create one for you []: Please enter the artifact bucket ARN for your Lambda function. If you do not have a bucket, we will create one for you []: Does your application contain any IMAGE type Lambda functions? [y/N]: [4] Summary Below is the summary of the answers: 1 - Account: 123456 2 - Stage configuration name: dev 3 - Region: us-east-1 4 - OIDC identity provider URL: https://token.actions.githubusercontent.com 5 - OIDC client ID: sts.amazonaws.com 6 - GitHub organization: my-org 7 - GitHub repository: testing 8 - Deployment branch: main 9 - Pipeline execution role: [to be created] 10 - CloudFormation execution role: [to be created] 11 - Artifacts bucket: [to be created] 12 - ECR image repository: [skipped] Press enter to confirm the values above, or select an item to edit the value: This will create the following required resources for the 'dev' configuration: - IAM OIDC Identity Provider - Pipeline execution role - CloudFormation execution role - Artifact bucket Should we proceed with the creation? [y/N]:
了解更多信息
有关将 OIDC 与 Amazon SAM 管道配合使用的更多信息,请参阅。sam pipeline bootstrap