Secrets Helper
Create Kubernetes Secrets using the ohMyHelm secrets and secretsFromFile helpers, including random password generation and key GitOps warnings.
Secrets Helper
With the root helpers secrets and secretsFromFile, you can create generic v1/Secret resources independently of Chart mode. Values under secrets are automatically Base64-encoded (b64enc).
1. Generic Secrets (secrets)
According to values.schema.json, each entry in secrets[] accepts the fields name (required), namespace (optional, defaults to the release namespace), and values (required map of key-value pairs).
secrets:
- name: acme-db-credentials
namespace: acme-prod
values:
username: acme_app
password: ""
- name: acme-api-keys
namespace: acme-prod
values:
webhook-token: ""
endpoint: "https://hooks.acme.example"
Automatic Password Generation and lookup Behavior
- If a value is left empty (
""ornull), the template automatically generates a 20-character alphanumeric random string (randAlphaNum 20) on the initialhelm install. - On a subsequent
helm upgradedirectly against the cluster,omh-helper-secret.yamlqueries the existing Secret vialookup "v1" "Secret"and retains the stored value for existing keys — preventing existing credentials from being overwritten. - Values are taken strictly as static strings: neither
{{ .Values.* }}nor shell-style expansion such as$(VAR)is evaluated.
1. Empty values (`password: ""`) are randomly regenerated on **every** sync or render run — causing running services to lose their credentials.
2. Existing values in the cluster are **not** protected.
Therefore, never use empty auto-generated values in GitOps setups and never store plaintext passwords in Git. Instead, rely on **External Secrets Operator**, **Sealed Secrets**, or SOPS-encrypted Secret resources.
2. Secrets from Chart Files (secretsFromFile)
With secretsFromFile (omh-helper-secret-from-file.yaml), ohMyHelm reads text files from the chart via .Files.Lines and writes them into a Secret as stringData:
secretsFromFile:
- name: acme-file-secret
namespace: acme-prod
values:
config.yaml: files/README.md
Using Secrets Safely in a Chart Workload
Reference generated Secrets in your container via secretKeyRef, envFrom, or as a volume mount under deploymentVolume / statefulsetVolume / daemonsetVolume:
chart:
enabled: true
fullnameOverride: "acme-backend"
container:
image: registry.acme.corp/backend:2.0.0
staticEnv:
- name: DB_USER
valueFrom:
secretKeyRef:
name: acme-db-credentials
key: username
- name: DB_PASS
valueFrom:
secretKeyRef:
name: acme-db-credentials
key: password