1SYSTEMD-CREDS(1)                 systemd-creds                SYSTEMD-CREDS(1)
2
3
4

NAME

6       systemd-creds - Lists, shows, encrypts and decrypts service credentials
7

SYNOPSIS

9       systemd-creds [OPTIONS...] COMMAND [ARGS...]
10

DESCRIPTION

12       systemd-creds is a tool for listing, showing, encrypting and decrypting
13       unit credentials. Credentials are limited-size binary or textual
14       objects that may be passed to unit processes. They are primarily used
15       for passing cryptographic keys (both public and private) or
16       certificates, user account information or identity information from the
17       host to services.
18
19       Credentials are configured in unit files via the LoadCredential=,
20       SetCredential=, LoadCredentialEncrypted= and SetCredentialEncrypted=
21       settings, see systemd.exec(5) for details.
22
23       For further information see System and Service Credentials[1]
24       documentation.
25

COMMANDS

27       The following commands are understood:
28
29       list
30           Show a list of credentials passed into the current execution
31           context. This command shows the files in the directory referenced
32           by the $CREDENTIALS_DIRECTORY environment variable, and is intended
33           to be executed from within service context.
34
35           Along with each credential name, the size and security state is
36           shown. The latter is one of "secure" (in case the credential is
37           backed by unswappable memory, i.e.  "ramfs"), "weak" (in case it is
38           backed by any other type of memory), or "insecure" (if having any
39           access mode that is not 0400, i.e. if readable by anyone but the
40           owner).
41
42       cat credential...
43           Show contents of specified credentials passed into the current
44           execution context. Takes one or more credential names, whose
45           contents shall be written to standard output.
46
47           When combined with --json= or --transcode= the output is transcoded
48           in simple ways before outputting.
49
50       setup
51           Generates a host encryption key for credentials, if one has not
52           been generated already. This ensures the
53           /var/lib/systemd/credential.secret file is initialized with a
54           random secret key if it doesn't exist yet. This secret key is used
55           when encrypting/decrypting credentials with encrypt or decrypt, and
56           is only accessible to the root user. Note that there's typically no
57           need to invoke this command explicitly as it is implicitly called
58           when encrypt is invoked, and credential host key encryption
59           selected.
60
61       encrypt input|- output|-
62           Loads the specified (unencrypted plaintext) input credential file,
63           encrypts it and writes the (encrypted ciphertext) output to the
64           specified target credential file. The resulting file may be
65           referenced in the LoadCredentialEncrypted= setting in unit files,
66           or its contents used literally in SetCredentialEncrypted= settings.
67
68           Takes two file system paths. The file name part of the output path
69           is embedded as name in the encrypted credential, to ensure
70           encrypted credentials cannot be renamed and reused for different
71           purposes without this being noticed. The credential name to embed
72           may be overridden with the --name= setting. The input or output
73           paths may be specified as "-", in which case the credential data is
74           read from/written to standard input and standard output. If the
75           output path is specified as "-" the credential name cannot be
76           derived from the file system path, and thus should be specified
77           explicitly via the --name= switch.
78
79           The credential data is encrypted and authenticated symmetrically
80           with one of the following encryption keys:
81
82            1. A secret key automatically derived from the system's TPM2 chip.
83               This encryption key is not stored on the host system and thus
84               decryption is only possible with access to the original TPM2
85               chip. Or in other words, the credential secured in this way can
86               only be decrypted again by the local machine.
87
88            2. A secret key stored in the /var/lib/systemd/credential.secret
89               file which is only accessible to the root user. This "host"
90               encryption key is stored on the host file system, and thus
91               decryption is possible with access to the host file system and
92               sufficient privileges. The key is automatically generated when
93               needed, but can also be created explicitly with the setup
94               command, see above.
95
96            3. A combination of the above: an encryption key derived from both
97               the TPM2 chip and the host file system. This means decryption
98               requires both access to the original TPM2 chip and the OS
99               installation. This is the default mode of operation if a TPM2
100               chip is available and /var/lib/systemd/ resides on persistent
101               media.
102
103           Which of the three keys shall be used for encryption may be
104           configured with the --with-key= switch. Depending on the use-case
105           for the encrypted credential the key to use may differ. For
106           example, for credentials that shall be accessible from the initial
107           RAM disk (initrd) of the system encryption with the host key is not
108           appropriate since access to the host key is typically not available
109           from the initrd. Thus, for such credentials only the TPM2 key
110           should be used.
111
112           Encrypted credentials are always encoded in Base64.
113
114           Use decrypt (see below) to undo the encryption operation, and
115           acquire the decrypted plaintext credential from the encrypted
116           ciphertext credential.
117
118           The credential data is encrypted using AES256-GCM, i.e. providing
119           both confidentiality and integrity, keyed by a SHA256 hash of one
120           or both of the secret keys described above.
121
122       decrypt input|- [output|-]
123           Undoes the effect of the encrypt operation: loads the specified
124           (encrypted ciphertext) input credential file, decrypts and
125           authenticates it and writes the (decrypted plaintext) output to the
126           specified target credential file.
127
128           Takes one or two file system paths. The file name part of the input
129           path is compared with the credential name embedded in the encrypted
130           file. If it does not match decryption fails. This is done in order
131           to ensure that encrypted credentials are not re-purposed without
132           this being detected. The credential name to compare with the
133           embedded credential name may also be overridden with the --name=
134           switch. If the input path is specified as "-", the encrypted
135           credential is read from standard input. If only one path is
136           specified or the output path specified as "-", the decrypted
137           credential is written to standard output. In this mode, the
138           expected name embedded in the credential cannot be derived from the
139           path and should be specified explicitly with --name=.
140
141           Decrypting credentials requires access to the original TPM2 chip
142           and/or credentials host key, see above. Information about which
143           keys are required is embedded in the encrypted credential data, and
144           thus decryption is entirely automatic.
145
146       has-tpm2
147           Reports whether the system is equipped with a TPM2 device usable
148           for protecting credentials. If a TPM2 device has been discovered,
149           is supported, and is being used by firmware, by the OS kernel
150           drivers and by userspace (i.e. systemd) this prints "yes" and exits
151           with exit status zero. If no such device is
152           discovered/supported/used, prints "no". Otherwise prints "partial".
153           In either of these two cases exits with non-zero exit status. It
154           also shows four lines indicating separately whether firmware,
155           drivers, the system and the kernel discovered/support/use TPM2.
156
157           Combine with --quiet to suppress the output.
158
159       -h, --help
160           Print a short help text and exit.
161
162       --version
163           Print a short version string and exit.
164

