如何搭配管線使用 OIDC 驗證 AWS SAM - AWS Serverless Application Model

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

如何搭配管線使用 OIDC 驗證 AWS SAM

AWS Serverless Application Model (AWS SAM)支持 OpenID Connect(OIDC)用戶身份驗證,用於比特存儲桶, GitHub操作以及持 GitLab 續集成和持續交付(CI/CD)平台。透過此支援,您可以使用這些平台的授權 CI/CD 使用者帳戶來管理無伺服器應用程式管道。否則,您需要建立和管理多個 AWS Identity and Access Management (IAM) 使用者,以控制對 AWS SAM 管道的存取。

使用管道設定 OIDC AWS SAM

sam pipeline bootstrap組態程序期間,請執行下列動作以使用管線設定 OIDC。 AWS SAM

  1. 當系統提示您選擇身分識別提供者時,請選取 OIDC

  2. 接下來,選取支援的 OIDC 提供者。

  3. 輸入 OIDC 提供者 URL,開頭為。https://

    注意

    AWS SAM 生成AWS::IAM::OIDCProvider資源類型時引用此 URL。

  4. 接下來,依照提示輸入存取所選平台所需的 CI/CD 平台資訊。這些詳細資料因平台而異,可能包括:

    • OIDC 用戶端識別碼。

    • 程式碼儲存庫名稱或通用唯一識別碼 (UUID)。

    • 與存放庫相關聯的群組或組織名稱。

    • GitHub 程式碼儲存庫所屬的組織。

    • GitHub 儲存庫名稱。

    • 將發生部署的分支。

  5. AWS SAM 顯示輸入 OIDC 組態的摘要。輸入要編輯的設定數字,或按Enter繼續。

  6. 當系統提示您確認建立支援輸入的 OIDC 連線所需的資源時,按下Y以繼續。

AWS SAM 使用提供的配置生成具有承擔管線執行角色的AWS::IAM::OIDCProvider AWS CloudFormation 資源。若要進一步了解此 AWS CloudFormation 資源類型,請參閱使用者指南中的 AWS:: IAM:: OIDC 供應商。AWS CloudFormation

注意

如果身分識別提供者 (IdP) 資源已存在於您的中 AWS 帳戶,請 AWS SAM 參考該資源,而不是建立新資源。

範例

以下是使 AWS SAM 用管線設定 OIDC 的範例。

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 與 AWS SAM 管線搭配使用的詳細資訊,請參閱。sam pipeline bootstrap