LoginSignup
3
2

More than 3 years have passed since last update.

AWS Security Hub のセキュリティ標準チェックが自動で有効化される条件

Last updated at Posted at 2020-03-25

※ 2020/3/25 時点の挙動を元に記載しているため、今後変更される可能性があります
※ 2020/4/22 にAWS Foundational Security Best Practices というセキュリティ標準が追加されたため、追記しています

Security Hubを有効化する方法によって挙動が異なる

AWS CLI や AWS SDK など EnableSecurityHub API を使用して Security Hubを有効化した場合、
デフォルトでは CIS AWS Foundations Benchmark および 2020/4/22 から利用になった
AWS Foundational Security Best Practices のセキュリティ標準チェックが自動で有効化されます。
オプションのパラメーターで自動で有効化しないように選択することもできます。
また2020/2/13 から利用可能になった PCI DSS のセキュリティ標準チェックは有効化されないため
利用者が明示的に有効化する必要があります。
以下の API リファレンスにも記載があります。

AWS Security Hub > API Reference > EnableSecurityHub
https://docs.aws.amazon.com/securityhub/1.0/APIReference/API_EnableSecurityHub.html

When you use the EnableSecurityHub operation to enable Security Hub, you also automatically enable the following standards.

  • CIS AWS Foundations
  • AWS Foundational Security Best Practices

You do not enable the Payment Card Industry Data Security Standard (PCI DSS) standard.
To not enable the automatically enabled standards, set EnableDefaultStandards to false.

一方、CloudFormation で Security Hubを有効化する場合、CIS AWS Foundations Benchmarkの
セキュリティ標準チェックは自動で有効化されません。

以前は CloudFormationで有効化した際もCISのチェックが有効化されていましたが、
どこかのタイミングでこのような挙動に変わっています。
PCIDSSのチェックが追加になった前後かなと予想はしていますが、ドキュメントには特に記載がありません。

問題となるケース

上記のような動作の違いにより、特定のセキュリティ標準チェックを有効化したつもりが
有効になっていなかった、または機能を使う予定がないのに自動的に有効化されている
ということが起こる可能性があります。

また、現状 CloudFormation では Security Hub の対応リソースが限られており、
AWS::SecurityHub::Hub(Security Hub 自体の有効化)のみ可能です。
セキュリティ標準チェックの有効/無効化に対応していないため、
CloudFormation 以外の操作が必要になります。(リソースの拡充に期待!)

SecurityHub Resource Type Reference
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/AWS_SecurityHub.html

以降、おまけ

AWS Security Hubとは

AWS Security Hub は AWS環境全体のセキュリティとコンプライアンスの状況を確認可能なサービスです。

Security Hub のセキュリティ標準機能を利用すると、サポートされているルールセットに対して
自動的かつ継続的なチェックを行うことができます。
2020年4月現在は以下の3つのルールセットがサポートされています。

  • CIS AWS Foundations Benchmark v1.2.0
  • AWS Foundational Security Best Practices v1.0.0
  • PCI DSS v3.2.1

セキュリティ標準機能は、以前コンプライアンス標準機能と呼ばれていました。
日本語のコンソールでは コンプライアンス標準のままになっていますが、近いうちに
修正されるかと思います。

CloudFormationのテンプレート例

AWSTemplateFormatVersion: "2010-09-09"
Description: Example Hub with Tags
Resources:
  ExampleHubWithTags:
    Type: 'AWS::SecurityHub::Hub'
    Properties:
      Tags:
        key1: value1
        key2: value2
Outputs:
  HubArn:
    Value: !Ref ExampleHubWithTags

ただし前述のとおり、上記のテンプレートで Security Hub を有効化しても
CIS AWS Foundations Benchmark のセキュリティ標準チェックは有効化されないため
他の方法で明示的に有効化する必要があります。

AWS SDK(boto3) で有効化する例

AWS Lambda で全リージョンのSecurity Hubを有効化することを想定した例です。
EnableDefaultStandards パラメーターを False にするとデフォルト
のセキュリティ標準チェックは有効化されません。
True or パラメーターを指定しない場合は、デフォルトのセキュリティ標準チェックが有効化されます。

lambda_function.py
from logging import getLogger, INFO
import sys
import boto3
from botocore.exceptions import ClientError

logger = getLogger()
logger.setLevel(INFO)

def get_client(service, region, credentials=None):
    """Returns the client for the specified region"""
    if credentials is None:
        client = boto3.client(service, region_name=region)
    else:
        client = boto3.client(
            service,
            region_name=region,
            aws_access_key_id=credentials['AccessKeyId'],
            aws_secret_access_key=credentials['SecretAccessKey'],
            aws_session_token=credentials['SessionToken']
        )
    return client

def get_region_list():
    """Return Available Region List"""
    ec2 = get_client('ec2', 'us-east-1')
    available_regions = map(lambda x: x['RegionName'], ec2.describe_regions()['Regions'])
    return available_regions

def lambda_handler(event, context):
    available_regions = get_region_list()
    logger.info("Enable Security Hub All Regions Start.")
    for region in available_regions:
        securityhub = get_client('securityhub', region)
        # Enalbe Security Hub
        try:
            securityhub.enable_security_hub(
                EnableDefaultStandards=False
            )
        except ClientError as err:
            logger.error(
                "Enalbe Security Hub Request failed in %s: %s",
                region, err.response['Error']['Message']
            )
            sys.exit(1)
        logger.info("Enabled Security Hub in %s", region)
    logger.info("Successfully enabled Security Hub for all regions.")

Boto3 Docs
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/securityhub.html#SecurityHub.Client.enable_security_hub

以上です。
参考になれば幸いです。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2