Git 同期を使用してスタックを Git リポジトリに同期するための前提条件 - AWS CloudFormation

Git 同期を使用してスタックを Git リポジトリに同期するための前提条件

CloudFormation スタックを Git リポジトリに同期する前に、次の要件が満たされていることを確認します:

Git リポジトリ

Git リポジトリは、次のいずれかのプラットフォームでホストされている必要があります。

リポジトリは、パブリックでもプライベートでもかまいません。接続コンソールを使用して、Git リポジトリを CloudFormation に接続する必要があります。

CloudFormation テンプレート

Git リポジトリには、Git 同期で接続する対象のブランチにチェックインされた CloudFormation テンプレートファイルが含まれている必要があります。このテンプレートはスタックデプロイファイルによって参照されます。

Git 同期サービスロール

Git 同期には IAM ロールが必要です。Git 同期の設定時にスタック用の IAM ロールを作成するか、既存のロールを使用するかを選択できます。

注記

自動的に生成された IAM ロールは、そのロールが生成されたスタックにのみ権限を適用します。自動生成された IAM ロールを再利用するには、新しいスタックのロールを編集する必要があります。

Git 同期サービスロールに必要な権限

Git 同期に指定する IAM ロールには、以下の権限が必要です。

  • cloudformation:CreateChangeSet

  • cloudformation:DeleteChangeSet

  • cloudformation:DescribeChangeSet

  • cloudformation:DescribeStackEvents

  • cloudformation:DescribeStacks

  • cloudformation:ExecuteChangeSet

  • cloudformation:ListChangeSets

  • cloudformation:ValidateTemplate

  • events:PutRule

  • events:PutTargets

注記

上記の必要な権限は、Git 同期が生成する IAM ロールに自動的に追加されます。

次の IAM ロールの例には、Git 同期の前提条件となる権限が含まれています。

JSON
{ "Version": "2012-10-17", "Statement": [ { "Sid": "SyncToCloudFormation", "Effect": "Allow", "Action": [ "cloudformation:CreateChangeSet", "cloudformation:DeleteChangeSet", "cloudformation:DescribeChangeSet", "cloudformation:DescribeStackEvents", "cloudformation:DescribeStacks", "cloudformation:ExecuteChangeSet", "cloudformation:GetTemplate", "cloudformation:ListChangeSets", "cloudformation:ListStacks", "cloudformation:ValidateTemplate" ], "Resource": "*" }, { "Sid": "PolicyForManagedRules", "Effect": "Allow", "Action": [ "events:PutRule", "events:PutTargets" ], "Resource": "*", "Condition": { "StringEquals": { "events:ManagedBy": ["cloudformation.sync.codeconnections.amazonaws.com"] } } }, { "Sid": "PolicyForDescribingRule", "Effect": "Allow", "Action": "events:DescribeRule", "Resource": "*" } ] }

信頼ポリシー

信頼関係を定義するロールを作成する際、次の信頼ポリシーを指定する必要があります。

JSON
{ "Version": "2012-10-17", "Statement": [ { "Sid": "CfnGitSyncTrustPolicy", "Effect": "Allow", "Principal": { "Service": "cloudformation.sync.codeconnections.amazonaws.com" }, "Action": "sts:AssumeRole" } ] }

Confused Deputy Problem (混乱した使節の問題) から自分を守るために、aws:SourceArn および aws:SourceAccount の条件キーを使用することをお勧めします。ソースアカウントはアカウント ID で、ソース ARN は、CloudFormation が Git リポジトリに接続できるようにする CodeConnections サービス内の接続の ARN です。

JSON
{ "Version": "2012-10-17", "Statement": [ { "Sid": "CfnGitSyncTrustPolicy", "Effect": "Allow", "Principal": { "Service": "cloudformation.sync.codeconnections.amazonaws.com" }, "Action": "sts:AssumeRole", "Condition": { "StringEquals": { "aws:SourceAccount": "123456789012" }, "ArnLike": { "aws:SourceArn": "arn:aws:codeconnections:us-east-1:123456789012:connection/EXAMPLE64-8aad-4d5d-8878-dfcab0bc441f" } } } ] }

