EC2.25
--profile 指定がない場合は Workload アカウントで実行する。export AWS_PROFILE=Workload でデフォルトを設定しておくと便利。Control Tower の有効化・無効化操作(ステップ 6・8)は --profile Master(Organizations 管理アカウント)で実行する。
コントロールの説明
EC2 起動テンプレートのデフォルトバージョンに、ネットワークインターフェースへのパブリック IP 自動割り当て(AssociatePublicIpAddress: true)が設定されていないかをチェックする。デフォルトバージョンに 1 つでも AssociatePublicIpAddress: true のネットワークインターフェースがある場合に FAILED となる。
対応する Config ルール: EC2_LAUNCH_TEMPLATE_PUBLIC_IP_DISABLED(評価頻度: 変更トリガー)
結果
- 起動テンプレートが存在しない場合は PASSED。ResourceId は
AWS::::Account(評価対象リソースなし) AssociatePublicIpAddress: trueの起動テンプレートを作成すると FAILED。ResourceId は起動テンプレート ARN- 起動テンプレートを削除すると PASSED に復帰
- CT.EC2.PV.8(VPC BPA、Declarative Policy 型)を有効化しても finding は FAILED のまま変化しない。VPC BPA はインターネットアクセスをブロックするが、起動テンプレートの
AssociatePublicIpAddress設定自体は変更しないため
検証の流れ
flowchart LR
A[1. デフォルト状態の確認<br>PASSED] --> B[2. パブリック IP 割り当て設定の<br>起動テンプレート作成]
B --> C[3. FAILED 確認]
C --> D[4. 起動テンプレート削除]
D --> E[5. PASSED 復帰確認]
E --> F[6. CT.EC2.PV.8 有効化]
F --> G[7. FAILED のまま変化しないことを確認]
G --> H[8. クリーンアップ]
1. デフォルト状態の確認
既存の起動テンプレートを確認
aws ec2 describe-launch-templates \
--query 'LaunchTemplates[].{LaunchTemplateId:LaunchTemplateId,LaunchTemplateName:LaunchTemplateName}' \
--region ap-northeast-1[]起動テンプレートが存在しないため評価対象リソースなし。
Security Hub finding の現在の状態を確認
aws securityhub get-findings \
--filters '{
"ComplianceSecurityControlId": [{"Comparison": "EQUALS", "Value": "EC2.25"}],
"AwsAccountId": [{"Comparison": "EQUALS", "Value": "<アカウント ID>"}],
"WorkflowStatus": [{"Comparison": "NOT_EQUALS", "Value": "SUPPRESSED"}],
"RecordState": [{"Comparison": "EQUALS", "Value": "ACTIVE"}]
}' \
--query 'Findings[].{Status:Compliance.Status,ResourceId:Resources[0].Id}' \
--region ap-northeast-1[
{
"Status": "PASSED",
"ResourceId": "AWS::::Account:<アカウント ID>"
}
]起動テンプレートが存在しない場合、Config の評価結果は空となり、Security Hub はアカウントレベルの PASSED(AWS::::Account)を返す。
2. パブリック IP 割り当て設定の起動テンプレート作成
aws ec2 create-launch-template \
--launch-template-name cspm-ec2-25-test \
--launch-template-data '{
"NetworkInterfaces": [
{
"DeviceIndex": 0,
"AssociatePublicIpAddress": true
}
]
}' \
--query 'LaunchTemplate.{LaunchTemplateId:LaunchTemplateId,LaunchTemplateName:LaunchTemplateName,DefaultVersionNumber:DefaultVersionNumber}' \
--region ap-northeast-1{
"LaunchTemplateId": "<起動テンプレート ID>",
"LaunchTemplateName": "cspm-ec2-25-test",
"DefaultVersionNumber": 1
}作成確認
aws ec2 describe-launch-template-versions \
--launch-template-name cspm-ec2-25-test \
--versions '$Default' \
--query 'LaunchTemplateVersions[].{VersionNumber:VersionNumber,AssociatePublicIpAddress:LaunchTemplateData.NetworkInterfaces[0].AssociatePublicIpAddress}' \
--region ap-northeast-1[
{
"VersionNumber": 1,
"AssociatePublicIpAddress": true
}
]NetworkInterfaces のみを指定しており、ImageId や InstanceType は含まれていない。このテンプレートは EC2.25 のチェック対象(NIC 設定)を確認するためのものであり、実際にインスタンスを起動するためのテンプレートではない。3. FAILED 確認
Config ルールの手動トリガー
aws configservice start-config-rules-evaluation \
--config-rule-names securityhub-ec2-launch-template-public-ip-disabled-<サフィックス> \
--region ap-northeast-1
(出力なし)Config 評価結果の確認
aws configservice get-compliance-details-by-config-rule \
--config-rule-name securityhub-ec2-launch-template-public-ip-disabled-<サフィックス> \
--query 'EvaluationResults[].{ResourceId:EvaluationResultIdentifier.EvaluationResultQualifier.ResourceId,ComplianceType:ComplianceType}' \
--region ap-northeast-1[
{
"ResourceId": "<起動テンプレート ID>",
"ComplianceType": "NON_COMPLIANT"
}
]Security Hub finding の FAILED 確認
aws securityhub get-findings \
--filters '{
"ComplianceSecurityControlId": [{"Comparison": "EQUALS", "Value": "EC2.25"}],
"AwsAccountId": [{"Comparison": "EQUALS", "Value": "<アカウント ID>"}],
"WorkflowStatus": [{"Comparison": "NOT_EQUALS", "Value": "SUPPRESSED"}],
"RecordState": [{"Comparison": "EQUALS", "Value": "ACTIVE"}]
}' \
--query 'Findings[].{Status:Compliance.Status,ResourceId:Resources[0].Id}' \
--region ap-northeast-1[
{
"Status": "FAILED",
"ResourceId": "arn:aws:ec2:ap-northeast-1:<アカウント ID>:launch-template/<起動テンプレート ID>"
},
{
"Status": "PASSED",
"ResourceId": "AWS::::Account:<アカウント ID>"
}
]4. 起動テンプレート削除
aws ec2 delete-launch-template \
--launch-template-name cspm-ec2-25-test \
--query 'LaunchTemplate.{LaunchTemplateId:LaunchTemplateId,LaunchTemplateName:LaunchTemplateName}' \
--region ap-northeast-1{
"LaunchTemplateId": "<起動テンプレート ID>",
"LaunchTemplateName": "cspm-ec2-25-test"
}削除確認
aws ec2 describe-launch-templates \
--query 'LaunchTemplates[?LaunchTemplateName==`cspm-ec2-25-test`].LaunchTemplateName' \
--region ap-northeast-1[]5. PASSED 復帰確認
Config ルールの手動トリガー
aws configservice start-config-rules-evaluation \
--config-rule-names securityhub-ec2-launch-template-public-ip-disabled-<サフィックス> \
--region ap-northeast-1
(出力なし)Security Hub finding の PASSED 確認
aws securityhub get-findings \
--filters '{
"ComplianceSecurityControlId": [{"Comparison": "EQUALS", "Value": "EC2.25"}],
"AwsAccountId": [{"Comparison": "EQUALS", "Value": "<アカウント ID>"}],
"WorkflowStatus": [{"Comparison": "NOT_EQUALS", "Value": "SUPPRESSED"}],
"RecordState": [{"Comparison": "EQUALS", "Value": "ACTIVE"}]
}' \
--query 'Findings[].{Status:Compliance.Status,ResourceId:Resources[0].Id}' \
--region ap-northeast-1[
{
"Status": "PASSED",
"ResourceId": "AWS::::Account:<アカウント ID>"
}
]起動テンプレートを削除すると、起動テンプレート ARN の FAILED finding は消え、AWS::::Account の PASSED finding のみ残る。
6. CT.EC2.PV.8 有効化
まずパブリック IP 割り当て設定の起動テンプレートを作成して FAILED 状態を作成し、確認してから CT.EC2.PV.8 を有効化する。
起動テンプレート作成
aws ec2 create-launch-template \
--launch-template-name cspm-ec2-25-test \
--launch-template-data '{
"NetworkInterfaces": [
{
"DeviceIndex": 0,
"AssociatePublicIpAddress": true
}
]
}' \
--query 'LaunchTemplate.{LaunchTemplateId:LaunchTemplateId,LaunchTemplateName:LaunchTemplateName,DefaultVersionNumber:DefaultVersionNumber}' \
--region ap-northeast-1{
"LaunchTemplateId": "<起動テンプレート ID 2>",
"LaunchTemplateName": "cspm-ec2-25-test",
"DefaultVersionNumber": 1
}Config ルールの手動トリガーと FAILED 確認
aws configservice start-config-rules-evaluation \
--config-rule-names securityhub-ec2-launch-template-public-ip-disabled-<サフィックス> \
--region ap-northeast-1
(出力なし)aws configservice get-compliance-details-by-config-rule \
--config-rule-name securityhub-ec2-launch-template-public-ip-disabled-<サフィックス> \
--query 'EvaluationResults[].{ResourceId:EvaluationResultIdentifier.EvaluationResultQualifier.ResourceId,ComplianceType:ComplianceType}' \
--region ap-northeast-1[
{
"ResourceId": "<起動テンプレート ID 2>",
"ComplianceType": "NON_COMPLIANT"
}
]Security Hub finding の FAILED 確認
aws securityhub get-findings \
--filters '{
"ComplianceSecurityControlId": [{"Comparison": "EQUALS", "Value": "EC2.25"}],
"AwsAccountId": [{"Comparison": "EQUALS", "Value": "<アカウント ID>"}],
"WorkflowStatus": [{"Comparison": "NOT_EQUALS", "Value": "SUPPRESSED"}],
"RecordState": [{"Comparison": "EQUALS", "Value": "ACTIVE"}]
}' \
--query 'Findings[].{Status:Compliance.Status,ResourceId:Resources[0].Id}' \
--region ap-northeast-1[
{
"Status": "FAILED",
"ResourceId": "arn:aws:ec2:ap-northeast-1:<アカウント ID>:launch-template/<起動テンプレート ID 2>"
},
{
"Status": "PASSED",
"ResourceId": "AWS::::Account:<アカウント ID>"
}
]CT.EC2.PV.8 有効化
aws controltower enable-control \
--control-identifier arn:aws:controlcatalog:::control/acfp8qjz7eggnursu5pfw7q2w \
--target-identifier <OU の ARN> \
--region ap-northeast-1 --profile Master{
"arn": "<有効化 ARN>",
"operationIdentifier": "<オペレーション ID>"
}aws controltower get-control-operation \
--operation-identifier <オペレーション ID> \
--query 'controlOperation.{operationType:operationType,status:status}' \
--region ap-northeast-1 --profile Master{
"operationType": "ENABLE_CONTROL",
"status": "SUCCEEDED"
}7. FAILED のまま変化しないことを確認
Config ルールの手動トリガー
aws configservice start-config-rules-evaluation \
--config-rule-names securityhub-ec2-launch-template-public-ip-disabled-<サフィックス> \
--region ap-northeast-1
(出力なし)Config 評価結果の確認(NON_COMPLIANT のまま)
aws configservice get-compliance-details-by-config-rule \
--config-rule-name securityhub-ec2-launch-template-public-ip-disabled-<サフィックス> \
--query 'EvaluationResults[].{ResourceId:EvaluationResultIdentifier.EvaluationResultQualifier.ResourceId,ComplianceType:ComplianceType}' \
--region ap-northeast-1[
{
"ResourceId": "<起動テンプレート ID 2>",
"ComplianceType": "NON_COMPLIANT"
}
]Security Hub finding の確認(FAILED のまま)
aws securityhub get-findings \
--filters '{
"ComplianceSecurityControlId": [{"Comparison": "EQUALS", "Value": "EC2.25"}],
"AwsAccountId": [{"Comparison": "EQUALS", "Value": "<アカウント ID>"}],
"WorkflowStatus": [{"Comparison": "NOT_EQUALS", "Value": "SUPPRESSED"}],
"RecordState": [{"Comparison": "EQUALS", "Value": "ACTIVE"}]
}' \
--query 'Findings[].{Status:Compliance.Status,ResourceId:Resources[0].Id}' \
--region ap-northeast-1[
{
"Status": "FAILED",
"ResourceId": "arn:aws:ec2:ap-northeast-1:<アカウント ID>:launch-template/<起動テンプレート ID 2>"
},
{
"Status": "PASSED",
"ResourceId": "AWS::::Account:<アカウント ID>"
}
]VPC BPA は起動テンプレートの AssociatePublicIpAddress 設定自体を変更しないため、finding は NON_COMPLIANT のまま変化しない。
8. クリーンアップ
CT.EC2.PV.8 の無効化
aws controltower disable-control \
--control-identifier arn:aws:controlcatalog:::control/acfp8qjz7eggnursu5pfw7q2w \
--target-identifier <OU の ARN> \
--region ap-northeast-1 --profile Master{
"operationIdentifier": "<オペレーション ID>"
}aws controltower get-control-operation \
--operation-identifier <オペレーション ID> \
--query 'controlOperation.{operationType:operationType,status:status}' \
--region ap-northeast-1 --profile Master{
"operationType": "DISABLE_CONTROL",
"status": "SUCCEEDED"
}起動テンプレート削除
aws ec2 delete-launch-template \
--launch-template-name cspm-ec2-25-test \
--query 'LaunchTemplate.{LaunchTemplateId:LaunchTemplateId,LaunchTemplateName:LaunchTemplateName}' \
--region ap-northeast-1{
"LaunchTemplateId": "<起動テンプレート ID 2>",
"LaunchTemplateName": "cspm-ec2-25-test"
}補足:Config ルール名の確認方法
Config ルール名のサフィックスは環境によって異なる。以下のコマンドで確認できる。
aws configservice describe-config-rules \
--query 'ConfigRules[?contains(Source.SourceIdentifier,`EC2_LAUNCH_TEMPLATE_PUBLIC_IP_DISABLED`)].ConfigRuleName' \
--region ap-northeast-1補足:デフォルトバージョンの切り替えによる finding の変化
EC2.25 はデフォルトバージョンのみを評価する。デフォルトバージョンを切り替えることで finding が変化する。例えば、AssociatePublicIpAddress: false の v1 と AssociatePublicIpAddress: true の v2 が存在する場合、v2 をデフォルトに設定すると FAILED、v1 に戻すと PASSED となる。「デフォルトバージョンを変えるだけで finding が切り替わる」という点は運用上の注意点である。