Skip to content

Commit c2aeb4c

Browse files
authored
feat: added support for trusted_profile secret type<br>- added support for to pass trusted_profile value as part of the es_container_registry_secrets_chain input (#63)
1 parent f518603 commit c2aeb4c

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

modules/eso-external-secret/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ No modules.
3838
|------|-------------|------|---------|:--------:|
3939
| <a name="input_es_container_registry"></a> [es\_container\_registry](#input\_es\_container\_registry) | The registry URL to be used in dockerconfigjson | `string` | `"us.icr.io"` | no |
4040
| <a name="input_es_container_registry_email"></a> [es\_container\_registry\_email](#input\_es\_container\_registry\_email) | Optional - Email to be used in dockerconfigjson | `string` | `null` | no |
41-
| <a name="input_es_container_registry_secrets_chain"></a> [es\_container\_registry\_secrets\_chain](#input\_es\_container\_registry\_secrets\_chain) | Structure to generate a chain of secrets into a single dockerjsonconfig secret for multiple registries authentication. | <pre>list(object({<br/> es_container_registry = string<br/> sm_secret_id = string # id of the secret storing the apikey that will be used for the secrets chain<br/> es_container_registry_email = optional(string, null)<br/> }))</pre> | `[]` | no |
41+
| <a name="input_es_container_registry_secrets_chain"></a> [es\_container\_registry\_secrets\_chain](#input\_es\_container\_registry\_secrets\_chain) | Structure to generate a chain of secrets into a single dockerjsonconfig secret for multiple registries authentication. | <pre>list(object({<br/> es_container_registry = string<br/> sm_secret_id = string # id of the secret storing the apikey that will be used for the secrets chain<br/> es_container_registry_email = optional(string, null)<br/> trusted_profile = optional(string, null)<br/> }))</pre> | `[]` | no |
4242
| <a name="input_es_helm_rls_name"></a> [es\_helm\_rls\_name](#input\_es\_helm\_rls\_name) | Name to use for the helm release for externalsecrets resource. Must be unique in the namespace | `string` | n/a | yes |
4343
| <a name="input_es_helm_rls_namespace"></a> [es\_helm\_rls\_namespace](#input\_es\_helm\_rls\_namespace) | Namespace to deploy the helm release for the externalsecret. Default if null is the externalsecret namespace | `string` | `null` | no |
4444
| <a name="input_es_kubernetes_namespace"></a> [es\_kubernetes\_namespace](#input\_es\_kubernetes\_namespace) | Namespace to use to generate the externalsecret | `string` | n/a | yes |
@@ -54,7 +54,7 @@ No modules.
5454
| <a name="input_sm_kv_keyid"></a> [sm\_kv\_keyid](#input\_sm\_kv\_keyid) | Secrets-Manager key value (kv) keyid | `string` | `null` | no |
5555
| <a name="input_sm_kv_keypath"></a> [sm\_kv\_keypath](#input\_sm\_kv\_keypath) | Secrets-Manager key value (kv) keypath | `string` | `null` | no |
5656
| <a name="input_sm_secret_id"></a> [sm\_secret\_id](#input\_sm\_secret\_id) | Secrets-Manager secret ID where source data will be synchronized with Kubernetes secret. It can be null only in the case of a dockerjsonconfig secrets chain | `string` | n/a | yes |
57-
| <a name="input_sm_secret_type"></a> [sm\_secret\_type](#input\_sm\_secret\_type) | Secrets-manager secret type to be used as source data by ESO. Valid input types are 'arbitrary', 'username\_password' and 'iam\_credentials' | `string` | n/a | yes |
57+
| <a name="input_sm_secret_type"></a> [sm\_secret\_type](#input\_sm\_secret\_type) | Secrets-manager secret type to be used as source data by ESO. Valid input types are 'iam\_credentials', 'username\_password', 'trusted\_profile', 'arbitrary', 'imported\_cert', 'public\_cert', 'private\_cert', 'kv' | `string` | n/a | yes |
5858

5959
### Outputs
6060

modules/eso-external-secret/main.tf

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ locals {
1717
# dockerjsonconfig secrets chain flag
1818
is_dockerjsonconfig_chain = length(var.es_container_registry_secrets_chain) > 0 ? true : false
1919

20-
# validation for dockerjsonconfig secrets chain -> if it is a chain the kube secret type must be dockerconfigjson and sm secret type iam_credentials
21-
validate_condition_chain = local.is_dockerjsonconfig_chain == true && (var.es_kubernetes_secret_type != "dockerconfigjson" || var.sm_secret_type != "iam_credentials") # checkov:skip=CKV_SECRET_6: does not require high entropy string as is static value
22-
validate_msg_chain = "If the externalsecret is expected to generate a dockerjsonconfig secrets chain the only supported value for es_kubernetes_secret_type is dockerconfigjson and for sm_secret_type is iam_credentials"
20+
# validation for dockerjsonconfig secrets chain -> if it is a chain the kube secret type must be dockerconfigjson and sm secret types iam_credentials or trusted_profile
21+
validate_condition_chain = local.is_dockerjsonconfig_chain == true && (var.es_kubernetes_secret_type != "dockerconfigjson" || (var.sm_secret_type != "iam_credentials" && var.sm_secret_type != "trusted_profile")) # checkov:skip=CKV_SECRET_6: does not require high entropy string as is static value
22+
validate_msg_chain = "If the externalsecret is expected to generate a dockerjsonconfig secrets chain the only supported value for es_kubernetes_secret_type is dockerconfigjson and for sm_secret_type is iam_credentials or trusted_profile"
2323
# tflint-ignore: terraform_unused_declarations
2424
validate_check_chain = regex("^${local.validate_msg_chain}$", (!local.validate_condition_chain ? local.validate_msg_chain : ""))
2525

@@ -85,6 +85,10 @@ locals {
8585
"username" : "iamapikey", "password" : "{{ .secretid_${index} }}", "email" : (element.es_container_registry_email)
8686
}
8787
:
88+
(element.trusted_profile != null && element.trusted_profile != "") ?
89+
{
90+
"username" : element.trusted_profile, "password" : "{{ .secretid_${index} }}"
91+
} :
8892
{
8993
"username" : "iamapikey", "password" : "{{ .secretid_${index} }}"
9094
}
@@ -129,7 +133,7 @@ locals {
129133

130134
### Define kubernetes secret to be installed in cluster for sm_secret_type iam_credentials or arbitrary
131135
resource "helm_release" "kubernetes_secret" {
132-
count = (var.sm_secret_type == "iam_credentials" || var.sm_secret_type == "arbitrary") && local.is_dockerjsonconfig_chain == false ? 1 : 0
136+
count = (var.sm_secret_type == "iam_credentials" || var.sm_secret_type == "arbitrary" || var.sm_secret_type == "trusted_profile") && local.is_dockerjsonconfig_chain == false ? 1 : 0
133137
name = local.helm_secret_name
134138
namespace = local.es_helm_rls_namespace
135139
chart = "${path.module}/../../chart/${local.helm_raw_chart_name}"
@@ -201,12 +205,13 @@ resource "helm_release" "kubernetes_secret_chain_list" {
201205
%{for index, element in var.es_container_registry_secrets_chain~}
202206
- secretKey: secretid_${index}
203207
remoteRef:
204-
key: "${var.sm_secret_type}/${element.sm_secret_id}"
208+
key: "${var.sm_secret_type == "trusted_profile" ? "iam_credentials/${element.sm_secret_id}" : "${var.sm_secret_type}/${element.sm_secret_id}"}"
205209
%{endfor~}
206210
EOF
207211
]
208212
}
209213

214+
210215
### Define kubernetes secret to be installed in cluster for opaque secret type based on SM user credential secret type
211216
resource "helm_release" "kubernetes_secret_user_pw" {
212217
count = var.sm_secret_type == "username_password" ? 1 : 0

modules/eso-external-secret/variables.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ variable "es_kubernetes_secret_data_key" {
5050
}
5151

5252
variable "sm_secret_type" {
53-
description = "Secrets-manager secret type to be used as source data by ESO. Valid input types are 'arbitrary', 'username_password' and 'iam_credentials'"
53+
description = "Secrets-manager secret type to be used as source data by ESO. Valid input types are 'iam_credentials', 'username_password', 'trusted_profile', 'arbitrary', 'imported_cert', 'public_cert', 'private_cert', 'kv'"
5454
type = string
5555
validation {
56-
condition = can(regex("^iam_credentials$|^username_password$|^arbitrary$|^imported_cert$|^public_cert$|^private_cert|^kv$|$^$", var.sm_secret_type))
56+
condition = can(regex("^iam_credentials$|^username_password$|^trusted_profile$|^arbitrary$|^imported_cert$|^public_cert$|^private_cert|^kv$|$^$", var.sm_secret_type))
5757
# If it is empty, no secret will be created
58-
error_message = "The sm_secret_type value must be one of the following: iam_credentials, username_password, arbitrary, imported_cert, public_cert, private_cert, kv or leave it empty."
58+
error_message = "The sm_secret_type value must be one of the following: iam_credentials, username_password, trusted_profile, arbitrary, imported_cert, public_cert, private_cert, kv or leave it empty."
5959
}
6060
}
6161

@@ -82,6 +82,7 @@ variable "es_container_registry_secrets_chain" {
8282
es_container_registry = string
8383
sm_secret_id = string # id of the secret storing the apikey that will be used for the secrets chain
8484
es_container_registry_email = optional(string, null)
85+
trusted_profile = optional(string, null)
8586
}))
8687
default = []
8788
nullable = false

0 commit comments

Comments
 (0)