メインコンテンツまでスキップ

Security HubのCIS AWS Foundations Benchmarkへの対応を行いセキュリティスコア100%を達成する方法

· 約23分
moritalous

Security Hubでチェックができるセキュリティ基準は以下の3つがあります。

  • AWS 基礎セキュリティのベストプラクティス v1.0.0
  • CIS AWS Foundations Benchmark v1.2.0
  • PCI DSS v3.2.1

PCI DSSはクレジットカード業界などで使われるセキュリティレベルの高いチェックとなり、標準的にはその他の2つを有効化することが推奨されています。今回はCIS AWS Foundations Benchmark v1.2.0に対して対処を行い、スコア100%を目指します。

注記

AWS基礎セキュリティのベストプラクティスと合わせて、スコア100%を目指します

※順番は項番順ではなく私の対応した順番となります。

CIS AWS Foundations Benchmark v1.2.0への対応

[CIS.1.14]

The root user is the most privileged user in an AWS account. MFA adds an extra layer of protection on top of a user name and password. With MFA enabled, when a user signs in to an AWS website, they will be prompted for their user name and password as well as for an authentication code from their AWS MFA device. For Level 2, it is recommended that the root user be protected with a hardware MFA.

[CIS.1.14] root ユーザーは、AWS アカウントの中で最も特権のあるユーザーです。MFAは、ユーザー名とパスワードの上に追加の保護レイヤーを追加します。MFA を有効にすると、ユーザーが AWS ウェブサイトにサインインするときに、ユーザー名とパスワードだけでなく、AWS MFA デバイスからの認証コードの入力を求められます。レベル2では、ルートユーザーをハードウェアMFAで保護することが推奨されます。

ハードウェアMFAは持ってないのでできません!

注記

AWS基礎セキュリティのベストプラクティスと同じ指摘です。

[CIS.1.9]

Password policies are, in part, used to enforce password complexity requirements. IAM password policies can be used to ensure passwords are at least a given length. It is recommended that the password policy require a minimum password length 14.

[CIS.1.9] パスワードポリシーは、部分的には、パスワードの複雑さの要件を強制するために使用される。IAMパスワードポリシーは、パスワードが少なくとも所定の長さであることを確認するために使用することができます。パスワードポリシーでは、パスワードの最小長を14とすることが推奨される。

AWS基礎セキュリティのベストプラクティスでチェックした[IAM.7]ではパスワードの長さが8文字以上であることを指定しましたが、このチェックは14文字以上必要とのこと。

image.png

注記

14文字のパスワードを覚えるのは大変ですね。

[CIS.2.8]

AWS Key Management Service (KMS) allows customers to rotate the backing key which is key material stored within the KMS which is tied to the key ID of the Customer Created customer master key (CMK). It is the backing key that is used to perform cryptographic operations such as encryption and decryption. It is recommended that CMK key rotation be enabled.

[CIS.2.8] AWS Key Management Service (KMS) では、お客様が作成した顧客マスターキー(CMK)のキーIDに紐づくKMS内に保管されたキー素材であるバッキングキーをローテーションさせることができます。暗号化や復号化などの暗号化操作を行うために使用されるのがバッキング・キーです。CMKキーローテーションを有効にすることが推奨されます。

CloudTrail用に作成したKMSのキーのローテーション設定を行います。(TrailのキーもAWSマネージドで提供してくれたらいいのにね)

image.png

image.png

注記

暗号化の有効だけでなく、キーのローテーションも要求されます

[CIS.3.3]

Real-time monitoring of API calls can be achieved by directing CloudTrail Logs to CloudWatch Logs and establishing corresponding metric filters and alarms. It is recommended that a metric filter and alarm be established for root login attempts.

[CIS.3.3] CloudTrail LogsをCloudWatch Logsに誘導し、対応するメトリックフィルタとアラームを確立することにより、APIコールのリアルタイム監視を実現することができる。ルートログインの試行に対してメトリックフィルタとアラームを確立することが推奨される。

