AWS announces preview of AWS Interconnect - multicloud
AWS announces AWS Interconnect – multicloud (preview), providing simple, resilient, high-speed private connections to other cloud service providers. AWS Interconnect - multicloud is easy to configure and provides high-speed, resilient connectivity with dedicated bandwidth, enabling customers to interconnect AWS networking services such as AWS Transit Gateway, AWS Cloud WAN, and Amazon VPC to other cloud service providers with ease.
我如何使用跨账户 CodeCommit 存储库配置 CodePipeline 源阶段?
我想使用跨账户 AWS CodeCommit 存储库配置 AWS CodePipeline 源阶段。
解决方法
**注意:**CodeCommit 对新客户不可用。现有 CodeCommit 客户可以继续使用此服务。有关更多信息,请参阅如何将 AWS CodeCommit 存储库迁移到另一个 Git 提供商。
在以下解决方法,CodeCommit 存储库使用账户 A,CodePipeline 使用账户 B。
在账户 A 中创建 CodeCommit 存储库
要在账户 A 中创建 CodeCommit 存储库,请参阅创建 AWS CodeCommit 存储库。
在账户 A 中配置跨账户角色
完成以下步骤:
- 在账户 A 中打开 AWS Identity and Access Management (IAM) 控制台。
- 在导航窗格中,选择角色。
- 选择创建新角色,然后完成以下步骤:
选择 AWS 账户作为可信实体类型。
选择另一个 AWS 账户,然后输入账户 B 的 ID。
输入 IAM 角色的名称,例如,cross-account-access-role。 - 使用以下信任策略创建 IAM 角色:
**注意:**将 example-account-b 替换为账户 B ID。{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::example-account-b:root" }, "Action": "sts:AssumeRole", "Condition": {} } ] }
在账户 B 中创建 AWS KMS 密钥来用于 CodePipeline
**注意:**您必须使用 AWS Key Management Service (AWS KMS) 客户自主管理型密钥进行跨账户部署。如果您未配置此密钥,CodePipeline 会使用默认加密对对象进行加密,目标账户角色将无法解密这些对象。
完成以下步骤:
- 在账户 B 中打开 AWS KMS 控制台。
- 在导航窗格中,选择客户自主管理型密钥,然后完成以下步骤:
对于 Key type(密钥类型),选择 Symmetric(对称)。
为密钥使用选择加密和解密。 - 展开高级选项,然后完成以下步骤:
为密钥材料来源,选择 KMS。
在别名中,输入密钥的别名,例如,cmk-key。
对于密钥管理员,选择您想要授予密钥管理员访问权限的 IAM 身份。 - 在其他 AWS 账户部分,选择添加另一个 AWS 账户。
- 输入账户 A 的 ID。
- 选择完成。
在账户 B 中创建 CodePipeline
完成以下步骤:
- 打开 CodePipeline 控制台。
- 选择创建管道,然后为管道命名,例如,account\_B\_pipeline。
注意:****角色名称文本框会自动填充 AWSCodePipelineServiceRole-ap-southeast-2-account\_B\_pipeline 服务角色名称。您也可以选择有权访问 AWS KMS 密钥的现有服务角色。 - 展开高级设置,然后完成以下步骤:
为构件商店选择默认位置。如果需要,您可以选择自定义位置。
为加密密钥选择客户自主管理型密钥,然后在下拉列表中选择 cmk-key。
为源提供商,选择 CodeCommit。
在存储库名称中,输入存储库名称,例如,account-a-repository,以分支名称为主要部分。 - 在添加构建阶段页面上,选择跳过构建阶段,然后选择跳过。
- 在添加部署阶段页面上,为部署提供商选择一项服务。
- 选择下一步创建管道。
注意:如果您在创建管道后收到以下错误消息,请参阅此解决方法的更新管道以使用跨账户角色部分。
错误消息:
“The action failed because no AWS CodeCommit repository named account-a-repository was found.Make sure you are using the correct repository name, and then try again.Error: account-a-repository”
更新账户 B 中的 AWS KMS 使用策略
完成以下步骤:
- 在账户 B 中打开 AWS KMS 控制台。
- 在导航窗格中,选择客户自主管理型密钥。
- 在表中,选择密钥的别名,例如,cmk-key。
- 在密钥用户部分,选择添加。
- 输入管道服务角色,例如,AWSCodePipelineServiceRole-ap-southeast-2-account\_B\_pipeline。
- 将管道服务角色添加到 AWS KMS 密钥策略。以下是一个密钥策略示例:
{ "Id": "key-consolepolicy-3", "Version": "2012-10-17", "Statement": [{ "Sid": "Enable IAM User Permissions", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::example-account-b:root" }, "Action": "kms:*", "Resource": "*" }, { "Sid": "Allow use of the key", "Effect": "Allow", "Principal": { "AWS": ["arn:aws:iam::example-account-b:role/example-service-role/AWSCodePipelineServiceRole-ap-southeast-2-account_B_pipeline", "arn:aws:iam::<Account_A>:root"] }, "Action": ["kms:Encrypt", "kms:Decrypt", "kms:ReEncrypt*", "kms:GenerateDataKey*", "kms:DescribeKey"], "Resource": "*" }, { "Sid": "Allow attachment of persistent resources", "Effect": "Allow", "Principal": { "AWS": ["arn:aws:iam::example-account-b>:role/example-service-role/AWSCodePipelineServiceRole-ap-southeast-2-Account_B_pipeline", "arn:aws:iam::example-account-a:root"] }, "Action": ["kms:CreateGrant", "kms:ListGrants", "kms:RevokeGrant"], "Resource": "*", "Condition": { "Bool": { "kms:GrantIsForAWSResource": "true" } } }] }
在账户 B 中设置代入角色策略
完成以下步骤:
-
在账户 B 中打开 IAM 控制台。
-
在导航窗格中,选择角色,然后选择您的管道角色。
-
将以下策略添加到代入账户 A 角色的管道角色中:
{ "Version": "2012-10-17", "Statement": { "Effect": "Allow", "Action": "sts:AssumeRole", "Resource": [ "arn:aws:iam::example-account-a:example-pipeline-role/*" ] } }**注意:**将 example-account-A 替换为账户 A,将 example-pipeline-role 替换为管道角色。
更新账户 B 中 CodePipeline 构件存储桶的存储桶策略
完成以下步骤:
-
在导航窗格中,选择存储桶,然后选择您的管道存储桶。
-
选择权限,然后选择存储桶策略。
-
在文本编辑器中,更新您的策略,加入以下策略语句:
{ "Version": "2012-10-17", "Id": "example-policy-id", "Statement": [ { "Sid": "", "Effect": "Allow", "Principal": { "AWS": ["arn:aws:iam::example-account-a-id:root", "arn:aws:iam::example-account-b-id:root"] }, "Action": [ "s3:Get*", "s3:Put*" ], "Resource": "arn:aws:s3:::example-pipeline-bucket/*" }, { "Sid": "", "Effect": "Allow", "Principal": { "AWS": ["arn:aws:iam::example-account-a-id:root", "arn:aws:iam::example-account-b-id:root"] }, "Action": "s3:ListBucket", "Resource": "arn:aws:s3:::example-pipeline-bucket" } ] }**注意:**要与 JSON 格式保持一致,正确做法是在现有语句后添加逗号。将 example-policy-id 替换为您的策略 ID,将 example-account-a-id 替换为您的账户 A 的 ID,将 example-account-b-id 替换为您的账户 B 的 ID,将 example-pipeline-bucket 替换为管道存储桶名称。
为账户 A 创建内联 IAM 策略,授予使用账户 B 的 AWS KMS 密钥的权限
完成以下步骤:
- 在账户 A 中打开 IAM 控制台。
- 在导航窗格中,选择角色,然后选择您的 cross-account-access-role。
- 选择创建内联策略。
- 在 JSON 选项卡上,输入以下策略:
**注意:**将 example-account-b-id 替换为账户 B 的 ID,将 example-key-id 替换为 AWS KMS 密钥 ARN,将 example-pipeline-artifact-bucket-arn 替换为管道构件存储桶 ARN。{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "kms:DescribeKey", "kms:GenerateDataKey*", "kms:Encrypt", "kms:ReEncrypt*", "kms:Decrypt" ], "Resource": [ "arn:aws:kms:ap-southeast-2:example-account-b-id:key/example-key-id" ] }, { "Effect": "Allow", "Action": [ "s3:Put*" ], "Resource": [ "arn:aws:s3:::example-pipeline-artifact-bucket-arn/*" ] }, { "Effect": "Allow", "Action": [ "s3:ListBucket" ], "Resource": [ "arn:aws:s3:::example-pipeline-artifact-bucket-arn" ] } ] } - 选择查看策略,然后创建策略。
更新您的管道以使用跨账户角色
**注意:**如果在运行 AWS 命令行界面 (AWS CLI) 命令时收到错误,请参阅 AWS CLI 错误故障排除。此外,应确保您使用的是最新版本的 AWS CLI。
完成以下步骤:
-
要从名为 codepipeline.json 的文件中检索管道定义,运行 get-pipeline 命令:
aws codepipeline get-pipeline --name example-account-b-pipeline > codepipeline.json**注意:**将 example-account-b-pipeline 替换为账户 B 的管道名称。
-
将跨账户 IAM 角色 ARN 添加到 codepipeline.json 文件的源阶段:
{ "name": "Source", "actions": [ { "name": "Source", "actionTypeId": { "category": "Source", "owner": "AWS", "provider": "CodeCommit", "version": "1" }, "runOrder": 1, "roleArn": "arn:aws:iam::example-account-a-id:role/example-cross-account-access-role", "configuration": { "BranchName": "main", "OutputArtifactFormat": "CODE_ZIP", "PollForSourceChanges": "false", "RepositoryName": "example-account-a-repository" }, "outputArtifacts": [ { "name": "SourceArtifact" } ], "inputArtifacts": [], "region": "example-region", "namespace": "SourceVariables" } ] }**注意:**将 example-account-a-id 替换为账户 A 的 ID,将 example-cross-account-access-role 替换为跨账户角色,将 example-account-a-repository 替换为账户 A 的存储库,将 example-region 替换为您的 AWS 区域。
-
删除位于 codepipeline.json 文件末尾的元数据部分。同时删除元数据部分前面的逗号。
示例:"metadata": { "pipelineArn": "arn:aws:codepipeline:ap-southeast-2:12345678912:Account_B_pipeline", "created": "2023-01-11T05:09:20.235000+00:00", "updated": "2023-01-11T17:34:37.294000+00:00" } -
要更新管道,运行 update-pipeline 命令:
aws codepipeline update-pipeline --cli-input-json example-codepipeline.json**注意:**将 example-codepipeline.json 替换为管道 JSON 文件。
**注意:**您还可以使用上述解决方法在其他 AWS 服务上使用来自不同 AWS 账户的 CodeCommit 或 Amazon S3。使用时,将管道阶段的 AWS 服务与其他账户的源阶段相集成。有关更多信息,请参阅在 CodePipeline 中创建使用另一个 AWS 账户中资源的管道。
- 语言
- 中文 (简体)
