Skip to main content
13

How do you manage config and secrets?

MediumSecretsSecurityConfiguration

How do you manage configuration and secrets for applications, especially on Kubernetes?

TL;DR

Keep config out of the image so the same artifact runs in every environment (the twelve-factor rule): inject it as environment variables or mounted files. Non-sensitive config goes in ConfigMaps. Secrets (passwords, API keys, certificates) need more care. A Kubernetes Secret is only base64-encoded, not encrypted, so enable encryption at rest for etcd, restrict access with RBAC, and preferably keep the source of truth in an external manager (AWS Secrets Manager, GCP Secret Manager, HashiCorp Vault), synced into the cluster by the External Secrets Operator or a CSI driver. Never commit plaintext secrets to Git.

Key points

  • If secrets must live in Git (GitOps), encrypt them: SOPS or Sealed Secrets.
  • Prefer workload identity (IRSA on EKS, Workload Identity on GKE) over static cloud keys: the Pod gets short-lived credentials from its service account.
  • Dynamic secrets (Vault): credentials generated per app with a short TTL, revoked automatically.
  • Rotate secrets regularly, and make the app reload without a redeploy (mounted files update; env vars don't).
  • Mounted files are safer than env vars: env vars leak into crash dumps, /proc, and child processes.
  • Scan repos and images for leaked secrets (gitleaks, trufflehog), and rotate immediately if one leaks; deleting the commit isn't enough.

Example

yaml
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata: { name: db-credentials }
spec:
  refreshInterval: 1h
  secretStoreRef: { name: aws-secrets-manager, kind: ClusterSecretStore }
  target: { name: db-credentials }
  data:
    - secretKey: password
      remoteRef: { key: prod/api/db, property: password }

Common follow-ups

  • A secret was pushed to a public repo. What now? Revoke and rotate it at once, check access logs for misuse, then clean the history. Assume it was already scraped.
  • ConfigMap vs Secret? Same mechanics; Secrets are meant for sensitive data, can be encrypted at rest, and can have stricter RBAC.

What interviewers look for

Tip

Config separate from code, "base64 isn't encryption", an external secret manager, workload identity, and rotation.

  • Red flag: secrets baked into images or committed in .env files.

Was this helpful?

Related questions