This repository has been archived by the owner on Jan 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create CloudTrailEncryptionEnabled.py
- Loading branch information
1 parent
73f1fab
commit c4fdd1a
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
services/providers/hosting/rules/aws/CloudTrail/CloudTrailEncryptionEnabled.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from aws_cdk import core | ||
import boto3 | ||
|
||
class CloudTrailInfoRetrievalStack(core.Stack): | ||
|
||
def __init__(self, scope: core.Construct, id: str, info_function, **kwargs) -> None: | ||
super().__init__(scope, id, **kwargs) | ||
|
||
# Initialize a boto3 session | ||
session = boto3.Session() | ||
cloudtrail_client = session.client('cloudtrail') | ||
|
||
# Retrieve information about CloudTrails | ||
trails = cloudtrail_client.describe_trails()['trailList'] | ||
|
||
# Loop through every CloudTrail and call the info_function | ||
for trail in trails: | ||
trail_name = trail['Name'] | ||
info_function(cloudtrail_client, trail_name) | ||
|
||
def check_cloudtrail_encryption(cloudtrail_client, trail_name): | ||
trail_status = cloudtrail_client.get_trail_status(Name=trail_name) | ||
encryption_enabled = trail_status.get('CloudTrailEncryptionEnabled', False) | ||
print(f"Trail {trail_name} encryption enabled: {encryption_enabled}") | ||
|
||
app = core.App() | ||
|
||
# Initialize stack with the encryption check function | ||
CloudTrailInfoRetrievalStack(app, "CloudTrailInfoRetrievalStack", check_cloudtrail_encryption) | ||
|
||
app.synth() |