Encrypting & Decrypting Files with SOPS
Intermediatev1.0.0
Encrypt and decrypt secret files with SOPS — YAML, JSON, ENV, and binary formats using age keys, in-place editing, selective field encryption, and extracting individual secrets.
Content
Overview
SOPS encrypts secret values in structured files while keeping keys in plaintext for readable diffs. Master the core encrypt/decrypt workflow to store secrets safely in Git.
Why This Matters
- -Security — secrets encrypted at rest in version control
- -Collaboration — encrypted files can be committed and shared
- -Readability — keys stay plaintext, only values are encrypted
- -Auditability — git blame shows who changed which secrets
How It Works
Step 1: Generate Keys
Step 2: Encrypt Files
Step 3: Decrypt Files
Step 4: Edit Encrypted Files
Step 5: Selective Encryption
Best Practices
- -Use --encrypted-regex to encrypt only sensitive fields
- -Store age secret keys outside the repository
- -Use environment variables for the secret key path
- -Test decryption after encrypting (verify roundtrip)
- -Use --extract for scripts that need single values
Common Mistakes
- -Committing unencrypted secret files (check before git add)
- -Committing age secret keys to the repo
- -Not testing decryption after first encryption
- -Encrypting entire files when only some fields are sensitive
- -Using --decrypt --in-place on the only copy (no backup)
FAQ
Discussion
Loading comments...