-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for SSE-KMS encryption in Apiary managed S3 buckets (#161)
* rename apiary-bucket-policy.json * add encryption option * kms keys * test for_each condition * kms policy * kms client policy * fix * restrict writes to managed kms key * fix admin kms policy * restrict s3 bucket access to client roles * update readme * fix client roles * fix client_roles in template * kms alias * kms alias fix * remove client roles in bucket policy * update kms key admin policy * update changelog * cleanup * Update kms.tf Co-authored-by: Scott Barnhart <[email protected]> * update readme * update VARIABLES.md * Update VARIABLES.md Co-authored-by: Scott Barnhart <[email protected]> Co-authored-by: Raj Poluri <[email protected]> Co-authored-by: Scott Barnhart <[email protected]>
- Loading branch information
1 parent
3f0400e
commit 5ddc1d6
Showing
8 changed files
with
162 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
resource "aws_kms_key" "apiary_kms" { | ||
for_each = { | ||
for schema in local.schemas_info : "${schema["schema_name"]}" => schema if schema["encryption"] == "aws:kms" | ||
} | ||
|
||
description = "Apiary ${each.key} KMS key" | ||
policy = data.template_file.apiary_kms_key_policy[each.key].rendered | ||
|
||
lifecycle { | ||
prevent_destroy = true | ||
} | ||
} | ||
|
||
data "template_file" "apiary_kms_key_policy" { | ||
for_each = { | ||
for schema in local.schemas_info : "${schema["schema_name"]}" => schema if schema["encryption"] == "aws:kms" | ||
} | ||
|
||
template = file("${path.module}/templates/apiary-kms-key-policy.json") | ||
|
||
vars = { | ||
admin_roles = replace(each.value["admin_roles"], ",", "\",\"") | ||
client_roles = replace(lookup(each.value, "client_roles", ""), ",", "\",\"") | ||
} | ||
} | ||
|
||
resource "aws_kms_alias" "apiary_alias" { | ||
for_each = { | ||
for schema in local.schemas_info : "${schema["schema_name"]}" => schema if schema["encryption"] == "aws:kms" | ||
} | ||
|
||
name = "alias/${local.instance_alias}/${each.value["schema_name"]}" | ||
target_key_id = aws_kms_key.apiary_kms[each.key].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
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,64 @@ | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
%{if client_roles != ""} | ||
{ | ||
"Sid": "Allow use of the key", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"AWS": ["${client_roles}"] | ||
}, | ||
"Action": [ | ||
"kms:Encrypt", | ||
"kms:Decrypt", | ||
"kms:ReEncrypt*", | ||
"kms:GenerateDataKey*", | ||
"kms:DescribeKey" | ||
], | ||
"Resource": "*" | ||
}, | ||
{ | ||
"Sid": "Allow attachment of persistent resources", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"AWS": ["${client_roles}"] | ||
}, | ||
"Action": [ | ||
"kms:CreateGrant", | ||
"kms:ListGrants", | ||
"kms:RevokeGrant" | ||
], | ||
"Resource": "*", | ||
"Condition": { | ||
"Bool": { | ||
"kms:GrantIsForAWSResource": "true" | ||
} | ||
} | ||
}, | ||
%{endif} | ||
{ | ||
"Sid": "Allow access for Key Administrators", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"AWS": [ "${admin_roles}" ] | ||
}, | ||
"Action": [ | ||
"kms:Create*", | ||
"kms:Describe*", | ||
"kms:Enable*", | ||
"kms:List*", | ||
"kms:Put*", | ||
"kms:Update*", | ||
"kms:Revoke*", | ||
"kms:Disable*", | ||
"kms:Get*", | ||
"kms:Delete*", | ||
"kms:TagResource", | ||
"kms:UntagResource", | ||
"kms:ScheduleKeyDeletion", | ||
"kms:CancelKeyDeletion" | ||
], | ||
"Resource": "*" | ||
} | ||
] | ||
} |