]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cryptsetup: document that keyfile-erase does not apply to auto-discovered key files
authorDaan De Meyer <daan@amutable.com>
Wed, 3 Jun 2026 14:03:39 +0000 (14:03 +0000)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 3 Jun 2026 14:26:04 +0000 (16:26 +0200)
keyfile-erase only erases a key file explicitly configured in the third
field of crypttab. Key files automatically discovered in
/etc/cryptsetup-keys.d/ and /run/cryptsetup-keys.d/ are considered shared
resources not owned by an individual volume, and are never erased. Make
this explicit in the documentation and add a code comment clarifying the
intent.

Fixes: https://github.com/systemd/systemd/issues/41127
Co-developed-by: Claude Opus 4.8 <noreply@anthropic.com>
man/crypttab.xml
src/cryptsetup/cryptsetup.c

index d57823f88ad73da16896f136191ea7cd436df1f4..38ba4ceafbe80aead3025bc0866a3573a0a36ad5 100644 (file)
         activation (e.g. via a file in <filename>/run/</filename>, generated by a service running before
         activation), and shall be removed after use. Defaults to off.</para>
 
+        <para>Note that this option only applies to a key file explicitly configured in the third field, and
+        has no effect on key files that are automatically discovered in
+        <filename>/etc/cryptsetup-keys.d/</filename> and <filename>/run/cryptsetup-keys.d/</filename>. The
+        latter are considered shared resources that are not owned by an individual volume, and hence are never
+        erased. To erase an automatically discovered key file, configure its path explicitly in the third
+        field.</para>
+
         <xi:include href="version-info.xml" xpointer="v246"/></listitem>
       </varlistentry>
 
index 39562019e483bcfbae285121ab04ad53a2cc9717..9c7b2006baba73cd78b6e6152d49f587017a9a73 100644 (file)
@@ -2639,6 +2639,9 @@ static int verb_attach(int argc, char *argv[], uintptr_t _data, void *userdata)
         /* A delicious drop of snake oil */
         (void) safe_mlockall(MCL_CURRENT|MCL_FUTURE|MCL_ONFAULT);
 
+        /* Only erase key files explicitly configured on the command line, never the ones we
+         * auto-discover in /etc/cryptsetup-keys.d/ and /run/cryptsetup-keys.d/: those are shared
+         * resources not owned by an individual volume. (key_file is NULL when auto-discovery is used.) */
         if (key_file && arg_keyfile_erase)
                 destroy_key_file = key_file; /* let's get this baby erased when we leave */