ルートログインの試行をチェックします。

ここから先はCloudWatch Logsに対するメトリックフィルターとアラームの作成が続きます。

image.png

image.png

image.png

image.png

image.png

image.png

注記

ルートアカウントのログイン通知は、セキュリティ対策として有効です

[CIS.3.10]

Real-time monitoring of API calls can be achieved by directing CloudTrail Logs to CloudWatch Logs and establishing corresponding metric filters and alarms. Security Groups are a stateful packet filter that controls ingress and egress traffic within a VPC. It is recommended that a metric filter and alarm be established changes to Security Groups.

CloudTrail LogsをCloudWatch Logsに誘導し、対応するメトリックフィルターとアラームを確立することで、APIコールのリアルタイム監視を実現できます。セキュリティグループは、VPC内の入退出トラフィックを制御するステートフルパケットフィルタです。Security Groupsに対応したメトリックフィルタとアラームを設定することが推奨されます。

セキュリティグループの変更を検知。

同じようなものが続くので、CLIでやってみます。

aws logs put-metric-filter \
--log-group-name aws-cloudtrail-logs-567362107257-e1434b81 \
--filter-name aws-cloudtrail-logs-filter-cis-3.10 \
--filter-pattern "{($.eventName=AuthorizeSecurityGroupIngress) || ($.eventName=AuthorizeSecurityGroupEgress) || ($.eventName=RevokeSecurityGroupIngress) || ($.eventName=RevokeSecurityGroupEgress) || ($.eventName=CreateSecurityGroup) || ($.eventName=DeleteSecurityGroup)}" \
--metric-transformations metricName=cis3.10,metricNamespace=LogMetrics,metricValue=1
aws cloudwatch put-metric-alarm \
--alarm-name CIS-3.10-SecurityGroupChanges \
--alarm-actions arn:aws:sns:ap-northeast-1:567362107257:Default_CloudWatch_Alarms_Topic \
--metric-name cis3.10 \
--namespace LogMetrics \
--statistic Sum \
--period 300 \
--evaluation-periods 1 \
--datapoints-to-alarm 1 \
--threshold 1.0 \
--comparison-operator GreaterThanOrEqualToThreshold \
--treat-missing-data missing
注記

セキュリティグループの変更を通知します

[CIS.3.11]

Real-time monitoring of API calls can be achieved by directing CloudTrail Logs to CloudWatch Logs and establishing corresponding metric filters and alarms. NACLs are used as a stateless packet filter to control ingress and egress traffic for subnets within a VPC. It is recommended that a metric filter and alarm be established for changes made to NACLs.

CloudTrail LogsをCloudWatch Logsに誘導し、対応するメトリックフィルタやアラームを設定することで、APIコールのリアルタイム監視を実現することができる。NACLは、VPC内のサブネットの入退出トラフィックを制御するためのステートレスパケットフィルタとして使用されます。NACLへの変更には、メトリックフィルタとアラームを確立することが推奨されます。

ネットワークACLの変更を検知。

aws logs put-metric-filter \
--log-group-name aws-cloudtrail-logs-567362107257-e1434b81 \
--filter-name aws-cloudtrail-logs-filter-cis-3.11 \
--filter-pattern "{($.eventName=CreateNetworkAcl) || ($.eventName=CreateNetworkAclEntry) || ($.eventName=DeleteNetworkAcl) || ($.eventName=DeleteNetworkAclEntry) || ($.eventName=ReplaceNetworkAclEntry) || ($.eventName=ReplaceNetworkAclAssociation)}" \
--metric-transformations metricName=cis3.11,metricNamespace=LogMetrics,metricValue=1

aws cloudwatch put-metric-alarm \
--alarm-name CIS-3.11-NetworkACLChanges \
--alarm-actions arn:aws:sns:ap-northeast-1:567362107257:Default_CloudWatch_Alarms_Topic \
--metric-name cis3.11 \
--namespace LogMetrics \
--statistic Sum \
--period 300 \
--evaluation-periods 1 \
--datapoints-to-alarm 1 \
--threshold 1.0 \
--comparison-operator GreaterThanOrEqualToThresshellhold \
--treat-missing-data missing
注記

