Skip to content
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

fix: use the same CMK for encrypting the SNS topic #104

Merged
merged 2 commits into from
May 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/external-bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module "secure_baseline" {
aws = aws
aws.ap-northeast-1 = aws.ap-northeast-1
aws.ap-northeast-2 = aws.ap-northeast-2
aws.ap-northeast-3 = aws.ap-northeast-3
aws.ap-south-1 = aws.ap-south-1
aws.ap-southeast-1 = aws.ap-southeast-1
aws.ap-southeast-2 = aws.ap-southeast-2
Expand Down
7 changes: 7 additions & 0 deletions examples/external-bucket/regions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ provider "aws" {
alias = "ap-northeast-2"
}

provider "aws" {
access_key = var.access_key
secret_key = var.secret_key
region = "ap-northeast-3"
alias = "ap-northeast-3"
}

provider "aws" {
access_key = var.access_key
secret_key = var.secret_key
Expand Down
1 change: 1 addition & 0 deletions examples/organization/master/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module "secure_baseline" {
aws = aws
aws.ap-northeast-1 = aws.ap-northeast-1
aws.ap-northeast-2 = aws.ap-northeast-2
aws.ap-northeast-3 = aws.ap-northeast-3
aws.ap-south-1 = aws.ap-south-1
aws.ap-southeast-1 = aws.ap-southeast-1
aws.ap-southeast-2 = aws.ap-southeast-2
Expand Down
7 changes: 7 additions & 0 deletions examples/organization/master/regions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ provider "aws" {
alias = "ap-northeast-2"
}

provider "aws" {
access_key = var.access_key
secret_key = var.secret_key
region = "ap-northeast-3"
alias = "ap-northeast-3"
}

provider "aws" {
access_key = var.access_key
secret_key = var.secret_key
Expand Down
1 change: 1 addition & 0 deletions examples/organization/member/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module "secure_baseline" {
aws = aws
aws.ap-northeast-1 = aws.ap-northeast-1
aws.ap-northeast-2 = aws.ap-northeast-2
aws.ap-northeast-3 = aws.ap-northeast-3
aws.ap-south-1 = aws.ap-south-1
aws.ap-southeast-1 = aws.ap-southeast-1
aws.ap-southeast-2 = aws.ap-southeast-2
Expand Down
7 changes: 7 additions & 0 deletions examples/organization/member/regions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ provider "aws" {
alias = "ap-northeast-2"
}

provider "aws" {
access_key = var.access_key
secret_key = var.secret_key
region = "ap-northeast-3"
alias = "ap-northeast-3"
}

provider "aws" {
access_key = var.access_key
secret_key = var.secret_key
Expand Down
1 change: 1 addition & 0 deletions examples/select-region/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module "secure_baseline" {
aws = aws
aws.ap-northeast-1 = aws.ap-northeast-1
aws.ap-northeast-2 = aws.ap-northeast-2
aws.ap-northeast-3 = aws.ap-northeast-3
aws.ap-south-1 = aws.ap-south-1
aws.ap-southeast-1 = aws.ap-southeast-1
aws.ap-southeast-2 = aws.ap-southeast-2
Expand Down
7 changes: 7 additions & 0 deletions examples/select-region/regions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ provider "aws" {
alias = "ap-northeast-2"
}

provider "aws" {
access_key = var.access_key
secret_key = var.secret_key
region = "ap-northeast-3"
alias = "ap-northeast-3"
}

provider "aws" {
access_key = var.access_key
secret_key = var.secret_key
Expand Down
1 change: 1 addition & 0 deletions examples/simple/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module "secure_baseline" {
aws = aws
aws.ap-northeast-1 = aws.ap-northeast-1
aws.ap-northeast-2 = aws.ap-northeast-2
aws.ap-northeast-3 = aws.ap-northeast-3
aws.ap-south-1 = aws.ap-south-1
aws.ap-southeast-1 = aws.ap-southeast-1
aws.ap-southeast-2 = aws.ap-southeast-2
Expand Down
7 changes: 7 additions & 0 deletions examples/simple/regions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ provider "aws" {
alias = "ap-northeast-2"
}

provider "aws" {
access_key = var.access_key
secret_key = var.secret_key
region = "ap-northeast-3"
alias = "ap-northeast-3"
}

provider "aws" {
access_key = var.access_key
secret_key = var.secret_key
Expand Down
1 change: 0 additions & 1 deletion modules/cloudtrail-baseline/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Enable CloudTrail in all regions and deliver events to CloudWatch Logs. CloudTra
| region | The AWS region in which CloudTrail is set up. | `any` | n/a | yes |
| s3\_bucket\_name | The name of the S3 bucket which will store configuration snapshots. | `any` | n/a | yes |
| s3\_key\_prefix | The prefix for the specified S3 bucket. | `string` | `""` | no |
| sns\_topic\_kms\_master\_key\_id | The ID of an AWS-managed customer master key (CMK) for Amazon SNS or a custom CMK. | `string` | `"alias/aws/sns"` | no |
| tags | Specifies object tags key and value. This applies to all resources created by this module. | `map` | <pre>{<br> "Terraform": true<br>}</pre> | no |

## Outputs
Expand Down
16 changes: 15 additions & 1 deletion modules/cloudtrail-baseline/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,20 @@ data "aws_iam_policy_document" "cloudtrail_key_policy" {
values = ["arn:aws:cloudtrail:*:${var.aws_account_id}:trail/*"]
}
}

# https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-permissions-for-sns-notifications.html
statement {
sid = "Allow CloudTrail to send notifications to the encrypted SNS topic"
principals {
type = "Service"
identifiers = ["cloudtrail.amazonaws.com"]
}
actions = [
"kms:GenerateDataKey*",
"kms:Decrypt"
]
resources = ["*"]
}
}

resource "aws_kms_key" "cloudtrail" {
Expand All @@ -193,7 +207,7 @@ resource "aws_sns_topic" "cloudtrail-sns-topic" {
count = var.enabled ? 1 : 0

name = var.cloudtrail_sns_topic_name
kms_master_key_id = var.sns_topic_kms_master_key_id
kms_master_key_id = aws_kms_key.cloudtrail[0].id
}

data "aws_iam_policy_document" "cloudtrail-sns-policy" {
Expand Down
5 changes: 0 additions & 5 deletions modules/cloudtrail-baseline/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ variable "s3_key_prefix" {
default = ""
}

variable "sns_topic_kms_master_key_id" {
description = "The ID of an AWS-managed customer master key (CMK) for Amazon SNS or a custom CMK."
default = "alias/aws/sns"
}

variable "is_organization_trail" {
description = "Specifies whether the trail is an AWS Organizations trail. Organization trails log events for the master account and all member accounts. Can only be created in the organization master account."
default = false
Expand Down