Encrypted ZFS Filesystems On Linux

This is just a quick post about getting a fully kernel-space encrypted ZFS filesystem setup with GNU/Linux, while still keeping all the benefits of what ZFS offers. Rather than using dmcrypt and LUKS, which would bypass a lot of the features ZFS brings to the table, encryptfs is our ticket. The reason this is so elegant, is because Oracle has not released the source code to ZFS after version 28. Version 32 contains the code to create native ZFS encrypted filesystems. So, we need to rely on a 3rd party utility.

First, create your ZPOOL:

# zpool create rpool raidz1 sdb sdc sdd sde sdf

Then create your ZFS filesystem:

# zfs create rpool/private

Lastly, install the ecryptfs software, and make the encrypted filesystem by mounting it, and follow the prompts:

Notice that I enabled filename encryption, as I don't want anyone getting any of my USB drives to decipher what I'm trying to hide. This will mount the encrypted filesystem "on top" of the ZFS filesystem, allowing you to keep all the COW and error correcting goodness, while keeping your data 100% safe:

{ 21 } Comments

Yes they will. Of course they will. The eCryptfs filesystem resides "on top" of ZFS. So, as far as ZFS is concerned, it's just standard, run-of-the-mill data. It doesn't know any different. So, all of the benefits ZFS brings are still there. No compromises are made. Unlike ZFS on top of LUKS.

Is it really correct to say there are no compromises at all? Granted, any exceptions would be somewhat minimal, and without source access we don't know exactly how Oracle has chosen to implement encryption, BPR etc. But in principle it seems like some ZFS operations would work better if performed on the data as a step before encryption in the chain. It seems likely that dedup, to take Loïc's example, would be more effective if it was done and then the result was randomized rather then after the result was randomized. Compression would be useless (though that of course can get handled farther up) and I don't know if snapshots would be quite as efficient.

It's true that it's mostly transparent though, but in the end I still hope the illumos team comes through with their own native implementation as well as the improvements suggested by Delphix.

Deduplication happens at the block level, beneath ZFS. Regardless if the data is encrypted or not, deduplication is still possible. Now, granted, encrypting very similar, yet different data, can result in highly pseudorandom data. This can make data deduplication very difficult, but that doesn't change that with version 32, it's still the same problem, as it uses 256-bit AES. Same is said for compression. So, it's not eCryptFS that is causing these issues, but the disagreement in the technologies. These are the same issues you'll face with the latest version from Oracle. Regardless, the point is that ZFS knows nothing about the data it receives, only what it can do with it after the fact.

Not quite. The initialization vector is a nonce, and there is only one. It is what is responsible for kickstarting the CBC process. Further, deduplication sits underneath the encryption layer, not on top. At that level, the blocks are nothing more than zeros and ones. Now, granted, encryption algorithms are designed to mimic random data, and it is very hard to compress or deduplicate random data. With that said, it can still be done, and it's works just fine.

"Now, granted, encryption algorithms are designed to mimic random data, and it is very hard to compress or deduplicate random data. With that said, it can still be done, and it’s works just fine."

If you can compress your encrypted data, the encryption algorithm is egregiously leaking data. Same goes for deduplication - a crypto implementation that allows one to tell from ciphertext only that the plaintexts are the same is broken

Hi Aaron,
Can you help clarify what you mean by "using dmcrypt and LUKS, which would bypass a lot of the features ZFS brings to the table"? As I understand it, using LUKS would just change the underlying raw device to be an encrypted device. Since ZFS would then use that encrypted raw device, we would still be able to take advantage of all it's features. I probably am missing something so any clarification will help!

Great article! But I'm very curious, as MN, which disadvantages you get when using LUKS below ZFS. As far as I can see, dedup and compression are going to work properly with LUKS as opposed to ecryptfs. What I'm not sure about is are things like 4k sectors and such...

Hey Aaron, thanks for the post and series on ZFS. After testing eCryptfs with ZFS, I have unfortunately found a major trade-off that wasn't mentioned. When filename encryption is enabled, as is suggested, there is a limit posed on pre-encrypted filenames to be less than 143 characters in length. [1] Filenames longer than this produce an encrypted name that exceeds the length a ZFS filesystem can store for a filename (255 bytes) and worse yet, results in an unencrypted file.

Aaron, could you state which features of ZFS are bypassed if you use ZFS on top of a LUKS block device? I can think of none. However, using encryptfs on top of ZFS will prevent effective use of ZFS compression and/or deduplication.

It's not that features are bypassed. It's that you can no longer guarantee file integrity. Putting LUKS between the disk and ZFS opens up the possibility that data could get corrupt between LUKS and the disk, and ZFS would not know about it. the ZFS developers spent years closing all the bit rot holes. Putting LUKS underneath ZFS opens one up.

Aaron, A lot of people here are asking for clarification on how using zfs on top of block level encryption could impact data integrity. I am very interested as well. As I see it, LUKS would present a "plaintext" block level device to zfs and therefore any changes below LUKS would show up above. Granted changing a single bit on the physical storage could affect multiple nearby bits after decryption, this would still result in the violation of zfs checksum and initiate repair. There would probably be a bit more work to repair a single rotten bit but since bit rot is slow and rare I don't see this impacting performance too much, and the repair should still get done -especially in a raidz pool. I am really interested to know if I'm wrong and learn more about how this works.

Old hard drives will have a sector of at least 512 bytes, which is 16 times bigger than the block cipher size of AES256.

Modern hard drivers now use 4k block sectors (128 times bigger than the block cipher size of AES256)

When a hard drive is damaged and one bad sector is found you don't lose just one bit, but the whole sector.

So, there is really no difference between having dm-crypt on a hard drive or not. You are going to always lose at least one whole block sector worth of bytes, which is many times bigger than the block cipher block size.