OPTIONS

166       --system
167           When specified with the list and cat commands operates on the
168           credentials passed to system as a whole instead of on those passed
169           to the current execution context. This is useful in container
170           environments where credentials may be passed in from the container
171           manager.
172
173       --transcode=
174           When specified with the cat or decrypt commands, transcodes the
175           output before showing it. Takes one of "base64", "unbase64", "hex"
176           or "unhex" as argument, in order to encode/decode the credential
177           data with Base64 or as series of hexadecimal values.
178
179           Note that this has no effect on the encrypt command, as encrypted
180           credentials are unconditionally encoded in Base64.
181
182       --newline=
183           When specified with cat or decrypt controls whether to add a
184           trailing newline character to the end of the output if it doesn't
185           end in one, anyway. Takes one of "auto", "yes" or "no". The default
186           mode of "auto" will suffix the output with a single newline
187           character only when writing credential data to a TTY.
188
189       --pretty, -p
190           When specified with encrypt controls whether to show the encrypted
191           credential as SetCredentialEncrypted= setting that may be pasted
192           directly into a unit file.
193
194       --name=name
195           When specified with the encrypt command controls the credential
196           name to embed in the encrypted credential data. If not specified
197           the name is chosen automatically from the filename component of the
198           specified output path. If specified as empty string no credential
199           name is embedded in the encrypted credential, and no verification
200           of credential name is done when the credential is decrypted.
201
202           When specified with the decrypt command control the credential name
203           to validate the credential name embedded in the encrypted
204           credential with. If not specified the name is chosen automatically
205           from the filename component of the specified input path. If no
206           credential name is embedded in the encrypted credential file (i.e.
207           the --name= with an empty string was used when encrypted) the
208           specified name has no effect as no credential name validation is
209           done.
210
211           Embedding the credential name in the encrypted credential is done
212           in order to protect against reuse of credentials for purposes they
213           weren't originally intended for, under the assumption the
214           credential name is chosen carefully to encode its intended purpose.
215
216       --timestamp=timestamp
217           When specified with the encrypt command controls the timestamp to
218           embed into the encrypted credential. Defaults to the current time.
219           Takes a timestamp specification in the format described in
220           systemd.time(7).
221
222           When specified with the decrypt command controls the timestamp to
223           use to validate the "not-after" timestamp that was configured with
224           --not-after= during encryption. If not specified defaults to the
225           current system time.
226
227       --not-after=timestamp
228           When specified with the encrypt command controls the time when the
229           credential shall not be used anymore. This embeds the specified
230           timestamp in the encrypted credential. During decryption the
231           timestamp is checked against the current system clock, and if the
232           timestamp is in the past the decryption will fail. By default no
233           such timestamp is set. Takes a timestamp specification in the
234           format described in systemd.time(7).
235
236       --with-key=, -H, -T
237           When specified with the encrypt command controls the
238           encryption/signature key to use. Takes one of "host", "tpm2",
239           "host+tpm2", "tpm2-absent", "auto", "auto-initrd". See above for
240           details on the three key types. If set to "auto" (which is the
241           default) the TPM2 key is used if a TPM2 device is found and not
242           running in a container. The host key is used if /var/lib/systemd/
243           is on persistent media. This means on typical systems the
244           encryption is by default bound to both the TPM2 chip and the OS
245           installation, and both need to be available to decrypt the
246           credential again. If "auto" is selected but neither TPM2 is
247           available (or running in container) nor /var/lib/systemd/ is on
248           persistent media, encryption will fail. If set to "tpm2-absent" a
249           fixed zero length key is used (thus, in this mode no
250           confidentiality nor authenticity are provided!). This logic is
251           useful to cover for systems that lack a TPM2 chip but where
252           credentials shall be generated. Note that decryption of such
253           credentials is refused on systems that have a TPM2 chip and where
254           UEFI SecureBoot is enabled (this is done so that such a locked down
255           system cannot be tricked into loading a credential generated this
256           way that lacks authentication information). If set to "auto-initrd"
257           a TPM2 key is used if a TPM2 is found. If not a fixed zero length
258           key is used, equivalent to "tpm2-absent" mode. This option is
259           particularly useful to generate credentials files that are
260           encrypted/authenticated against TPM2 where available but still work
261           on systems lacking support for this.
262
263           The -H switch is a shortcut for --with-key=host. Similar, -T is a
264           shortcut for --with-key=tpm2.
265
266           When encrypting credentials that shall be used in the initial RAM
267           disk (initrd) where /var/lib/systemd/ is typically not available
268           make sure to use --with-key=auto-initrd mode, to disable binding
269           against the host secret.
270
271           This switch has no effect on the decrypt command, as information on
272           which key to use for decryption is included in the encrypted
273           credential already.
274
275       --tpm2-device=PATH
276           Controls the TPM2 device to use. Expects a device node path
277           referring to the TPM2 chip (e.g.  /dev/tpmrm0). Alternatively the
278           special value "auto" may be specified, in order to automatically
279           determine the device node of a suitable TPM2 device (of which there
280           must be exactly one). The special value "list" may be used to
281           enumerate all suitable TPM2 devices currently discovered.
282
283       --tpm2-pcrs= [PCR...]
284           Configures the TPM2 PCRs (Platform Configuration Registers) to bind
285           the encryption key to. Takes a "+" separated list of numeric PCR
286           indexes in the range 0...23. If not used, defaults to PCR 7 only.
287           If an empty string is specified, binds the encryption key to no
288           PCRs at all. For details about the PCRs available, see the
289           documentation of the switch of the same name for systemd-
290           cryptenroll(1).
291
292       --quiet, -q
293           When used with has-tpm2 suppresses the output, and only returns an
294           exit status indicating support for TPM2.
295
296       --no-pager
297           Do not pipe output into a pager.
298
299       --no-legend
300           Do not print the legend, i.e. column headers and the footer with
301           hints.
302
303       --json=MODE
304           Shows output formatted as JSON. Expects one of "short" (for the
305           shortest possible output without any redundant whitespace or line
306           breaks), "pretty" (for a pretty version of the same, with
307           indentation and line breaks) or "off" (to turn off JSON output, the
308           default).
309

