😡
共有されたAMIのAutoScalingは追加で許可が必要
背景
共通アカウントで作成したAMIを開発アカウントに共有した。
このAMIで起動テンプレートとAutoScalingでEC2を起動させようとしたところエラーになった。
今回はこの中で意識外の箇所があったため残しておきたい。
前提条件
- AMIは別のアカウントから共有されている
- AMIはKMS(CMK)で暗号化されておりKMSのポリシーで開発アカウントは許可していた
- 今まで他のアカウントではうまくできていた。何かが足りていない
エラー内容の一部
Launching a new EC2 instance: i-0c0355afba1c09d8a. Status Reason: Instance became unhealthy while waiting for instance to be in InService state. Termination Reason: Client.InvalidKMSKey.InvalidState: The KMS key provided is in an incorrect state
At 2025-04-10T06:59:54Z an instance was started in response to a difference between desired and actual capacity, increasing the capacity from 0 to 1.
解決への道のり
CloudTrailを参照
復号化に失敗しているように見える。
"errorMessage": "User: arn:aws:sts::123456789145:assumed-role/AWSServiceRoleForAutoScaling/AutoScaling is not authorized to perform: kms:ReEncryptFrom on the resource associated with this ciphertext because no identity-based policy allows the kms:ReEncryptFrom action",
"requestParameters": null,
注目箇所
当時は見逃してたが認証エラーを起こしていた
assumed-role/AWSServiceRoleForAutoScaling/AutoScaling is not authorized
解決
キーポリシーの追加とcreate-grantコマンドによる権限付与が必要だった
暗号化された AMI または Amazon EC2 Auto Scaling を使用して暗号化されたボリュームで EC2 インスタンスを起動できないに書かれていた。
Discussion