Skip to content

Commit d8ffad1

Browse files
committed
vault-auto-unseal: Add role for configuring auto unseal
1 parent 33e6c28 commit d8ffad1

File tree

4 files changed

+84
-1
lines changed

4 files changed

+84
-1
lines changed

.github/workflows/pull_request.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
else
6666
ansible_package=ansible-core
6767
fi
68-
python3 -m pip install $ansible_package==$ansible_version.* docker git+https://github.com/stackhpc/ansible-modules-hashivault@stackhpc
68+
python3 -m pip install $ansible_package==$ansible_version.* docker git+https://github.com/stackhpc/ansible-modules-hashivault@stackhpc-test
6969
ansible-galaxy collection build
7070
ansible-galaxy collection install *.tar.gz
7171
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
vault_auto_unseal_transit_engine_name: "transit"
3+
4+
vault_auto_unseal_key_name: "autounseal"
5+
6+
vault_auto_unseal_policy_name: "autounseal"
7+
8+
vault_auto_unseal_token_name: "autounseal"
9+
vault_auto_unseal_token_period: "120"
10+
vault_auto_unseal_token_wrap_ttl: "24h"
+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
- name: "Ensure transit secret engine is configured"
3+
hashivault_secret_engine:
4+
name: "{{ vault_auto_unseal_transit_engine_name }}"
5+
backend: "transit"
6+
state: "present"
7+
ca_cert: "{{ vault_ca_cert | default(omit) }}"
8+
url: "{{ vault_api_addr }}"
9+
token: "{{ vault_token }}"
10+
ca_cert: "{{ vault_ca_cert | default(omit) }}"
11+
12+
- name: "Create transit/keys/autounseal"
13+
hashivault_secret:
14+
mount_point: "transit/keys"
15+
secret: "{{ vault_auto_unseal_key_name }}"
16+
url: "{{ vault_api_addr }}"
17+
token: "{{ vault_token }}"
18+
ca_cert: "{{ vault_ca_cert | default(omit) }}"
19+
20+
- name: "Create autounseal policy"
21+
hashivault_policy:
22+
name: "{{ vault_auto_unseal_policy_name }}"
23+
rules: |
24+
path "transit/encrypt/{{ vault_auto_unseal_key_name }}" {
25+
capabilities = [ "update" ]
26+
}
27+
path "transit/decrypt/{{ vault_auto_unseal_key_name }}" {
28+
capabilities = [ "update" ]
29+
}
30+
state: present
31+
url: "{{ vault_api_addr }}"
32+
token: "{{ vault_token }}"
33+
ca_cert: "{{ vault_ca_cert | default(omit) }}"
34+
35+
- name: "Create an orphan periodic client token with the autounseal policy attached"
36+
hashivault_token_create:
37+
display_name: "{{ vault_auto_unseal_token_name }}"
38+
period: "{{ vault_auto_unseal_token_period }}"
39+
policies:
40+
- "{{ vault_auto_unseal_policy_name }}"
41+
wrap_ttl: "{{ vault_auto_unseal_token_wrap_ttl }}"
42+
url: "{{ vault_api_addr }}"
43+
token: "{{ vault_token }}"
44+
ca_cert: "{{ vault_ca_cert | default(omit) }}"
45+
register: vault_auto_unseal_wrapping_token
46+
47+
- name: Print vault keys
48+
debug:
49+
var: vault_auto_unseal_wrapping_token
50+
when:
51+
- vault_auto_unseal_log_token | bool
52+
53+
- name: Set vault_auto_unseal_token fact
54+
set_fact:
55+
vault_keys: "{{ vault_auto_unseal_wrapping_token }}"
56+
when:
57+
- vault_auto_unseal_set_token_fact | bool
58+
59+
- name: Write vault keys to a file
60+
copy:
61+
content: "{{ vault_auto_unseal_wrapping_token | to_nice_json }}"
62+
dest: "{{ vault_auto_unseal_write_token_file_path }}"
63+
mode: 0600
64+
delegate_to: "{{ vault_auto_unseal_write_token_file_host }}"
65+
when:
66+
- vault_auto_unseal_write_token_file | bool

tests/test_vault.yml

+7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
vault_unseal_keys: "{{ vault_keys.keys_base64 }}"
2929
vault_protocol: "http"
3030

31+
- name: Configure auto unseal
32+
import_role:
33+
name: vault_auto_unseal
34+
vars:
35+
vault_token: "{{ vault_keys.root_token }}"
36+
vault_auto_unseal_log_token: true
37+
3138
- name: Configure PKI
3239
import_role:
3340
name: vault_pki

0 commit comments

Comments
 (0)