ネットワークACLの変更を通知

[CIS.3.12]

Real-time monitoring of API calls can be achieved by directing CloudTrail Logs to CloudWatch Logs and establishing corresponding metric filters and alarms. Network gateways are required to send/receive traffic to a destination outside of a VPC. It is recommended that a metric filter and alarm be established for changes to network gateways.

CloudTrail LogsをCloudWatch Logsに誘導し、対応するメトリックフィルタやアラームを設定することで、APIコールのリアルタイム監視を実現することができる。VPC外の宛先にトラフィックを送受信するためには、ネットワークゲートウェイが必要である。ネットワークゲートウェイの変更には、メトリックフィルタとアラームを設定することが推奨されます。

ネットワークゲートウェイの変更を検知。

aws logs put-metric-filter \
--log-group-name aws-cloudtrail-logs-567362107257-e1434b81 \
--filter-name aws-cloudtrail-logs-filter-cis-3.12 \
--filter-pattern "{($.eventName=CreateCustomerGateway) || ($.eventName=DeleteCustomerGateway) || ($.eventName=AttachInternetGateway) || ($.eventName=CreateInternetGateway) || ($.eventName=DeleteInternetGateway) || ($.eventName=DetachInternetGateway)}" \
--metric-transformations metricName=cis3.12,metricNamespace=LogMetrics,metricValue=1

aws cloudwatch put-metric-alarm \
--alarm-name CIS-3.12-NetworkGatewayChanges \
--alarm-actions arn:aws:sns:ap-northeast-1:567362107257:Default_CloudWatch_Alarms_Topic \
--metric-name cis3.12 \
--namespace LogMetrics \
--statistic Sum \
--period 300 \
--evaluation-periods 1 \
--datapoints-to-alarm 1 \
--threshold 1.0 \
--comparison-operator GreaterThanOrEqualToThreshold \
--treat-missing-data missing
注記

ネットワークゲートウェイの変更を通知

[CIS.3.13]

Real-time monitoring of API calls can be achieved by directing CloudTrail Logs to CloudWatch Logs and establishing corresponding metric filters and alarms. Routing tables are used to route network traffic between subnets and to network gateways. It is recommended that a metric filter and alarm be established for changes to route tables.

CloudTrail LogsをCloudWatch Logsに誘導し、対応するメトリックフィルターとアラームを確立することで、APIコールのリアルタイム監視を実現することができる。ルーティングテーブルは、サブネット間やネットワークゲートウェイにネットワークトラフィックをルーティングするために使用される。ルートテーブルの変更には、メトリックフィルタとアラームを確立することが推奨されます。

ルートテーブルの変更を検知。

aws logs put-metric-filter \
--log-group-name aws-cloudtrail-logs-567362107257-e1434b81 \
--filter-name aws-cloudtrail-logs-filter-cis-3.13 \
--filter-pattern "{($.eventName=CreateRoute) || ($.eventName=CreateRouteTable) || ($.eventName=ReplaceRoute) || ($.eventName=ReplaceRouteTableAssociation) || ($.eventName=DeleteRouteTable) || ($.eventName=DeleteRoute) || ($.eventName=DisassociateRouteTable)}" \
--metric-transformations metricName=cis3.13,metricNamespace=LogMetrics,metricValue=1

aws cloudwatch put-metric-alarm \
--alarm-name CIS-3.13-RouteTableChanges \
--alarm-actions arn:aws:sns:ap-northeast-1:567362107257:Default_CloudWatch_Alarms_Topic \
--metric-name cis3.13 \
--namespace LogMetrics \
--statistic Sum \
--period 300 \
--evaluation-periods 1 \
--datapoints-to-alarm 1 \
--threshold 1.0 \
--comparison-operator GreaterThanOrEqualToThreshold \
--treat-missing-data missing
注記

