123DevOps··7 min read

What is SOPS? Encrypted secrets in Git with age, PGP, or KMS

Learn how SOPS encrypts only the values of YAML, JSON, and ENV files, how to set up .sops.yaml with creation_rules, and how to integrate it with GitOps using Flux (native support) and Argo CD (through plugins such as KSOPS).

Kubernetes

In GitOps, everything the cluster needs should be in Git. Everything except the database password in plain text. And a Kubernetes Secret doesn’t solve it: data is just base64, which anyone can decode. That leaves two options: take secrets out of Git and fetch them from a vault, or store them in Git already encrypted. SOPS is the most widely used tool for the second option.

What SOPS is

SOPS (Secrets OPerationS) is an editor of encrypted files. It encrypts the values of YAML, JSON, ENV, and INI files while keeping the keys readable, and it also encrypts whole binary files. Master keys can be age, PGP, AWS KMS, GCP KMS, Azure Key Vault, HashiCorp Vault/OpenBao, or HuaweiCloud KMS.

Created at Mozilla, the project now lives in the getsops organization (github.com/getsops/sops), under the MPL 2.0 license. It was accepted into the CNCF in May 2023 and is at the Sandbox level as of November 2026 (check the project page). The latest version on the releases page during this research was v3.13.3.

What problem it solves

  • Secrets versioned with everything else: the same PR that changes the Deployment changes the password, with review and history.
  • Readable diffs: since only values are encrypted, the reviewer sees which key changed, even without seeing the value.
  • No secret shared between people: each person or cluster uses its own key; access is granted and revoked by public key.
  • Integrity: a MAC computed over all values detects whether someone added, removed, or changed a value without going through SOPS.

How it works

SOPS uses envelope encryption. When encrypting a file, it generates a random data key, encrypts each value with AES-256-GCM, and then encrypts that data key with each configured master key. All of this lives in a sops: block at the end of the file itself. To decrypt, you only need access to one of the master keys.

Backend Where the master key lives Good for
age A private key file (keys.txt) or an SSH key Small teams, clusters with their own key, simplicity
PGP GnuPG keyring Teams that already have PGP infrastructure
AWS KMS, GCP KMS, Azure Key Vault Managed cloud service, controlled by IAM Access audited and revocable through the cloud
HashiCorp Vault / OpenBao Vault’s transit engine Teams that already centralize cryptography in Vault

With key groups, you can require keys from different groups at the same time (via Shamir), for example a KMS key and one held by a security owner.

The .sops.yaml file

.sops.yaml, at the root of the repository, defines which key to use for which file. creation_rules are evaluated in order and the first match wins; a rule without path_regex matches everything:

creation_rules:
  # Production Kubernetes Secrets: only data/stringData are encrypted
  - path_regex: k8s/production/.*\.yaml$
    encrypted_regex: ^(data|stringData)$
    age: >-
      age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p,
      age1zvkyg2lqzraa2lnjvqej32nkuu0ues2s82hzrye869xeexvn73equnujwj
  # Development .env files
  - path_regex: \.env\.dev$
    age: age1zvkyg2lqzraa2lnjvqej32nkuu0ues2s82hzrye869xeexvn73equnujwj
  # Everything else: AWS KMS
  - kms: arn:aws:kms:us-east-1:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab

encrypted_regex: ^(data|stringData)$ is essential for Kubernetes manifests: without it, SOPS would also encrypt apiVersion, kind, and metadata, and no tool could read the object. The age keys above are fictitious; use the public keys of your team and of each cluster.

Hands-on example

The commands below follow the official SOPS and Flux documentation; SOPS and age weren’t installed in this lab, so they weren’t run. The .sops.yaml and the manifests went through a YAML parser, and the native Kubernetes objects through kubectl apply --dry-run=server.

Encrypt, edit, and rotate

# generate an age key pair (age tool) and store the private key where SOPS looks for it
mkdir -p ~/.config/sops/age
age-keygen -o ~/.config/sops/age/keys.txt   # on macOS: ~/Library/Application Support/sops/age/

# encrypt the Secret in place, using the .sops.yaml rule
sops encrypt -i k8s/production/database.enc.yaml

# open it in $EDITOR already decrypted; on save, SOPS encrypts it again
sops edit k8s/production/database.enc.yaml

# read it (for debugging; never redirect it to a versioned file)
sops decrypt k8s/production/database.enc.yaml

# someone joined or left the team: apply the current keys from .sops.yaml
sops updatekeys k8s/production/database.enc.yaml

# after removing a key, generate a new data key
sops rotate -i k8s/production/database.enc.yaml

