summaryrefslogtreecommitdiff
path: root/docs/formatsecret.rst
blob: d0c37ff1652fc1b9be2d3c7de178cf46cb77755d (plain)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
.. role:: since

=================
Secret XML format
=================

.. contents::

Secret XML
----------

Secrets stored by libvirt may have attributes associated with them, using the
``secret`` element. The ``secret`` element has two optional attributes, each
with values '``yes``' and '``no``', and defaulting to '``no``':

``ephemeral``
   This secret must only be kept in memory, never stored persistently.
``private``
   The value of the secret must not be revealed to any caller of libvirt, nor to
   any other node.

The top-level ``secret`` element may contain the following elements:

``uuid``
   An unique identifier for this secret (not necessarily in the UUID format). If
   omitted when defining a new secret, a random UUID is generated.
``description``
   A human-readable description of the purpose of the secret.
``usage``
   Specifies what this secret is used for. A mandatory ``type`` attribute
   specifies the usage category, currently only ``volume``, ``ceph``, ``iscsi``,
   ``tls``, and ``vtpm`` are defined. Specific usage categories are described
   below.

Usage type "volume"
~~~~~~~~~~~~~~~~~~~

This secret is associated with a volume, whether the format is either for a
"luks" encrypted volume. Each volume will have a unique secret associated with
it and it is safe to delete the secret after the volume is deleted. The
``<usage type='volume'>`` element must contain a single ``volume`` element that
specifies the path of the volume this secret is associated with. For example,
create a volume-secret.xml file as follows:

::

   <secret ephemeral='no' private='yes'>
      <description>Super secret name of my first puppy</description>
      <uuid>0a81f5b2-8403-7b23-c8d6-21ccc2f80d6f</uuid>
      <usage type='volume'>
         <volume>/var/lib/libvirt/images/puppyname.img</volume>
      </usage>
   </secret>

Define the secret and set the passphrase as follows:

::

   # virsh secret-define volume-secret.xml
   Secret 0a81f5b2-8403-7b23-c8d6-21ccc2f80d6f created

See `Setting secret values in virsh`_ on how to set the value of the secret
using ``virsh secret-set-value``.

The volume type secret can be supplied either in volume XML during creation of a
`storage volume <formatstorage.html#storage-volume-xml>`__ in order to provide
the passphrase to encrypt the volume or in domain XML
`disk device <formatdomain.html#hard-drives-floppy-disks-cdroms>`__ in order to provide the
passphrase to decrypt the volume, :since:`since 2.1.0` . An example follows:

::

   # cat luks-secret.xml
   <secret ephemeral='no' private='yes'>
      <description>LUKS Sample Secret</description>
      <uuid>f52a81b2-424e-490c-823d-6bd4235bc57</uuid>
      <usage type='volume'>
         <volume>/var/lib/libvirt/images/luks-sample.img</volume>
      </usage>
   </secret>

   # virsh secret-define luks-secret.xml
   Secret f52a81b2-424e-490c-823d-6bd4235bc57 created

See `Setting secret values in virsh`_ on how to set the value of the secret
using ``virsh secret-set-value``.

The volume type secret can be supplied in domain XML for a luks storage volume
`encryption <formatstorageencryption.html>`__ as follows:

::

   <encryption format='luks'>
     <secret type='passphrase' uuid='f52a81b2-424e-490c-823d-6bd4235bc57'/>
   </encryption>

Usage type "ceph"
~~~~~~~~~~~~~~~~~

This secret is associated with a Ceph RBD (rados block device). The
``<usage type='ceph'>`` element must contain a single ``name`` element that
specifies a usage name for the secret. The Ceph secret can then be used by UUID
or by this usage name via the ``<auth>`` element of a `disk
device <formatdomain.html#hard-drives-floppy-disks-cdroms>`__ or a `storage pool
(rbd) <formatstorage.html>`__. :since:`Since 0.9.7` . The following is an
example of the steps to be taken. First create a ceph-secret.xml file:

