Skip to content

Commit b207735

Browse files
authored
External-Secrets: Add variable for decrypting aliased KMS keys (cloudposse/terraform-aws-components#1068)
1 parent 34e14f3 commit b207735

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

src/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ components:
8989
# chart_values:
9090
# installCRDs: true
9191
chart_values: {}
92+
kms_aliases_allow_decrypt: []
93+
# - "alias/foo/bar"
9294
```
9395

9496
<!-- prettier-ignore-start -->
@@ -126,6 +128,7 @@ components:
126128
|------|------|
127129
| [kubernetes_namespace.default](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/namespace) | resource |
128130
| [aws_eks_cluster_auth.eks](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/eks_cluster_auth) | data source |
131+
| [aws_kms_alias.kms_aliases](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/kms_alias) | data source |
129132
| [kubernetes_resources.crd](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/data-sources/resources) | data source |
130133

131134
## Inputs
@@ -150,6 +153,7 @@ components:
150153
| <a name="input_environment"></a> [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
151154
| <a name="input_helm_manifest_experiment_enabled"></a> [helm\_manifest\_experiment\_enabled](#input\_helm\_manifest\_experiment\_enabled) | Enable storing of the rendered manifest for helm\_release so the full diff of what is changing can been seen in the plan | `bool` | `false` | no |
152155
| <a name="input_id_length_limit"></a> [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).<br>Set to `0` for unlimited length.<br>Set to `null` for keep the existing setting, which defaults to `0`.<br>Does not affect `id_full`. | `number` | `null` | no |
156+
| <a name="input_kms_aliases_allow_decrypt"></a> [kms\_aliases\_allow\_decrypt](#input\_kms\_aliases\_allow\_decrypt) | A list of KMS aliases that the SecretStore is allowed to decrypt. | `list(string)` | `[]` | no |
153157
| <a name="input_kube_data_auth_enabled"></a> [kube\_data\_auth\_enabled](#input\_kube\_data\_auth\_enabled) | If `true`, use an `aws_eks_cluster_auth` data source to authenticate to the EKS cluster.<br>Disabled by `kubeconfig_file_enabled` or `kube_exec_auth_enabled`. | `bool` | `false` | no |
154158
| <a name="input_kube_exec_auth_aws_profile"></a> [kube\_exec\_auth\_aws\_profile](#input\_kube\_exec\_auth\_aws\_profile) | The AWS config profile for `aws eks get-token` to use | `string` | `""` | no |
155159
| <a name="input_kube_exec_auth_aws_profile_enabled"></a> [kube\_exec\_auth\_aws\_profile\_enabled](#input\_kube\_exec\_auth\_aws\_profile\_enabled) | If `true`, pass `kube_exec_auth_aws_profile` as the `profile` to `aws eks get-token` | `bool` | `false` | no |

src/main.tf

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,17 @@ module "external_secrets_operator" {
6262
"arn:aws:ssm:${var.region}:${local.account}:*"
6363
]
6464
}],
65-
local.overridable_additional_iam_policy_statements
65+
local.overridable_additional_iam_policy_statements,
66+
length(var.kms_aliases_allow_decrypt) > 0 ? [
67+
{
68+
sid = "DecryptKMS"
69+
effect = "Allow"
70+
actions = [
71+
"kms:Decrypt"
72+
]
73+
resources = local.kms_aliases_target_arns
74+
}
75+
] : []
6676
)
6777
}]
6878

@@ -133,3 +143,12 @@ module "external_ssm_secrets" {
133143
module.external_secrets_operator,
134144
]
135145
}
146+
147+
data "aws_kms_alias" "kms_aliases" {
148+
for_each = { for i, v in var.kms_aliases_allow_decrypt : v => v }
149+
name = each.value
150+
}
151+
152+
locals {
153+
kms_aliases_target_arns = [for k, v in data.aws_kms_alias.kms_aliases : data.aws_kms_alias.kms_aliases[k].target_key_arn]
154+
}

src/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@ variable "resources" {
3434
})
3535
description = "The cpu and memory of the deployment's limits and requests."
3636
}
37+
38+
variable "kms_aliases_allow_decrypt" {
39+
type = list(string)
40+
description = "A list of KMS aliases that the SecretStore is allowed to decrypt."
41+
default = []
42+
}

0 commit comments

Comments
 (0)