TExcelTAD
Home › GitOps: Argo CD & Flux › Secrets in a GitOps Repository

Secrets in a GitOps Repository

GitOps wants everything in Git; security wants passwords nowhere near Git. A base64-encoded Kubernetes Secret is not encrypted (base64 -d reads it), and Git history keeps it forever, even after you delete the file. Three patterns resolve the conflict, and production setups often use more than one.

Pattern What Git holds Who decrypts Works with
SOPS (Mozilla SOPS with age, PGP or a cloud KMS) the Secret YAML with values encrypted, keys readable Flux kustomize-controller natively; Argo CD through a plugin Flux (first-class), Argo CD (plugin)
Sealed Secrets (Bitnami Labs controller, kubeseal CLI) a SealedSecret: the whole value encrypted with the cluster's public key the in-cluster controller, which creates a normal Secret both
External Secrets Operator (ESO) an ExternalSecret: only a reference ("key linkly/db in Vault") the operator fetches the value from AWS Secrets Manager, Vault, GCP/Azure secret stores… both

SOPS: encrypted values in the repo

A SOPS-encrypted Secret keeps its structure, so reviews still show which key changed:

yaml
apiVersion: v1
kind: Secret
metadata:
  name: linkly-db
  namespace: linkly-prod
stringData:
  url: ENC[AES256_GCM,data:4tJhW0...,iv:...,tag:...,type:str]
sops:
  age:
    - recipient: age1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs3290gq
      enc: |
        -----BEGIN AGE ENCRYPTED FILE-----
        ...
  encrypted_regex: ^(data|stringData)$
  version: 3.10.2

(Sample file: the ciphertext is abridged.) A .sops.yaml at the repository root says which files to encrypt and for which keys, so sops -e -i secret.yaml needs no flags. Flux decrypts during the build when the Kustomization names the private key's Secret:

bash · try it yourself
flux create kustomization linkly-production \
  --source=GitRepository/linkly-deploy --path=./apps/production \
  --prune=true --interval=10m \
  --decryption-provider=sops --decryption-secret=sops-age --export > ks.yaml
cat ks.yaml
kubeconform -strict -summary ks.yaml
---
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
  name: linkly-production
  namespace: flux-system
spec:
  decryption:
    provider: sops
    secretRef:
      name: sops-age
  interval: 10m0s
  path: ./apps/production
  prune: true
  sourceRef:
    kind: GitRepository
    name: linkly-deploy
Summary: 1 resource found in 1 file - Valid: 1, Invalid: 0, Errors: 0, Skipped: 0

The sops-age Secret in flux-system holds the age private key; it is created once by hand (or by Terraform) and is the one secret that does not live in Git. With a cloud KMS, the controller's workload identity grants decrypt rights instead, and no key file exists at all.

External Secrets Operator: references only

ESO keeps secret values out of Git entirely. A ClusterSecretStore says how to reach the store; each ExternalSecret says which keys to copy into which Kubernetes Secret, and how often to refresh:

bash · try it yourself
cat > external.yaml <<'EOF'
apiVersion: external-secrets.io/v1
kind: ClusterSecretStore
metadata: {name: aws-secrets}
spec:
  provider:
    aws:
      service: SecretsManager
      region: eu-west-1
      auth:
        jwt: {serviceAccountRef: {name: external-secrets, namespace: external-secrets}}
---
apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata: {name: linkly-db, namespace: linkly-prod}
spec:
  refreshInterval: 1h
  secretStoreRef: {kind: ClusterSecretStore, name: aws-secrets}
  target: {name: linkly-db}
  data:
    - secretKey: url
      remoteRef: {key: prod/linkly/database, property: url}
EOF
kubeconform -strict -summary external.yaml
Summary: 2 resources found in 1 file - Valid: 2, Invalid: 0, Errors: 0, Skipped: 0

The Deployment keeps referencing secretKeyRef: {name: linkly-db, key: url} exactly as before; only the source of the Secret changed. Rotation happens in the secret store, and the operator picks it up at the next refresh.

Choosing

  • One cluster, small team, Flux: SOPS with age is the least infrastructure.
  • Many clusters or a central security team: ESO, because secrets are managed, rotated and audited in one store and Git never sees them, even encrypted.
  • Sealed Secrets: simple, but each SealedSecret is bound to one cluster's key (re-seal for every cluster, back up the controller's key or lose every secret on a rebuild).

Whatever you choose, run a secret scanner on the GitOps repo in CI (gitleaks): one accidental kubectl create secret … -o yaml > secret.yaml committed in plain text is enough. Deeper coverage of Vault and SOPS is planned in Secrets & Policy as Code.

Test yourself

Why is committing a plain Kubernetes Secret (base64 data) to a GitOps repo a leak?

  1. base64 is encryption only the cluster can reverse
  2. base64 is an encoding anyone can decode, and Git keeps the value in history
  3. Git rejects binary data
  4. It isn't a leak if the repo is private

With External Secrets Operator, what does the Git repository contain?

  1. The encrypted value
  2. A reference to the key in an external store plus the target Secret name
  3. The plain value
  4. The cluster's private key

How does Flux's kustomize-controller decrypt SOPS files?

  1. It doesn't: a plugin is required
  2. spec.decryption with provider sops and a Secret holding the age/PGP key (or KMS access)
  3. With kubeseal
  4. By reading the key from Git