Skip to content
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

zfs: refactor - adding new option for support of new native encryption format #34559

Closed
wants to merge 9 commits into from

Conversation

sjau
Copy link

@sjau sjau commented Feb 3, 2018

Motivation for this change

In zfsUnstable there's native encryption available for zfs. However this has some issues and there was a stability patch applied to it on feb 2. That stability patch however forces a new dataset format. Meaning old datasets can only be mounted in read-only mode.

Because of that I did add a new option for the configuration.nix: boot.zfs.enableCryptoStability = true; (probably should use a better name but couldn't think of it - feel free to make sugestions). This will use latest zfs/spl master with the included stability patches.

Also, I had to update Mic92's patch for NixOS.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

other encrypted mounts, you will probably need to convert them to new
format as well first.
If you have encrypted your root dataset you will need to nuke it
and re-create completely anew.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, this should not be in the option description. The option description should specify what it does and the caveat about backwards compatibility, but then link elsewhere for migration details.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to invert option instead to help users to migrate: #34559 (comment)

@adisbladis
Copy link
Member

adisbladis commented Feb 3, 2018

Thanks for your PR.

I'm not so sure this is the right approach. This format change is in upstream master and will sooner or later land in the zfsUnstable nix package.

@sjau
Copy link
Author

sjau commented Feb 3, 2018

@adisbladis

My thinking is that the format change requires quite some action... existing datasets can't be used anymore. E.g. someone has the nixos root installation in an encrypted dataset. At some point in the boot process it will stop booting (after entering password though). So if it gets added to unstable now and someone just upgrades they might now know where the problem is.

Hence I think some time should be given for those that do not want to make the format change just now.

E.g. in my situation I only have about 100 GB left on my disk but one dataset is 500GB in size... I need to send it first somewhere else, delete the existing one and reimport it... it just takes time and it could take a lot of time for bigger setups.

@@ -75,6 +79,23 @@ in
'';
};

enableCryptoStability = mkOption {
type = types.bool;
default = false;
Copy link
Member

@Mic92 Mic92 Feb 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options should be inverted here and provide an option to use the old version instead. We want new users to receive the new version by default - otherwise they have to migrate later.
Therefore, enableCryptoStability should be named enableLegacyCryptoVersion.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did make those changes now. I also altered description for the config options accordingly.

@@ -175,4 +176,28 @@ in {

spl = splUnstable;
};

zfsCryptoStability = common {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be zfsUnstable. The other version should be called zfsLegacyCrypto.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have switched between unstable and CryptoStability (now LegacyCrypto)

@Mic92
Copy link
Member

Mic92 commented Feb 3, 2018

I will write a mailing-list announcement before merging this.

default = false;
description = ''
Enabling this option will allow you to continue to use the old format for
encrypted datasets. With the inclusion of stabiity patches the format of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/stabiity/stability/

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed :)

@sjau
Copy link
Author

sjau commented Feb 5, 2018

I just udpate the legacy versions to their latest commit before the merge of the encryption stability patch.

extraPatches = [
# Mic92's patch updated for current zfs master
(fetchpatch {
url = "https://raw.githubusercontent.com/sjau/nix-expressions/master/customPatches/nixos-zfs-2018-02-02.patch";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will refactor this into my branch.

@Mic92 Mic92 closed this in 0d65e2e Feb 7, 2018
@Mic92
Copy link
Member

Mic92 commented Dec 8, 2018

As we already removed the legacy zfs version. I will also cleanup the wiki text for it. In case someone still needs it. I leave a copy here:

== Encrypted Dataset Format Change ==

The introduction of native encryption on ZFS was highly anticipated. However since it was introduced, there have been various issues discovered. Due to this, a rather large patch containing many fixes was merged into master, see https://github.com/zfsonlinux/zfs/pull/6864 for more information.

However this leads to a format change of the encrypted datasets. As a result of this format change, encrypted datasets that were created by older zfs versions can only be mounted as read-only. Encrypted datasets created with the new format cannot be opened at all on older versions. Unencrypted datasets were not altered and work as before.

If you've followed this wiki entry and didn't create an encrypted top-level dataset but a child-dataset, e.g. <code>zroot/root/nixos</code> where <code>zroot</code> is the name of the pool and the top-level dataset and <code>root</code> is the encrypted child-dataset, then you can easily use zfs send/recv to migrate it to the new format.

# Create a custom NixOS iso with crypto stability patch applied
# Boot into that live environment
# Import the pool and load the key
# Create a new encrypted dataset, e.g.<br/><code>zfs create -o encryption=aes-256-gcm -o keyformat=passphrase -o mountpoint=none zroot/rootNEW</code>
# Use zfs send and receive to copy the data to new format:<br/><code>zfs send zpool/root/nixos | zfs receive zpool/rootNew/nixos</code>
# Set correct mountpoint for the newly created dataset:<br/><code>zfs set moutpoint=legacy zpool/root/New/nixos</code>
# Rename the old and new datasets:<br/><code>zfs rename zpool/root zpool/rootOLD</code><br/><code>zfs rename zpool/rootNEW zpool/root</code>
# That should allow to boot Nixos already with new format. If you have other encrypted mounts, you will probably need to convert them to new format as well first.

It's also recommended to have two usb sticks available. One custom iso with the old zfs format and one with the new one. So you can easily switch between them.

If you don't have enough free space to move a dataset completely, you can just use both usb sticks to boot either version and transfer files partially by rsync like this:

# Boot usb with stability patches applied
# Import the pool and load the key
# Create a new encrypted dataset, e.g.<br/><code>zfs create -o encryption=aes-256-gcm -o keyformat=passphrase -o mountpoint=legacy zroot/mediaNEW</code>
# Mount the format one and the new format one, e.g. <br/><code>mkdir -p /mtn/media{OLD,NEW}</code><br/><code>mount -o ro -t zfs zroot/media /mnt/mediaOLD</code><br/><code>mount -t zfs zroot/mediaNEW /mnt/mediaNEW</code>
# Once mounted, you can use rsync to transfer (part) of the data:<br/><code>rsync -avp /mnt/mediaOLD/Music /mnt/mediaNew/</code><br/>Notice: In the source folder there's no trailing "/" so that in the destination location provided that whole folder will be created. Of course you can also just start with a sub folder if one is too big.
# Rsync (or copy) over as much data as you can. Since the old format dataset can only be mounted as read-only, you'll have to boot into the other usb stick with the old format, mount the old media folder and delete files in there. You may also need to delete snapshots first.
# Afterwards boot again into the new format usb stick and repeat.

Of course if there's no sensitive data that needs encryption, you can just boot up into the old format, create a new, non-encrypted dataset and start moving files over. Once done, boot into new format, create an encrypted pool and move files over again.

@sjau
Copy link
Author

sjau commented Dec 8, 2018

Sounds good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants