-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Encrypted datasets are not mounted automatically #8750
Comments
The Arch Linux Wiki has a section on unlocking an encrypted dataset at boot time, but on CentOS this leads to dependency cycles: https://wiki.archlinux.org/index.php/ZFS#Unlock_at_boot_time I'm wondering whether it would be better to add the -l option to the zfs-mount.service file by default. This would only work if the dataset is encrypted with a key file. |
Adding the "-l" option to zfs-mount.service does work for key files btw. My point is, if you use a password rather than a key file, the service seems to fail. |
Let's see if we can get @aerusso, @Fabian-Gruenbichler, or @rlaager's thoughts on this so systemd can prompt for the password when required. |
I'm not an expert on this, but I did some looking... We need to invoke Here is an example shell script that loads passwords using systemd-ask-password.
I have tested this with an encryption root with spaces in it and it works. I'm not sure if Edit: This assumes the password is entered correctly. A production-quality implementation really needs to prompt multiple (e.g. 3) times. Also, this further assumes that you even have the passwords at all. That may not be a valid assumption at all. Imagine that everyone's home directory is separately encrypted with their login password. It's not going to be possible to mount those at boot. (One might argue that they should be Perhaps the best approach would be to have a Edit 2: There is a separate question of how this all needs to work with |
On Fri, May 24, 2019 at 02:54:08PM -0700, Brian Behlendorf wrote:
Let's see if we can get @aerusso, @Fabian-Gruenbichler, or @rlaager's thoughts on this so systemd can prompt for the password when required.
I'll get back to you later this week!
|
The zfs-mount-generator infrastructure could be easily modified to produce
mount units with a dependency on @rlaager's systemd unit. It would be nice
if that unit also loaded the key files, too, because
the zfs-mount-generator units don't use zfs mount, and cannot use the -l
option.
We should also use printf to safely get the newline character into the IFS
variable.
I've also been thinking about the issue of not knowing the password. I
agree that datasets of that type should be set to canmount=noauto, and be
handled by another system that understands when and how to ask for a
password. They're not supposed to be automatically mounted by zfs!
…On Fri, May 24, 2019, 4:46 PM Richard Laager ***@***.***> wrote:
I'm not an expert on this, but I did some looking... We need to invoke
systemd-ask-password to prompt for passwords. Then, we can use zfs mount
-a -l safely.
Here is an example shell script that loads passwords using
systemd-ask-password.
#!/bin/sh
# Set IFS to a newline:
IFS="
"
for dataset in $(zfs list -H -p -o name,encryptionroot | \
awk -F "\t" '{if ($1 == $2) { print $1 }}')
do
if [ "$(zfs get -H -p -o value keylocation "$dataset")" = "prompt" ] &&
[ "$(zfs get -H -p -o value keystatus "$dataset")" = "unavailable" ]
then
systemd-ask-password --id="zfs:$dataset" \
"Enter passphrase for '$dataset':" | \
zfs load-key "$dataset"
fi
done
I *have* tested this with an encryption root with spaces in it and it
works.
I'm not sure if sh is the best approach for this, or if we should have
some small helper (or alternate mode for zfs load-key) that does all this.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#8750>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABRTSK6T5K7SFDLMOPMM2UDPXBV6BANCNFSM4HNI2A6A>
.
|
Those dependency cycles are because the Arch instructions don't disable default dependencies and It seems to work fine for me if I disable default dependencies. I don't understand what the As cat << 'EOF' > /etc/systemd/system/[email protected]
[Unit]
Description=Load ZFS keys
DefaultDependencies=no
Before=zfs-mount.service
After=zfs-import.target
Requires=zfs-import.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/sbin/zfs load-key %I
[Install]
WantedBy=zfs-mount.service
EOF The capital systemctl enable zfs-load-key@tank-enc So far that's working for me with a file based passphrase:
|
IMHO the following approach would be a good idea:
Optionally, we might want to add ordering and/or cycle detection for keys stored on encrypted datasets which are needed by other encrypted datasets, although cycles are not that much of a problem since systemd will break them one way or another anyway, and if they exists the admin needs to fix them and not us ;) I did not yet have time to play around with encryption, but I hope to get to it soon. If desired, I can attempt to at least whip up a PoC for the above in the next 1-2 weeks? |
That seems like a well-thought-out, comprehensive solution. |
We could significantly reduce the complexity of this process by deprecating I'm also assuming that we're doing this with a generator because we're concerned about calling If we can guarantee that |
IIRC, |
It was also argued that |
On Fri, May 31, 2019 at 03:45:51PM -0700, Antonio Russo wrote:
It was also [argued](#7329 (comment)) that `zfs list` could be dangerously slow. We also don't need information about encryption until much later in the boot process in this case, though.
if we want to support encrypted / datasets, we'd need to somehow get
this information into the initrd though (for Debian-based distros,
that means adapting the update-initramfs hook similar to how
cryptsetup/LUKS is handled, not sure about dracut).
|
If the root filesystem dataset is encrypted, the zfs script in the initramfs prompts for the key. That already works today for initramfs-tools. (I assume it does for dracut too, but I don't use that.) |
On Sat, Jun 01, 2019 at 02:21:26AM -0700, Richard Laager wrote:
> if we want to support encrypted / datasets, we'd need to somehow get this information into the initrd though (for Debian-based distros, that means adapting the update-initramfs hook similar to how cryptsetup/LUKS is handled, not sure about dracut).
If the root filesystem dataset is encrypted, the zfs script in the initramfs prompts for the key. That already works today for initramfs-tools. (I assume it does for dracut too, but I don't use that.)
but it does not support copying keyfiles to the initrd for automatic
decryption (which is what cryptsetup's initramfs hooks support, at least
in Debian/Ubuntu). it's a niche use case, but I wanted to mention it
anyway ;)
usually people use it like this:
- LUKS-encrypted /boot (which is bootable by Grub with a single prompt
for just this device)
- lots of keyfiles for different volumes/datasets/partitions
- marking those needed in initrd for inclusion in /etc/crypttab
- automatic decryption in initrd to avoid entering lots of
passphrases on each boot
the keyfiles in initrd are readable by root only (via the UMASK setting),
just like on the regular disks.
|
What I'm imagining (and have partially written up) is:
So @Fabian-Gruenbichler, I think I do understand your comment about |
Modify zfs-mount-generator to produce a dependency on a new zfs-import-key-*.service, dynamically created to call zfs load-key for the encryption root before attempting to mount any encrypted datasets. This dynamically generated unit RequiresMountsFor on the keyfile location, if present, or calls systemd-ask-password if a passphrase is requested. This patch includes suggestions from @Fabian-Gruenbichler, @rlaager, and @ryanjaeb. Closes: openzfs#8750 Signed-off-by: Antonio Russo <[email protected]>
Modify zfs-mount-generator to produce a dependency on new zfs-import-key-*.service units, dynamically created at boot to call zfs load-key for the encryption root, before attempting to mount any encrypted datasets. These units are created by zfs-mount-generator, and RequiresMountsFor on the keyfile, if present, or call systemd-ask-password if a passphrase is requested. This patch includes suggestions from @Fabian-Gruenbichler, @rlaager, and @ryanjaeb. Closes: openzfs#8750 Signed-off-by: Antonio Russo <[email protected]>
I don't know if this is exactly the same issue, but when I manually run:
I expect all the mountable datasets contained within, to be mounted, consistent with the behaviour of The fact that it mounts nothing at all, is a bit surprising and frustrating, from a user's perspective. I think both of those commands should have consistent mounting behaviour, if someone needs to not mount anything, maybe have a switch to stop that from happening. |
The current behavior of We are still looking into the use-cases here and may revisit this decision in the future after the feature gets a bit more use. |
I mean that I don't mean that it should do nothing, because I will try I assume it's possible to update the mounting options for a dataset, before the key is loaded. So the user already specified what they wanted, prior to loading the key. |
Modify zfs-mount-generator to produce a dependency on new zfs-import-key-*.service units, dynamically created at boot to call zfs load-key for the encryption root, before attempting to mount any encrypted datasets. These units are created by zfs-mount-generator, and RequiresMountsFor on the keyfile, if present, or call systemd-ask-password if a passphrase is requested. This patch includes suggestions from @Fabian-Gruenbichler, @rlaager, and @ryanjaeb. Closes: openzfs#8750 Signed-off-by: Antonio Russo <[email protected]>
Modify zfs-mount-generator to produce a dependency on new zfs-import-key-*.service units, dynamically created at boot to call zfs load-key for the encryption root, before attempting to mount any encrypted datasets. These units are created by zfs-mount-generator, and RequiresMountsFor on the keyfile, if present, or call systemd-ask-password if a passphrase is requested. This patch includes suggestions from @Fabian-Gruenbichler, @ryanjaeb and @rlaager, as well an adaptation of @rlaager's script to retry on incorrect password entry. Closes: openzfs#8750 Signed-off-by: Antonio Russo <[email protected]>
Reviewed-by: Richard Laager <[email protected]> Reviewed-by: Fabian Grünbichler <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Antonio Russo <[email protected]> Closes openzfs#8750 Closes openzfs#8848
Modify zfs-mount-generator to produce a dependency on new zfs-import-key-*.service units, dynamically created at boot to call zfs load-key for the encryption root, before attempting to mount any encrypted datasets. These units are created by zfs-mount-generator, and RequiresMountsFor on the keyfile, if present, or call systemd-ask-password if a passphrase is requested. This patch includes suggestions from @Fabian-Gruenbichler, @ryanjaeb and @rlaager, as well an adaptation of @rlaager's script to retry on incorrect password entry. Reviewed-by: Richard Laager <[email protected]> Reviewed-by: Fabian Grünbichler <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Antonio Russo <[email protected]> Closes openzfs#8750 Closes openzfs#8848
Reviewed-by: Richard Laager <[email protected]> Reviewed-by: Fabian Grünbichler <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Antonio Russo <[email protected]> Closes openzfs#8750 Closes openzfs#8848
Modify zfs-mount-generator to produce a dependency on new zfs-import-key-*.service units, dynamically created at boot to call zfs load-key for the encryption root, before attempting to mount any encrypted datasets. These units are created by zfs-mount-generator, and RequiresMountsFor on the keyfile, if present, or call systemd-ask-password if a passphrase is requested. This patch includes suggestions from @Fabian-Gruenbichler, @ryanjaeb and @rlaager, as well an adaptation of @rlaager's script to retry on incorrect password entry. Reviewed-by: Richard Laager <[email protected]> Reviewed-by: Fabian Grünbichler <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Antonio Russo <[email protected]> Closes openzfs#8750 Closes openzfs#8848
Reviewed-by: Richard Laager <[email protected]> Reviewed-by: Fabian Grünbichler <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Antonio Russo <[email protected]> Closes openzfs#8750 Closes openzfs#8848
Modify zfs-mount-generator to produce a dependency on new zfs-import-key-*.service units, dynamically created at boot to call zfs load-key for the encryption root, before attempting to mount any encrypted datasets. These units are created by zfs-mount-generator, and RequiresMountsFor on the keyfile, if present, or call systemd-ask-password if a passphrase is requested. This patch includes suggestions from @Fabian-Gruenbichler, @ryanjaeb and @rlaager, as well an adaptation of @rlaager's script to retry on incorrect password entry. Reviewed-by: Richard Laager <[email protected]> Reviewed-by: Fabian Grünbichler <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Antonio Russo <[email protected]> Closes openzfs#8750 Closes openzfs#8848
Modify zfs-mount-generator to produce a dependency on new zfs-import-key-*.service units, dynamically created at boot to call zfs load-key for the encryption root, before attempting to mount any encrypted datasets. These units are created by zfs-mount-generator, and RequiresMountsFor on the keyfile, if present, or call systemd-ask-password if a passphrase is requested. This patch includes suggestions from @Fabian-Gruenbichler, @ryanjaeb and @rlaager, as well an adaptation of @rlaager's script to retry on incorrect password entry. Reviewed-by: Richard Laager <[email protected]> Reviewed-by: Fabian Grünbichler <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Antonio Russo <[email protected]> Closes openzfs#8750 Closes openzfs#8848
Modify zfs-mount-generator to produce a dependency on new zfs-import-key-*.service units, dynamically created at boot to call zfs load-key for the encryption root, before attempting to mount any encrypted datasets. These units are created by zfs-mount-generator, and RequiresMountsFor on the keyfile, if present, or call systemd-ask-password if a passphrase is requested. This patch includes suggestions from @Fabian-Gruenbichler, @ryanjaeb and @rlaager, as well an adaptation of @rlaager's script to retry on incorrect password entry. Reviewed-by: Richard Laager <[email protected]> Reviewed-by: Fabian Grünbichler <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Antonio Russo <[email protected]> Closes openzfs#8750 Closes openzfs#8848
Modify zfs-mount-generator to produce a dependency on new zfs-import-key-*.service units, dynamically created at boot to call zfs load-key for the encryption root, before attempting to mount any encrypted datasets. These units are created by zfs-mount-generator, and RequiresMountsFor on the keyfile, if present, or call systemd-ask-password if a passphrase is requested. This patch includes suggestions from @Fabian-Gruenbichler, @ryanjaeb and @rlaager, as well an adaptation of @rlaager's script to retry on incorrect password entry. Reviewed-by: Richard Laager <[email protected]> Reviewed-by: Fabian Grünbichler <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Antonio Russo <[email protected]> Closes openzfs#8750 Closes openzfs#8848
Modify zfs-mount-generator to produce a dependency on new zfs-import-key-*.service units, dynamically created at boot to call zfs load-key for the encryption root, before attempting to mount any encrypted datasets. These units are created by zfs-mount-generator, and RequiresMountsFor on the keyfile, if present, or call systemd-ask-password if a passphrase is requested. This patch includes suggestions from @Fabian-Gruenbichler, @ryanjaeb and @rlaager, as well an adaptation of @rlaager's script to retry on incorrect password entry. Reviewed-by: Richard Laager <[email protected]> Reviewed-by: Fabian Grünbichler <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Antonio Russo <[email protected]> Closes openzfs#8750 Closes openzfs#8848
Modify zfs-mount-generator to produce a dependency on new zfs-import-key-*.service units, dynamically created at boot to call zfs load-key for the encryption root, before attempting to mount any encrypted datasets. These units are created by zfs-mount-generator, and RequiresMountsFor on the keyfile, if present, or call systemd-ask-password if a passphrase is requested. This patch includes suggestions from @Fabian-Gruenbichler, @ryanjaeb and @rlaager, as well an adaptation of @rlaager's script to retry on incorrect password entry. Reviewed-by: Richard Laager <[email protected]> Reviewed-by: Fabian Grünbichler <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Antonio Russo <[email protected]> Closes openzfs#8750 Closes openzfs#8848
Modify zfs-mount-generator to produce a dependency on new zfs-import-key-*.service units, dynamically created at boot to call zfs load-key for the encryption root, before attempting to mount any encrypted datasets. These units are created by zfs-mount-generator, and RequiresMountsFor on the keyfile, if present, or call systemd-ask-password if a passphrase is requested. This patch includes suggestions from @Fabian-Gruenbichler, @ryanjaeb and @rlaager, as well an adaptation of @rlaager's script to retry on incorrect password entry. Reviewed-by: Richard Laager <[email protected]> Reviewed-by: Fabian Grünbichler <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Antonio Russo <[email protected]> Closes openzfs#8750 Closes openzfs#8848
Modify zfs-mount-generator to produce a dependency on new zfs-import-key-*.service units, dynamically created at boot to call zfs load-key for the encryption root, before attempting to mount any encrypted datasets. These units are created by zfs-mount-generator, and RequiresMountsFor on the keyfile, if present, or call systemd-ask-password if a passphrase is requested. This patch includes suggestions from @Fabian-Gruenbichler, @ryanjaeb and @rlaager, as well an adaptation of @rlaager's script to retry on incorrect password entry. Reviewed-by: Richard Laager <[email protected]> Reviewed-by: Fabian Grünbichler <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Antonio Russo <[email protected]> Closes #8750 Closes #8848
Is there any guide on how to make the above system to work? I'm trying to do the samething similar but apparently Any advice? |
@alexsmartens it used to work, but it seems it recently broke - I haven't had time to investigate yet, but looking at changes to the ZFS initramfs scripts/hooks should probably shed some light. |
Thanks @Fabian-Gruenbichler, changing |
I was able to use LUKS+ext4 encryption which can be decrypted by SSH before start all systemd services using this excellent tutorial https://blog.iwakd.de/headless-luks-decryption-via-ssh I want to do the same with ZFS native encryption (with passphrase). Note that my root partition is not encrypted (nor uses ZFS). My encryption is in another partition. For LUKS the key was For ZFS as I understand, none of this are used. So I could put a dependency for my decrypt service on the mount point, but starting the service does not make it ask for password as Is this possible? |
I've achieved the same reading https://manpages.ubuntu.com/manpages/focal/man8/zfs-mount-generator.8.html |
Why is this not mounted automatically? All the needed options are specified.
|
System information
Describe the problem you're observing
After some testing with encrypted datasets on Fedora 30, I found that encrypted datasets are not mounted automatically after reboot. That's OK if you use keylocation=prompt, but it is also happening if you use keylocation=file://.
It looks like the /usr/lib/systemd/system/zfs-mount.service file is missing the -l option to the mount command. I added the -l option to the mount command, and then my encrypted datasets are mounted automatically after reboot.
Describe how to reproduce the problem
Generate a raw key and a encrypted dataset:
After reboot verify mounted datasets:
trunk/secure is not mounted. But after running the command:
It will be.
Include any warning/errors/backtraces from the system logs
The text was updated successfully, but these errors were encountered: