Can I define secretStoreRef's name of a ExternalSecret in my configMap?

498 Views Asked by At

I have an ExternalSecret definition pulling secrets from Azure key vault.

apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
  name: my-es
spec:
  dataFrom:
    - find:
    ... copy some values over
  secretStoreRef:
    kind: SecretStore
    name: my-special-store        <-- This is the name I want to pull from my config map

The thing is that the above store is the same across all my environments apart from the secretStoreRef.Name. Hence I have to redefine an ExternalSecret in each environment. Not the whole thing but I do have to override the name.

Each environment already has a config map. Is there no way to add the name in the ConfigMap and somehow reference it from withing in the ExternalSecret defintion?

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-cm
data:
  val: value1
  my_special_secret_store_name: my-special-store     <-- Can I not define my secret store name here and use it in the ExternalSecret

I know there is a way of using yq but I do not have yq available and all kustomise configs in one file separated by --- per environment aka i do not have a configmap.yaml. $(cat configmap.yaml | yq eval '.data.myVaultName' -)

Is there a way to pull the name from the configMap?

1

There are 1 best solutions below

1
On BEST ANSWER

You can patch the resource using kustomize. Given an input of:

apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
  name: my-es
spec:
  dataFrom:
    - find:
  secretStoreRef:
    kind: SecretStore
    name: original-name

If you use the following kustomization.yaml:

resources:
  - externalsecret.yaml

patches:
  - patch: |
      apiVersion: external-secrets.io/v1beta1
      kind: ExternalSecret
      metadata:
        name: my-es
      spec:
        secretStoreRef:
          name: my-special-store

The output of kustomize build will be:

apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
  name: my-es
spec:
  dataFrom:
  - find: null
  secretStoreRef:
    kind: SecretStore
    name: my-special-store