LoginSignup
1
0

真夏の怪談話~謎のConfig通知~

Posted at

おばんです。
昨日から今日にかけて謎のタイミングでAWS Config から大量の通知が届いてたので、なにゆえ発砲されたのか調査した備忘録です。
結論答えにたどり着けなかったので、思い当たる人至急メールくれや。

導入

私は個人AWSアカウント6個ほどをOrganizations組んで、Control Tower、Security Hub と色々導入して検証してます。
今はコンピュートリソースを動かしてないのでConfig通知がオオカミ少年化しており基本無視しちゃうのですが、今日(9/1)たまたま変なタイミングで10通ほど届いてたので重い腰を上げて中身を見てみました。

本編

その中の一つがこんな通知でした。

{
    "version": "0",
    "id": "744efd4c-76c0-fc6e-a363-f46e169c090c",
    "detail-type": "Config Rules Compliance Change",
    "source": "aws.config",
    "account": "************",
    "time": "2023-09-01T10:47:53Z",
    "region": "us-east-1",
    "resources": [],
    "detail": {
        "resourceId": "sg-04***********",
        "awsRegion": "us-east-1",
        "awsAccountId": "************",
        "configRuleName": "securityhub-restricted-ssh-4934398b",
        "recordVersion": "1.0",
        "configRuleARN": "arn:aws:config:us-east-1:************:config-rule/aws-service-rule/securityhub.amazonaws.com/config-rule-gsvycf",
        "messageType": "ComplianceChangeNotification",
        "newEvaluationResult": {
            "evaluationResultIdentifier": {
                "evaluationResultQualifier": {
                    "configRuleName": "securityhub-restricted-ssh-4934398b",
                    "resourceType": "AWS::EC2::SecurityGroup",
                    "resourceId": "sg-04***********"",
                    "evaluationMode": "DETECTIVE"
                },
                "orderingTimestamp": "2022-07-28T04:20:25.237Z"
            },
            "complianceType": "COMPLIANT",
            "resultRecordedTime": "2023-09-01T10:47:52.764Z",
            "configRuleInvokedTime": "2023-09-01T10:47:52.525Z"
        },
        "notificationCreationTime": "2023-09-01T10:47:53.354Z",


        "resourceType": "AWS::EC2::SecurityGroup"
    }
}

restricted-sshはセキュリティグループのSSHポートが全開放(0.0.0.0/0)されてないかをチェックしてくれるConfigルールです。
https://docs.aws.amazon.com/ja_jp/config/latest/developerguide/restricted-ssh.html

この例ではsg-04~というセキュリティグループのチェック結果が*COMPLIANT(準拠)*だったよ~と教えてくれました。ええやん。

ただこの通知、昨日(8/31)も来てました。それがこちら。

{
    "version": "0",
    "id": "12040e53-584c-21bd-6d4d-82e181d74f4b",
    "detail-type": "Config Rules Compliance Change",
    "source": "aws.config",
    "account": "************",
    "time": "2023-08-31T00:53:28Z",
    "region": "us-east-1",
    "resources": [],
    "detail": {
        "resourceId": "sg-04***********",
        "awsRegion": "us-east-1",
        "awsAccountId": "************",
        "configRuleName": "securityhub-restricted-ssh-4934398b",
        "recordVersion": "1.0",
        "configRuleARN": "arn:aws:config:us-east-1:************:config-rule/aws-service-rule/securityhub.amazonaws.com/config-rule-gsvycf",
        "messageType": "ComplianceChangeNotification",
        "newEvaluationResult": {
            "evaluationResultIdentifier": {
                "evaluationResultQualifier": {
                    "configRuleName": "securityhub-restricted-ssh-4934398b",
                    "resourceType": "AWS::EC2::SecurityGroup",
                    "resourceId": "sg-04***********",
                    "evaluationMode": "DETECTIVE"
                },
                "orderingTimestamp": "2023-08-31T00:51:46.525Z"
            },
            "complianceType": "NOT_APPLICABLE",
            "resultRecordedTime": "2023-08-31T00:53:28.223Z",
            "configRuleInvokedTime": "2023-08-31T00:52:18.462Z"
        },
        "oldEvaluationResult": {
            "evaluationResultIdentifier": {
                "evaluationResultQualifier": {
                    "configRuleName": "securityhub-restricted-ssh-4934398b",
                    "resourceType": "AWS::EC2::SecurityGroup",
                    "resourceId": "sg-04***********",
                    "evaluationMode": "DETECTIVE"
                },
                "orderingTimestamp": "2022-07-28T04:20:25.237Z"
            },
            "complianceType": "COMPLIANT",
            "resultRecordedTime": "2023-08-28T16:47:47.208Z",
            "configRuleInvokedTime": "2023-08-28T16:47:46.953Z"
        },
        "notificationCreationTime": "2023-08-31T00:53:28.681Z",


        "resourceType": "AWS::EC2::SecurityGroup"
    }
}

