Cloud and deployment · Intermediate · 22 min
Choose a secrets manager for your app, and encrypt config files with SOPS
By Padding · Updated 18 Nov 2026
Ubuntu 26.04 · SOPS 3.13.3 · age 1.3.2
You will weigh cloud, self-hosted, hosted and Git-based secrets stores for a small team, then use SOPS 3.13 and age 1.3 to encrypt the secret values in per-environment config files, run an app from them without a plaintext copy, and rotate a leaked key.
On this page
Every app has a handful of values that must not leak: a database URL with a password in it, an API token for payments, an SMTP password. Where those values live decides who can read them, how you change them, and what you can find out after something goes wrong. There is no single right answer. A two-person team shipping one app to one cloud needs something different from a team running services across three providers.
This tutorial has two halves. The first step compares the four kinds of secrets store a small team usually considers, against the same five questions, so you can pick one on purpose. The rest is hands-on with the option that costs nothing and needs no account: encrypted config files in Git, using SOPS and age. You will encrypt only the secret values in a YAML config for production and development, give each environment its own key, start a small Python app with the values injected at launch, change a value safely, and recover from a leaked key.
Step 1 · Pick the kind of store that fits your team
Judge every option on the same five questions:
- Rotation: can a value be changed on a schedule, ideally without a person doing it?
- Audit: can you see who read a secret, not only who changed it?
- Access control: can you say "the production server reads production values and nothing else"?
- Cost: what does it charge, and in which currency? (Prices below were checked on 26 November 2026, in US dollars.)
- Lock-in: how hard is it to leave?
Your cloud's own manager
AWS Secrets Manager, Google Secret Manager and Azure Key Vault all store values encrypted, control access with the cloud's own identity system (IAM roles, service accounts, Azure RBAC) and can log access to the cloud's audit trail.
- Rotation is strongest on AWS, which rotates RDS and some other database credentials for you and runs a Lambda function you supply for anything else. Google sends a Pub/Sub message on a rotation schedule and Azure raises an event before a secret expires; in both, the code that actually changes the password is yours to write.
- Audit of reads is on by default only on AWS, where CloudTrail records every
GetSecretValuecall. On Google Cloud, Data Access audit logs, which record who read a secret, are off by default and must be turned on. On Azure, Key Vault logs nothing until you add a diagnostic setting that sends its AuditEvent logs to a Log Analytics workspace, storage account or event hub. - Cost on AWS is USD 0.40 per secret per month plus USD 0.05 per 10,000 API calls. Google gives 6 active secret versions and 10,000 access operations a month free, then about USD 0.06 per active version a month and USD 0.03 per 10,000 accesses. Azure Key Vault charges per operation rather than per stored secret; check its pricing page for your region.
- Lock-in is real but shallow. Your app calls one SDK at start-up; moving means changing that call and copying the values across.
Pick this when the app already runs on one cloud and you want rotation and read audit without running anything yourself; on Google and Azure, read audit takes one setup step to turn on.
A self-hosted manager: OpenBao
OpenBao is an open source fork of HashiCorp Vault, made after Vault moved to the Business Source License in 2023, and is now run under the Linux Foundation's OpenSSF. It goes further than the cloud managers: its database secrets engine can create a short-lived database user for each app instance and remove it when the lease ends, so there is no long-lived password to rotate at all. Audit devices log every request, and policies give fine-grained access.
The cost is your time. You run it, keep it highly available, back it up, upgrade it, and unseal it after a restart. If it is down, apps that read secrets at start-up cannot start. Lock-in to a cloud is low; lock-in to the OpenBao API is moderate.
Pick this when you run on more than one cloud or on your own servers, need short-lived credentials, and have someone whose job includes operating it.
A hosted secrets platform
Services such as Doppler and Infisical keep secrets in their dashboard and push them into many places at once: CI, Vercel or Netlify, Kubernetes, local development. They usually offer per-environment access, change history and integrations that save a lot of glue. Read-level audit, rotation features and price depend on the plan, so check the vendor's current pricing and docs against the five questions before you commit, and note that billing is usually per user in US dollars.
Pick this when you deploy to several platforms, have no one to run infrastructure, and are happy for a third party to hold your secrets.
Encrypted files in Git
Tools such as SOPS keep secrets in the repository, encrypted, next to the config they belong to. Nothing runs and nothing is billed. Access control is "who holds a key that can decrypt this file", and you can give each environment its own key. Git history shows who changed a value, but nobody can see who read one, because decryption happens on the reader's machine. Rotation is a manual job.
That audit gap shrinks if you encrypt to a cloud KMS key instead of, or as well as, an age key: SOPS supports AWS KMS, Google Cloud KMS and Azure Key Vault keys, and every decrypt then appears in that cloud's audit log. Lock-in is minimal; the files are plain YAML with encrypted values.
Pick this when the team is small, there are tens of secrets rather than hundreds, deployments already come from the repository, and you want something you can understand completely in an afternoon.
A note for teams in Africa
If your servers are in Cape Town, Johannesburg or Lagos, check that your chosen cloud manager is offered in that region before you design around it; choosing a cloud region in Africa covers how. Encrypted files have one quiet advantage on slow or prepaid connections: the app starts from a file that is already on disk, with no API call to a secrets service on every boot.
Check it worked
Write down, in your project notes, one line per question (rotation, audit, access control, cost, lock-in) saying what your app needs, then the one option that meets most of them. If you circled encrypted files in Git, or want to see how they work before deciding, carry on.
Step 2 · Install SOPS and age
SOPS (Secrets OPerationS) encrypts the values inside YAML, JSON, dotenv and INI files and leaves the keys readable, so a diff still shows which setting changed. It does not do the cryptography of who-can-open-it itself; it hands that to a key system. Here that system is age, a small modern file-encryption tool whose keys are a single line of text.
Both tools ship as release files on GitHub, not as Ubuntu packages at these versions. Install curl and Python first (the demo app in a later step is written in Python), then download SOPS and its checksum list and check the binary before you install it. dpkg --print-architecture gives amd64 or arm64, which matches both projects' file names:
sudo apt update
sudo apt install -y curl ca-certificates python3
ARCH=$(dpkg --print-architecture)
SOPS_VERSION=3.13.3
cd "$(mktemp -d)"
curl -fsSLO "https://github.com/getsops/sops/releases/download/v${SOPS_VERSION}/sops-v${SOPS_VERSION}.linux.${ARCH}"
curl -fsSLO "https://github.com/getsops/sops/releases/download/v${SOPS_VERSION}/sops-v${SOPS_VERSION}.checksums.txt"
sha256sum --ignore-missing -c "sops-v${SOPS_VERSION}.checksums.txt"
sudo install -m 0755 "sops-v${SOPS_VERSION}.linux.${ARCH}" /usr/local/bin/sopsThe sha256sum line must print sops-v3.13.3.linux.<arch>: OK. If it prints FAILED, delete the file and download it again before installing.
age does not publish a checksum list; each archive has a transparency-log proof instead. The two SHA-256 values below are those of the official 1.3.2 Linux archives. Download yours, compare, and install the two programs you need:
AGE_VERSION=1.3.2
case "$ARCH" in
amd64) AGE_SHA256=cbe24006683f8eb669266162894b9a522a1af52f2665fbc63a4bb032ed26ac10 ;;
arm64) AGE_SHA256=6b8dc4333c53a5a57c9e5834e3a48f92605d7154014cd07269ff3327db5d37f4 ;;
esac
curl -fsSLO "https://github.com/FiloSottile/age/releases/download/v${AGE_VERSION}/age-v${AGE_VERSION}-linux-${ARCH}.tar.gz"
echo "${AGE_SHA256} age-v${AGE_VERSION}-linux-${ARCH}.tar.gz" | sha256sum -c
tar -xzf "age-v${AGE_VERSION}-linux-${ARCH}.tar.gz" age/age age/age-keygen
sudo install -m 0755 age/age age/age-keygen /usr/local/bin/
cd ~
sops --version
age --versionPrograms you install by hand get no security updates from apt. To upgrade, check the two release pages, change SOPS_VERSION or AGE_VERSION (and, for age, the checksum) and run the same commands again.
On a Mac, Homebrew has both tools. Its versions may be newer than the ones pinned here, which is fine for everything that follows:
brew install sops ageCheck it worked
sops --version starts with sops 3.13.3, and age --version prints v1.3.2.
Step 3 · Make one key per environment
An age key pair is a private identity (a line starting AGE-SECRET-KEY-) and a public recipient (starting age1). Anyone with the public half can encrypt for you; only the private half decrypts.
You will make three:
you.txt: yours, as the person who maintains the config. It can open every environment.prod.txt: the production server's. It can open production only.dev.txt: the one shared by developers. It can open development only.
In everyday use, prod.txt is created on the production server and never leaves it, and your own key lives in ~/.config/sops/age/keys.txt on Linux (or ~/Library/Application Support/sops/age/keys.txt on a Mac), where SOPS finds it on its own. To see the effect of each key on one machine, keep all three in a demo folder outside the project, created private from the start:
mkdir -p ~/sops-demo-keys
cd ~/sops-demo-keys
(umask 077 && age-keygen -o you.txt && age-keygen -o prod.txt && age-keygen -o dev.txt)
YOU_PUB=$(age-keygen -y you.txt)
PROD_PUB=$(age-keygen -y prod.txt)
DEV_PUB=$(age-keygen -y dev.txt)
echo "you: $YOU_PUB"
echo "prod: $PROD_PUB"
echo "dev: $DEV_PUB"
ls -lage-keygen -y reads a private key file and prints its public recipient. The three variables hold only public keys, which are safe to show and to commit. They last for this terminal session; if you open a new one, run the three age-keygen -y lines again.
Check it worked
Each echo prints a different string starting with age1, and ls -l shows all three files as -rw-------, readable by you alone. Back these private keys up somewhere safe, such as a password manager: if every private key for a file is lost, nobody can decrypt it again.
Step 4 · Write the rules that pick keys per environment
SOPS reads a file called .sops.yaml at the top of the project. Its creation_rules say, for each file path, which recipients to encrypt for and which values to encrypt. Make the project folder:
mkdir -p ~/sops-demo/config
cd ~/sops-demoWrite .sops.yaml. The heredoc fills in the three public keys from your variables:
cat > .sops.yaml <<EOF
creation_rules:
- path_regex: config/prod\.yaml$
encrypted_regex: '^(DATABASE_URL|.*_TOKEN|.*_PASSWORD)$'
age: >-
${YOU_PUB},
${PROD_PUB}
- path_regex: config/dev\.yaml$
encrypted_regex: '^(DATABASE_URL|.*_TOKEN|.*_PASSWORD)$'
age: >-
${YOU_PUB},
${DEV_PUB}
EOF
cat .sops.yamlThree things are going on:
path_regexis a regular expression matched against the file path. SOPS uses the first rule that matches, so put narrow rules before broad ones. A file that matches no rule is refused, which stops you encrypting a new file for the wrong people by accident.encrypted_regexlimits encryption to keys that match: the database URL, and anything ending_TOKENor_PASSWORD. Everything else, such as the log level, stays readable, so a reviewer can see in a pull request that someone changedLOG_LEVELwithout being able to read the database password. Without this line SOPS encrypts every value, which is the safer default if you are unsure.agelists the recipients. Your key is in both rules; the production and development keys each appear in one.
Check it worked
cat .sops.yaml shows two rules, each with two age1... recipients, and your recipient is the first line in both. If a line shows an empty value after age: >-, a variable was not set: run the age-keygen -y lines from the previous step again in this terminal and rewrite the file.
Step 5 · Encrypt the config files
For your own secrets, create each encrypted file with sops edit config/prod.yaml (shown in a later step) so the secret values never sit on disk unencrypted. To have something to work with here, write two config files with obviously fake values. umask 077 makes them private while they are still in plaintext, and sops encrypt -i replaces each one with its encrypted form straight away:
(
umask 077
cat > config/prod.yaml <<'YAML'
APP_ENV: production
LOG_LEVEL: info
DATABASE_URL: postgres://app:demo-prod-pass-not-real@db.prod.internal:5432/app
PAYMENTS_API_TOKEN: demo-prod-token-not-real-7f3a
YAML
cat > config/dev.yaml <<'YAML'
APP_ENV: development
LOG_LEVEL: debug
DATABASE_URL: postgres://app:demo-dev-pass-not-real@localhost:5432/app
PAYMENTS_API_TOKEN: demo-dev-token-not-real-19bc
YAML
)
sops encrypt -i config/prod.yaml
sops encrypt -i config/dev.yaml
cat config/prod.yamlEncrypting needs only the public keys from .sops.yaml, so no private key was involved. The file now has the same four keys. APP_ENV and LOG_LEVEL are unchanged. DATABASE_URL and PAYMENTS_API_TOKEN are now ENC[AES256_GCM,data:...]. At the bottom, a sops: block holds the file's data key encrypted once for each recipient, a message authentication code that detects tampering, and the encrypted_regex you set.
Now see the access rules work. Each command points SOPS at one private key with SOPS_AGE_KEY_FILE, as if you were on that machine, and asks for the production database URL:
SOPS_AGE_KEY_FILE="$HOME/sops-demo-keys/prod.txt" sops decrypt --extract '["DATABASE_URL"]' config/prod.yaml; echo
SOPS_AGE_KEY_FILE="$HOME/sops-demo-keys/dev.txt" sops decrypt config/prod.yaml > /dev/null || echo "dev key cannot open production"Check it worked
The production key prints the demo production URL. The development key fails with an error that no key could decrypt the data key, followed by dev key cannot open production. grep -n ENC config/*.yaml lists exactly two encrypted lines per file. Both files and .sops.yaml are safe to commit; the key files are not, and live outside the project for that reason.
Step 6 · Run the app with secrets injected at start-up
The app is a start-up check of the kind many services have: it reads its settings from environment variables, refuses to start if one is missing, and prints a summary that never shows a full secret. Create app.py:
cat > app.py <<'PY'
import os
import sys
from urllib.parse import urlsplit
REQUIRED = ["APP_ENV", "DATABASE_URL", "PAYMENTS_API_TOKEN"]
missing = [name for name in REQUIRED if not os.environ.get(name)]
if missing:
print("refusing to start, missing settings: " + ", ".join(missing))
sys.exit(1)
db = urlsplit(os.environ["DATABASE_URL"])
token = os.environ["PAYMENTS_API_TOKEN"]
print(f"starting in {os.environ['APP_ENV']} with log level {os.environ.get('LOG_LEVEL', 'info')}")
print(f"database host: {db.hostname}")
print(f"payments token ends: ...{token[-4:]}")
print("smtp configured: " + ("yes" if os.environ.get("SMTP_PASSWORD") else "no"))
PYRun it on its own first:
python3 app.pyIt prints refusing to start, missing settings: APP_ENV, DATABASE_URL, PAYMENTS_API_TOKEN and exits with status 1. Now start it through sops exec-env, which decrypts the file in memory, puts each top-level key into the environment of one child process, and runs the command you give it. Use the production server's key:
export SOPS_AGE_KEY_FILE="$HOME/sops-demo-keys/prod.txt"
sops exec-env config/prod.yaml 'python3 app.py'
echo "back in your shell, DATABASE_URL is ${DATABASE_URL:-not set}"This is the shape to use on the server: in a systemd unit, a Docker entrypoint or a deploy script, start the app with sops exec-env /path/to/config/prod.yaml '<your start command>', with the server's key in its default keys.txt location or in SOPS_AGE_KEY_FILE. No decrypted copy of the config is written to disk, and the values exist only in the app's environment. Keep exec-env for files with flat keys like these, since each top-level key becomes one variable.
Check it worked
You see four lines: starting in production with log level info, database host: db.prod.internal, payments token ends: ...7f3a and smtp configured: no. The last line printed by your own shell says DATABASE_URL is not set, because the variables went to the child process only.
Step 7 · Change a value with sops edit
To change or add a secret, never decrypt the file to disk and re-encrypt it by hand. sops edit decrypts into a private temporary file, opens your editor, and when you save and close, encrypts the result back into place and deletes the temporary copy. It needs a key that can decrypt, so switch to yours:
export SOPS_AGE_KEY_FILE="$HOME/sops-demo-keys/you.txt"Open the production config. SOPS uses the editor in $SOPS_EDITOR or $EDITOR, or falls back to vim, nano or vi:
sops edit config/prod.yamlThe editor shows the four settings in plaintext. Add this line at the end, then save and close (in nano: Ctrl+O, Enter, Ctrl+X):
SMTP_PASSWORD: demo-smtp-pass-not-realThe new key ends in _PASSWORD, so it matches the file's encrypted_regex and is encrypted without any extra step. Look at the file and start the app again:
grep -n 'SMTP_PASSWORD' config/prod.yaml
sops exec-env config/prod.yaml 'python3 app.py'In Git, this change shows as one new line and a changed sops: block, so a reviewer sees that an SMTP password was added to production without seeing it.
Check it worked
grep prints one line that starts with its line number, such as 5:SMTP_PASSWORD: ENC[AES256_GCM,..., and the app now ends with smtp configured: yes.
Step 8 · Rotate a leaked key with updatekeys
Suppose the production server's private key is exposed: a disk image was shared, or a backup went to the wrong place. Removing that key from the file is not enough on its own, because whoever holds it already has the file's data key. SOPS's own guidance is to remove the key with updatekeys first and then make a new data key with rotate, in that order.
Make the replacement key. Normally you would generate it on the production server and send yourself only the public line:
cd ~/sops-demo-keys
(umask 077 && age-keygen -o prod-2.txt)
PROD2_PUB=$(age-keygen -y prod-2.txt)
cd ~/sops-demoRewrite .sops.yaml with the new production recipient in place of the old one. The development rule is unchanged:
cat > .sops.yaml <<EOF
creation_rules:
- path_regex: config/prod\.yaml$
encrypted_regex: '^(DATABASE_URL|.*_TOKEN|.*_PASSWORD)$'
age: >-
${YOU_PUB},
${PROD2_PUB}
- path_regex: config/dev\.yaml$
encrypted_regex: '^(DATABASE_URL|.*_TOKEN|.*_PASSWORD)$'
age: >-
${YOU_PUB},
${DEV_PUB}
EOFsops updatekeys compares the file's recipients with the rules and shows a diff: a --- line for the old key and a +++ line for the new one. Without -y it asks Is this okay? (y/n); here -y accepts. Then sops rotate -i re-encrypts every value under a fresh data key. Both use your key, which is still set in SOPS_AGE_KEY_FILE:
sops updatekeys -y config/prod.yaml
sops rotate -i config/prod.yamlCheck that the old key is locked out and the new one works:
SOPS_AGE_KEY_FILE="$HOME/sops-demo-keys/prod.txt" sops decrypt config/prod.yaml > /dev/null || echo "old production key no longer works"
SOPS_AGE_KEY_FILE="$HOME/sops-demo-keys/prod-2.txt" sops exec-env config/prod.yaml 'python3 app.py'Two limits to be honest about. First, older versions of the file in Git history are still encrypted for the old key, and so are copies anyone took. Treat every value the old key could read as leaked: change the database password, issue a new payments token, then put the new values in with sops edit. Second, the same updatekeys then rotate pair is how you remove someone who leaves the team, and the same advice about changing the values applies. Running sops rotate -i on a schedule, even without a leak, is a cheap habit.
Check it worked
The first command prints old production key no longer works. The second prints the app's four lines, ending smtp configured: yes, using the new key. grep -c 'recipient: age1' config/prod.yaml still prints 2.
Step 9 · Clean up
The demo project and keys hold nothing you need. Removing the keys makes the demo files permanently unreadable, which is the point. Delete both folders, and the two programs if you do not plan to keep using them:
cd ~
rm -rf ~/sops-demo ~/sops-demo-keys
sudo rm /usr/local/bin/sops /usr/local/bin/age /usr/local/bin/age-keygenCheck it worked
ls ~/sops-demo ~/sops-demo-keys reports that neither exists, and command -v sops prints nothing.
Next steps
- Make sure plaintext values cannot slip into a commit in the first place: keep secrets out of Git.
- Already using Ansible? Compare this approach with encrypting secrets with Ansible Vault.
Related tutorials
- How to Keep Passwords and API Keys Out of GitYou will keep secrets in a git-ignored .env file, commit a safe template instead, stop a commit that contains a key with a pre-commit hook, and learn what to do when a secret has already been committed.
- Encrypt passwords and keys in your Ansible project with Ansible VaultYou will have an Ansible project whose passwords and tokens live encrypted in Git, with separate dev and prod vault passwords read from a private file and a password manager, secrets hidden from playbook output, and a rotated password.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials