Skip to content

Commit 1cb9164

Browse files
authored
Merge pull request #74 from stackhpc/feature/improve_tls_support
Add support for configuring QEMU/VNC TLS
2 parents 27144f8 + 31284ba commit 1cb9164

File tree

6 files changed

+156
-2
lines changed

6 files changed

+156
-2
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,33 @@ systemd.socket for format. Default is unset.
187187

188188
`libvirt_host_tls_cacert`: TLS CA certificate. Default is unset.
189189

190+
`libvirt_host_qemu_tls_enabled`: Encrypt communication between QEMU instances using TLS.
191+
Default is `false`.
192+
193+
`libvirt_host_qemu_tls_server_cert`: TLS server certificate. Default is `libvirt_host_tls_server_cert`.
194+
195+
`libvirt_host_qemu_tls_server_key`: TLS server key. Default is `libvirt_host_tls_server_key`.
196+
197+
`libvirt_host_qemu_tls_client_cert`: TLS client certificate. Default is `libvirt_host_tls_client_cert`.
198+
199+
`libvirt_host_qemu_tls_client_key`: TLS client key. Default is `libvirt_host_tls_client_key`.
200+
201+
`libvirt_host_qemu_tls_cacert`: TLS CA certificate. Default is `libvirt_host_tls_cacert`.
202+
203+
`libvirt_host_qemu_user`: The user that QEMU runs as. This will be used for TLS file ownership
204+
Default is `libvirt-qemu`.
205+
206+
`libvirt_host_qemu_group`: The group that the QEMU user belongs to. This will be used for TLS file ownership.
207+
Default is `libvirt-qemu`.
208+
209+
`libvirt_host_vnc_tls_enabled`: Encrypt VNC traffic using TLS. Default is `false`.
210+
211+
`libvirt_host_vnc_tls_server_cert`: TLS server certificate. Default is `libvirt_host_tls_server_cert`.
212+
213+
`libvirt_host_vnc_tls_server_key`: TLS server key. Default is `libvirt_host_tls_server_key`.
214+
215+
`libvirt_host_vnc_tls_cacert`: TLS CA certificate. Default is `libvirt_host_tls_cacert`.
216+
190217
`libvirt_host_configure_apparmor`: Whether to configure AppArmor for directory
191218
storage pools.
192219

defaults/main.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,17 @@ libvirt_host_tls_client_cert:
148148
libvirt_host_tls_client_key:
149149
libvirt_host_tls_cacert:
150150

151+
# Configure QEMU to use TLS for data transfer between hypervisors
152+
# This is more secure than SASL authentication.
153+
libvirt_host_qemu_tls_enabled: false
154+
155+
# The user/group used to run the QEMU process. For security reasons,
156+
# Libvirt normally sets this to something other than root.
157+
libvirt_host_qemu_user: "qemu"
158+
libvirt_host_qemu_group: "qemu"
159+
160+
# Encrypt VNC traffic
161+
libvirt_host_vnc_tls_enabled: false
162+
151163
# Whether to configure AppArmor for directory storage pools.
152164
libvirt_host_configure_apparmor: "{{ libvirt_host_install_daemon | bool }}"

tasks/config.yml

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
- reload systemd
8484
- restart libvirt
8585

86-
- name: Create directory for TLS certificates and keys
86+
- name: Create directory for Libvirt TLS certificates and keys
8787
file:
8888
path: "{{ item }}"
8989
state: directory
@@ -100,7 +100,7 @@
100100
when:
101101
- libvirt_host_tls_listen | bool
102102

103-
- name: Copy TLS certificates and keys
103+
- name: Copy Libvirt TLS certificates and keys
104104
copy:
105105
content: "{{ _libvirt_loop_item.content }}"
106106
dest: "{{ _libvirt_loop_item.dest }}"
@@ -131,6 +131,76 @@
131131
loop: "{{ libvirt_host_sasl_credentials }}"
132132
when: libvirt_host_enable_sasl_support | bool
133133

