Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
795ad1c
Breaking: Added support for trusted profile as an input
sai-madhav-k Apr 13, 2025
f18d05b
Merge branch 'main' into trusted-profile
sai-madhav-k Apr 13, 2025
cda23e9
Chore: Removed unused variables
sai-madhav-k Apr 13, 2025
e1adaaa
Merge remote-tracking branch 'refs/remotes/origin/trusted-profile' in…
sai-madhav-k Apr 13, 2025
372b9b6
Merge branch 'main' into trusted-profile
sai-madhav-k Apr 14, 2025
3feaa64
Merge branch 'main' into trusted-profile
vbontempi Apr 14, 2025
79c707d
Merge branch 'main' into trusted-profile
sai-madhav-k Apr 14, 2025
ec54d56
Chore: removed trusted_profile from docker_user
sai-madhav-k Apr 15, 2025
c0e5d5f
Chore: Updated the comments
sai-madhav-k Apr 15, 2025
5e71c54
Chore: Updated the description and error message for the variable sm_…
sai-madhav-k Apr 15, 2025
a12369b
Chore: Updated the docker_user
sai-madhav-k Apr 15, 2025
cdb8400
Merge branch 'main' into trusted-profile
vbontempi Apr 17, 2025
89fec96
Merge branch 'main' into trusted-profile
sai-madhav-k Apr 21, 2025
be521bd
Update: Merged the secret chain list blocks
sai-madhav-k Apr 23, 2025
08e61a4
Merge branch 'main' into trusted-profile
sai-madhav-k Apr 23, 2025
b76fae2
Merge branch 'main' into trusted-profile
sai-madhav-k Apr 24, 2025
2616e81
Chore: Removed the trusted profile type from docker_user
sai-madhav-k Apr 24, 2025
beb805e
Chore: Pre-commit correction
sai-madhav-k Apr 25, 2025
d54ab6d
docs: fix readmes
daniel-butler-irl Apr 25, 2025
1d4ea70
Merge branch 'main' into trusted-profile
ocofaigh Apr 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 50 additions & 5 deletions modules/eso-external-secret/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ locals {
# dockerjsonconfig secrets chain flag
is_dockerjsonconfig_chain = length(var.es_container_registry_secrets_chain) > 0 ? true : false

# validation for dockerjsonconfig secrets chain -> if it is a chain the kube secret type must be dockerconfigjson and sm secret type iam_credentials
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
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"
# validation for dockerjsonconfig secrets chain -> if it is a chain the kube secret type must be dockerconfigjson and sm secret types iam_credentials, trusted_profile
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of comma an 'or' would be more clear

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been resolved

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
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 and trusted_profile"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean iam_credentials or trusted_profile?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# tflint-ignore: terraform_unused_declarations
validate_check_chain = regex("^${local.validate_msg_chain}$", (!local.validate_condition_chain ? local.validate_msg_chain : ""))

Expand All @@ -46,7 +46,7 @@ locals {
certificate_spec_data = local.is_certificate ? (var.sm_secret_type == "public_cert" ? local.public_certificate_spec_data : (var.sm_secret_type == "imported_cert" ? local.imported_certificate_spec_data : (var.sm_secret_type == "private_cert" ? local.private_certificate_spec_data : ""))) : "" # checkov:skip=CKV_SECRET_6: does not require high entropy string as is static value

# dockerjson format
docker_user = var.sm_secret_type == "username_password" ? "{{ .username }}" : "iamapikey" # checkov:skip=CKV_SECRET_6: does not require high entropy string as is static value
docker_user = var.sm_secret_type == "username_password" || var.sm_secret_type=="trusted_profile" ? "{{ .username }}" : "iamapikey" # checkov:skip=CKV_SECRET_6: does not require high entropy string as is static value
docker_password = var.sm_secret_type == "username_password" ? "{{ .password }}" : "{{ .secretid }}"

# setting data_type according to the kube secret and the SM secret types
Expand Down Expand Up @@ -85,6 +85,10 @@ locals {
"username" : "iamapikey", "password" : "{{ .secretid_${index} }}", "email" : (element.es_container_registry_email)
}
:
(element.trusted_profile != null && element.trusted_profile != "") ?
{
"username" : element.trusted_profile, "password" : "{{ .secretid_${index} }}"
}:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if at line #49 you specify that the username is apikey for trustedprofile, why do you put a different username here?
In addition, what's the expected username?
Last: has a trusted profile an apikey?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the following line can be avoided as I am giving the username in the variable data_payload_chain_map

https://github.com/sai-madhav-k/terraform-ibm-external-secrets-operator/blob/3feaa647b45f5510ee6190d66f36daaec2ca59fe/modules/eso-external-secret/main.tf#L49

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, so you can remove it

{
"username" : "iamapikey", "password" : "{{ .secretid_${index} }}"
}
Expand Down Expand Up @@ -168,7 +172,7 @@ resource "helm_release" "kubernetes_secret" {

### Define kubernetes secret to be installed in cluster for sm_secret_type iam_credentials and kubernetes secret type dockerjsonconfig and configured with a chain of secrets
resource "helm_release" "kubernetes_secret_chain_list" {
count = local.is_dockerjsonconfig_chain == true ? 1 : 0
count = local.is_dockerjsonconfig_chain == true && var.sm_secret_type!="trusted_profile" ? 1 : 0
name = local.helm_secret_name
namespace = local.es_helm_rls_namespace
chart = "${path.module}/../../chart/${local.helm_raw_chart_name}"
Expand Down Expand Up @@ -207,6 +211,47 @@ resource "helm_release" "kubernetes_secret_chain_list" {
]
}

resource "helm_release" "kubernetes_secret_chain_list_tp" {
count = local.is_dockerjsonconfig_chain == true && var.sm_secret_type=="trusted_profile" ? 1 : 0
name = local.helm_secret_name
namespace = local.es_helm_rls_namespace
chart = "${path.module}/../../chart/${local.helm_raw_chart_name}"
version = local.helm_raw_chart_version
timeout = 600
values = [
<<-EOF
resources:
- apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
name: "${var.es_kubernetes_secret_name}"
namespace: "${var.es_kubernetes_namespace}"
spec:
refreshInterval: ${var.es_refresh_interval}
secretStoreRef:
name: "${var.eso_store_name}"
kind: "${local.secret_store_ref_kind}"
target:
name: "${var.es_kubernetes_secret_name}"
template:
engineVersion: v2
type: "${local.es_kubernetes_secret_type}"
metadata:
annotations:
${local.reloader_annotation}
data:
${local.data_chain}
data:
%{for index, element in var.es_container_registry_secrets_chain~}
- secretKey: secretid_${index}
remoteRef:
key: "${element.sm_secret_id}"
%{endfor~}
EOF
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the reason for duplicating the code of kubernetes_secret_chain_list? the only difference that I see is the value of sm_secret_type

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its better to have a separate block for trusted-profile's dockerconfigjson, since the format of giving the secret id is different. The below is reference for secret if the selected secret type is trusted_profile

remoteRef:
              key: "${element.sm_secret_id}"

whereas for the normal dockerconfigjson it is :

remoteRef:
              key: "${var.sm_secret_type}/${element.sm_secret_id}"

I thought its better to give it like this, since there might be little chance of breaking things if anything goes wrong

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would mean to duplicate the code for a little change, you could differentiate the string to put here with a condition and keep the block not duplicated

}


### Define kubernetes secret to be installed in cluster for opaque secret type based on SM user credential secret type
resource "helm_release" "kubernetes_secret_user_pw" {
count = var.sm_secret_type == "username_password" ? 1 : 0
Expand Down
5 changes: 3 additions & 2 deletions modules/eso-external-secret/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ variable "sm_secret_type" {
description = "Secrets-manager secret type to be used as source data by ESO. Valid input types are 'arbitrary', 'username_password' and 'iam_credentials'"
type = string
validation {
condition = can(regex("^iam_credentials$|^username_password$|^arbitrary$|^imported_cert$|^public_cert$|^private_cert|^kv$|$^$", var.sm_secret_type))
condition = can(regex("^iam_credentials$|^username_password$|^trusted_profile$|^arbitrary$|^imported_cert$|^public_cert$|^private_cert|^kv$|$^$", var.sm_secret_type))
# If it is empty, no secret will be created
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."
error_message = "The sm_secret_type value must be one of the following: iam_credentials, trusted_profile, username_password, arbitrary, imported_cert, public_cert, private_cert, kv or leave it empty."
}
}

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