What it does
SOPS (Secrets OPerationS, a CNCF project) encrypts the values of a file and keeps the keys readable, so you still see the structure and Git diffs make sense. It uses age keys, PGP, or cloud KMS (Azure Key Vault, AWS KMS, GCP KMS). A .sops.yaml file in the repo says which files use which keys.
Flux decrypts SOPS files by itself; Argo CD can with a plugin (KSOPS, helm-secrets).
How to write it
sops [encrypt|decrypt|edit|updatekeys|rotate] [OPTIONS] FILEMain parts
Commands
editFILE(orjust`sopsFILE`)- Open decrypted in your editor, encrypt on save.
encryptFILE/-e- Encrypt a file.
decryptFILE/-d- Decrypt to stdout.
updatekeysFILE- Re-encrypt for the keys now in .sops.yaml (add a person).
rotateFILE- Make a new data key.
exec-envFILECMD- Run a command with the secrets as env vars.
exec-fileFILECMD- Run a command with a temporary decrypted file.
Options 8
Most used
Flags
Nothing matches this filter.
Examples 11
$ run as a normal user# run as root (or with sudo)
1Make an age key
age-keygen -o ~/.config/sops/age/keys.txt Public key: age1qz8x0examplepublickeyonly0000000000000000000000000000q9lc52Set rules for the repo
cat .sops.yaml creation_rules: - path_regex: k8s/.*\.secret\.yaml$ encrypted_regex: ^(data|stringData)$ age: age1qz8x0examplepublickeyonly0000000000000000000000000000q9lc53Encrypt a Kubernetes Secret
sops encrypt -i k8s/db.secret.yaml head -12 k8s/db.secret.yaml apiVersion: v1 kind: Secret metadata: name: db stringData: password: ENC[AES256_GCM,data:3kq9…,type:str]4Edit it later
sops k8s/db.secret.yaml5Decrypt and apply
sops decrypt k8s/db.secret.yaml | kubectl apply -f -6Read one value in a script
sops decrypt --extract '["stringData"]["password"]' k8s/db.secret.yaml7Use an Azure Key Vault key
sops encrypt --azure-kv https://kv-s0sta-lab.vault.azure.net/keys/sops/0123456789abcdef0123456789abcdef -i secrets.env8Run a program with secrets as variables
sops exec-env secrets.env 'terraform plan'9Add a new team member
vim .sops.yaml sops updatekeys k8s/db.secret.yaml10Let Flux decrypt with the age key
kubectl create secret generic sops-age -n flux-system --from-file=age.agekey=$HOME/.config/sops/age/keys.txt11Stop unencrypted secrets in CI
Nothing matches this filter.
Watch out
- The age private key never goes into Git; back it up safely.
sops decrypt > filewrites clear text to disk — do not commit it (add patterns to.gitignore).- Removing a person from
.sops.yamldoes not hide old secrets from them: rotate the secrets.
Files
.sops.yaml- Rules: which files, which keys.
~/.config/sops/age/keys.txt- Your age private key(s).
Tips to remember
- Encrypt only
data/stringDatain Kubernetes Secrets so names and labels stay readable.
Exit codes
0 | Success. |
1 | General error. |
51 | MAC mismatch (the file was changed outside sops). |
100 | No file given. |
128 | Could not get the data key (no matching key — wrong age key, no Key Vault access). |
200 | File not changed (edit). |
203 | File is already encrypted. |