You can also point to the private key with SOPS_AGE_KEY_FILE or SOPS_AGE_KEY, which is handy in pipelines. The encrypted file keeps a readable structure (shortened values):

apiVersion: v1
kind: Secret
metadata:
    name: payments-database
    namespace: payments
type: Opaque
stringData:
    DB_USER: ENC[AES256_GCM,data:3q1f…,iv:Zt0…,tag:Hx9…,type:str]
    DB_PASSWORD: ENC[AES256_GCM,data:k7Pq…,iv:a8M…,tag:Q2c…,type:str]
sops:
    age:
        - recipient: age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p
          enc: |
            -----BEGIN AGE ENCRYPTED FILE-----
            …
            -----END AGE ENCRYPTED FILE-----
    lastmodified: "2026-11-25T06:00:00Z"
    mac: ENC[AES256_GCM,data:9vB…,iv:Lw4…,tag:r1E…,type:str]
    encrypted_regex: ^(data|stringData)$
    version: 3.13.3

Flux: native support

Flux’s kustomize-controller decrypts SOPS files at apply time. You store the private key in a cluster Secret and turn on decryption in the Kustomization:

age-keygen -o age.agekey
cat age.agekey | kubectl create secret generic sops-age \
  --namespace=flux-system \
  --from-file=age.agekey=/dev/stdin
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
  name: payments
  namespace: flux-system
spec:
  interval: 10m
  path: ./k8s/production
  prune: true
  sourceRef:
    kind: GitRepository
    name: platform
  decryption:
    provider: sops
    secretRef:
      name: sops-age

The private key only exists in the cluster; the repository holds only the public key, in .sops.yaml. With a cloud KMS, the controller can use workload identity instead of a Secret.

Argo CD: through a plugin, with caveats

Argo CD doesn’t decrypt SOPS on its own. The most common path is KSOPS, a Kustomize generator:

apiVersion: viaduct.ai/v1
kind: ksops
metadata:
  name: payments-secrets
  annotations:
    config.kubernetes.io/function: |
      exec:
        path: ksops
files:
  - ./payments-database.enc.yaml

The generator goes under generators: in kustomization.yaml, and Argo CD must allow exec plugins:

apiVersion: v1
kind: ConfigMap
metadata:
  name: argocd-cm
  namespace: argocd
data:
  kustomize.buildOptions: "--enable-alpha-plugins --enable-exec"

On top of that, argocd-repo-server needs the ksops binary and access to the age key (for example, through SOPS_AGE_KEY_FILE). There’s an important caveat: the Argo CD documentation cautions against injecting secrets during manifest generation, because generated manifests sit in plain text in the Redis cache, and it recommends managing secrets in the destination cluster. If you use KSOPS or helm-secrets, restrict access to Redis and the repo-server.

When to use it (and when not to)

  • Use it when you want secrets versioned and reviewed as code, especially with Flux.
  • Use it for configuration files outside Kubernetes (.env, Terraform, Ansible): SOPS doesn’t depend on a cluster.
  • Don’t use it as a central vault: database password rotation, dynamic secrets, and per-access auditing are the job of Vault or a cloud secrets manager.
  • Watch the history: removing a key doesn’t remove access to old versions in Git. When someone leaves the team, run rotate and actually change the secrets.
  • Don’t decrypt to disk in pipelines; prefer sops exec-env or exec-file, which hand the content to a process without writing it into the repository.

To block plain-text secrets before they’re committed, combine this with the practices in silent DevSecOps. The broader context is in What is GitOps?.

Alternatives

Tool Where the secret lives Main difference
SOPS In Git, encrypted Encrypted values with readable keys; many backends
Sealed Secrets In Git, encrypted for an in-cluster controller Kubernetes only; the private key stays in the controller
External Secrets Operator In an external vault (AWS, GCP, Azure, Vault…) Git holds only the reference; recommended by Argo CD
Vault / OpenBao Central vault Dynamic secrets, leasing, and auditing
git-crypt In Git, whole file encrypted No per-value encryption; unreadable diffs

Summary

  • SOPS encrypts values in YAML, JSON, ENV, and INI, keeping keys readable
  • It’s a CNCF Sandbox project as of November 2026, under getsops/sops
  • age, PGP, and cloud KMS encrypt the data key; any one of the master keys decrypts
  • .sops.yaml with creation_rules: the first matching rule wins; use encrypted_regex for Secrets
  • Flux decrypts natively with spec.decryption; with Argo CD, use KSOPS carefully
  • When removing a key, run rotate and change the secrets

Encrypting the secret in Git solves storage; who holds the private key is still the question that matters.

Get updates on new posts and stay in the loop!