Debian Codegraph @

docs/howto/sensitive-dotfiles.md

raw
1 # Handle secrets
2
3 * [Using environment variables](#using-environment-variables)
4 * [Store encrypted dotfiles using GPG](#store-encrypted-dotfiles-using-gpg)
5 * [GPG examples](#gpg-examples)
6
7 ## Using environment variables
8
9 For example, you can have an `.env` file in the directory where your `config.yaml` lies:
10 ```bash
11 ## Some secrets
12 pass="verysecurepassword"
13 ```
14
15 If this file contains secrets that should not be tracked by Git,
16 put it in your `.gitignore`.
17
18 You can then invoke dotdrop with the help of an alias
19 ```bash
20 # when dotdrop is installed as a submodule
21 alias dotdrop='eval $(grep -v "^#" ~/dotfiles/.env) ~/dotfiles/dotdrop.sh'
22
23 # when dotdrop is installed from package
24 alias dotdrop='eval $(grep -v "^#" ~/dotfiles/.env) /usr/bin/dotdrop --cfg=~/dotfiles/config.yaml'
25 ```
26
27 The above aliases load all the variables from `~/dotfiles/.env`
28 (while omitting lines starting with `#`) before calling dotdrop.
29 Defined variables can then be used [in the config](../config/config-file.md#template-config-entries)
30 or [for templating dotfiles](../template/templating.md)
31
32 For more see [the doc on environment variables](../template/template-variables.md#environment-variables).
33
34 ## Store encrypted dotfiles using GPG
35
36 First you need to define the encryption/decryption methods, for example
37 ```yaml
38 variables:
39 keyid: "11223344"
40 trans_install:
41 _decrypt: "gpg -q --for-your-eyes-only--no-tty -d {0} > {1}"
42 trans_update:
43 _encrypt: "gpg -q -r {{@@ keyid @@}} --armor --no-tty -o {1} -e {0}"
44 ```
45
46 You can then import your dotfile and specify the transformations to apply/associate.
47 ```bash
48 dotdrop import --transw=_encrypt --transr=_decrypt ~/.secret
49 ```
50
51 Now whenever you install/compare your dotfile, the `_decrypt` transformation will be executed
52 to get the clear version of the file.
53 When updating the `_encrypt` transformation will transform the file to store it encrypted.
54
55 See [transformations](../config/config-transformations.md).
56
57 ## gpg examples
58
59 Using GPG keys:
60 ```yaml
61 variables:
62 keyid: "11223344"
63 trans_install:
64 _decrypt: "gpg -q --for-your-eyes-only--no-tty -d {0} > {1}"
65 trans_update:
66 _encrypt: "gpg -q -r {{@@ keyid @@}} --armor --no-tty -o {1} -e {0}"
67 ```
68
69 Passphrase is stored in an environment variable:
70 ```yaml
71 trans_install:
72 _decrypt: "echo {{@@ env['THE_KEY'] @@}} | gpg -q --batch --yes --for-your-eyes-only --passphrase-fd 0 --no-tty -d {0} > {1}"
73 trans_update:
74 _encrypt: "echo {{@@ env['THE_KEY'] @@}} | gpg -q --batch --yes --passphrase-fd 0 --no-tty -o {1} -c {0}"
75 ```
76
77 Passphrase is stored as a variable:
78 ```yaml
79 variables:
80 gpg_password: "some password"
81 trans_install:
82 _decrypt: "echo {{@@ gpg_password @@}} | gpg -q --batch --yes --for-your-eyes-only --passphrase-fd 0 --no-tty -d {0} > {1}"
83 trans_update:
84 _encrypt: "echo {{@@ gpg_password @@}} | gpg -q --batch --yes --passphrase-fd 0 --no-tty -o {1} -c {0}"
85 ```
86
87 Passphrase is retrieved using a script:
88 ```yaml
89 dynvariables:
90 gpg_password: "./get-password.sh"
91 trans_install:
92 _decrypt: "echo {{@@ gpg_password @@}} | gpg -q --batch --yes --for-your-eyes-only --passphrase-fd 0 --no-tty -d {0} > {1}"
93 trans_update:
94 _encrypt: "echo {{@@ gpg_password @@}} | gpg -q --batch --yes --passphrase-fd 0 --no-tty -o {1} -c {0}"
95 ```
96
97 Passphrase is stored in a file:
98 ```yaml
99 variables:
100 gpg_password_file: "/tmp/the-password"
101 dynvariables:
102 gpg_password: "cat {{@@ gpg_password_file @@}}"
103 trans_install:
104 _decrypt: "echo {{@@ gpg_password @@}} | gpg -q --batch --yes --for-your-eyes-only --passphrase-fd 0 --no-tty -d {0} > {1}"
105 trans_update:
106 _encrypt: "echo {{@@ gpg_password @@}} | gpg -q --batch --yes --passphrase-fd 0 --no-tty -o {1} -c {0}"
107 ```
108
109 See also [transformations](../config/config-transformations.md).