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 initrd,
107           encryption with the host key is not appropriate, since access to
108           the host key is typically not available from the initrd. Thus, for
109           such credentials only the TPM2 key should be used.
110
111           Encrypted credentials are always encoded in Base64.
112
113           Use decrypt (see below) to undo the encryption operation, and
114           acquire the decrypted plaintext credential from the encrypted
115           ciphertext credential.
116
117           The credential data is encrypted using AES256-GCM, i.e. providing
118           both confidentiality and integrity, keyed by a SHA256 hash of one
119           or both of the secret keys described above.
120
121       decrypt input|- [output|-]
122           Undoes the effect of the encrypt operation: loads the specified
123           (encrypted ciphertext) input credential file, decrypts and
124           authenticates it and writes the (decrypted plaintext) output to the
125           specified target credential file.
126
127           Takes one or two file system paths. The file name part of the input
128           path is compared with the credential name embedded in the encrypted
129           file. If it does not match decryption fails. This is done in order
130           to ensure that encrypted credentials are not re-purposed without
131           this being detected. The credential name to compare with the
132           embedded credential name may also be overridden with the --name=
133           switch. If the input path is specified as "-", the encrypted
134           credential is read from standard input. If only one path is
135           specified or the output path specified as "-", the decrypted
136           credential is written to standard output. In this mode, the
137           expected name embedded in the credential cannot be derived from the
138           path and should be specified explicitly with --name=.
139
140           Decrypting credentials requires access to the original TPM2 chip
141           and/or credentials host key, see above. Information about which
142           keys are required is embedded in the encrypted credential data, and
143           thus decryption is entirely automatic.
144
145       has-tpm2
146           Reports whether the system is equipped with a TPM2 device usable
147           for protecting credentials. If a TPM2 device has been discovered,
148           is supported, and is being used by firmware, by the OS kernel
149           drivers and by userspace (i.e. systemd) this prints "yes" and exits
150           with exit status zero. If no such device is
151           discovered/supported/used, prints "no". Otherwise prints "partial".
152           In either of these two cases exits with non-zero exit status. It
153           also shows four lines indicating separately whether firmware,
154           drivers, the system and the kernel discovered/support/use TPM2.
155
156           Combine with --quiet to suppress the output.
157
158       -h, --help
159           Print a short help text and exit.
160
161       --version
162           Print a short version string and exit.
163

OPTIONS

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

EXIT STATUS

341       On success, 0 is returned.
342
343       In case of the has-tpm2 command returns 0 if a TPM2 device is
344       discovered, supported and used by firmware, driver, and userspace (i.e.
345       systemd). Otherwise returns the OR combination of the value 1 (in case
346       firmware support is missing), 2 (in case driver support is missing) and
347       4 (in case userspace support is missing). If no TPM2 support is
348       available at all, value 7 is hence returned.
349

EXAMPLES

351       Example 1. Encrypt a password for use as credential
352
353       The following command line encrypts the specified password "hunter2",
354       writing the result to a file password.cred.
355
356           # echo -n hunter2 | systemd-creds encrypt - password.cred
357
358       This decrypts the file password.cred again, revealing the literal
359       password:
360
361           # systemd-creds decrypt password.cred
362           hunter2
363
364       Example 2. Encrypt a password and include it in a unit file
365
366       The following command line prompts the user for a password and
367       generates a SetCredentialEncrypted= line from it for a credential named
368       "mysql-password", suitable for inclusion in a unit file.
369
370           # systemd-ask-password -n | systemd-creds encrypt --name=mysql-password -p - -
371           🔐 Password: ****
372           SetCredentialEncrypted=mysql-password: \
373                   k6iUCUh0RJCQyvL8k8q1UyAAAAABAAAADAAAABAAAAASfFsBoPLIm/dlDoGAAAAAAAAAA \
374                   NAAAAAgAAAAAH4AILIOZ3w6rTzYsBy9G7liaCAd4i+Kpvs8mAgArzwuKxd0ABDjgSeO5k \
375                   mKQc58zM94ZffyRmuNeX1lVHE+9e2YD87KfRFNoDLS7F3YmCb347gCiSk2an9egZ7Y0Xs \
376                   700Kr6heqQswQEemNEc62k9RJnEl2q7SbcEYguegnPQUATgAIAAsAAAASACA/B90W7E+6 \
377                   yAR9NgiIJvxr9bpElztwzB5lUJAxtMBHIgAQACCaSV9DradOZz4EvO/LSaRyRSq2Hj0ym \
378                   gVJk/dVzE8Uxj8H3RbsT7rIBH02CIgm/Gv1ukSXO3DMHmVQkDG0wEciyageTfrVEer8z5 \
379                   9cUQfM5ynSaV2UjeUWEHuz4fwDsXGLB9eELXLztzUU9nsAyLvs3ZRR+eEK/A==
380
381       The generated line can be pasted 1:1 into a unit file, and will ensure
382       the acquired password will be made available in the
383       $CREDENTIALS_DIRECTORY/mysql-password credential file for the started
384       service.
385
386       Utilizing the unit file drop-in logic this can be used to securely pass
387       a password credential to a unit. A similar, more comprehensive set of
388       commands to insert a password into a service xyz.service:
389
390           # mkdir -p /etc/systemd/system/xyz.service.d
391           # systemd-ask-password -n | ( echo "[Service]" && systemd-creds encrypt --name=mysql-password -p - - ) >/etc/systemd/system/xyz.service.d/50-password.conf
392           # systemctl daemon-reload
393           # systemctl restart xyz.service
394

SEE ALSO

396       systemd(1), systemd.exec(5), systemd-measure(1)
397

NOTES

399        1. System and Service Credentials
400           https://systemd.io/CREDENTIALS
401
402
403
404systemd 253                                                   SYSTEMD-CREDS(1)
Impressum