[AWS Security Hub]セキュリティ基準のコントロールを AWS CLIから無効化する

AWS Security Hub のセキュリティ基準のコントロールを、AWS CLIを使って無効化してみます
2020.12.14

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

はじめに

Security Hub のセキュリティ基準に対する操作を AWS CLIから行ってみます。

今回はいくつかのアカウントで、複数のコントロールの無効化をまとめて行いたかったため、 AWS CLIから実施してみます。 実施したコマンドの説明をしていきます。

※実施時のAWS CLI のバージョンは 2.1.6

特定コントロールの無効化手順

流れは以下の通り。

  1. セキュリティ基準のサブスクリプションARNを取得
  2. セキュリティ基準のコントロール一覧を取得
  3. コントロールを更新(無効化)

1. get-enabled-standards でセキュリティ基準のサブスクリプションARNを取得

aws securityhub get-enabled-standards で 有効化しているセキュリティ基準のサブスクリプションARN StandardsSubscriptionArn を取得しましょう。

> aws securityhub get-enabled-standards --output yaml

StandardsSubscriptions:
- StandardsArn: arn:aws:securityhub:ap-northeast-1::standards/aws-foundational-security-best-practices/v/1.0.0
  StandardsInput: {}
  StandardsStatus: READY
  StandardsSubscriptionArn: arn:aws:securityhub:ap-northeast-1:123456789012:subscription/aws-foundational-security-best-practices/v/1.0.0
  # ↑ コレ

2. describe-standards-controls でセキュリティ基準のコントロール一覧を取得

aws securityhub describe-standards-controls で セキュリティ基準のコントロール一覧を取得します。 コマンドのパラメータとして先程の StandardsSubscriptionArn が必要です。

> STD_SUBSCRIPTION_ARN="arn:aws:securityhub:ap-northeast-1:123456789012:subscription/aws-foundational-security-best-practices/v/1.0.0"
> aws securityhub describe-standards-controls --standards-subscription-arn $STD_SUBSCRIPTION_ARN --output yaml

Controls:
- ControlId: ACM.1
  ControlStatus: ENABLED
  ControlStatusUpdatedAt: '2020-07-20T02:19:02.424000+00:00'
  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.
  RelatedRequirements: []
  RemediationUrl: https://docs.aws.amazon.com/console/securityhub/ACM.1/remediation
  SeverityRating: MEDIUM
  StandardsControlArn: arn:aws:securityhub:ap-northeast-1:123456789012:control/aws-foundational-security-best-practices/v/1.0.0/ACM.1
  Title: ACM certificates should be renewed after a specified time period
- ControlId: AutoScaling.1
  ControlStatus: ENABLED
  ControlStatusUpdatedAt: '2020-07-28T00:09:46.154000+00:00'
  # 以下略

次の工程(無効化)に必要なのはセキュリティ基準のコントロールARN StandardsControlArn です。 一覧は以下のように query 使って出力できます。

> aws securityhub describe-standards-controls --standards-subscription-arn $STD_SUBSCRIPTION_ARN --query "Controls[*].StandardsControlArn" --output yaml
- arn:aws:securityhub:ap-northeast-1:123456789012:control/aws-foundational-security-best-practices/v/1.0.0/ACM.1
- arn:aws:securityhub:ap-northeast-1:123456789012:control/aws-foundational-security-best-practices/v/1.0.0/AutoScaling.1
- arn:aws:securityhub:ap-northeast-1:123456789012:control/aws-foundational-security-best-practices/v/1.0.0/CloudTrail.1
- arn:aws:securityhub:ap-northeast-1:123456789012:control/aws-foundational-security-best-practices/v/1.0.0/CloudTrail.2
- arn:aws:securityhub:ap-northeast-1:123456789012:control/aws-foundational-security-best-practices/v/1.0.0/CodeBuild.1
  # 以下略

3. update-standards-control でコントロールを更新(無効化)

aws securityhub update-standards-control で セキュリティ基準のコントロールを無効化します。

実行例は以下の通り。( EC2.6: VPC フローログ記録はすべての VPC で有効にする必要があります を無効化しています)

STD_CONTROL_ARN="arn:aws:securityhub:ap-northeast-1:123456789012:control/aws-foundational-security-best-practices/v/1.0.0/EC2.6"
REASON="費用がかさむため必須では無い。重要なワークロードがある場合、最低限 Reject(拒否されたログ) の記録を検討。"
aws securityhub update-standards-control \
  --standards-control-arn $STD_CONTROL_ARN \
  --control-status DISABLED \
  --disabled-reason $REASON

実行後に Security Hub のマネジメントコンソールを確認します。

img

正しく無効化できました。

おわりに

以上、Security Hub セキュリティ基準のコントロールを AWS CLIから無効化してみました。

以下のようなスクリプトを作成しておくと複数アカウントで同じような処理を行えるので便利です。 (AWS基礎セキュリティのベストプラクティスの例)

PROFILE=xxx
ACCOUNT_ID=`aws --profile $PROFILE sts get-caller-identity --output text --query Account`

# EC2.6 を無効化
ID=EC2.6
REASON="費用がかさむため必須では無い。重要なワークロードがある場合、最低限 Reject(拒否されたログ) の記録を検討。"
STD_CONTROL_ARN="arn:aws:securityhub:ap-northeast-1:$ACCOUNT_ID:control/aws-foundational-security-best-practices/v/1.0.0/$ID"
aws --profile $PROFILE securityhub update-standards-control --standards-control-arn $STD_CONTROL_ARN --control-status DISABLED --disabled-reason $REASON

# S3.1 を無効化
ID=S3.1
REASON="パブリック用途のバケットが存在するため。"
STD_CONTROL_ARN="arn:aws:securityhub:ap-northeast-1:$ACCOUNT_ID:control/aws-foundational-security-best-practices/v/1.0.0/$ID"
aws --profile $PROFILE securityhub update-standards-control --standards-control-arn $STD_CONTROL_ARN --control-status DISABLED --disabled-reason $REASON

# ...

少しでもどなたかのお役に立てば幸いです。

参考