|
1 | 1 | # Ansible KeePass Lookup Plugin
|
2 | 2 |
|
3 |
| -Perhaps, from a security view point, this solution is the same as `ansible-vault`. |
4 |
| -Just if you are storing secrets data in KeePass, then why not use it, |
5 |
| -instead of duplicating to `ansible-vault`. |
| 3 | +The plugin allows to read data from KeePass file (modifying is not supported) |
| 4 | + |
| 5 | +## How it works |
| 6 | + |
| 7 | +The plugin opens a UNIX socket with decrypted KeePass file. |
| 8 | +For performance reasons, decryption occurs only once at socket startup, |
| 9 | +and the KeePass file remains decrypted as long as the socket is open. |
| 10 | +The UNIX socket file is stored in a temporary folder according to OS. |
6 | 11 |
|
7 | 12 |
|
8 | 13 | ## Installation
|
9 | 14 |
|
10 |
| -Dependency: `pykeepass==3.2.1` |
| 15 | +Requirements: `python 3`, `pykeepass==4.0.1` |
11 | 16 |
|
12 |
| - pip install 'pykeepass==3.2.1' --user |
| 17 | + pip install 'pykeepass==4.0.1' --user |
13 | 18 | mkdir -p ~/.ansible/plugins/lookup && cd "$_"
|
14 |
| - curl https://raw.githubusercontent.com/viczem/ansible-keepass/master/keepass.py -o ./keepass.py |
15 |
| - |
16 |
| -[More about ansible plugins installation](https://docs.ansible.com/ansible/latest/dev_guide/developing_locally.html) |
| 19 | + curl https://raw.githubusercontent.com/viczem/ansible-keepass/main/keepass.py -o ./keepass.py |
17 | 20 |
|
18 | 21 |
|
19 | 22 | ## Variables
|
20 | 23 |
|
21 | 24 | - `keepass_dbx` - path to KeePass file
|
22 |
| -- `keepass_psw` - password. [*optional*] if the socket is used |
23 |
| -- `keepass_key` - [*optional*] path to keyfile |
24 |
| - |
25 |
| - |
26 |
| -## Usage with UNIX socket |
27 |
| - |
28 |
| -> _This usage is more preferred for performance reason, |
29 |
| -because of KeePass file stay decrypted and not need to reopen after done each playbook task |
30 |
| -[(see the issue for more info)](https://github.com/viczem/ansible-keepass/issues/1)_ |
31 |
| - |
32 |
| -In this case, there is no need to enter a password for KeePass each time Ansible is called. |
33 |
| -Run socket by the command and after that enter a password to make to open KeePass file. |
| 25 | +- `keepass_psw` - password |
| 26 | +- `keepass_key` - *Optional*. Path to keyfile |
| 27 | +- `keepass_ttl` - *Optional*. Socket TTL (will be closed automatically when not used). |
| 28 | +Default 60 seconds. |
34 | 29 |
|
35 |
| -**Supported only Python 3** |
36 | 30 |
|
37 |
| - python3 kpsock.py ~/.keepass/database.kdbx |
| 31 | +## Usage |
38 | 32 |
|
| 33 | +`ansible-doc -t lookup keepass` to get description of the plugin |
39 | 34 |
|
40 |
| -The command will creates UNIX socket in a system temp directory. Only one socket |
41 |
| -> **WARNING**: The KeePass file and password are stay decrypted in memory while the socket is open. |
| 35 | +> **WARNING**: For security reasons, do not store KeePass passwords in plain text. |
| 36 | +Use `ansible-vault encrypt_string` to encrypt it and use it like below |
42 | 37 |
|
43 |
| -The socket timeout is 1 minute since past access (will be closed automatically when not used). |
44 |
| -To change timeout use `--ttl` argument. |
45 |
| -For logging requests in a file use `--log` (default `--log-level` is `INFO`). |
| 38 | + # file: group_vars/all |
46 | 39 |
|
47 |
| -For help `python kpsock.py --help` |
48 |
| - |
49 |
| -To send the running command in background press <kbd>CTRL</kbd>+<kbd>Z</kbd> and execute `bg` |
50 |
| -(`fg` to get the job into the foreground again). |
51 |
| - |
52 |
| - |
53 |
| -## Example |
54 |
| - |
55 |
| -Define variables you need e.g. in any file in group_vars |
| 40 | + keepass_dbx: "~/.keepass/database.kdbx" |
| 41 | + keepass_psw: !vault | |
| 42 | + $ANSIBLE_VAULT;1.1;AES256 |
| 43 | + ...encrypted password... |
56 | 44 |
|
| 45 | +### Example |
57 | 46 |
|
58 | 47 | ansible_user : "{{ lookup('keepass', 'path/to/entry', 'username') }}"
|
59 | 48 | ansible_become_pass : "{{ lookup('keepass', 'path/to/entry', 'password') }}"
|
60 |
| - ansible_custom_field : "{{ lookup('keepass', 'path/to/entry', 'custom_field_property', true) }}" |
61 |
| - ansible_all_custom_fields: "{{ lookup('keepass', 'path/to/entry', '*', true) }}" |
62 |
| - |
63 |
| - |
64 |
| -You can get another [properties of an KeePass entry](https://github.com/pschmitt/pykeepass/blob/master/pykeepass/entry.py) |
65 |
| -(not only `username` or `password`) |
| 49 | + ansible_custom_field : "{{ lookup('keepass', 'path/to/entry', 'custom_properties', 'a_custom_property_name') }}" |
66 | 50 |
|
67 |
| -Specify a boolean value of true to use custom field properties |
68 |
| - |
69 |
| -`ansible-doc -t lookup keepass` - to get description of the plugin |
| 51 | +More examples see in [/examples](/examples). |
0 commit comments