All guides

Secrets in GitOps: Sealed Secrets, SOPS or External Secrets Operator

The Flux documentation calls storing Secrets in Git in plain text or base64 unsafe, whatever the visibility of the repository. Sealed Secrets and SOPS encrypt the secret before it is committed. External Secrets Operator reads it from an external secret manager.

A whiteboard with handwritten release notes and sticky notes

Three approaches

Each project describes itself this way:

  • Sealed Secrets. The kubeseal utility encrypts a secret with asymmetric cryptography, and the controller in the cluster is the only party able to decrypt it. The result is a SealedSecret resource.
  • SOPS. An editor for encrypted files in YAML, JSON, ENV, INI and binary formats. It encrypts with AWS KMS, GCP KMS, Azure Key Vault, age and PGP, among others.
  • External Secrets Operator. A Kubernetes operator that reads information from external APIs, such as AWS Secrets Manager, HashiCorp Vault or Azure Key Vault, and injects the values into a Kubernetes Secret.

Sealed Secrets

Sealed Secrets has two parts: a cluster-side controller and the client-side kubeseal. The README's usage example creates a Secret as a local file and seals it:

Shell

echo -n bar | kubectl create secret generic mysecret --dry-run=client \
  --from-file=foo=/dev/stdin -o json >mysecret.json
kubeseal -f mysecret.json -w mysealedsecret.json

mysecret, foo and bar are the README's example names. kubeseal fetches the certificate from the controller at runtime, or uses a saved copy passed with --cert. The controller unseals the SealedSecret into a normal Secret. In the default strict scope, the name and the namespace are part of the encrypted data, and changing either leads to a decryption error.

The README says nobody can obtain the original Secret from the SealedSecret, the original author included. Sealing keys are renewed every 30 days, and old keys are not deleted. The private keys are stored only in the Secret managed by the controller. With no backup of them, the README says, you cannot decrypt after losing the cluster. This is its backup command:

Shell

kubectl get secret -n kube-system \
  -l sealedsecrets.bitnami.com/sealed-secrets-key -o yaml >main.key

The file contains the controller's public and private keys. The README says to recreate the backup after each sealing key renewal.

SOPS

The Flux guide for SOPS encrypts a Secret manifest with an age public key:

Shell

sops --age=<age-public-key> \
--encrypt --encrypted-regex '^(data|stringData)$' --in-place basic-auth.yaml

basic-auth.yaml is the guide's example file. The SOPS documentation shows the same option with its encrypt subcommand, in common operations: sops encrypt --encrypted-regex '^(data|stringData)$' k8s-secrets.yaml.

Flux's kustomize-controller decrypts with the .spec.decryption field of a Kustomization. This is the example from its API reference, with the optional serviceAccountName line left out and the required prune field added:

YAML

apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
  name: sops-encrypted
  namespace: default
spec:
  interval: 5m
  path: "./"
  prune: true
  sourceRef:
    kind: GitRepository
    name: repository-with-secrets
  decryption:
    provider: sops
    secretRef:
      name: sops-keys-and-credentials

provider is required, and sops is the only supported value. The Secret named in secretRef holds the keys, and an age private key sits in an entry whose name ends in .agekey. The metadata, kind and apiVersion of an encrypted manifest must stay in plain text.

For Argo CD, the KSOPS README describes a Kustomize plugin for SOPS-encrypted resources and the changes to the Argo CD repo server that it needs. The Argo CD secret management page strongly cautions against injecting secrets during manifest generation with a plugin. Among its reasons: Argo CD then needs access to the secrets, and it stores generated manifests in plaintext in its Redis cache.

External Secrets Operator

A SecretStore specifies how to access the external API and is namespaced. A ClusterSecretStore is cluster-wide and can be referenced from all namespaces. An ExternalSecret declares what data to fetch:

YAML

apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
  name: my-app-db
  namespace: my-app
spec:
  refreshInterval: 1h
  secretStoreRef:
    name: aws-secrets
    kind: SecretStore
  target:
    name: my-app-db
  data:
    - secretKey: password
      remoteRef:
        key: prod/my-app/db
        property: password

The names, the remote key and the one-hour interval are choices for this example. target.name is the name of the Secret to create. Each data entry connects a key of that Secret to data at the provider. refreshInterval is the time before the values are read again from the store. If the secret in the external API changes, the controller updates the Secret.

The documented facts side by side

  • What Git holds. A SealedSecret, which its README calls safe to store even in a public repository. A SOPS-encrypted file. Or an ExternalSecret, which declares what data to fetch.
  • Who can decrypt. For Sealed Secrets, only the controller in the target cluster. For SOPS, the Flux guide says the public key is sufficient to create new files, and the secret key is required to decrypt and edit existing ones.
  • What a change takes. The Sealed Secrets README says to rotate the actual secrets and craft new SealedSecret resources. External Secrets Operator reconciles when the value changes in the external API.
  • What each GitOps tool documents. Flux has guides for SOPS and for Sealed Secrets, and SOPS is the only decryption provider of its kustomize-controller. Argo CD strongly recommends populating secrets on the destination cluster, and names Sealed Secrets and External Secrets Operator as examples.

Checks for any of the three

  1. The Kubernetes documentation says Secrets are, by default, stored unencrypted in etcd. Enable encryption at rest and least-privilege RBAC rules for Secrets, as it advises.
  2. Back up the decryption keys. The Flux guide suggests a password manager or offline storage for the SOPS key.
  3. Rotate the secret values too. The Sealed Secrets README says sealing key renewal is not a substitute for rotating your actual secrets.
  4. The same README says that anything stored in version control must be assumed impossible to delete. Rotate a secret that was committed in plain text.

Sources

Want a second pair of eyes on yours? We do this work for a living.

Book a call

More guides