Encrypted Raid1 or Raid 1 of encrypted devices?
Hello,
I have 2 disks currently as a RAID1, and want to encrypt it. I've done several tests with loopback devices, and found that I can either create a raid1 with the raw devices, and then encrypt the /dev/md device, eg:
losetup /dev/loop1 /tmp/a
losetup /dev/loop2 /tmp/b
mdadm --create /dev/md3 --level=1 /dev/loop1 /dev/loop2 --raid-devices=2
cryptsetup luksFormat /dev/md3
cryptsetup luksOpen /dev/md3 md3
or instead encrypt each device, and then make the 2 encrypted devices into a raid, eg:
losetup /dev/loop3 /tmp/c
losetup /dev/loop4 /tmp/d
cryptsetup luksFormat /dev/loop3
cryptsetup luksFormat /dev/loop4
cryptsetup luksOpen /dev/loop3 data3
cryptsetup luksOpen /dev/loop4 data4
mdadm --create /dev/md4 --level=1 /dev/mapper/data3 /dev/mapper/data4 --raid-devices=2
Is there a recommended way to do this?
I've read the FAQ, especially the part about bad RAM, how single bit flip errors get amplified - would that mean encrypting each disk separately is safer, because a bit flip error would be only be copied to only one device instead of both? If that happened and a verification test spotted it, I could remove each device in turn to find which has the corruption, and repair it. I am planning on running the full set of RAM tests anyway. Is there any reason not to encrypt each device separately, or any other general advice here?
Thanks,
Laurence
Quoted 1 line · Laurence Darby
Is there a recommended way to do this?
Hello Laurence,
That's an interesting question: encrypted raid1 or raid1 of encrypted disks? That also could be phrased as "dm-crypt on top of dm-raid" or "dm-raid on top of dm-crypt"?
I must admit I would have never thought about a "raid1 of encrypted disks" (seems awkward) but apparently it works. I'm new here (and to disk encryption at all) but here are my two cents:
# Performance
I guess from the point of view of performance (CPU-wise) , an "encrypted RAID1" would be better as you would be only encrypting once and DM-raid will take care of copying those bits as they are to the 2nd disk. I suggest you do some tests (copying large amount of data to the encrypted disk) and measure it.
# Management
There's no doubt that an encrypted raid1 is much better (much less
commands: you just need to format once, luksOpen once, luksClose once. one backup of the header)
# Reliability
I'm not sure about this part. Let's see what others have to say regarding this.
Regards,
Jorge
Quoted 7 lines · Jorge Fábregas
That's an interesting question: encrypted raid1 or raid1 of encrypted disks? That also could be phrased as "dm-crypt on top of dm-raid" or "dm-raid on top of dm-crypt"?
I must admit I would have never thought about a "raid1 of encrypted disks" (seems awkward) but apparently it works. I'm new here (and to disk encryption at all) but here are my two cents:
Technically both works.
Quoted 6 lines
# Performance
I guess from the point of view of performance (CPU-wise) , an "encrypted RAID1" would be better as you would be only encrypting once and DM-raid will take care of copying those bits as they are to the 2nd disk. I suggest you do some tests (copying large amount of data to the encrypted disk) and measure it.
This depends on kernel version and if the system is SMP/multi-cpu. For <2.6.38 you may get better performance for raid over crypt, for newer kernel it will be different.
(I am not saying better because there are still performance issues with crypt over MD Raid. Depends on io pattern and if IO are issued from different cpus or not. Like dd can be slower but threaded fs test can have much more better performance.)
Quoted 4 lines
# Management
There's no doubt that an encrypted raid1 is much better (much less
commands: you just need to format once, luksOpen once, luksClose once. one backup of the header)
yes, I would suggest crypt over MD always too.
Quoted 3 lines
# Reliability
I'm not sure about this part. Let's see what others have to say regarding this.
IMHO both solutions are similar here. Some errors are propagated, hw failure (RAM, disk) would have similar effect.
RAID is not backup. You should backup LUKS header and data anyway.
Milan
Quoted 10 lines · Milan Broz
Quoted 7 lines · Jorge F?bregas
That's an interesting question: encrypted raid1 or raid1 of encrypted disks? That also could be phrased as "dm-crypt on top of dm-raid" or "dm-raid on top of dm-crypt"?
I must admit I would have never thought about a "raid1 of encrypted disks" (seems awkward) but apparently it works. I'm new here (and to disk encryption at all) but here are my two cents:
Technically both works.
Technically, RAID and encryption are on the same layer of the storage system and you can do arbitrary conbinations.
Quoted 15 lines
Quoted 6 lines
# Performance
I guess from the point of view of performance (CPU-wise) , an "encrypted RAID1" would be better as you would be only encrypting once and DM-raid will take care of copying those bits as they are to the 2nd disk. I suggest you do some tests (copying large amount of data to the encrypted disk) and measure it.This depends on kernel version and if the system is SMP/multi-cpu. For <2.6.38 you may get better performance for raid over crypt, for newer kernel it will be different.
(I am not saying better because there are still performance issues with crypt over MD Raid. Depends on io pattern and if IO are issued from different cpus or not. Like dd can be slower but threaded fs test can have much more better performance.)
Quoted 6 lines
Quoted 4 lines
# Management
There's no doubt that an encrypted raid1 is much better (much less
commands: you just need to format once, luksOpen once, luksClose once. one backup of the header)yes, I would suggest crypt over MD always too.
Good point. And you ned to enter your passphrase twice, exposing it more.
The main difference security-wise is that an attacker gets the same data-set encrypted with two different keys when RAIDing encrypted devices. That can be a concern.
Quoted 6 lines
Quoted 3 lines
# Reliability
I'm not sure about this part. Let's see what others have to say regarding this.IMHO both solutions are similar here. Some errors are propagated, hw failure (RAM, disk) would have similar effect.
Reliability with regard to data corryption really belongs into the filesystem-layer and above and into the hysocal device layer.
RAID seems to be reliability, but in fact it is redundancy only, and detection of errors (bit errors, unreadable sectors and dead disks) is done below (or for bit-errors possibly in the filesystem-layer with a checksumming FS). The RAID cannot detect errors, it can just react to errors reported by lower layers using the redundancy it provides.
One exception: It can do consistency checks, but it can only do somethign about inconsistencioes if it is at least 3-way redundant by voting, i.e. >= 3-way RAID1 or RAID6. And consistency checks are not a normal RAID operation, but rather an externally triggered RAID maintenance operation.
Quoted 1 line
RAID is not backup. You should backup LUKS header and data anyway.
Indeed. See FAQ ;-)
Arno
Signature · 7 lines
Arno Wagner, Dr. sc. techn., Dipl. Inform., CISSP -- Email: [email protected] GnuPG: ID: 1E25338F FP: 0C30 5782 9D93 F785 E79C 0296 797F 6B50 1E25 338F ---- Cuddly UI's are the manifestation of wishful thinking. -- Dylan Evans If it's in the news, don't worry about it. The very definition of "news" is "something that hardly ever happens." -- Bruce Schneier
Hi Arno, All,
Thanks very much for your comments, I'll definitely go with encrypting the RAID.
Quoted 11 lines · Arno Wagner
Quoted 10 lines · Milan Broz
Quoted 8 lines · Jorge F?bregas
That's an interesting question: encrypted raid1 or raid1 of encrypted disks? That also could be phrased as "dm-crypt on top of dm-raid" or "dm-raid on top of dm-crypt"?
I must admit I would have never thought about a "raid1 of encrypted disks" (seems awkward) but apparently it works. I'm new here (and to disk encryption at all) but here are my two cents:
Quoted 20 lines
Quoted 1 line
Technically both works.
Technically, RAID and encryption are on the same layer of the storage system and you can do arbitrary conbinations.
Quoted 15 lines
Quoted 6 lines
# Performance
I guess from the point of view of performance (CPU-wise) , an "encrypted RAID1" would be better as you would be only encrypting once and DM-raid will take care of copying those bits as they are to the 2nd disk. I suggest you do some tests (copying large amount of data to the encrypted disk) and measure it.This depends on kernel version and if the system is SMP/multi-cpu. For <2.6.38 you may get better performance for raid over crypt, for newer kernel it will be different.
(I am not saying better because there are still performance issues with crypt over MD Raid. Depends on io pattern and if IO are issued from different cpus or not. Like dd can be slower but threaded fs test can have much more better performance.)
Yes, I noticed this - a single dd process has to wait for both the encryption and then IO, so more processes are needed to fill the pipeline.
There's not much of a performance difference anyway - I have a 2 core machine, and found that both disks (loopback files) got encrypted at the same time (top showed 2 kworker processes, each using 80% cpu, the rest mostly waiting on IO.)
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
# Management
There's no doubt that an encrypted raid1 is much better (much less
commands: you just need to format once, luksOpen once, luksClose once. one backup of the header)
Quoted 10 lines
Quoted 1 line
yes, I would suggest crypt over MD always too.
Good point. And you ned to enter your passphrase twice, exposing it more.
The main difference security-wise is that an attacker gets the same data-set encrypted with two different keys when RAIDing encrypted devices. That can be a concern.
Thank you for pointing that out - it's exactly the kind of thing I wasn't aware of but should be.
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
# Reliability
I'm not sure about this part. Let's see what others have to say regarding this.IMHO both solutions are similar here. Some errors are propagated, hw failure (RAM, disk) would have similar effect.
Reliability with regard to data corryption really belongs into the filesystem-layer and above and into the hysocal device layer.
Quoted 14 lines
RAID seems to be reliability, but in fact it is redundancy only, and detection of errors (bit errors, unreadable sectors and dead disks) is done below (or for bit-errors possibly in the filesystem-layer with a checksumming FS). The RAID cannot detect errors, it can just react to errors reported by lower layers using the redundancy it provides.
One exception: It can do consistency checks, but it can only do somethign about inconsistencioes if it is at least 3-way redundant by voting, i.e. >= 3-way RAID1 or RAID6. And consistency checks are not a normal RAID operation, but rather an externally triggered RAID maintenance operation.Quoted 1 line
RAID is not backup. You should backup LUKS header and data anyway.
This RAID1 is my backup device, that I do daily rsync-snapshots to. I'll admit, I'm not doing automated integrity checks yet, I know I should be, but encryption is more fun :)
I was thinking that with a RAID of encrypted devices, rather than the encrypted RAID, that I wouldn't need a header backup - If I break one, that mistake isn't immediately written to both drives, so I can just reformat it, and rebuild the array. Although, yes, just restoring a header backup does sound a lot easier, and after what Arno said above, it's not feasible anyway.
I'll reply to the other thread tomorrow, bedtime now.
Thanks,
Laurence
Hi Laurence,
for security reasons, encrypt the RAID1. Otherwise you a re giving an attacker more data, namely everything encrypted with two different keys.
For Performance reasons, the same. If you RAID1 encrypted disk, everything has to be encrypted twice, if you encrypot the RAID1, all data is encrypted only once, halving the effort.
Quoted 25 lines · Laurence Darby
Hello,
I have 2 disks currently as a RAID1, and want to encrypt it. I've done several tests with loopback devices, and found that I can either create a raid1 with the raw devices, and then encrypt the
/dev/mddevice, eg:losetup
/dev/loop1/tmp/a
losetup/dev/loop2/tmp/bmdadm --create
/dev/md3--level=1/dev/loop1/dev/loop2--raid-devices=2cryptsetup luksFormat
/dev/md3
cryptsetup luksOpen/dev/md3md3or instead encrypt each device, and then make the 2 encrypted devices into a raid, eg:
losetup
/dev/loop3/tmp/c
losetup/dev/loop4/tmp/dcryptsetup luksFormat
/dev/loop3
cryptsetup luksFormat/dev/loop4
Quoted 8 lines
cryptsetup luksOpen
/dev/loop3data3
cryptsetup luksOpen/dev/loop4data4mdadm --create
/dev/md4--level=1/dev/mapper/data3/dev/mapper/data4--raid-devices=2Is there a recommended way to do this?
See abofe, place encryption direcly below the filesystem and above any RAID/LVM,... mechanism.
Quoted 1 line
I've read the FAQ,
Very good!
Quoted 4 lines
especially the part about bad RAM, how single bit
flip errors get amplified - would that mean encrypting each disk separately is safer, because a bit flip error would be only be copied to only one device instead of both?
Good thinking, but no. It has zero advantage having one good and one corrupted copy, but no way to tell which is which. If you have bit-errors, you have a najor problem. If they get amplified, the main difference is that you may detect them eralier, which is an advantage.
Quoted 3 lines
If that happened and a
verification test spotted it, I could remove each device in turn to find which has the corruption, and repair it.
A RAID consistency check would spot it,but how would you identify the good copy? And if the bit-error does hapen before encryption, this does not help at all. In addition, as encryption does run mainly in the CPU caches, bit errors are not very likely there anyways.
Quoted 3 lines
I am planning on running
the full set of RAM tests anyway. Is there any reason not to encrypt each device separately, or any other general advice here?
See above. Don't worry about adapting your disk encryption to the possibility of bit-errors. These are separate issues and should not be mixed.
Waht you should do with regard tobit-errors is whenever you copy something large or archive something large or do backups, always do a verify that compares the data. This is the best way to detect errors and ensure data integrity. For small writes, bit errors are very, very unlikely, unless your system is extremely instable.
I think I will add a section on encryption vs. RAID in the FAQ.
Arno
Signature · 7 lines
Arno Wagner, Dr. sc. techn., Dipl. Inform., CISSP -- Email: [email protected] GnuPG: ID: 1E25338F FP: 0C30 5782 9D93 F785 E79C 0296 797F 6B50 1E25 338F ---- Cuddly UI's are the manifestation of wishful thinking. -- Dylan Evans If it's in the news, don't worry about it. The very definition of "news" is "something that hardly ever happens." -- Bruce Schneier