Amazon GuardDutyのマルウェア保護をAPIで有効化する際の挙動を調べた

こんにちは。サービス部の武田です。API(boto3)経由でGuardDutyを有効化する際にマルウェア保護が有効化されるのか調べる機会がありましたので共有します。
2022.08.31

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

こんにちは。サービス部の武田です。

先日Amazon GuardDutyがアップデートされ、マルウェア保護機能が追加されました。

API(boto3)経由でGuardDutyを有効化する際にどういう挙動をするのか調べる機会がありましたので共有します。

GuardDutyの新規作成

MalwareProtectionを指定しない

明示的に有効化を指定しなくても 有効化されました

guardduty = boto3.client("guardduty")

guardduty.create_detector(
    Enable=True,
    FindingPublishingFrequency="SIX_HOURS",
    DataSources={
        "S3Logs": {"Enable": True},
        "Kubernetes": {"AuditLogs": {"Enable": True}},
    },
)

MalwareProtectionを指定する

明示的に有効化を指定すると 有効化されました

guardduty = boto3.client("guardduty")

guardduty.create_detector(
    Enable=True,
    FindingPublishingFrequency="SIX_HOURS",
    DataSources={
        "S3Logs": {"Enable": True},
        "Kubernetes": {"AuditLogs": {"Enable": True}},
        "MalwareProtection": {
            "ScanEc2InstanceWithFindings": {"EbsVolumes": True}
        },
    },
)

GuardDutyの更新

MalwareProtectionを指定しない

明示的に有効化を指定しないと 有効化されませんでした 。正確にいうと 既存の設定を変更しない という挙動になります。そのためもともと無効化状態であった場合、無効化のままということになります。

guardduty = boto3.client("guardduty")

detector_id = guardduty.list_detectors()["DetectorIds"][0]

guardduty.update_detector(
    DetectorId=detector_id,
    Enable=True,
    FindingPublishingFrequency="SIX_HOURS",
    DataSources={
        "S3Logs": {"Enable": True},
        "Kubernetes": {"AuditLogs": {"Enable": True}},
    },
)

MalwareProtectionを指定する

明示的に有効化を指定すると 有効化されました

guardduty = boto3.client("guardduty")

detector_id = guardduty.list_detectors()["DetectorIds"][0]

guardduty.update_detector(
    DetectorId=detector_id,
    Enable=True,
    FindingPublishingFrequency="SIX_HOURS",
    DataSources={
        "S3Logs": {"Enable": True},
        "Kubernetes": {"AuditLogs": {"Enable": True}},
        "MalwareProtection": {
            "ScanEc2InstanceWithFindings": {"EbsVolumes": True}
        },
    },
)

まとめ

挙動をまとめると次のようになります。

有効化指定 無指定
新規 有効化される 有効化される
更新 有効化される 変更されない

新規有効化時はデフォルトで有効化されます(明示的に無効を指定すれば無効化)。更新時は明示的に指定しない限り、元の設定のまま変更されません。

参考になりましたら幸いです。