Skip to content

[#316] Add Cloudtrail module as an optional module#318

Open
tung-nimblehq wants to merge 2 commits intofeature/316-add-vpc-flows-log-modulefrom
feature/316-add-vpc-cloud-trail-module
Open

[#316] Add Cloudtrail module as an optional module#318
tung-nimblehq wants to merge 2 commits intofeature/316-add-vpc-flows-log-modulefrom
feature/316-add-vpc-cloud-trail-module

Conversation

@tung-nimblehq
Copy link
Copy Markdown
Contributor

@tung-nimblehq tung-nimblehq commented Oct 5, 2025

What happened 👀

  • Created CloudTrail for Management, Insight, and Data events.
  • Created an S3 bucket for both CloudTrail, separated by prefix.
  • Created Event Bridge + AWS Chatbox + SNS topic to notify when failed login events happen.
  • Add some unit tests.

Insight 📝

Proof Of Work 📹

Applied correctly

Cloudtrail
Screenshot 2025-10-05 at 22 12 30
Screenshot 2025-10-05 at 22 12 39

S3 bucket
Screenshot 2025-10-05 at 22 15 04

Sns topic
Screenshot 2025-10-05 at 22 14 38

Slack alerts
Screenshot 2025-10-05 at 22 14 03
Screenshot 2025-10-05 at 22 14 24

Does not create Cloudtrail in Blank template.

Screen.Recording.2025-10-05.at.22.27.44.mov

Does not create CloudTrail in the Advanced template with the flag not set.

Screen.Recording.2025-10-05.at.22.29.50.mov

Create CloudTrail in the Advanced template with the flag set.

Screen.Recording.2025-10-05.at.22.29.03.mov

Install CloudTrail into Bank template.

Screen.Recording.2025-10-05.at.22.28.16.mov

@tung-nimblehq tung-nimblehq added this to the 2.4.0 milestone Oct 5, 2025
@tung-nimblehq tung-nimblehq self-assigned this Oct 5, 2025
@tung-nimblehq tung-nimblehq added the type : feature New feature or request label Oct 5, 2025
@tung-nimblehq tung-nimblehq marked this pull request as ready for review October 5, 2025 15:42
}

# trivy:ignore:AVD-AWS-0089 Access logging not required for CloudTrail log bucket
resource "aws_s3_bucket" "cloudtrail_logs" {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are duplicating S3 code in a few modules. Should we adjust the current S3 module, or create a new S3 module that we can use for these purposes? What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅 I don’t think so, since this bucket is dedicated to CloudTrail logs, it’s quite different from a general S3 bucket. Adjusting or creating a new S3 module would require adding many new variables to adapt it and easily cause confusion. I think we should keep it under CloudTrail for easier management.


# trivy:ignore:AVD-AWS-0136 No encryption for CloudTrail compatibility
# trivy:ignore:AVD-AWS-0095 No encryption for CloudTrail compatibility
resource "aws_sns_topic" "cloudtrail" {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for SNS, can we create a general SNS module and reuse here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as this one
it’s dedicated to the CloudTrail configuration. I’d prefer to keep it under CloudTrail rather than introduce new modules that can’t work independently.

@tung-nimblehq tung-nimblehq force-pushed the feature/316-add-vpc-flows-log-module branch from b55003b to 73b05d7 Compare October 12, 2025 02:09
@tung-nimblehq tung-nimblehq requested a review from suho as a code owner October 12, 2025 02:09
@tung-nimblehq tung-nimblehq force-pushed the feature/316-add-vpc-cloud-trail-module branch from f600b45 to 5f47bab Compare October 12, 2025 02:37
@tung-nimblehq
Copy link
Copy Markdown
Contributor Author

@hoangmirs Can you recheck it? 🙏

@tung-nimblehq tung-nimblehq force-pushed the feature/316-add-vpc-flows-log-module branch from 2625247 to 220e3c5 Compare October 17, 2025 03:46
@tung-nimblehq tung-nimblehq force-pushed the feature/316-add-vpc-cloud-trail-module branch from a512c22 to c3b6064 Compare October 17, 2025 03:47
@tung-nimblehq tung-nimblehq force-pushed the feature/316-add-vpc-flows-log-module branch from 220e3c5 to c222713 Compare January 10, 2026 04:38
@tung-nimblehq tung-nimblehq force-pushed the feature/316-add-vpc-cloud-trail-module branch 2 times, most recently from 7421b23 to 0a89c65 Compare January 10, 2026 09:43
@tung-nimblehq tung-nimblehq force-pushed the feature/316-add-vpc-flows-log-module branch from c222713 to 8f894f4 Compare January 15, 2026 15:55
@tung-nimblehq tung-nimblehq force-pushed the feature/316-add-vpc-cloud-trail-module branch from 0a89c65 to 491687b Compare January 15, 2026 16:09
@tung-nimblehq tung-nimblehq force-pushed the feature/316-add-vpc-flows-log-module branch from 8f894f4 to 84a9710 Compare January 16, 2026 14:57
@tung-nimblehq tung-nimblehq force-pushed the feature/316-add-vpc-cloud-trail-module branch from 491687b to 88243e5 Compare January 16, 2026 15:07
- **CloudWatch integration**: Sends logs to CloudWatch for real-time monitoring and alerting
- **S3 storage**: Stores all CloudTrail logs securely in Amazon S3 with configurable key prefix organization
- **SNS notifications**: Integrates with SNS topics for immediate alerting on critical events
- **Insight events**: Captures unusual activity patterns like API call rate and error rate anomalies
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Insight events overlapping with Comprehensive event logging?


- **Comprehensive event logging**: Captures management events, data events, and insight events based on configuration
- **Multi-region support**: Can be configured to log events across all AWS regions for complete visibility
- **CloudWatch integration**: Sends logs to CloudWatch for real-time monitoring and alerting
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preferably put CloudWatch integration together with SNS notifications

→ Group them, as they both relate to alerting/monitoring.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 54e1427

s3_key_prefix = "cloudtrail"
log_retention_days = var.cloudtrail_log_retention_days
s3_ignore_data_bucket_arns = ["arn:aws:s3:::\${module.cloudtrail_s3_bucket.aws_s3_bucket_name}"]
cloud_watch_arn = module.cloudtrail_cloudwatch.aws_cloudwatch_log_group_arn
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it have cloudtrail_event_type here too? Or, just rely on the default?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just rely on cloudtrail_event_type default value for the template here. If in case the project want to change it, there is already one var for the project to adjust.

variable "log_retention_days" {
description = "Number of days to retain CloudTrail logs in CloudWatch Logs."
type = number
default = 90
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm, I see we defined 365 in the other cloudtrail.ts.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to 30 days in 54e1427

variable "cloudtrail_log_retention_days" {
description = "The number of days to retain CloudTrail logs in CloudWatch"
type = number
default = 365
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's too long? Similar to this comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to 30 days in 54e1427


const cloudtrailLocalesContent = dedent`
### Begin CloudTrail ###
locals {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment as here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tung-nimblehq tung-nimblehq force-pushed the feature/316-add-vpc-cloud-trail-module branch from 88243e5 to 2a604e2 Compare March 6, 2026 06:51
@tung-nimblehq tung-nimblehq force-pushed the feature/316-add-vpc-flows-log-module branch from 0d16418 to fe38800 Compare March 6, 2026 07:27
@tung-nimblehq tung-nimblehq force-pushed the feature/316-add-vpc-cloud-trail-module branch from 2a604e2 to 54e1427 Compare March 6, 2026 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type : feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants