Skip to content

Lesson 7 of 13 · 14m

Encrypt Backups Like They'll Be Stolen

Client-side encryption moves the trust boundary to the repo key, which becomes the artifact that decides whether restores are possible.

A backup is a concentration of everything an attacker wants, stored somewhere quieter than production. The whole database, /etc with its TLS keys and ssh host keys, uploads, application secrets — compressed and conveniently packaged. Encrypt it at the source, because "the bucket is encrypted" protects a different threat than the one that will actually get you.

Server-side vs. client-side

S3 server-side encryption (SSE-S3, SSE-KMS) encrypts at rest in the provider's datacenter. It protects against a stolen disk at AWS. It protects nothing against someone holding credentials with s3:GetObject on the bucket — the service happily decrypts for them. The actual threat to a backup is almost never the provider's disks; it is your leaked API key, your compromised CI runner, your stolen console session. That is a client-side problem. Provider-managed keys also carry a restore-time trap: an EBS snapshot encrypted under a KMS CMK can only be copied to another account if that key's policy allows it, so "cross-account snapshot as the offsite copy" fails at the API unless the CMK was shared beforehand — a detail best discovered on a Tuesday afternoon, not mid-incident.

restic and borg encrypt client-side and unconditionally: data is chunked, encrypted, and authenticated on the source host before anything leaves it. The repository stores ciphertext; the key never exists server-side. This moves the trust boundary from "whoever holds storage credentials" to "whoever holds the repo password" — which is smaller, and entirely under your control.

The key is now the backup

Client-side encryption makes the repository password the single artifact a restore cannot proceed without. Two failure modes, both common:

  • Key stored with the data. The repo password in /srv/secrets/ — which is itself backed up into the repo — is the safe key taped inside the safe. The encryption is real; it buys the attacker nothing and buys you nothing.
  • Key nowhere. Nobody wrote it down because "it's in the password manager," and the password manager entry was created on the laptop that just died, or belongs to the person who left. Encryption does not distinguish between an attacker and an amnesiac. Losing the repo key means the encryption did its job — on you.

restic's key model: the repository has one master key, wrapped by password-derived keys (scrypt); restic key add adds another password without re-encrypting data, restic key list shows the authorized set, restic key remove revokes. Rotation is easy for access — add a key, remove the old — while the master key underneath stays put; retiring a compromised repository entirely means a new repo, not a re-keyed old one. restic key passwd rotates a single password in place; none of the key commands touch the master key — rotation changes who can unwrap it, never what it is. borg's equivalent is repokey (key inside the repo, passphrase-wrapped) versus keyfile (key in a file you manage) — keyfile lets you keep the decrypting key physically off the storage path, which is the pattern you want when the repo destination might be readable by untrusted parties.

What else leaks plaintext

pg_dump output is plaintext rows — Postgres TDE or at-rest disk encryption does not survive a logical dump; encrypt the dump artifact itself (gpg -c, age, or the repo's own encryption). Terraform state is a secret-bearing document: it stores resource attributes in cleartext, including ones you marked sensitive — the flag hides them from terraform plan output, not from terraform.tfstate. Back it up and encrypt it and treat access like the secrets it contains. Same for etcd snapshots (etcdctl snapshot save) — Kubernetes secrets live in there, base64-encoded, which is encoding, not encryption.

The practice

Encrypt client-side at the source — restic/borg already do; for anything they don't cover, age or gpg -c before upload (pg_dump ... | age -r <recipient> > dump.sql.age is a complete pipeline). Custody the repository password like a root CA: in the team password manager and on an offline copy (paper in a safe, a USB in a drawer), with names attached to who holds it. Once a quarter, prove the equation works: key + repo + restic restore on a scratch host = a bootable system. If you cannot perform that, you have an encrypted pile of ciphertext and a rumor.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.