ルートテーブルの変更を通知

[CIS.3.14]

Real-time monitoring of API calls can be achieved by directing CloudTrail Logs to CloudWatch Logs and establishing corresponding metric filters and alarms. It is possible to have more than 1 VPC within an account, in addition it is also possible to create a peer connection between 2 VPCs enabling network traffic to route between VPCs. It is recommended that a metric filter and alarm be established for changes made to VPCs.

CloudTrail LogsをCloudWatch Logsに転送し、対応するメトリックフィルタやアラームを設定することで、APIコールのリアルタイム監視を実現できます。1つのアカウントで複数のVPCを持つことができ、さらに2つのVPC間でピア接続を行い、VPC間のネットワークトラフィックをルーティングすることが可能です。VPCの変更には、メトリックフィルターとアラームを設定することが推奨されます。

VPCの変更を検知。

aws logs put-metric-filter \
--log-group-name aws-cloudtrail-logs-567362107257-e1434b81 \
--filter-name aws-cloudtrail-logs-filter-cis-3.14 \
--filter-pattern "{($.eventName=CreateVpc) || ($.eventName=DeleteVpc) || ($.eventName=ModifyVpcAttribute) || ($.eventName=AcceptVpcPeeringConnection) || ($.eventName=CreateVpcPeeringConnection) || ($.eventName=DeleteVpcPeeringConnection) || ($.eventName=RejectVpcPeeringConnection) || ($.eventName=AttachClassicLinkVpc) || ($.eventName=DetachClassicLinkVpc) || ($.eventName=DisableVpcClassicLink) || ($.eventName=EnableVpcClassicLink)}" \
--metric-transformations metricName=cis3.14,metricNamespace=LogMetrics,metricValue=1

aws cloudwatch put-metric-alarm \
--alarm-name CIS-3.14-VPCChanges \
--alarm-actions arn:aws:sns:ap-northeast-1:567362107257:Default_CloudWatch_Alarms_Topic \
--metric-name cis3.14 \
--namespace LogMetrics \
--statistic Sum \
--period 300 \
--evaluation-periods 1 \
--datapoints-to-alarm 1 \
--threshold 1.0 \
--comparison-operator GreaterThanOrEqualToThreshold \
--treat-missing-data missing
注記

VPCの変更を通知

[CIS.3.1]

Real-time monitoring of API calls can be achieved by directing CloudTrail Logs to CloudWatch Logs and establishing corresponding metric filters and alarms. It is recommended that a metric filter and alarm be established for unauthorized API calls.

CloudTrail LogsをCloudWatch Logsに誘導し、対応するメトリックフィルタとアラームを確立することで、APIコールのリアルタイム監視を実現することができる。不正なAPIコールに対しては、メトリックフィルタとアラームを確立することが推奨されます。

不正なAPIコールを検知。

aws logs put-metric-filter \
--log-group-name aws-cloudtrail-logs-567362107257-e1434b81 \
--filter-name aws-cloudtrail-logs-filter-cis-3.1 \
--filter-pattern '{($.errorCode="*UnauthorizedOperation") || ($.errorCode="AccessDenied*")}' \
--metric-transformations metricName=cis3.1,metricNamespace=LogMetrics,metricValue=1

aws cloudwatch put-metric-alarm \
--alarm-name CIS-3.1-UnauthorizedAPICalls \
--alarm-actions arn:aws:sns:ap-northeast-1:567362107257:Default_CloudWatch_Alarms_Topic \
--metric-name cis3.1 \
--namespace LogMetrics \
--statistic Sum \
--period 300 \
--evaluation-periods 1 \
--datapoints-to-alarm 1 \
--threshold 1.0 \
--comparison-operator GreaterThanOrEqualToThreshold \
--treat-missing-data missing
注記

不正なAPIコールを通知

[CIS.3.2]