::

   <secret ephemeral='no' private='yes'>
      <description>CEPH passphrase example</description>
      <usage type='ceph'>
         <name>ceph_example</name>
      </usage>
   </secret>

Next, use ``virsh secret-define ceph-secret.xml`` to define the secret and
``virsh secret-set-value`` using the generated UUID value and a base64 generated
secret value in order to define the chosen secret pass phrase.

::

   # virsh secret-define ceph-secret.xml
   Secret 1b40a534-8301-45d5-b1aa-11894ebb1735 created
   #
   # virsh secret-list
    UUID                                 Usage
   -----------------------------------------------------------
    1b40a534-8301-45d5-b1aa-11894ebb1735 cephx ceph_example

See `Setting secret values in virsh`_ on how to set the value of the secret
using ``virsh secret-set-value``.

The ceph secret can then be used by UUID or by the usage name via the ``<auth>``
element in a domain's `<disk> <formatdomain.html#hard-drives-floppy-disks-cdroms>`__ element as
follows:

::

   <auth username='myname'>
     <secret type='ceph' usage='ceph_example'/>
   </auth>

As well as the ``<auth>`` element in a `storage pool
(rbd) <formatstorage.html>`__ ``<source>`` element as follows:

::

   <auth type='ceph' username='myname'>
     <secret usage='ceph_example'/>
   </auth>

Usage type "iscsi"
~~~~~~~~~~~~~~~~~~

This secret is associated with an iSCSI target for CHAP authentication. The
``<usage type='iscsi'>`` element must contain a single ``target`` element that
specifies a usage name for the secret. The iSCSI secret can then be used by UUID
or by this usage name via the ``<auth>`` element of a `disk
device <formatdomain.html#hard-drives-floppy-disks-cdroms>`__ or a `storage pool
(iscsi) <formatstorage.html>`__. :since:`Since 1.0.4` . The following is an
example of the XML that may be used to generate a secret for iSCSI CHAP
authentication. Assume the following sample entry in an iSCSI authentication
file:

::

   <target iqn.2013-07.com.example:iscsi-pool>
   backing-store /home/tgtd/iscsi-pool/disk1
   backing-store /home/tgtd/iscsi-pool/disk2
   incominguser myname mysecret
   </target>

Define an iscsi-secret.xml file to describe the secret. Use the ``incominguser``
username used in your iSCSI authentication configuration file as the value for
the ``username`` attribute. The ``description`` attribute should contain
configuration specific data. The ``target`` name may be any name of your
choosing to be used as the ``usage`` when used in the pool or disk XML
description.

::

   <secret ephemeral='no' private='yes'>
      <description>Passphrase for the iSCSI example.com server</description>
      <usage type='iscsi'>
         <target>libvirtiscsi</target>
      </usage>
   </secret>

Next, use ``virsh secret-define iscsi-secret.xml`` to define the secret and
``virsh secret-set-value`` using the generated UUID value and a base64 generated
secret value in order to define the chosen secret pass phrase. The pass phrase
must match the password used in the iSCSI authentication configuration file.

::

   # virsh secret-define secret.xml
   Secret c4dbe20b-b1a3-4ac1-b6e6-2ac97852ebb6 created

   # virsh secret-list
    UUID                                 Usage
   -----------------------------------------------------------
    c4dbe20b-b1a3-4ac1-b6e6-2ac97852ebb6 iscsi libvirtiscsi


See `Setting secret values in virsh`_ on how to set the value of the secret
using ``virsh secret-set-value``.

The iSCSI secret can then be used by UUID or by the usage name via the
``<auth>`` element in a domain's `<disk> <formatdomain.html#hard-drives-floppy-disks-cdroms>`__
element as follows:

::

   <auth username='myname'>
     <secret type='iscsi' usage='libvirtiscsi'/>
   </auth>

As well as the ``<auth>`` element in a `storage pool
(iscsi) <formatstorage.html>`__ ``<source>`` element as follows:

::

   <auth type='chap' username='myname'>
     <secret usage='libvirtiscsi'/>
   </auth>

