2024-08-14 01:05:06 +00:00
|
|
|
from models import RuleCheckResult, RuleChecker
|
2024-08-05 02:30:34 +00:00
|
|
|
import boto3
|
|
|
|
|
|
|
|
|
2024-08-14 01:05:06 +00:00
|
|
|
class KMSRuleChecker(RuleChecker):
|
|
|
|
def __init__(self):
|
|
|
|
self.client = boto3.client("kms")
|
2024-08-05 02:30:34 +00:00
|
|
|
|
2024-08-14 01:05:06 +00:00
|
|
|
def cmk_backing_key_rotation_enabled(self):
|
|
|
|
compliant_resources = []
|
|
|
|
non_compliant_resources = []
|
|
|
|
keys = self.client.list_keys()["Keys"]
|
2024-08-05 02:30:34 +00:00
|
|
|
|
2024-08-14 01:05:06 +00:00
|
|
|
for key in keys:
|
|
|
|
response = self.client.get_key_rotation_status(KeyId=key["KeyId"])
|
2024-08-07 11:55:23 +00:00
|
|
|
|
2024-08-14 01:05:06 +00:00
|
|
|
if response["KeyRotationEnabled"] == True:
|
|
|
|
compliant_resources.append(response["KeyId"])
|
|
|
|
else:
|
|
|
|
non_compliant_resources.append(response["KeyId"])
|
2024-08-07 11:55:23 +00:00
|
|
|
|
2024-08-14 01:05:06 +00:00
|
|
|
return RuleCheckResult(
|
|
|
|
passed=not non_compliant_resources,
|
|
|
|
compliant_resources=compliant_resources,
|
|
|
|
non_compliant_resources=non_compliant_resources,
|
|
|
|
)
|
2024-08-07 11:55:23 +00:00
|
|
|
|
2024-08-14 01:05:06 +00:00
|
|
|
|
|
|
|
rule_checker = KMSRuleChecker
|