Real-time monitoring of API calls can be achieved by directing CloudTrail Logs to CloudWatch Logs and establishing corresponding metric filters and alarms. It is recommended that a metric filter and alarm be established for console logins that are not protected by multi-factor authentication (MFA).

CloudTrail LogsをCloudWatch Logsに誘導し、対応するメトリックフィルタとアラームを確立することで、APIコールのリアルタイム監視を実現することができます。多要素認証(MFA)で保護されていないコンソールログインに対して、メトリックフィルタとアラームを確立することが推奨されます。

多要素認証していないログイン時を検知。

aws logs put-metric-filter \
--log-group-name aws-cloudtrail-logs-567362107257-e1434b81 \
--filter-name aws-cloudtrail-logs-filter-cis-3.2 \
--filter-pattern '{ ($.eventName = "ConsoleLogin") && ($.additionalEventData.MFAUsed != "Yes") && ($.userIdentity.type = "IAMUser") && ($.responseElements.ConsoleLogin = "Success") }' \
--metric-transformations metricName=cis3.2,metricNamespace=LogMetrics,metricValue=1

aws cloudwatch put-metric-alarm \
--alarm-name CIS-3.2-ConsoleSigninWithoutMFA \
--alarm-actions arn:aws:sns:ap-northeast-1:567362107257:Default_CloudWatch_Alarms_Topic \
--metric-name cis3.2 \
--namespace LogMetrics \
--statistic Sum \
--period 300 \
--evaluation-periods 1 \
--datapoints-to-alarm 1 \
--threshold 1.0 \
--comparison-operator GreaterThanOrEqualToThreshold \
--treat-missing-data missing
注記

他要素認証していないログインを通知

[CIS.3.4]

Real-time monitoring of API calls can be achieved by directing CloudTrail Logs to CloudWatch Logs and establishing corresponding metric filters and alarms. It is recommended that a metric filter and alarm be established changes made to Identity and Access Management (IAM) policies.

CloudTrail LogsをCloudWatch Logsに誘導し、対応するメトリックフィルタとアラームを確立することで、APIコールのリアルタイム監視を実現することができる。メトリックフィルタとアラームは、IAM(Identity and Access Management)ポリシーに加えられた変更を確立することが推奨されます。

IAMポリシーの変更を検知。

aws logs put-metric-filter \
--log-group-name aws-cloudtrail-logs-567362107257-e1434b81 \
--filter-name aws-cloudtrail-logs-filter-cis-3.4 \
--filter-pattern "{($.eventName=DeleteGroupPolicy) || ($.eventName=DeleteRolePolicy) || ($.eventName=DeleteUserPolicy) || ($.eventName=PutGroupPolicy) || ($.eventName=PutRolePolicy) || ($.eventName=PutUserPolicy) || ($.eventName=CreatePolicy) || ($.eventName=DeletePolicy) || ($.eventName=CreatePolicyVersion) || ($.eventName=DeletePolicyVersion) || ($.eventName=AttachRolePolicy) || ($.eventName=DetachRolePolicy) || ($.eventName=AttachUserPolicy) || ($.eventName=DetachUserPolicy) || ($.eventName=AttachGroupPolicy) || ($.eventName=DetachGroupPolicy)}" \
--metric-transformations metricName=cis3.4,metricNamespace=LogMetrics,metricValue=1

aws cloudwatch put-metric-alarm \
--alarm-name CIS-3.4-IAMPolicyChanges \
--alarm-actions arn:aws:sns:ap-northeast-1:567362107257:Default_CloudWatch_Alarms_Topic \
--metric-name cis3.4 \
--namespace LogMetrics \
--statistic Sum \
--period 300 \
--evaluation-periods 1 \
--datapoints-to-alarm 1 \
--threshold 1.0 \
--comparison-operator GreaterThanOrEqualToThreshold \
--treat-missing-data missing
注記

IAMポリシーの変更を通知

[CIS.3.5]

