bp-check/services/kms.py

26 lines
684 B
Python
Raw Normal View History

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