Repository navigation
Is there a way to use postBuild with secrets containing none env formatted keys #6172
|
We substitute some secret files that are generated by crossplane into config for management of databases. We are also changing crossplane providers and one of the quirks of the new one is some of the fields are output like So does anyone know of a way to get it to accept a key as a key and ignore the fact it isn't a true env format as it is a perfectly valid format for a secret? |
Replies: 1 comment 1 reply
|
Unfortunately there's no setting for that in Flux today. Before substituting anything, kustomize-controller checks the name of every key in every This is by design: an earlier request for keys with periods (#3959) was closed as not planned, and the docs point it out. There's an open issue asking Flux to skip malformed keys (#4885); a 👍 there is the way to push for it. Until then, the fix is to give Flux a Secret with well-formed keys. A few ways to do that, depending on how the Secret is produced and used: 1. Rename the key in Crossplane. If the managed resource is part of a Composition, map the key when you publish the connection details (function-patch-and-transform syntax): connectionDetails:
- name: master_password
type: FromConnectionSecretKey
fromConnectionSecretKey: attribute.master_passwordThe XR's connection Secret then has 2. Copy it into a second Secret with External Secrets Operator. If you use the MR directly, the Kubernetes provider can read the provider's Secret and write a copy with your own key names: apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
name: db-substitution-vars
namespace: flux-system
spec:
secretStoreRef:
kind: SecretStore
name: in-cluster # a store using the kubernetes provider
target:
name: db-substitution-vars
data:
- secretKey: master_password
remoteRef:
key: <crossplane-connection-secret>
property: attribute.master_passwordThen use 3. Skip substitution for the secret value. If the password ends up in a Pod or a Helm chart, you can read the key as-is without going through env:
- name: MASTER_PASSWORD
valueFrom:
secretKeyRef:
name: <crossplane-connection-secret>
key: attribute.master_password# HelmRelease
valuesFrom:
- kind: Secret
name: <crossplane-connection-secret>
valuesKey: attribute.master_password
targetPath: auth.passwordThat also keeps the password out of the rendered manifests that Flux applies, which is worth having for credentials anyway. |
Unfortunately there's no setting for that in Flux today. Before substituting anything, kustomize-controller checks the name of every key in every
substituteFromsource, including keys you never reference, and stops at the first one that doesn't match^[_[:alpha:]][_[:alpha:][:digit:]]*$(varSubstitutionin fluxcd/pkg). Thekustomize.toolkit.fluxcd.io/substitute: disabledlabel doesn't help either, because the keys come from the Kustomization, not from the individual resource.This is by design: an earlier request for keys with periods (#3959) was closed as not planned, and the docs point it out. There's an open issue asking Flux to skip malformed keys (#4885); a 👍 there is the way to push…