

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 如何对管道使用 OIDC 身份验证 AWS SAM
<a name="deploying-with-oidc"></a>

AWS Serverless Application Model (AWS SAM) 支持 OpenID Connect (OIDC) 用户身份验证，支持 Bitbucket、 GitHub Actions、 GitLab 持续集成和持续交付（来自这些平台的CI/CD) platforms. With this support, you can use authorized CI/CD用户账户），用于管理您的无服务器应用程序管道。 否则，您需要创建和管理多个 AWS Identity and Access Management (IAM) 用户来控制对 AWS SAM 管道的访问权限。

## 使用管道设置 OIDC AWS SAM
<a name="deploying-with-oidc-setup"></a>

在`sam pipeline bootstrap`配置过程中，请执行以下操作以在您的 AWS SAM 管道中设置 OIDC。

1. 当系统提示您选择身份提供商时，请选择 **OIDC**。

1. 接下来，选择支持的 OIDC 提供商。

1. 输入 OIDC 提供商 URL，以 **https://** 开头。
**注意**  
AWS SAM 生成`AWS::IAM::OIDCProvider`资源类型时会引用此 URL。

1. 接下来，按照提示输入访问所选 CI/CD 平台所需的平台信息。这些详细信息因平台而异，可能包括：
   + OIDC 客户端 ID。
   + 代码存储库名称或通用唯一标识符 (UUID)。
   + 与存储库关联的组或组织名称。
   + GitHub 代码仓库所属的组织。
   + GitHub 存储库名称。
   + 部署将发生的分支。

1. AWS SAM 显示输入的 OIDC 配置的摘要。输入某项设置的数字进行编辑，或按下 Enter 以继续。

1. 当系统提示您确认创建支持输入的 OIDC 连接所需的资源时，按下 Y 以继续。

AWS SAM 使用提供的配置生成一个承担管道执行角色的`AWS::IAM::OIDCProvider` AWS CloudFormation 资源。要了解有关此 CloudFormation 资源类型的更多信息，请参阅*AWS CloudFormation 用户指南OIDCProvider*中的 [AWS:: IAM](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-oidcprovider.html)::。

**注意**  
如果身份提供者 (IdP) 资源已存在于您的中 AWS 账户，请 AWS SAM 引用该资源，而不是创建新资源。

## 示例
<a name="deploying-with-oidc-setup-example"></a>

以下是使用管道设置 OIDC 的 AWS 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]:
```

## 了解详情
<a name="deploying-with-oidc-setup-learn-more"></a>

有关将 OIDC 与 AWS SAM 管道配合使用的更多信息，请参阅。[sam pipeline bootstrap](sam-cli-command-reference-sam-pipeline-bootstrap.md)