おぉそうか、24時間ごとにチェックしてるから昨日も来てるんや~と思ったんですが、おととい(8/30)には来てませんでした。
ん?と思いConfigARNで調べたら、その前は7/30でした。それがこちら

{
    "version": "0",
    "id": "3aa373c0-1fa7-ae1f-475d-b587bc695525",
    "detail-type": "Config Rules Compliance Change",
    "source": "aws.config",
    "account": "************",
    "time": "2023-07-30T09:56:33Z",
    "region": "us-east-1",
    "resources": [],
    "detail": {
        "resourceId": "sg-04***********",
        "awsRegion": "us-east-1",
        "awsAccountId": "************",
        "configRuleName": "securityhub-restricted-ssh-4934398b",
        "recordVersion": "1.0",
        "configRuleARN": "arn:aws:config:us-east-1:************:config-rule/aws-service-rule/securityhub.amazonaws.com/config-rule-gsvycf",
        "messageType": "ComplianceChangeNotification",
        "newEvaluationResult": {
            "evaluationResultIdentifier": {
                "evaluationResultQualifier": {
                    "configRuleName": "securityhub-restricted-ssh-4934398b",
                    "resourceType": "AWS::EC2::SecurityGroup",
                    "resourceId": "sg-04***********",
                    "evaluationMode": "DETECTIVE"
                },
                "orderingTimestamp": "2022-07-28T04:20:25.237Z"
            },
            "complianceType": "COMPLIANT",
            "resultRecordedTime": "2023-07-30T09:56:33.013Z",
            "configRuleInvokedTime": "2023-07-30T09:56:32.883Z"
        },
        "notificationCreationTime": "2023-07-30T09:56:33.394Z",
        "resourceType": "AWS::EC2::SecurityGroup"
    }
}

ここでようやく、7/30と9/1が同じ内容、8/31だけ違う内容なことに気づきました。相違点は二つ。

  1. 8/30にはoldEvaluationResultというオブジェクトがある
  2. 8/30はComplianceTypeがNOT_APPLICABLEである

ということでoldEvaluationResultオブジェクトとNOT_APPLICABLEについて調べました。

oldEvaluationResult は前回の状態

oldEvaluationResultオブジェクトは前回のチェック結果を表しています。
https://docs.aws.amazon.com/ja_jp/config/latest/developerguide/how-does-config-work.html

コンプライアンスタイプは、リソースが特定の AWS Config ルールに準拠しているかどうかを示し、メッセージの ComplianceType キーで示されます。メッセージには、比較のために newEvaluationResult オブジェクトと oldEvaluationResult オブジェクトが含まれます。

つまり8/30の通知では、"orderingTimestamp": "2023-08-28T16:47:47.208Z"COMPLIANTだった状態がNOT_APPLICABLEになった。という通知だということが分かりました。

NOT_APPLICABLEは対象外のリソース

次にNOT_APPLICABLEですが、これはルール評価対象外を示す状態でした。
https://docs.aws.amazon.com/ja_jp/config/latest/developerguide/evaluate-config.html

NOT_APPLICABLE - ルールのロジックを適用できないリソースを除外するために使用されます。
例えば、alb-desync-mode-check ルールは Application Load Balancer のみをチェックし、Network Load Balancer と Gateway Load Balancer は無視します。

つまり8/30の通知では。sg-04***********restricted-sshルールの評価対象外になったという通知だということが分かりました。…え?なんで?

CloudTrailも調べてみたが

CloudTrailイベント履歴も調べてみました。
しかしConfigイベントしか記録されておらずSGに何か変更があったこともなさそうでした。image.png

(もしかしたらデータイベントで記録されてないだけかもなので、次同じことあったら調べてみます)
(データイベント記録を有効化してなかった)

このConfigルールはSecurity Hubが自動作成してくれているルールなので、Security Hub側で何か更新があったタイミングで通知されたのかもしれないです。
あとこのルールは30日タームなのかな?

参考

https://docs.aws.amazon.com/ja_jp/config/latest/developerguide/how-does-config-work.html
https://docs.aws.amazon.com/ja_jp/config/latest/APIReference/API_Evaluation.html
https://docs.aws.amazon.com/ja_jp/config/latest/developerguide/evaluate-config.html
https://docs.aws.amazon.com/ja_jp/config/latest/developerguide/restricted-ssh.html
https://docs.aws.amazon.com/ja_jp/config/latest/APIReference/API_EvaluationResult.html

1
0
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
1
0