Image Builder で暗号化された AMI の配布エラーをトラブルシューティングするにはどうすればよいですか?
暗号化された AMI を EC2 Image Builder の別のアカウントに配布しようとすると、エラーが発生します。これを解決するにはどうすれば良いですか?
簡単な説明
以下のシナリオでは、暗号化された Amazon マシンイメージ (AMI) を別のアカウントに配布するときに、EC2 Image Builder で配布エラーを発生することがあります。
- 配布される AMI は、Amazon Elastic Block Store (Amazon EBS) のデフォルトの AWS マネージドキーを使用して暗号化されます。
- AWS Key Management Service (AWS KMS) または AWS Identity and Access Management (IAM) エンティティには、必要な権限がありません。
解決方法
配布される AMI は、Amazon EBS のデフォルトの AWS マネージドキーを使用して暗号化されます
次のエラーが表示されます。
Distribution failed with JobId 'XXXXXXXXXXXXXX', status = 'Failed' for ARN 'arn:aws:imagebuilder:us-east-1:xxxxxxxxxxxx:image/test-recipe/0.0.1/1'. 'Not all distribution jobs are completed. 1) EC2 Client Error: 'Snapshots encrypted with the AWS Managed CMK can’t be shared. Specify another snapshot.' when distributing the image from the source account (ID: xxxxxxxxxxxx) to the destination account (ID: xxxxxxxxxxxx) in Region us-east-1.'
デフォルトの AWS KMS キーで暗号化された AMI を共有できません。詳細については、「AMI を特定の AWS アカウントと共有する」を参照してください。
確認するシナリオは次の内容を含みます。
- AWS が管理する KMS キーが、recipe のストレージ設定で指定されています。
- AWS が管理する KMS キーが、1つ以上のターゲットアカウントとともに配布設定で指定されています。
- 親 AMI は、AWS が管理する KMS キーを使用して暗号化されます。
- 親 AMI には複数のスナップショットがあり、少なくとも 1 つは AWS が管理する KMS キーで暗号化されています。
- AWS リージョンで[Encryption by default] (デフォルトで暗号化) が有効になっており、AWS が管理する KMS キーを使用しています。
この問題を解決するには、イメージ recipe の新しいバージョンを作成し、recipe のストレージ設定でお客様が管理する KMS キーを暗号化用に指定します。配布設定の KMS キーでは、AMI を他のアカウントに配布するときに、お客様が管理する KMS キーを暗号化用に指定します。
AWS KMS または IAM エンティティに必要な権限がありません
launchPermissions またはtargetAccountIds 設定のいずれかを使用して、Image Builder で AMI を配布できます。
launchPermissions
launchPermissions を使用して AMI を配布する場合、Image Builder はソースアカウントで IAM ロールAWSServiceRoleForImageBuilder を使用します。デフォルトでは、AWSServiceRoleForImageBuilder に、ソースアカウントのリソースに必要な AWS KMS 権限があります。
KMS キーポリシーには、ルートユーザーに対して**「kms:**」アクションを許可するステートメントがあります。このステートメントがキーポリシーに含まれていない場合、[service-linked role] (サービスにリンクされたロール) はソースアカウントのキーにアクセスできません。ルートユーザーに「kms:**」**アクションが許可されていない場合、サービスにリンクされた役割がキーを使用できるようにポリシーを変更します。
例:
{ "Sid": "Enable IAM User Permissions", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::source_account_id:role/aws-service-role/imagebuilder.amazonaws.com/AWSServiceRoleForImageBuilder" }, "Action": [ "kms:Decrypt", "kms:Encrypt", "kms:GenerateDataKeyWithoutPlaintext", "kms:DescribeKey", "kms:CreateGrant", "kms:ReEncryptFrom", "kms:ReEncryptTo" ], "Resource": "*" }
注: source_account_id をソースアカウントの ID に置き換えます。
targetAccountIds
宛先アカウントに IAM ロール EC2ImageBuilderDistributionCrossAccountRole がない場合、または送信元アカウントが信頼ポリシーにリストされていない場合、次のエラーが発生します。
Distribution failed with JobId 'xxxxxxxxxxxxxx', status = 'Failed' for ARN 'arn:aws:imagebuilder:us-east-1:XXXXXXXXXX:image/testdistribution/2.0.0/3'. 'Not all distribution jobs are completed. 1) STS Client Error: 'User: arn:aws:sts::XXXXXXXXXXXX:assumed-role/AWSServiceRoleForImageBuilder/Ec2ImageBuilderIntegrationService is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::xxxxxxxxx:role/EC2ImageBuilderDistributionCrossAccountRole'. Please make sure your 'EC2ImageBuilderDistributionCrossAccountRole' is setup with correct permission policies. If you are copying AMI to opt-in regions, please make sure the region is enabled in the account when distributing the image from the source account (ID: XXXXXXXXXXXX) to the destination account (ID: XXXXXXXXXXXX) in Region us-east-1.'STS Client Error User is not authorized to perform: sts:AssumeRole on resource.
この問題を解決するには、ロール EC2ImageBuilderDistributionCrossAccountRole を作成します。次に、Ec2ImageBuilderCrossAccountDistributionAccess ポリシーをアタッチして、クロスアカウント配布を許可します。次に、EC2ImageBuilderDistributionCrossAccountRoleの 信頼ポリシーに AWSServiceRoleForImageBuilder をリストします。
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "ec2.amazonaws.com", "AWS": "arn:aws:iam::XXXXXXXXXX:root" }, "Action": "sts:AssumeRole" } ] }
クロスアカウント AWS KMS 権限の問題により、次のエラーが発生する場合があります。
Distribution failed with JobId 'xxxxxxxxxxxxxx', status = 'Failed' for ARN 'arn:aws:imagebuilder:ap-southeast-2:11111111111:image/test/1.0.0/1'. 'Not all distribution jobs are completed. 1) AMI Copy Reported Failure For 'ami-0047623fbcxxxxx' when distributing the image from the source account (ID: 11111111111) to the destination account (ID: 222222222222) in Region ap-southeast-2.'
targetAccountIdsを使用して AMI を配布する場合、Image Builder はソースアカウントでロール AWSServiceRoleForImageBuilderを使用します。宛先アカウントでは、ロール EC2ImageBuilderDistributionCrossAccountRole を使用します。配布設定と recipe のストレージ設定で EC2ImageBuilderDistributionCrossAccountRole に、 AWS KMS キーを使用する権限を付与していることを確認してください。
例:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "kms:Decrypt", "kms:Encrypt", "kms:GenerateDataKeyWithoutPlaintext", "kms:DescribeKey", "kms:CreateGrant", "kms:ReEncryptFrom", "kms:ReEncryptTo" ], "Resource": "*" } ] }
注: AWS KMS キーの ARN を指定して、[Resource] (リソース) セクションを制限することもできます。
お客様が管理する KMS キーが宛先アカウントに属している場合は、AWS KMS キーをソースアカウントと共有する必要があります。お客様が管理する KMS キーがソースアカウントに属している場合は、AWS KMS キーを宛先アカウントと共有する必要があります。
AWS KMS キーを共有するには、次のステップを実行します。
1. KMS キーがあるアカウントにログインします。
2. 同じ AWS リージョンで [AWS KMS console] (AWS KMS コンソール) を開きます。
3. 左側のナビゲーションペインで、[Customer managed keys] (カスタマーマネージドキー) を選択します。
4. [KMS key ID] (KMS キー ID) を選択します。
5. [Key Policy] (キーポリシー) タブを選択します。
6. [Other AWS accounts] (その他の AWS アカウント) セクションで、[Add other AWS accounts] (その他の AWS アカウントを追加) を選択します。
7. KMS キーを共有するアカウントの ID を指定します。
8. [Save Changes] (変更を保存) を選択します。
関連情報
関連するコンテンツ
- 質問済み 3日前lg...
- 質問済み 6年前lg...
- 承認された回答質問済み 8ヶ月前lg...
- AWS公式更新しました 9ヶ月前
- AWS公式更新しました 1年前