Loading...
Loading...
SOPS and age encryption for secrets management in git repositories. Use when: (1) Setting up encrypted secrets in a project (initial .sops.yaml configuration) (2) Encrypting/decrypting YAML, JSON, ENV, or INI files with age keys (3) Managing age keys (generation, distribution, rotation) (4) Configuring path-based encryption rules for different environments (5) Integrating SOPS decryption in CI/CD pipelines (GitHub Actions, GitLab CI) (6) Troubleshooting SOPS decryption failures or key issues (7) Selective encryption with encrypted_regex patterns
npx skill4agent add dimdasci/vps-setup sops-age-secrets| Task | Command |
|---|---|
| Generate age key | |
| Extract public key | |
| Encrypt file | |
| Decrypt file | |
| Edit encrypted file | |
| Update recipients | |
| Rotate data key | |
# Create key directory
mkdir -p ~/.config/sops/age
# Generate keypair
age-keygen -o ~/.config/sops/age/keys.txt
# Output: public key: age1abc123...creation_rules:
- age: age1yourpublickeyhere...sops encrypt config/secrets.yaml > config/secrets.enc.yaml
rm config/secrets.yaml
git add config/secrets.enc.yaml .sops.yaml# Create plaintext file
cat > secrets.yaml << 'EOF'
database:
password: secret123
api_key: abc-xyz
EOF
# Encrypt (uses .sops.yaml rules)
sops encrypt secrets.yaml > secrets.enc.yaml
rm secrets.yaml# Opens decrypted in $EDITOR, re-encrypts on save
sops edit secrets.enc.yaml# To stdout
sops decrypt secrets.enc.yaml
# To file
sops decrypt secrets.enc.yaml > secrets.yaml
# Extract single value
sops decrypt --extract '["database"]["password"]' secrets.enc.yaml# As environment variables
sops exec-env secrets.enc.yaml './deploy.sh'
# As temporary file
sops exec-file secrets.enc.yaml 'source {}'# .sops.yaml
creation_rules:
# Production - admin + CI only
- path_regex: ^config/secrets/prod\..*
age: >-
age1admin...,
age1cicd...
# Staging/Dev - broader access
- path_regex: ^config/secrets/.*
age: >-
age1admin...,
age1cicd...,
age1dev...creation_rules:
- age: age1...
encrypted_regex: ^(password|secret|token|key|api_key|private)$database:
host: localhost # plaintext
password: ENC[AES256_GCM,data:...,type:str] # encrypted- name: Decrypt secrets
env:
SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }}
run: sops decrypt config/secrets.enc.yaml > secrets.yamlAGE-SECRET-KEY-1...SOPS_AGE_KEY# Key file location
export SOPS_AGE_KEY_FILE=/path/to/keys.txt
# Key value directly (CI/CD)
export SOPS_AGE_KEY="AGE-SECRET-KEY-1...".sops.yamlsops updatekeys -y file.enc.yaml.sops.yamlsops updatekeys -y file.enc.yaml
sops rotate -i file.enc.yaml| Platform | Default Path |
|---|---|
| Linux | |
| macOS | |
| File | When to Read |
|---|---|
| age-keys.md | Key generation, storage, distribution patterns |
| sops-config.md | .sops.yaml syntax, path rules, key groups |
| cli-reference.md | Full command reference, all flags |
| ci-cd-patterns.md | GitHub Actions, GitLab CI, Docker integration |
| troubleshooting.md | Common errors and solutions |
| Problem | Solution |
|---|---|
| "could not decrypt data key" | Wrong key - check |
| "no matching keys found" | File uses Shamir key groups - need multiple keys |
| Run from repo root or ensure file is in parent directory |
| path_regex not matching | Use regex syntax ( |
keys.txt*.agekey.gitignoresops rotate| Topic | URL |
|---|---|
| SOPS | https://getsops.io/docs/ |
| SOPS GitHub | https://github.com/getsops/sops |
| age | https://github.com/FiloSottile/age |