Real-time monitoring of API calls can be achieved by directing CloudTrail Logs to CloudWatch Logs and establishing corresponding metric filters and alarms. It is recommended that a metric filter and alarm be established for detecting changes to CloudTrail's configurations.

CloudTrail LogsをCloudWatch Logsに誘導し、対応するメトリックフィルタとアラームを確立することで、APIコールのリアルタイム監視を実現することができる。CloudTrailの設定変更を検出するために、メトリックフィルタとアラームを確立することが推奨されます。

CloudTrailの設定変更を検知。

aws logs put-metric-filter \
--log-group-name aws-cloudtrail-logs-567362107257-e1434b81 \
--filter-name aws-cloudtrail-logs-filter-cis-3.5 \
--filter-pattern "{($.eventName=CreateTrail) || ($.eventName=UpdateTrail) || ($.eventName=DeleteTrail) || ($.eventName=StartLogging) || ($.eventName=StopLogging)}" \
--metric-transformations metricName=cis3.5,metricNamespace=LogMetrics,metricValue=1

aws cloudwatch put-metric-alarm \
--alarm-name CIS-3.5-CloudTrailChanges \
--alarm-actions arn:aws:sns:ap-northeast-1:567362107257:Default_CloudWatch_Alarms_Topic \
--metric-name cis3.5 \
--namespace LogMetrics \
--statistic Sum \
--period 300 \
--evaluation-periods 1 \
--datapoints-to-alarm 1 \
--threshold 1.0 \
--comparison-operator GreaterThanOrEqualToThreshold \
--treat-missing-data missing
注記

CloudTrailの変更を通知

[CIS.3.6]

Real-time monitoring of API calls can be achieved by directing CloudTrail Logs to CloudWatch Logs and establishing corresponding metric filters and alarms. It is recommended that a metric filter and alarm be established for failed console authentication attempts.

CloudTrail LogsをCloudWatch Logsに誘導し、対応するメトリックフィルタとアラームを確立することで、APIコールのリアルタイム監視を実現することができる。コンソール認証の失敗に対して、メトリックフィルタとアラームを確立することが推奨されます。

コンソールログインの失敗を検知。

aws logs put-metric-filter \
--log-group-name aws-cloudtrail-logs-567362107257-e1434b81 \
--filter-name aws-cloudtrail-logs-filter-cis-3.6 \
--filter-pattern '{($.eventName=ConsoleLogin) && ($.errorMessage="Failed authentication")}' \
--metric-transformations metricName=cis3.6,metricNamespace=LogMetrics,metricValue=1

aws cloudwatch put-metric-alarm \
--alarm-name CIS-3.6-ConsoleAuthenticationFailure \
--alarm-actions arn:aws:sns:ap-northeast-1:567362107257:Default_CloudWatch_Alarms_Topic \
--metric-name cis3.6 \
--namespace LogMetrics \
--statistic Sum \
--period 300 \
--evaluation-periods 1 \
--datapoints-to-alarm 1 \
--threshold 1.0 \
--comparison-operator GreaterThanOrEqualToThreshold \
--treat-missing-data missing
注記

ログインの失敗を通知。本当のミスも通知が来るので、大量の通知が来そうですね。。

[CIS.3.7]

Real-time monitoring of API calls can be achieved by directing CloudTrail Logs to CloudWatch Logs and establishing corresponding metric filters and alarms. It is recommended that a metric filter and alarm be established for customer created CMKs which have changed state to disabled or scheduled deletion.

CloudTrail LogsをCloudWatch Logsに誘導し、対応するメトリックフィルタとアラームを確立することで、APIコールのリアルタイム監視を実現することができる。顧客によって作成されたCMKの状態が無効または削除予定に変更された場合、メトリックフィルタとアラームを確立することが推奨されます。

CMKの変更を検知。

aws logs put-metric-filter \
--log-group-name aws-cloudtrail-logs-567362107257-e1434b81 \
--filter-name aws-cloudtrail-logs-filter-cis-3.7 \
--filter-pattern "{($.eventSource=kms.amazonaws.com) && (($.eventName=DisableKey) || ($.eventName=ScheduleKeyDeletion))}" \
--metric-transformations metricName=cis3.7,metricNamespace=LogMetrics,metricValue=1

