こんにちは、エンタープライズクラウド部の山本拓海です。
ブランキージェットシティで好きなアルバムはLOVE FLASH FEVERです。1つに絞るのが難しいところですが。
先日、CloudFormationを用いて、SecurityHubのセキュリティ標準の有効化とコントロールの無効化をいたしました。
その際に遭遇したもやもやポイントをご紹介いたします。
もやもやポイント1. コントロールのARNはセキュリティ標準を有効化しないと把握できない
CloudFormationでコントロールの無効化を行う場合、無効化したいコントロールのARNの入力が必要ですが、webには情報がありません。
ARNは以下のCLIコマンドで取得できます。
aws securityhub describe-standards-controls --standards-subscription-arn "${セキュリティ標準のサブスクリプションARN}" # 実行結果 # { # "Controls": [ # { # "StandardsControlArn": "arn:aws:securityhub:ap-northeast-1:111111111111:control/aws-foundational-security-best-practices/v/1.0.0/ACM.1", # "ControlStatus": "ENABLED", # "ControlStatusUpdatedAt": "2022-08-30T05:55:38.703000+00:00", # "ControlId": "ACM.1", # "Title": "Imported and ACM-issued certificates should be renewed after a specified time period", # "Description": "This AWS control checks whether ACM Certificates in your account are marked for expiration within a specified time period. Certificates provided by ACM are automatically renewed. ACM does not automatically renew certificates that you import.", # "RemediationUrl": "https://docs.aws.amazon.com/console/securityhub/ACM.1/remediation", # "SeverityRating": "MEDIUM", # "RelatedRequirements": [] # } # ....
このCLIコマンドを実行するには、オプションで指定するセキュリティ標準のサブスクリプションARNがわからないと実行できません。
セキュリティ標準のサブスクリプションARNは以下のCLIコマンドで取得できます。
aws securityhub get-enabled-standards
このコマンドは有効化されているセキュリティ標準のARNを取得します。有効化されていないセキュリティ標準のサブスクリプションARNはありません。なので、セキュリティ標準を有効化する必要があります。
つまり、以下のようなステップを踏まないとコントロールの正確なARNを把握することができません。(なんとなくARNは予測はできますが。)
- セキュリティ標準を有効化する
- 有効化されているセキュリティ標準のサブスクリプションARNを取得する
- 無効化したいコントロールのARNを取得する
コントロールのARNを把握するだけで手間がかかります。私は心が折れかけました。
なお、コントロールを取得するコマンドではフィルターをかけないと全コントロールが出力されます。
適宜フィルターして実行しましょう。
以下は返り値のControl Idでフィルターした実行例と実行結果です
aws securityhub describe-standards-controls --standards-subscription-arn "${セキュリティ標準のサブスクリプションARN}" | jq '.Controls[] | select(.ControlId == "IAM.6")' # { # "StandardsControlArn": "arn:aws:securityhub:ap-northeast-1:xxxxxxxx:control/aws-foundational-security-best-practices/v/1.0.0/IAM.6", # "ControlStatus": "ENABLED", # "ControlStatusUpdatedAt": "2023-07-04T05:20:06.660000+00:00", # "ControlId": "IAM.6", # "Title": "Hardware MFA should be enabled for the root user", # "Description": "This AWS control checks whether your AWS account is enabled to use a hardware multi-factor authentication (MFA) device to sign in with root user credentials.", # "RemediationUrl": "https://docs.aws.amazon.com/console/securityhub/IAM.6/remediation", # "SeverityRating": "CRITICAL", # "RelatedRequirements": [] # }
もやもやポイント2. 2つ以上のセキュリティ標準を有効化する場合、セキュリティ標準ごとに無効化が必要なコントロールがある
CloudFormationでセキュリティ標準の有効化を行う場合、有効化するセキュリティ標準ごとにAWS::SecurityHub::Standardリソースを記述します。
同じリソースでコントロールを無効化する場合、DisabledStandardsControls.StandardsControlArn を指定します。
SecurityStandard1: Type: AWS::SecurityHub::Standard Properties: StandardsArn: 有効化するセキュリティ標準のARN DisabledStandardsControls: - StandardsControlArn: 無効化したいコントロールのARN Reason: 文字列
例えば、「IAM.6 ハードウェア MFA はルートユーザーに対して有効にする必要があります」 を無効化する場合、もやもやポイント1のCLIでコントロールのARNを取得し、DisabledStandardsControls.StandardsControlArn にて指定します。
さらに、セキュリティ標準 CIS AWS Foundations Benchmark v1.2.0も有効化するようにCFnテンプレートを書くと、以下のようになると思います。
SecurityStandard1: Type: AWS::SecurityHub::Standard Properties: StandardsArn: !Sub arn:${AWS::Partition}:securityhub:${AWS::Region}::standards/aws-foundational-security-best-practices/v/1.0.0 DisabledStandardsControls: - StandardsControlArn: !Sub arn:${AWS::Partition}:securityhub:${AWS::Region}:${AWS::AccountId}:control/aws-foundational-security-best-practices/v/1.0.0/IAM.6 Reason: "checked" SecurityStandard2: Type: AWS::SecurityHub::Standard Properties: StandardsArn: arn:aws:securityhub:::ruleset/cis-aws-foundations-benchmark/v/1.2.0
ですが、この状態だと「IAM.6 ハードウェア MFA はルートユーザーに対して有効にする必要があります」 を無効化できません。 CIS AWS Foundations Benchmark v1.2.0にも「IAM.6 ハードウェア MFA はルートユーザーに対して有効にする必要があります」に該当するコントロールが存在するため、 SecurityStandard2リソースでもDisabledStandardsControls.StandardsControlArn の指定が必要になります。 無効化の指定をしないことにより有効化すると見なされ、無効化の指定を上書きしてしまう挙動のようです。
どのコントロールの無効化が必要になるかは、コントロールのリファレンスガイドにあります。
https://docs.aws.amazon.com/ja_jp/securityhub/latest/userguide/iam-controls.html#iam-6
[IAM.6] ルートユーザーに対してハードウェア MFA を有効にする必要があります 関連する要件: PCI DSS v3.2.1/8.3.1、CIS AWS Foundations Benchmark v1.2.0/1.14、CIS AWS Foundations Benchmark v1.4.0/1.6、NIST.800-53.r5 AC-2(1)、NIST.800-53.r5 AC-3(15)、NIST.800-53.r5 IA-2(1)、NIST.800-53.r5 IA-2(2)、NIST.800-53.r5 IA-2(6)、NIST.800-53.r5 IA-2(8)
CIS AWS Foundations Benchmark v1.2.0/1.14が該当するので、このARNを指定します。
SecurityStandard1: Type: AWS::SecurityHub::Standard Properties: StandardsArn: !Sub arn:${AWS::Partition}:securityhub:${AWS::Region}::standards/aws-foundational-security-best-practices/v/1.0.0 DisabledStandardsControls: - StandardsControlArn: !Sub arn:${AWS::Partition}:securityhub:${AWS::Region}:${AWS::AccountId}:control/aws-foundational-security-best-practices/v/1.0.0/IAM.6 Reason: "checked" SecurityStandard2: Type: AWS::SecurityHub::Standard Properties: StandardsArn: arn:aws:securityhub:::ruleset/cis-aws-foundations-benchmark/v/1.2.0 DisabledStandardsControls: - StandardsControlArn: !Sub arn:aws:securityhub:${AWS::Region}:${AWS::AccountId}:control/cis-aws-foundations-benchmark/v/1.2.0/1.14 Reason: "checked"
これで「IAM.6 ハードウェア MFA はルートユーザーに対して有効にする必要があります」が無効化されます。
もやもやポイント3. リージョンによって存在しないセキュリティコントロールがある
SecurityHubはリージョンレベルのリソースなので、リージョンごとに管理が必要になります。 以下のCloudFormationテンプレートをap-northeast-1とap-northeast-3で実行し、AWS Foundational Security Best Practices標準とIAM.6とRDS.13のコントロールを無効化しようと思います。
SecurityStandard1: Type: AWS::SecurityHub::Standard Properties: StandardsArn: !Sub arn:${AWS::Partition}:securityhub:${AWS::Region}::standards/aws-foundational-security-best-practices/v/1.0.0 DisabledStandardsControls: - StandardsControlArn: !Sub arn:${AWS::Partition}:securityhub:${AWS::Region}:${AWS::AccountId}:control/aws-foundational-security-best-practices/v/1.0.0/IAM.6 Reason: "checked" - StandardsControlArn: !Sub arn:${AWS::Partition}:securityhub:${AWS::Region}:${AWS::AccountId}:control/aws-foundational-security-best-practices/v/1.0.0/RDS.13 Reason: "checked"
すると、ap-northeast-3リージョンでエラーとなります。 原因はAWS Foundational Security Best Practices標準のRDS.13のコントロールがap-northeast-3では存在しないからです。 そのため、同じCloudFormationテンプレートを実行する場合、実行するリソースをリージョンで切り替えられるようにする必要があります。 以下が例となります。
Conditions: IsOsaka: !Equals - !Ref AWS::Region - ap-northeast-3 IsNotOsaka: !Not - !Condition IsOsaka Resources: SecurityStandard1: Type: AWS::SecurityHub::Standard Condition: IsNotOsaka Properties: StandardsArn: !Sub arn:${AWS::Partition}:securityhub:${AWS::Region}::standards/aws-foundational-security-best-practices/v/1.0.0 DisabledStandardsControls: - StandardsControlArn: !Sub arn:${AWS::Partition}:securityhub:${AWS::Region}:${AWS::AccountId}:control/aws-foundational-security-best-practices/v/1.0.0/IAM.6 Reason: "enough" - StandardsControlArn: !Sub arn:${AWS::Partition}:securityhub:${AWS::Region}:${AWS::AccountId}:control/aws-foundational-security-best-practices/v/1.0.0/RDS.13 Reason: "enough" ## ap-northeast-3 に RDS.13のコントロールがないため、実行するリソースを分ける SecurityStandard1Osaka: Type: AWS::SecurityHub::Standard Condition: IsOsaka Properties: StandardsArn: !Sub arn:${AWS::Partition}:securityhub:${AWS::Region}::standards/aws-foundational-security-best-practices/v/1.0.0 DisabledStandardsControls: - StandardsControlArn: !Sub arn:${AWS::Partition}:securityhub:${AWS::Region}:${AWS::AccountId}:control/aws-foundational-security-best-practices/v/1.0.0/IAM.6 Reason: "enough"
コントロールを無効化できるかを事前に把握するためには、大阪リージョンで該当のセキュリティ標準を有効化し、コントロールが存在するか確認する必要があります。(もやもやポイント1参照)
おわりに
CFnでセキュリティ標準の対応した時に遭遇したもやもやポイントを3つ紹介いたしました。
事前にわかっていれば作業をスムーズにすすめられるポイントばかりなので、開発前に目を通していただき、開発時間の短縮のお力になれれば幸いです。