-
Notifications
You must be signed in to change notification settings - Fork 1
Enhance Trivy IaC scanning #77
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ | |
|
|
||
| data "aws_region" "current" {} | ||
|
|
||
| data "aws_caller_identity" "current" {} | ||
|
|
||
| data "terraform_remote_state" "core" { | ||
| backend = "s3" | ||
| config = { | ||
|
|
@@ -38,6 +40,8 @@ locals { | |
| alb_listener_arn = data.terraform_remote_state.core.outputs.alb_listener_arn | ||
| ecs_cluster_name = data.terraform_remote_state.core.outputs.ecs_cluster_name | ||
| ecr_repository_url = data.terraform_remote_state.core.outputs.ecr_repository_url | ||
|
|
||
| log_kms_key_id = var.log_kms_key_id != null ? var.log_kms_key_id : aws_kms_key.log_group[0].arn | ||
| } | ||
|
|
||
| ############################ | ||
|
|
@@ -141,6 +145,57 @@ resource "aws_iam_role_policy" "task_exec_command" { | |
| resource "aws_cloudwatch_log_group" "branch" { | ||
| name = local.log_group_name | ||
| retention_in_days = var.log_retention_days | ||
| kms_key_id = local.log_kms_key_id | ||
| } | ||
|
|
||
| resource "aws_kms_key" "log_group" { | ||
| count = var.log_kms_key_id == null ? 1 : 0 | ||
|
|
||
| description = "KMS key for preview CloudWatch Logs" | ||
| deletion_window_in_days = 30 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to keep logs for 30 days? Seems like a long time, and if we ever have a lot going on it might be a lot of logs.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Each environment gets its own logs so should always be easy to focus down. |
||
| 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 = "AllowCloudWatchLogs" | ||
| Effect = "Allow" | ||
| Principal = { | ||
| Service = "logs.${data.aws_region.current.name}.amazonaws.com" | ||
| } | ||
| Action = [ | ||
| "kms:Encrypt", | ||
| "kms:Decrypt", | ||
| "kms:ReEncrypt*", | ||
| "kms:GenerateDataKey*", | ||
| "kms:DescribeKey" | ||
| ] | ||
| Resource = "*" | ||
| Condition = { | ||
| ArnLike = { | ||
| "kms:EncryptionContext:aws:logs:arn" = "arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:${local.log_group_name}*" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }) | ||
| } | ||
|
|
||
| resource "aws_kms_alias" "log_group" { | ||
| count = var.log_kms_key_id == null ? 1 : 0 | ||
|
|
||
| name = "alias/preview-logs-${local.branch_role_suffix}" | ||
| target_key_id = aws_kms_key.log_group[0].key_id | ||
| } | ||
|
|
||
| ############################ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excuse my ignorance, what's the magic number for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic number is the commit hash of a specific release of the action.
so instead of pinning it ti V4.2 we are pining it to s specific hash (considered best practice so as to prevent malicious re-releases...)