aws cloudwatch put-metric-alarm \
--alarm-name CIS-3.7-DisableOrDeleteCMK \
--alarm-actions arn:aws:sns:ap-northeast-1:567362107257:Default_CloudWatch_Alarms_Topic \
--metric-name cis3.7 \
--namespace LogMetrics \
--statistic Sum \
--period 300 \
--evaluation-periods 1 \
--datapoints-to-alarm 1 \
--threshold 1.0 \
--comparison-operator GreaterThanOrEqualToThreshold \
--treat-missing-data missing
注記

CMKの変更を通知

[CIS.3.8]

Real-time monitoring of API calls can be achieved by directing CloudTrail Logs to CloudWatch Logs and establishing corresponding metric filters and alarms. It is recommended that a metric filter and alarm be established for changes to S3 bucket policies.

CloudTrail LogsをCloudWatch Logsに誘導し、対応するメトリックフィルタとアラームを確立することで、APIコールのリアルタイム監視を実現できる。S3バケットポリシーの変更に対して、メトリックフィルタとアラームを確立することが推奨されます。

S3バケットポリシーの変更を検知。

aws logs put-metric-filter \
--log-group-name aws-cloudtrail-logs-567362107257-e1434b81 \
--filter-name aws-cloudtrail-logs-filter-cis-3.8 \
--filter-pattern "{($.eventSource=s3.amazonaws.com) && (($.eventName=PutBucketAcl) || ($.eventName=PutBucketPolicy) || ($.eventName=PutBucketCors) || ($.eventName=PutBucketLifecycle) || ($.eventName=PutBucketReplication) || ($.eventName=DeleteBucketPolicy) || ($.eventName=DeleteBucketCors) || ($.eventName=DeleteBucketLifecycle) || ($.eventName=DeleteBucketReplication))}" \
--metric-transformations metricName=cis3.8,metricNamespace=LogMetrics,metricValue=1

aws cloudwatch put-metric-alarm \
--alarm-name CIS-3.8-S3BucketPolicyChanges \
--alarm-actions arn:aws:sns:ap-northeast-1:567362107257:Default_CloudWatch_Alarms_Topic \
--metric-name cis3.8 \
--namespace LogMetrics \
--statistic Sum \
--period 300 \
--evaluation-periods 1 \
--datapoints-to-alarm 1 \
--threshold 1.0 \
--comparison-operator GreaterThanOrEqualToThreshold \
--treat-missing-data missing
注記

バケットポリシーの変更を通知

[CIS.3.9]

Real-time monitoring of API calls can be achieved by directing CloudTrail Logs to CloudWatch Logs and establishing corresponding metric filters and alarms. It is recommended that a metric filter and alarm be established for detecting changes to Config's configurations.

CloudTrail LogsをCloudWatch Logsに誘導し、対応するメトリックフィルタとアラームを確立することで、APIコールのリアルタイム監視を実現することができる。Configの設定変更を検出するために、メトリックフィルタとアラームを確立することが推奨されます。

※マネジメントコンソール上はConfigではなくCloudTrailと誤記 Configの設定変更を検知。

aws logs put-metric-filter \
--log-group-name aws-cloudtrail-logs-567362107257-e1434b81 \
--filter-name aws-cloudtrail-logs-filter-cis-3.9 \
--filter-pattern "{($.eventSource=config.amazonaws.com) && (($.eventName=StopConfigurationRecorder) || ($.eventName=DeleteDeliveryChannel) || ($.eventName=PutDeliveryChannel) || ($.eventName=PutConfigurationRecorder))}" \
--metric-transformations metricName=cis3.9,metricNamespace=LogMetrics,metricValue=1

