generated from NHSDigital/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Eli 704/adding cloudwatch metric filter cloudtrail #613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
robbailiff2
wants to merge
11
commits into
main
Choose a base branch
from
ELI-704/adding-cloudwatch-metric-filter-cloudtrail
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2932190
updated cloud watch alarms and metrics to notify when dynamodb access…
oneeb-nhs eb52145
updated cloudwatch config
oneeb-nhs 1d8c6ca
started code to add cloudtrail for dynamodb logs
oneeb-nhs 37addd7
Separated out and refactored new terrafrom resources
robbailiff2 1d9f3ea
Fixed some errors
robbailiff2 00f511d
resolved PR comments
oneeb-nhs 5a0ef6f
updated policies
oneeb-nhs 2174e0c
updated principals for s3 cloud trail bucket policy and added s3:GetB…
oneeb-nhs ffd81b8
Merge branch 'main' into ELI-704/adding-cloudwatch-metric-filter-clou…
robbailiff2 b99dda3
Skip unwanted checkov flags
robbailiff2 6c4f456
updated cloud trail data events to log read & write
oneeb-nhs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,103 @@ | ||
| resource "aws_cloudtrail" "data_events_trail" { | ||
| #checkov:skip=CKV_AWS_67: Ensure CloudTrail is enabled in all Regions | ||
| #checkov:skip=CKV_AWS_252: Ensure CloudTrail defines an SNS Topic | ||
| name = "${var.project_name}-${var.environment}-data-events-trail" | ||
| s3_bucket_name = module.s3_cloudtrail_bucket.storage_bucket_name | ||
| kms_key_id = aws_kms_key.cloudtrail_kms_key.arn | ||
| include_global_service_events = true | ||
| is_multi_region_trail = false | ||
| enable_log_file_validation = true | ||
|
|
||
| cloud_watch_logs_role_arn = aws_iam_role.cloudtrail_cloudwatch_role.arn | ||
| cloud_watch_logs_group_arn = "${aws_cloudwatch_log_group.cloudtrail_log_group.arn}:*" | ||
|
|
||
| event_selector { | ||
| read_write_type = "All" | ||
| include_management_events = false | ||
|
|
||
| data_resource { | ||
| type = "AWS::DynamoDB::Table" | ||
| values = [module.eligibility_status_table.arn] | ||
| } | ||
| } | ||
| } | ||
robbailiff2 marked this conversation as resolved.
Dismissed
Show dismissed
Hide dismissed
|
||
|
|
||
| resource "aws_kms_key" "cloudtrail_kms_key" { | ||
| description = "KMS key for CloudTrail log file encryption" | ||
| deletion_window_in_days = 14 | ||
| enable_key_rotation = true | ||
|
|
||
| policy = jsonencode({ | ||
| Version = "2012-10-17" | ||
| Statement = [ | ||
| { | ||
| Sid = "EnableRootPermissions" | ||
| Effect = "Allow" | ||
| Principal = { | ||
| AWS = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root" | ||
| } | ||
| Action = "kms:*" | ||
| Resource = "*" | ||
| }, | ||
| { | ||
| Sid = "AllowCloudTrailEncryptLogs" | ||
| Effect = "Allow" | ||
| Principal = { | ||
| Service = "cloudtrail.amazonaws.com" | ||
| } | ||
| Action = [ | ||
| "kms:GenerateDataKey*", | ||
| "kms:DescribeKey", | ||
| "kms:Encrypt" | ||
| ] | ||
| Resource = "*" | ||
| } | ||
| ] | ||
| }) | ||
|
|
||
| tags = { | ||
| environment = var.environment | ||
| project_name = var.project_name | ||
| stack_name = local.stack_name | ||
| workspace = terraform.workspace | ||
| } | ||
|
|
||
| } | ||
|
|
||
| # KMS key alias | ||
| resource "aws_kms_alias" "cloudtrail_kms_alias" { | ||
| name = "alias/${var.project_name}-${var.environment}-cloudtrail-cmk" | ||
| target_key_id = aws_kms_key.cloudtrail_kms_key.key_id | ||
| } | ||
|
|
||
| # KMS key policy to allow CloudTrail and CloudWatch Logs to use the key for encryption and decryption | ||
| resource "aws_kms_key_policy" "cloudtrail_kms_key_policy" { | ||
| key_id = aws_kms_key.cloudtrail_kms_key.id | ||
| policy = jsonencode({ | ||
| Version = "2012-10-17" | ||
| Statement = [ | ||
| { | ||
| Effect = "Allow" | ||
| Principal = { | ||
| AWS = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root" | ||
| } | ||
| Action = "kms:*" | ||
| Resource = "*" | ||
| }, | ||
| { | ||
| Effect = "Allow" | ||
| Principal = { | ||
| Service = "logs.amazonaws.com" | ||
| } | ||
| Action = [ | ||
| "kms:Encrypt", | ||
| "kms:Decrypt", | ||
| "kms:ReEncrypt*", | ||
| "kms:GenerateDataKey*", | ||
| "kms:DescribeKey" | ||
| ] | ||
| Resource = "*" | ||
| } | ||
| ] | ||
| }) | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.