-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add kms to eks cloudwatch log group (#360)
- Loading branch information
Showing
5 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
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
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,36 @@ | ||
## Requirements | ||
|
||
No requirements. | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a | | ||
|
||
## Modules | ||
|
||
No modules. | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [aws_kms_key.kms](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource | | ||
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source | | ||
| [aws_iam_policy_document.kms](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | | ||
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source | | ||
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source | | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| <a name="input_log_group_name"></a> [log\_group\_name](#input\_log\_group\_name) | Log group name of cloud watch | `string` | `"log-group-default"` | no | | ||
| <a name="input_tags"></a> [tags](#input\_tags) | n/a | `map(any)` | n/a | yes | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_kms_arn"></a> [kms\_arn](#output\_kms\_arn) | Arn of kms for log group of cloudwatch | |
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,89 @@ | ||
# This is a standard kms that frees any cloud watch log group from vulnerabilities. | ||
# Docs: https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/encrypt-log-data-kms.html | ||
|
||
locals { | ||
arn_format = "arn:${data.aws_partition.current.partition}" | ||
} | ||
data "aws_partition" "current" {} | ||
data "aws_caller_identity" "current" {} | ||
data "aws_region" "current" {} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# CREATE A KMS | ||
# We can attach KMS to CloudWatch Log. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
data "aws_iam_policy_document" "kms" { | ||
statement { | ||
sid = "Enable Root User Permissions" | ||
effect = "Allow" | ||
|
||
actions = [ | ||
"kms:Create*", | ||
"kms:Describe*", | ||
"kms:Enable*", | ||
"kms:List*", | ||
"kms:Put*", | ||
"kms:Update*", | ||
"kms:Revoke*", | ||
"kms:Disable*", | ||
"kms:Get*", | ||
"kms:Delete*", | ||
"kms:Tag*", | ||
"kms:Untag*", | ||
"kms:ScheduleKeyDeletion", | ||
"kms:CancelKeyDeletion" | ||
] | ||
|
||
#bridgecrew:skip=CKV_AWS_109:This policy applies only to the key it is attached to | ||
#bridgecrew:skip=CKV_AWS_111:This policy applies only to the key it is attached to | ||
resources = [ | ||
"*" | ||
] | ||
|
||
principals { | ||
type = "AWS" | ||
|
||
identifiers = [ | ||
"${local.arn_format}:iam::${data.aws_caller_identity.current.account_id}:root" | ||
] | ||
} | ||
} | ||
|
||
statement { | ||
sid = "Allow KMS to CloudWatch Log Group ${var.log_group_name}" | ||
effect = "Allow" | ||
|
||
actions = [ | ||
"kms:Encrypt*", | ||
"kms:Decrypt*", | ||
"kms:ReEncrypt*", | ||
"kms:GenerateDataKey*", | ||
"kms:Describe*" | ||
] | ||
|
||
resources = [ | ||
"*" | ||
] | ||
|
||
principals { | ||
type = "Service" | ||
|
||
identifiers = [ | ||
"logs.${data.aws_region.current.name}.amazonaws.com" | ||
] | ||
} | ||
condition { | ||
test = "ArnEquals" | ||
variable = "kms:EncryptionContext:aws:logs:arn" | ||
values = ["arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:${var.log_group_name}"] | ||
} | ||
} | ||
} | ||
|
||
resource "aws_kms_key" "kms" { | ||
description = "KMS key for log-group: ${var.log_group_name}" | ||
deletion_window_in_days = 10 | ||
enable_key_rotation = true | ||
policy = join("", data.aws_iam_policy_document.kms.*.json) | ||
tags = var.tags | ||
} |
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,4 @@ | ||
output "kms_arn" { | ||
description = "Arn of kms for log group of cloudwatch" | ||
value = aws_kms_key.kms.arn | ||
} |
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,9 @@ | ||
variable "log_group_name" { | ||
type = string | ||
default = "log-group-default" | ||
description = "Log group name of cloud watch" | ||
} | ||
|
||
variable "tags" { | ||
type = map(any) | ||
} |