aws cloudwatch put-metric-alarm \
--alarm-name CIS-3.9-AWSConfigChanges \
--alarm-actions arn:aws:sns:ap-northeast-1:567362107257:Default_CloudWatch_Alarms_Topic \
--metric-name cis3.9 \
--namespace LogMetrics \
--statistic Sum \
--period 300 \
--evaluation-periods 1 \
--datapoints-to-alarm 1 \
--threshold 1.0 \
--comparison-operator GreaterThanOrEqualToThreshold \
--treat-missing-data missing
注記

Configの変更を通知

[CIS.1.10]

IAM password policies can prevent the reuse of a given password by the same user. It is recommended that the password policy prevent the reuse of passwords.

IAMのパスワードポリシーは、同一ユーザーによる所定のパスワードの再利用を防止することができます。パスワードポリシーでパスワードの再利用を防止することが推奨されます。

メトリックフィルター地獄が終わりました!次はまたIAMのパスワード強度ですね。再利用防止を追加。

image.png

注記

結構厳しいIAMパスワードのポリシーですね

[CIS.1.11]

IAM password policies can require passwords to be rotated or expired after a given number of days. It is recommended that the password policy expire passwords after 90 days or less.

IAMパスワードポリシーでは、パスワードをローテートするか、所定の日数後に期限切れとすることを要求できます。パスワードポリシーでは、90日以内にパスワードを失効させることが推奨されます。

IAMパスワード地獄が始まりましたね。。有効期限を追加。

image.png

注記

こちらもIAMパスワードポリシーについて

[CIS.1.20]

AWS provides a support center that can be used for incident notification and response, as well as technical support and customer services. Create an IAM Role to allow authorized users to manage incidents with AWS Support.

AWSは、インシデントの通知や対応、テクニカルサポートやカスタマーサービスに利用できるサポートセンターを提供しています。許可されたユーザーがAWSサポートでインシデントを管理できるように、IAM Roleを作成します。

Organizationで作成したアカウントだからですかね?親アカウントからサポートできるようにIAMロールを作成するということだと思います。

image.png

image.png

注記

サポート用のIAMロールを作成

[CIS.1.1]

The root user has unrestricted access to all resources in the AWS account. It is highly recommended that the use of this user be avoided.

root ユーザーは、AWS アカウントのすべてのリソースに無制限にアクセスすることができます。このユーザーの使用は避けることを強く推奨します。

メトリックフィルター地獄再び!!

aws logs put-metric-filter \
--log-group-name aws-cloudtrail-logs-567362107257-e1434b81 \
--filter-name aws-cloudtrail-logs-filter-cis-1.1 \
--filter-pattern "{$.userIdentity.type="Root" && $.userIdentity.invokedBy NOT EXISTS && $.eventType !="AwsServiceEvent"}" \
--metric-transformations metricName=cis1.1,metricNamespace=LogMetrics,metricValue=1

aws cloudwatch put-metric-alarm \
--alarm-name CIS-1.1-RootAccountUsage \
--alarm-actions arn:aws:sns:ap-northeast-1:567362107257:Default_CloudWatch_Alarms_Topic \
--metric-name cis1.1 \
--namespace LogMetrics \
--statistic Sum \
--period 300 \
--evaluation-periods 1 \
--datapoints-to-alarm 1 \
--threshold 1.0 \
--comparison-operator GreaterThanOrEqualToThreshold \
--treat-missing-data missing
注記

ルートユーザーのログインを通知

結果

ここまでの対応でセキュリティスコア99%まで達成しました!やったね!

image.png

失敗の2件はいずれもハードウェアMFAです。

image.png

image.png

ここで終わっていいのですが、 せっかくなので100%を見たい! ということで、この2件を抑制してしまいます。

image.png

image.png

この状態で暫く待つと、、、

image.png

セキュリティスコア100%!!! 100%!!! 100%!!! 👏👏👏👏👏👏👏

初期状態はこちらの75%でしたがとうとう100%を達成しました! うれしい~。ハードウェアMFAを持ってない以外は、正攻法で対処ができました。