-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhost_keys.yml
70 lines (61 loc) · 1.93 KB
/
host_keys.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
---
- name: 0-Check host required variables
fail: msg="Variable '{{ item.checkvar }}' is not defined - {{ item.checkmsg }}"
when: item.checkvar not in vars
with_items: "{{ host_required_vars }}"
- name: load actual public host key
set_fact:
ssh_public_key: "{{ lookup('file', '/etc/ssh/{{ sshd_certfile }}.pub') }}"
- name: generate signed host key
register: signed_host_key
uri:
url: "{{ vault_addr }}/v1/{{ host_ssh_path }}/sign/{{ host_ssh_role }}"
validate_certs: no
method: POST
body: "{ \"cert_type\": \"host\", \"public_key\": \"{{ ssh_public_key }}\" }"
body_format: json
return_content: yes
headers:
X-Vault-Request: "true"
X-Vault-Token: "{{ vault_login.json.auth.client_token }}"
- name: update signed host key certificate
copy:
content: "{{ signed_host_key.json.data.signed_key }}"
dest: "/etc/ssh/{{ sshd_certfile }}_signed.pub"
mode: "0640"
owner: root
group: root
notify:
- restart sshd
- name: ensure ssh config with enabled host key
lineinfile:
regexp: "^HostKey"
line: "HostKey /etc/ssh/{{ sshd_certfile }}"
dest: /etc/ssh/sshd_config
mode: 0640
notify:
- restart sshd
- name: update ssh config with signed host certificate from vault
lineinfile:
regexp: "^HostCertificate"
line: "HostCertificate /etc/ssh/{{ sshd_certfile }}_signed.pub"
dest: /etc/ssh/sshd_config
mode: 0640
notify:
- restart sshd
- name: load trusted ca from vault
register: vault_trusted_keys
uri:
url: "{{ vault_addr }}/v1/{{ host_ssh_path }}/config/ca"
body_format: json
return_content: true
headers:
X-Vault-Request: "true"
X-Vault-Token: "{{ vault_login.json.auth.client_token }}"
- name: add trust authority configuration
connection: local
become: no
lineinfile:
dest: ~/.ssh/known_hosts
regexp: "^@cert-authority *"
line: "@cert-authority * {{ vault_trusted_keys.json.data.public_key }}"