-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from confusdcodr/kms
Add kms encryption
- Loading branch information
Showing
14 changed files
with
279 additions
and
8 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
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
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
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,3 @@ | ||
# Premade KMS Key Test | ||
|
||
|
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 @@ | ||
# Premade KMS Key Test |
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,23 @@ | ||
provider "aws" { | ||
region = "us-east-1" | ||
} | ||
|
||
data "terraform_remote_state" "prereq" { | ||
backend = "local" | ||
config = { | ||
path = "prereq/terraform.tfstate" | ||
} | ||
} | ||
|
||
module "premade_kms_key" { | ||
source = "../../" | ||
|
||
providers = { | ||
aws = aws | ||
} | ||
|
||
create_cloudtrail = true | ||
cloudtrail_name = data.terraform_remote_state.prereq.outputs.random_name | ||
cloudtrail_bucket = data.terraform_remote_state.prereq.outputs.bucket_id | ||
kms_key_id = data.terraform_remote_state.prereq.outputs.kms_key_id | ||
} |
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,53 @@ | ||
provider "aws" { | ||
region = "us-east-1" | ||
} | ||
|
||
locals { | ||
partition = "aws" | ||
} | ||
|
||
data "aws_caller_identity" "current" {} | ||
|
||
resource "random_id" "name" { | ||
byte_length = 6 | ||
prefix = "tardigrade-cloudtrail-" | ||
} | ||
|
||
resource "aws_s3_bucket" "this" { | ||
bucket = random_id.name.hex | ||
policy = join("", data.template_file.this.*.rendered) | ||
force_destroy = true | ||
} | ||
|
||
resource "aws_kms_key" "this" { | ||
policy = join("", data.template_file.kms_policy.*.rendered) | ||
} | ||
|
||
data "template_file" "this" { | ||
template = file("${path.module}/../../templates/cloudtrail-bucket-policy.json") | ||
|
||
vars = { | ||
bucket = random_id.name.hex | ||
partition = local.partition | ||
} | ||
} | ||
|
||
data "template_file" "kms_policy" { | ||
template = file("${path.module}/../../templates/cloudtrail-kms-key-policy.json") | ||
|
||
vars = { | ||
account_id = data.aws_caller_identity.current.account_id | ||
} | ||
} | ||
|
||
output "random_name" { | ||
value = random_id.name.hex | ||
} | ||
|
||
output "bucket_id" { | ||
value = aws_s3_bucket.this.id | ||
} | ||
|
||
output "kms_key_id" { | ||
value = aws_kms_key.this.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,3 @@ | ||
terraform { | ||
required_version = ">= 0.12" | ||
} |
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,63 @@ | ||
{ | ||
"Statement": [ | ||
{ | ||
"Action": "kms:*", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"AWS": [ | ||
"*" | ||
] | ||
}, | ||
"Resource": "*", | ||
"Sid": "Enable IAM User Permissions" | ||
}, | ||
{ | ||
"Action": "kms:GenerateDataKey*", | ||
"Condition": { | ||
"StringLike": { | ||
"kms:EncryptionContext:aws:cloudtrail:arn": "arn:aws:cloudtrail:*:${account_id}:trail/*" | ||
} | ||
}, | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": [ | ||
"cloudtrail.amazonaws.com" | ||
] | ||
}, | ||
"Resource": "*", | ||
"Sid": "Allow CloudTrail to encrypt logs" | ||
}, | ||
{ | ||
"Action": "kms:DescribeKey", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": [ | ||
"cloudtrail.amazonaws.com" | ||
] | ||
}, | ||
"Resource": "*", | ||
"Sid": "Allow CloudTrail to describe key" | ||
}, | ||
{ | ||
"Action": [ | ||
"kms:Decrypt", | ||
"kms:ReEncryptFrom" | ||
], | ||
"Condition": { | ||
"StringEquals": { | ||
"kms:CallerAccount": "${account_id}" | ||
}, | ||
"StringLike": { | ||
"kms:EncryptionContext:aws:cloudtrail:arn": "arn:aws:cloudtrail:*:${account_id}:trail/*" | ||
} | ||
}, | ||
"Effect": "Allow", | ||
"Principal": { | ||
"AWS": "*" | ||
}, | ||
"Resource": "*", | ||
"Sid": "Allow principals in the account to decrypt log files" | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
} |
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