134+
- name: Create directory for QEMU TLS certificates and keys
135+
file:
136+
path: "{{ item }}"
137+
state: directory
138+
owner: "{{ libvirt_host_qemu_user }}"
139+
group: "{{ libvirt_host_qemu_group }}"
140+
mode: 0700
141+
become: true
142+
loop: >-
143+
{{ _libvirt_host_qemu_tls_certs.values() |
144+
selectattr('content') |
145+
map(attribute='dest') |
146+
map('dirname') |
147+
unique }}
148+
when:
149+
- libvirt_host_qemu_tls_enabled | bool
150+
151+
- name: Copy QEMU TLS certificates and keys
152+
copy:
153+
content: "{{ _libvirt_host_qemu_loop_item.content }}"
154+
dest: "{{ _libvirt_host_qemu_loop_item.dest }}"
155+
owner: "{{ libvirt_host_qemu_user }}"
156+
group: "{{ libvirt_host_qemu_group }}"
157+
mode: "{{ _libvirt_host_qemu_loop_item.mode }}"
158+
become: true
159+
# NOTE: Loop over keys of _libvirt_host_qemu_tls_certs to avoid leaking the key
160+
# contents.
161+
loop: "{{ _libvirt_host_qemu_tls_certs.keys() }}"
162+
when:
163+
- libvirt_host_qemu_tls_enabled | bool
164+
- _libvirt_host_qemu_loop_item.content
165+
vars:
166+
_libvirt_host_qemu_loop_item: "{{ _libvirt_host_qemu_tls_certs[item] }}"
167+
notify: restart libvirt
168+
169+
- name: Create directory for Libvirt VNC TLS certificates and keys
170+
file:
171+
path: "{{ item }}"
172+
state: directory
173+
owner: "{{ libvirt_host_qemu_user }}"
174+
group: "{{ libvirt_host_qemu_group }}"
175+
mode: 0700
176+
become: true
177+
loop: >-
178+
{{ _libvirt_host_vnc_tls_certs.values() |
179+
selectattr('content') |
180+
map(attribute='dest') |
181+
map('dirname') |
182+
unique }}
183+
when:
184+
- libvirt_host_vnc_tls_enabled | bool
185+
186+
- name: Copy Libvirt VNC TLS certificates and keys
187+
copy:
188+
content: "{{ _libvirt_host_vnc_loop_item.content }}"
189+
dest: "{{ _libvirt_host_vnc_loop_item.dest }}"
190+
owner: "{{ libvirt_host_qemu_user }}"
191+
group: "{{ libvirt_host_qemu_group }}"
192+
mode: "{{ _libvirt_host_vnc_loop_item.mode }}"
193+
become: true
194+
# NOTE: Loop over keys of _libvirt_host_vnc_tls_certs to avoid leaking the key
195+
# contents.
196+
loop: "{{ _libvirt_host_vnc_tls_certs.keys() }}"
197+
when:
198+
- libvirt_host_vnc_tls_enabled | bool
199+
- _libvirt_host_vnc_loop_item.content
200+
vars:
201+
_libvirt_host_vnc_loop_item: "{{ _libvirt_host_vnc_tls_certs[item] }}"
202+
notify: restart libvirt
203+
134204
- name: Flush handlers
135205
meta: flush_handlers
136206

templates/qemu.conf.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# {{ ansible_managed }}
2+
{% if libvirt_host_vnc_tls_enabled | bool %}
3+
vnc_tls=1
4+
vnc_tls_x509_verify=1
5+
{% endif -%}
26
{% for key, value in libvirt_host_qemu_conf.items() %}
37
{# While the value is not JSON formatted, it is close enough - strings need to be double quoted. #}
48
{{ key }} = {{ value | to_json }}

vars/Debian.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,10 @@ libvirt_host_packages_sasl:
4040
- libsasl2-modules-gssapi-mit
4141
- sasl2-bin
4242

43+
# The user/group used to run the QEMU process. For security reasons,
44+
# Libvirt normally sets this to something other than root.
45+
libvirt_host_qemu_user: "libvirt-qemu"
46+
libvirt_host_qemu_group: "libvirt-qemu"
47+
4348
# These are passed to the lineinfile module to customize configuration files
4449
libvirt_host_lineinfile_extra_rules: []

vars/main.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,39 @@ _libvirt_tls_certs:
4646
content: "{{ libvirt_host_tls_cacert }}"
4747
dest: /etc/pki/CA/cacert.pem
4848
mode: "0644"
49+
50+
_libvirt_host_qemu_tls_certs:
51+
servercert:
52+
content: "{{ libvirt_host_qemu_tls_server_cert | default(libvirt_host_tls_server_cert) }}"
53+
dest: /etc/pki/qemu/server-cert.pem
54+
mode: "0600"
55+
serverkey:
56+
content: "{{ libvirt_host_qemu_tls_server_key | default(libvirt_host_tls_server_key) }}"
57+
dest: /etc/pki/qemu/server-key.pem
58+
mode: "0600"
59+
clientcert:
60+
content: "{{ libvirt_host_qemu_tls_client_cert | default(libvirt_host_tls_client_cert) }}"
61+
dest: /etc/pki/qemu/client-cert.pem
62+
mode: "0600"
63+
clientkey:
64+
content: "{{ libvirt_host_qemu_tls_client_key | default(libvirt_host_tls_client_key) }}"
65+
dest: /etc/pki/qemu/client-key.pem
66+
mode: "0600"
67+
cacert:
68+
content: "{{ libvirt_host_qemu_tls_cacert | default(libvirt_host_tls_cacert) }}"
69+
dest: /etc/pki/qemu/ca-cert.pem
70+
mode: "0644"
71+
72+
_libvirt_host_vnc_tls_certs:
73+
servercert:
74+
content: "{{ libvirt_host_vnc_tls_server_cert | default(libvirt_host_tls_server_cert) }}"
75+
dest: /etc/pki/libvirt-vnc/server-cert.pem
76+
mode: "0600"
77+
serverkey:
78+
content: "{{ libvirt_host_vnc_tls_server_key | default(libvirt_host_tls_server_key) }}"
79+
dest: /etc/pki/libvirt-vnc/server-key.pem
80+
mode: "0600"
81+
cacert:
82+
content: "{{ libvirt_host_vnc_tls_cacert | default(libvirt_host_tls_cacert) }}"
83+
dest: /etc/pki/libvirt-vnc/ca-cert.pem
84+
mode: "0644"

0 commit comments

Comments
 (0)