EXIT STATUS

311       On success, 0 is returned.
312
313       In case of the has-tpm2 command returns 0 if a TPM2 device is
314       discovered, supported and used by firmware, driver, and userspace (i.e.
315       systemd). Otherwise returns the OR combination of the value 1 (in case
316       firmware support is missing), 2 (in case driver support is missing) and
317       4 (in case userspace support is missing). If no TPM2 support is
318       available at all, value 7 is hence returned.
319

EXAMPLES

321       Example 1. Encrypt a password for use as credential
322
323       The following command line encrypts the specified password "hunter2",
324       writing the result to a file password.cred.
325
326           # echo -n hunter2 | systemd-creds encrypt - password.cred
327
328       This decrypts the file password.cred again, revealing the literal
329       password:
330
331           # systemd-creds decrypt password.cred
332           hunter2
333
334       Example 2. Encrypt a password and include it in a unit file
335
336       The following command line prompts the user for a password and
337       generates a SetCredentialEncrypted= line from it for a credential named
338       "mysql-password", suitable for inclusion in a unit file.
339
340           # systemd-ask-password -n | systemd-creds encrypt --name=mysql-password -p - -
341           🔐 Password: ****
342           SetCredentialEncrypted=mysql-password: \
343                   k6iUCUh0RJCQyvL8k8q1UyAAAAABAAAADAAAABAAAAASfFsBoPLIm/dlDoGAAAAAAAAAA \
344                   NAAAAAgAAAAAH4AILIOZ3w6rTzYsBy9G7liaCAd4i+Kpvs8mAgArzwuKxd0ABDjgSeO5k \
345                   mKQc58zM94ZffyRmuNeX1lVHE+9e2YD87KfRFNoDLS7F3YmCb347gCiSk2an9egZ7Y0Xs \
346                   700Kr6heqQswQEemNEc62k9RJnEl2q7SbcEYguegnPQUATgAIAAsAAAASACA/B90W7E+6 \
347                   yAR9NgiIJvxr9bpElztwzB5lUJAxtMBHIgAQACCaSV9DradOZz4EvO/LSaRyRSq2Hj0ym \
348                   gVJk/dVzE8Uxj8H3RbsT7rIBH02CIgm/Gv1ukSXO3DMHmVQkDG0wEciyageTfrVEer8z5 \
349                   9cUQfM5ynSaV2UjeUWEHuz4fwDsXGLB9eELXLztzUU9nsAyLvs3ZRR+eEK/A==
350
351       The generated line can be pasted 1:1 into a unit file, and will ensure
352       the acquired password will be made available in the
353       $CREDENTIALS_DIRECTORY/mysql-password credential file for the started
354       service.
355
356       Utilizing the unit file drop-in logic this can be used to securely pass
357       a password credential to a unit. A similar, more comprehensive set of
358       commands to insert a password into a service xyz.service:
359
360           # mkdir -p /etc/systemd/system/xyz.service.d
361           # systemd-ask-password -n | systemd-creds encrypt --name=mysql-password -p - - > /etc/systemd/system/xyz.service.d/50-password.conf
362           # systemctl daemon-reload
363           # systemctl restart xyz.service
364

SEE ALSO

366       systemd(1), systemd.exec(5)
367

NOTES

369        1. System and Service Credentials
370           https://systemd.io/CREDENTIALS
371
372
373
374systemd 251                                                   SYSTEMD-CREDS(1)
Impressum