tech:notes_sops
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédente | |||
| tech:notes_sops [2026/03/30 17:49] – Jean-Baptiste | tech:notes_sops [2026/07/16 23:28] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Notes SOPS | ||
| + | |||
| + | |||
| + | Voir : | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | Voir aussi : | ||
| + | * [[Crypto - Découper ses clefs en plusieurs morceaux grâce au secret reparti]] | ||
| + | * GPG | ||
| + | * HashiCorp Vault | ||
| + | * https:// | ||
| + | |||
| + | ~~~ | ||
| + | # age-keygen -o ~/ | ||
| + | $ age-keygen -o " | ||
| + | Public key: age1p6svvezfcg3jz33d0ynd27n3j72p7tjrqxdkssmwsvph7ct3y44qxvv8s7 | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | source <(sops completion bash) | ||
| + | |||
| + | # SOPS variables | ||
| + | export SOPS_AGE_KEY_FILE=" | ||
| + | # Ansible variables | ||
| + | export ANSIBLE_SOPS_AGE_KEYFILE=" | ||
| + | # Public key | ||
| + | export SOPS_AGE_RECIPIENTS=age1p6svvezfcg3jz33d0ynd27n3j72p7tjrqxdkssmwsvph7ct3y44qxvv8s7 | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | Avec GPG | ||
| + | # On récupère la fingerprint de notre clé | ||
| + | gpg --list-keys | ||
| + | # On export le fingerprint | ||
| + | export SOPS_PGP_FP="< | ||
| + | ~~~ | ||
| + | |||
| + | Usage | ||
| + | |||
| + | ~~~bash | ||
| + | sops --encrypt --encrypted-regex ' | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | sops -e secrets.yaml > secrets.enc.yaml | ||
| + | sops -d secrets.enc.yaml > secrets.decrypted.yaml | ||
| + | |||
| + | # Déconseillé | ||
| + | sops edit secrets.yaml | ||
| + | |||
| + | |||
| + | sops set plop.yaml ' | ||
| + | sops unset plop.yaml ' | ||
| + | |||
| + | sops encrypt --age age1yt3tfqlfrwdwx0z0ynwplcr6qxcxfaqycuprpmy89nr83ltx74tqdpszlw test.yaml > test.enc.yaml | ||
| + | |||
| + | sops decrypt mynewtestfile.yaml | ||
| + | sops -d mynewtestfile.yaml | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | # Chiffrer depuis stdin (JSON) | ||
| + | echo ' | ||
| + | |||
| + | # Écrire le résultat dans un fichier | ||
| + | sops decrypt secrets.enc.yaml --output secrets.yaml | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Rotate / rekey | ||
| + | ~~~bash | ||
| + | sops rotate -i example.yaml | ||
| + | ~~~ | ||
| + | |||
| + | Rekey | ||
| + | ~~~bash | ||
| + | sops updatekeys -y secrets.enc.yaml | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Looks for keys.txt in $XDG_CONFIG_HOME/ | ||
| + | Falls back to $HOME/ | ||
| + | |||
| + | Cloud | ||
| + | ~~~bash | ||
| + | sops -e --kms arn: | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Config | ||
| + | |||
| + | `.sops.yaml` | ||
| + | ~~~yaml | ||
| + | # creation rules are evaluated sequentially, | ||
| + | creation_rules: | ||
| + | # upon creation of a file that matches the pattern *.dev.yaml, | ||
| + | # KMS set A as well as PGP and age is used | ||
| + | - path_regex: \.dev\.yaml$ | ||
| + | age: ' | ||
| + | |||
| + | # prod files use KMS set B in the PROD IAM, PGP and age | ||
| + | - path_regex: \.prod\.yaml$ | ||
| + | age: ' | ||
| + | ~~~ | ||
| + | |||
| + | ~~~yaml | ||
| + | creation_rules: | ||
| + | # Prod : ne chiffrer que les secrets | ||
| + | - path_regex: ' | ||
| + | age: age1abc... | ||
| + | encrypted_regex: | ||
| + | |||
| + | # Dev : tout chiffrer | ||
| + | - path_regex: ' | ||
| + | age: age1abc... | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ~~~bash | ||
| + | # Injecter les secrets comme variables d' | ||
| + | sops exec-env secrets.enc.env 'echo DB_PASSWORD=$DB_PASSWORD' | ||
| + | # DB_PASSWORD=super-secret-123 | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | FIXME | ||
| + | |||
