bp-check/services/security_hub.py

29 lines
740 B
Python
Raw Normal View History

2024-08-05 02:30:34 +00:00
from models import RuleCheckResult
import boto3
2024-08-12 04:06:13 +00:00
client = boto3.client("securityhub")
sts_client = boto3.client("sts")
2024-08-05 02:30:34 +00:00
def securityhub_enabled():
2024-08-12 04:06:13 +00:00
compliant_resources = []
non_compliant_resources = []
aws_account_id = sts_client.get_caller_identity()["Account"]
try:
hub = client.describe_hub()
compliant_resources.append(aws_account_id)
except Exception as e:
if e.__class__.__name__ == "InvalidAccessException":
non_compliant_resources.append(aws_account_id)
else:
raise e
2024-08-05 02:30:34 +00:00
return RuleCheckResult(
2024-08-12 04:06:13 +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
)