AWS Security HubコントロールのパラメーターをAWS CLIで操作する

AWS Security HubコントロールのパラメーターをAWS CLIで操作する

Clock Icon2025.03.26

こんにちは。サービス開発室の武田です。

AWS Security Hubではさまざまなチェック項目が「コントロール」として提供されています。一部のコントロールではチェックの挙動をカスタマイズできるようになっており、それはパラメーターと呼ばれます。

https://dev.classmethod.jp/articles/security-hub-custom-control-params/

今回AWS CLIでパラメーターを操作する機会がありましたので、コマンドについてまとめておきます。

関連コマンド

パラメーターに関するコマンドは次の4つあります。

  • batch-get-security-controls
  • get-security-control-definition
  • list-security-control-definitions
  • update-security-control

関連していそうなコマンドとしてdescribe-standards-controlsというものがありますが、このコマンドは パラメーターに関する情報は含まれていません 。罠です。気をつけましょう。

コマンドを実行してみた

実際にコマンドを実行して結果を確認してみました。

batch-get-security-controls

コントロールの状態を取得します。--security-control-idsで1つ以上のコントロールを指定します。たとえばConfig.1を指定すると次のような結果が取得できます。.SecurityControls[].Parametersにデータが含まれています。

$ aws securityhub batch-get-security-controls --security-control-ids Config.1
{
    "SecurityControls": [
        {
            "SecurityControlId": "Config.1",
            "SecurityControlArn": "arn:aws:securityhub:ap-northeast-1:123456789012:security-control/Config.1",
            "Title": "AWS Config should be enabled and use the service-linked role for resource recording",
            "Description": "This control checks whether AWS Config is enabled in your account in the current AWS Region, records all resources that correspond to controls that are enabled in the current Region, and uses the service-linked AWS Config role.",
            "RemediationUrl": "https://docs.aws.amazon.com/console/securityhub/Config.1/remediation",
            "SeverityRating": "CRITICAL",
            "SecurityControlStatus": "ENABLED",
            "UpdateStatus": "READY",
            "Parameters": {
                "includeConfigServiceLinkedRoleCheck": {
                    "ValueType": "DEFAULT",
                    "Value": {
                        "Boolean": true
                    }
                }
            }
        }
    ]
}

get-security-control-definition

コントロールの定義を取得します。たとえばConfig.1であれば次のような結果が取得できます。

$ aws securityhub get-security-control-definition --security-control-id Config.1
{
    "SecurityControlDefinition": {
        "SecurityControlId": "Config.1",
        "Title": "AWS Config should be enabled and use the service-linked role for resource recording",
        "Description": "This control checks whether AWS Config is enabled in your account in the current AWS Region, records all resources that correspond to controls that are enabled in the current Region, and uses the service-linked AWS Config role.",
        "RemediationUrl": "https://docs.aws.amazon.com/console/securityhub/Config.1/remediation",
        "SeverityRating": "CRITICAL",
        "CurrentRegionAvailability": "AVAILABLE",
        "ParameterDefinitions": {
            "includeConfigServiceLinkedRoleCheck": {
                "Description": "The control doesn't evaluate whether AWS Config uses the service-linked role if the parameter is set to 'false'.",
                "ConfigurationOptions": {
                    "Boolean": {
                        "DefaultValue": true
                    }
                }
            }
        }
    }
}

list-security-control-definitions

コントロールの定義を一覧で取得します。Parametersがあるかないかは把握できますが、get-security-control-definitionと異なり具体的なパラメーター名などはわかりません。

$ aws securityhub list-security-control-definitions --max-items 2
{
    "SecurityControlDefinitions": [
        {
            "SecurityControlId": "ACM.1",
            "Title": "Imported and ACM-issued certificates should be renewed after a specified time period",
            "Description": "This control checks whether an AWS Certificate Manager (ACM) certificate is renewed within the specified time period. It checks both imported certificates and certificates provided by ACM. The control fails if the certificate isn't renewed within the specified time period. Unless you provide a custom parameter value for the renewal period, Security Hub uses a default value of 30 days.",
            "RemediationUrl": "https://docs.aws.amazon.com/console/securityhub/ACM.1/remediation",
            "SeverityRating": "MEDIUM",
            "CurrentRegionAvailability": "AVAILABLE",
            "CustomizableProperties": [
                "Parameters"
            ]
        },
        {
            "SecurityControlId": "ACM.2",
            "Title": "RSA certificates managed by ACM should use a key length of at least 2,048 bits",
            "Description": "This control checks whether RSA certificates managed by AWS Certificate Manager use a key length of at least 2,048 bits. The control fails if the key length is smaller than 2,048 bits.",
            "RemediationUrl": "https://docs.aws.amazon.com/console/securityhub/ACM.2/remediation",
            "SeverityRating": "HIGH",
            "CurrentRegionAvailability": "AVAILABLE",
            "CustomizableProperties": []
        }
    ],
    "NextToken": ""
}

update-security-control

前述したコマンドは取得系でしたが、最後のコマンドは更新系です。たとえば次のコマンドはConfig.1includeConfigServiceLinkedRoleCheckfalseにしています。

$ aws securityhub update-security-control --security-control-id 'Config.1' --parameters '{"includeConfigServiceLinkedRoleCheck": {"ValueType": "CUSTOM", "Value": {"Boolean": false}}}'

デフォルト値に戻したい場合はもう少し指定が簡単です。

$ aws securityhub update-security-control --security-control-id 'Config.1' --parameters '{"includeConfigServiceLinkedRoleCheck": {"ValueType": "DEFAULT"}}'

まとめ

パラメーターに関するコマンドを調査している最中、batch-get-security-controlsをなかなか見つけられず苦労しました。パラメーターに関して操作することがあれば覚えておきましょう。

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.