Skip to content

Commit 0cd905b

Browse files
authored
Merge pull request #3 from cloudtruth/feature/kms_support
Added support for custom kms keys
2 parents d30b9a2 + b7fe68a commit 0cd905b

File tree

3 files changed

+73
-3
lines changed

3 files changed

+73
-3
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ module "grant_cloudtruth_access" {
4444
| ssm\_resources | The ssm resources to explicitly grant access to, defaults to all, and listing<br>all is always allowed (for chooser in UI) even if access<br>isn't granted here | `list(string)` | <pre>[<br> "*"<br>]</pre> | no |
4545
| secretsmanager\_policy | A custom policy to use for secrets manager instead of the one this module would define | `string` | `""` | no |
4646
| secretsmanager\_resources | The secrets manager resources to explicitly grant access to, defaults to all, and listing<br>all is always allowed (for chooser in UI) even if access<br>isn't granted here | `list(string)` | <pre>[<br> "*"<br>]</pre> | no |
47+
| kms\_decrypt\_enabled | Enable kms decryption using the specified kms keys; required only if ssm parameters or secretsmanager secrets use custom kms keys | `bool` | `false` | no |
48+
| kms\_encrypt\_enabled | Enable kms decryption/encryption using the specified kms keys; required only if ssm parameters or secretsmanager secrets use custom kms keys | `bool` | `false` | no |
49+
| kms\_keys | The kms keys to explicitly grant access to | `list(string)` | <pre>[]</pre> | no |
4750

4851
## Outputs
4952

main.tf

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,35 @@ data "aws_iam_policy_document" "secretsmanager_write" {
163163

164164
}
165165

166+
// This policy allows cloudtruth to perform kms decrypt operations using the specified key(s)
167+
//
168+
data "aws_iam_policy_document" "kms_decrypt" {
169+
170+
statement {
171+
sid = "AllowKMSDecrypt"
172+
effect = "Allow"
173+
actions = [
174+
"kms:Decrypt"
175+
]
176+
resources = var.kms_keys
177+
}
178+
}
179+
180+
// This policy allows cloudtruth to perform kms encrypt operations using the specified key(s)
181+
//
182+
data "aws_iam_policy_document" "kms_encrypt" {
183+
184+
statement {
185+
sid = "AllowKMSEncrypt"
186+
effect = "Allow"
187+
actions = [
188+
"kms:Encrypt",
189+
"kms:GenerateDataKey"
190+
]
191+
resources = var.kms_keys
192+
}
193+
}
194+
166195
locals {
167196
policy_lookup = {
168197
s3 = var.s3_policy != "" ? var.s3_policy : data.aws_iam_policy_document.s3.json
@@ -191,3 +220,17 @@ resource "aws_iam_role_policy" "cloudtruth_write_policies" {
191220
role = aws_iam_role.cloudtruth_access.id
192221
policy = local.write_policy_lookup[each.key]
193222
}
223+
224+
resource "aws_iam_role_policy" "cloudtruth_kms_decrypt" {
225+
count = var.kms_decrypt_enabled || var.kms_encrypt_enabled ? 1 : 0
226+
name = "allow-cloudtruth-kms-decrypt"
227+
role = aws_iam_role.cloudtruth_access.id
228+
policy = data.aws_iam_policy_document.kms_decrypt.json
229+
}
230+
231+
resource "aws_iam_role_policy" "cloudtruth_kms_encrypt" {
232+
count = var.kms_encrypt_enabled ? 1 : 0
233+
name = "allow-cloudtruth-kms-encrypt"
234+
role = aws_iam_role.cloudtruth_access.id
235+
policy = data.aws_iam_policy_document.kms_encrypt.json
236+
}

variables.tf

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ variable "s3_resources" {
3939

4040
variable "s3_policy" {
4141
description = <<-EOD
42-
A custom poilicy to use for s3 instead of the one this module would define
42+
A custom policy to use for s3 instead of the one this module would define
4343
EOD
4444
default = ""
4545
}
@@ -54,7 +54,7 @@ variable "ssm_resources" {
5454

5555
variable "ssm_policy" {
5656
description = <<-EOD
57-
A custom poilicy to use for ssm instead of the one this module would define
57+
A custom policy to use for ssm instead of the one this module would define
5858
EOD
5959
default = ""
6060
}
@@ -70,7 +70,31 @@ variable "secretsmanager_resources" {
7070

7171
variable "secretsmanager_policy" {
7272
description = <<-EOD
73-
A custom poilicy to use for secrets manager instead of the one this module would define
73+
A custom policy to use for secrets manager instead of the one this module would define
7474
EOD
7575
default = ""
7676
}
77+
78+
variable "kms_decrypt_enabled" {
79+
description = <<-EOD
80+
Enable kms decryption using the specified kms keys; required only if ssm parameters or secretsmanager secrets use custom kms keys
81+
EOD
82+
type = bool
83+
default = false
84+
}
85+
86+
variable "kms_encrypt_enabled" {
87+
description = <<-EOD
88+
Enable kms decryption/encryption using the specified kms keys; required only if ssm parameters or secretsmanager secrets use custom kms keys
89+
EOD
90+
type = bool
91+
default = false
92+
}
93+
94+
variable "kms_keys" {
95+
description = <<-EOD
96+
The kms keys to explicitly grant access to, defaults to none
97+
EOD
98+
type = list(string)
99+
default = []
100+
}

0 commit comments

Comments
 (0)