Usage type "tls"
~~~~~~~~~~~~~~~~

This secret may be used in order to provide the passphrase for the private key
used to provide TLS credentials. The ``<usage type='tls'>`` element must contain
a single ``name`` element that specifies a usage name for the secret.
:since:`Since 2.3.0` . The following is an example of the expected XML and
processing to define the secret:

::

   # cat tls-secret.xml
   <secret ephemeral='no' private='yes'>
      <description>sample tls secret</description>
      <usage type='tls'>
         <name>TLS_example</name>
      </usage>
   </secret>

   # virsh secret-define tls-secret.xml
   Secret 718c71bd-67b5-4a2b-87ec-a24e8ca200dc created

   # virsh secret-list
    UUID                                 Usage
   -----------------------------------------------------------
    718c71bd-67b5-4a2b-87ec-a24e8ca200dc  tls TLS_example

A secret may also be defined via the
`virSecretDefineXML <html/libvirt-libvirt-secret.html#virSecretDefineXML>`__
API. Once the secret is defined, a secret value will need to be set. The secret
would be the passphrase used to access the TLS credentials. The following is a
simple example of using ``virsh secret-set-value`` to set the secret value. The
`virSecretSetValue <html/libvirt-libvirt-secret.html#virSecretSetValue>`__ API
may also be used to set a more secure secret without using printable/readable
characters.

Usage type "vtpm"
~~~~~~~~~~~~~~~~~

This secret is associated with a virtualized TPM (vTPM) and serves as a
passphrase for deriving a key from for encrypting the state of the vTPM. The
``<usage type='vtpm'>`` element must contain a single ``name`` element that
specifies a usage name for the secret. The vTPM secret can then be used by UUID
via the ``<encryption>`` element of a `tpm <formatdomain.html#tpm-device>`__
when using an emulator. :since:`Since 5.6.0` . The following is an example of
the steps to be taken. First create a vtpm-secret.xml file:

::

   # cat vtpm-secret.xml
   <secret ephemeral='no' private='yes'>
      <description>sample vTPM secret</description>
      <usage type='vtpm'>
         <name>VTPM_example</name>
      </usage>
   </secret>

   # virsh secret-define vtpm-secret.xml
   Secret 6dd3e4a5-1d76-44ce-961f-f119f5aad935 created

   # virsh secret-list
    UUID                                   Usage
   ----------------------------------------------------------------------------------------
    6dd3e4a5-1d76-44ce-961f-f119f5aad935   vtpm VTPM_example

A secret may also be defined via the
`virSecretDefineXML <html/libvirt-libvirt-secret.html#virSecretDefineXML>`__
API. Once the secret is defined, a secret value will need to be set. The secret
would be the passphrase used to decrypt the vTPM state. The following is a
simple example of using ``virsh secret-set-value`` to set the secret value. The
`virSecretSetValue <html/libvirt-libvirt-secret.html#virSecretSetValue>`__ API
may also be used to set a more secure secret without using printable/readable
characters.

Setting secret values in virsh
------------------------------

To set the value of the secret you can use the following virsh commands. If the
secret is a password-like string (printable characters, no newline) you can use:

::

   # virsh secret-set-value --interactive 6dd3e4a5-1d76-44ce-961f-f119f5aad935
   Enter new value for secret:
   Secret value set

Another secure option is to read the secret from a file. This way the secret can
contain any bytes (even NUL and non-printable characters). The length of the
secret is the length of the input file. Alternatively the ``--plain`` option can
be omitted if the file contents are base64-encoded.

::

   # virsh secret-set-value 6dd3e4a5-1d76-44ce-961f-f119f5aad935 --file --plain secretinfile
   Secret value set

**WARNING** The following approach is **insecure** and deprecated. The secret
can also be set via an argument. Note that other users may see the actual secret
in the process listing! The secret must be base64 encoded.

::

   # MYSECRET=`printf %s "open sesame" | base64`
   # virsh secret-set-value 6dd3e4a5-1d76-44ce-961f-f119f5aad935 $MYSECRET
   Secret value set