2024-08-14 01:05:06 +00:00
|
|
|
from models import RuleCheckResult, RuleChecker
|
|
|
|
from functools import cached_property
|
2024-08-05 02:30:34 +00:00
|
|
|
import boto3
|
|
|
|
|
|
|
|
|
2024-08-14 01:05:06 +00:00
|
|
|
class SNSRuleChecker(RuleChecker):
|
|
|
|
def __init__(self):
|
|
|
|
self.client = boto3.client("sns")
|
2024-08-05 02:30:34 +00:00
|
|
|
|
2024-08-14 01:05:06 +00:00
|
|
|
@cached_property
|
|
|
|
def topics(self):
|
|
|
|
topics = self.client.list_topics()["Topics"]
|
|
|
|
return [
|
|
|
|
self.client.get_topic_attributes(TopicArn=topic["TopicArn"])["Attributes"]
|
|
|
|
for topic in topics
|
|
|
|
]
|
2024-08-05 02:30:34 +00:00
|
|
|
|
2024-08-14 01:05:06 +00:00
|
|
|
def sns_encrypted_kms(self):
|
|
|
|
compliant_resources = []
|
|
|
|
non_compliant_resources = []
|
2024-08-05 02:30:34 +00:00
|
|
|
|
2024-08-14 01:05:06 +00:00
|
|
|
for topic in self.topics:
|
|
|
|
if "KmsMasterKeyId" in topic:
|
|
|
|
compliant_resources.append(topic["TopicArn"])
|
|
|
|
else:
|
|
|
|
non_compliant_resources.append(topic["TopicArn"])
|
|
|
|
|
|
|
|
return RuleCheckResult(
|
|
|
|
passed=not non_compliant_resources,
|
|
|
|
compliant_resources=compliant_resources,
|
|
|
|
non_compliant_resources=non_compliant_resources,
|
|
|
|
)
|
|
|
|
|
|
|
|
def sns_topic_message_delivery_notification_enabled(self):
|
|
|
|
compliant_resources = []
|
|
|
|
non_compliant_resources = []
|
|
|
|
|
|
|
|
for topic in self.topics:
|
|
|
|
notification_roles = [
|
|
|
|
attribute
|
|
|
|
for attribute in topic.keys()
|
|
|
|
if attribute.endswith("FeedbackRoleArn")
|
|
|
|
]
|
|
|
|
|
|
|
|
if notification_roles:
|
|
|
|
compliant_resources.append(topic["TopicArn"])
|
|
|
|
else:
|
|
|
|
non_compliant_resources.append(topic["TopicArn"])
|
2024-08-05 02:30:34 +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-12 02:17:57 +00:00
|
|
|
|
|
|
|
|
2024-08-14 01:05:06 +00:00
|
|
|
rule_checker = SNSRuleChecker
|