混乱した代理に関する問題の詳細については、「サービス間の混乱した代理の防止」を参照してください。

コンソールユーザーの IAM アクセス権限

CloudFormation コンソールを使用して Git 同期を正常にセットアップするには、エンドユーザーにも IAM を通じてアクセス許可を付与する必要があります。

Git リポジトリへの接続を作成および管理するには、次の codeconnections アクセス許可が必要です。

  • codeconnections:CreateRepositoryLink

  • codeconnections:CreateSyncConfiguration

  • codeconnections:DeleteRepositoryLink

  • codeconnections:DeleteSyncConfiguration

  • codeconnections:GetRepositoryLink

  • codeconnections:GetSyncConfiguration

  • codeconnections:ListRepositoryLinks

  • codeconnections:ListSyncConfigurations

  • codeconnections:ListTagsForResource

  • codeconnections:TagResource

  • codeconnections:UntagResource

  • codeconnections:UpdateRepositoryLink

  • codeconnections:UpdateSyncBlocker

  • codeconnections:UpdateSyncConfiguration

  • codeconnections:UseConnection

コンソールユーザーには、Git 同期セットアッププロセス中にスタックを表示および管理するための次の cloudformation アクセス許可も必要です。

  • cloudformation:CreateChangeSet

  • cloudformation:DeleteChangeSet

  • cloudformation:DescribeChangeSet

  • cloudformation:DescribeStackEvents

  • cloudformation:DescribeStacks

  • cloudformation:ExecuteChangeSet

  • cloudformation:GetTemplate

  • cloudformation:ListChangeSets

  • cloudformation:ListStacks

  • cloudformation:ValidateTemplate

注記

コンソールのみの使用では、変更セットのアクセス許可 (cloudformation:CreateChangeSetcloudformation:DeleteChangeSetcloudformation:DescribeChangeSetcloudformation:ExecuteChangeSet) は厳密に必要ではない場合がありますが、フルスタック検査および管理機能を有効にするために推奨されます。

次の IAM ポリシーの例には、コンソールを使用して Git 同期を設定するために必要なユーザーアクセス許可が含まれています。

JSON
{ "Version": "2012-10-17", "Statement": [ { "Sid": "CodeConnectionsPermissions", "Effect": "Allow", "Action": [ "codeconnections:CreateRepositoryLink", "codeconnections:CreateSyncConfiguration", "codeconnections:DeleteRepositoryLink", "codeconnections:DeleteSyncConfiguration", "codeconnections:GetRepositoryLink", "codeconnections:GetSyncConfiguration", "codeconnections:ListRepositoryLinks", "codeconnections:ListSyncConfigurations", "codeconnections:ListTagsForResource", "codeconnections:TagResource", "codeconnections:UntagResource", "codeconnections:UpdateRepositoryLink", "codeconnections:UpdateSyncBlocker", "codeconnections:UpdateSyncConfiguration", "codeconnections:UseConnection", "codeconnections:CreateForcedTargetSync", "codeconnections:CreatePullRequestForResource" ], "Resource": "*" }, { "Sid": "CloudFormationConsolePermissions", "Effect": "Allow", "Action": [ "cloudformation:CreateChangeSet", "cloudformation:DeleteChangeSet", "cloudformation:DescribeChangeSet", "cloudformation:DescribeStackEvents", "cloudformation:DescribeStacks", "cloudformation:ExecuteChangeSet", "cloudformation:GetTemplate", "cloudformation:ListChangeSets", "cloudformation:ListStacks", "cloudformation:ValidateTemplate" ], "Resource": "*" } ] }
注記

アクセス許可 codeconnections:CreateForcedTargetSynccodeconnections:CreatePullRequestForResource を含む IAM ポリシーを作成すると、これらのアクションが存在しないことを示す警告が IAM コンソールに表示されることがあります。この警告を無視しても、ポリシーは正常に作成されます。これらのアクセス許可は、IAM コンソールでは認識されないものの、特定の Git 同期オペレーションには必要です。