From Fedora Project Wiki

(→‎How will I access the encrypted devices after installation? (System Startup): Add some text about using a global passphrase, change the section name slightly.)
Line 26: Line 26:
'''TODO: add a note warning against encrypting software suspend swap devices'''
'''TODO: add a note warning against encrypting software suspend swap devices'''


=== How will I access the encrypted devices after installation? (System Boot Sequence) ===
=== How will I access the encrypted devices after installation? (System Startup) ===
During system boot, you will be presented with a passphrase prompt. After the correct passphrase has been provided, the system will continue to boot normally.
During system boot, you will be presented with a passphrase prompt. After the correct passphrase has been provided, the system will continue to boot normally. If you used different passphrases for some devices you may need to enter more than one passphrase during the boot sequence.
 
{{admon/tip|Tip|Consider using the same passphrase for all encrypted block devices in a given system. This will simplify the boot sequence and you will have fewer passphrases to remember. Just make sure you choose a good passphrase!}}


=== Passphrase Discussion ===
=== Passphrase Discussion ===

Revision as of 00:31, 5 September 2008

What is block device encryption?

Block device encryption protects the data on a block device by encrypting it. To access the device's decrypted contents, a user must provide a passphrase or key as authentication. This provides additional security beyond existing OS security mechanisms in that it protects the device's contents even if it has been physically removed from the system.

Encrypting block devices using dm-crypt/LUKS

LUKS (Linux Unified Key Setup) is a specification for block device encryption. It establishes an on-disk format for the data, as well as passphrase/key management policy.

LUKS uses the kernel device mapper subsystem, via the dm-crypt module, to provide a low-level mapping that handles encryption and decryption of the device's data. User-level operations, such as creating and accessing encrypted devices, are accomplished through use of the cryptsetup utility.

Overview of LUKS

  • LUKS encrypts entire block devices
    • This makes it well-suited for protecting the contents of mobile devices:
      • Removable storage media
      • Laptop disk drives
    • The underlying contents of the encrypted block device are arbitrary.
      • This makes it useful for encrypting swap devices.
      • This can be useful with certain databases that use specially formatted block devices for data storage.
    • LUKS is not well-suited for applications requiring file-level encryption.
  • LUKS uses the existing device mapper kernel subsystem.
    • This is the same subsystem used by LVM, so it is well tested.
  • LUKS provides passphrase strengthening.
    • This protects against dictionary attacks.
  • LUKS devices contain multiple key slots.
    • This allows users to add backup keys/passphrases.
    • LUKS is not well-suited for applications requiring many (more than eight) users to have distinct access keys to the same device.

TODO: add a note warning against encrypting software suspend swap devices

How will I access the encrypted devices after installation? (System Startup)

During system boot, you will be presented with a passphrase prompt. After the correct passphrase has been provided, the system will continue to boot normally. If you used different passphrases for some devices you may need to enter more than one passphrase during the boot sequence.

Idea.png
Tip
Consider using the same passphrase for all encrypted block devices in a given system. This will simplify the boot sequence and you will have fewer passphrases to remember. Just make sure you choose a good passphrase!

Passphrase Discussion

While dm-crypt/LUKS supports both keys and passphrases, the anaconda installer only supports the use of passphrases for creating and accessing encrypted block devices during installation.

LUKS does provide passphrase strengthening, but it is still a good idea to choose a good (meaning "difficult to guess") passphrase. Note the use of the term "passphrase", as opposed to the term "password". This is intentional, and means that you should provide a phrase containing multiple words to increase the security of your data.

Creating Encrypted Block Devices in Anaconda

You can create encrypted devices during system installation. This allows you to easily configure a system with encrypted partitions, including the root partition.

What Kinds of Block Devices Can Be Encrypted?

Block devices of most types can be encrypted using LUKS. From anaconda, you can encrypt partitions, LVM physical volumes, LVM logical volumes, and software RAID arrays.

Limitations of Anaconda's Block Device Encryption Support

Filling the Device with Random Data Before Encrypting

Filling a device with random data prior to encrypting improves the strength of the encryption. However, it can take a very long time to fill the device with random data. For this reason, anaconda does not offer this option. Users who wish to perform this step can do so manually, perhaps using a kickstart %pre script. Instructions can be found here.

Using a Key Comprised of Randomly Generated Data to Access Encrypted Devices

In addition to passphrases, LUKS devices can be accessed with a key comprised of randomly generated data. Users who wish to set up one or more keys to access the encrypted devices on their systems can do so manually on the installed system or through the use of a kickstart %post script. Instructions can be found here.

Creating Encrypted Block Devices on the Installed System After Installation

You can also create and configure encrypted block devices on the system after installation.

Create the block devices

Create the block devices you wish to encrypt using parted, pvcreate, lvcreate, mdadm, &c.

Optional: Fill the device with random data

Filling <device> (eg: /dev/sda3) with random data before encrypting it greatly increases the strength of the encryption. The downside is that it can take a very long time.

Warning.png
Warning
The commands below will destroy any existing data on the device.
  • Best way, which provides high quality random data but takes a long time (several minutes per gigabyte on most systems)
    dd if=/dev/urandom of=<device>
  • Fastest way, which provides lower quality random data
    badblocks -c 10240 -s -w -t random -v <device>

Format the device as a dm-crypt/LUKS encrypted device

In this step you format <device> (eg: /dev/sda3) as a LUKS encrypted device.

Warning.png
Warning
The command below will destroy any existing data on the device.
cryptsetup luksFormat <device>
Idea.png
Tip
For more information, read the cryptsetup(8) man page.

After supplying the passphrase twice, the device should be formatted for use. To verify this, use the following command:

cryptsetup isLuks <device> && echo Success

To see a summary of the encryption information for the device, use the following command:

cryptsetup luksDump <device>

Create a mapping to allow access to the device's decrypted contents

To access the device's decrypted contents, a mapping must be established using the kernel device-mapper.

It is useful to choose a meaningful name for this mapping. LUKS provides a UUID (Universally Unique Identifier) for each device. This, unlike the device name (eg: /dev/sda3), is guaranteed to remain constant as long as the LUKS header remains intact. To find a LUKS device's UUID, run the following command:

cryptsetup luksUUID <device>

An example of a reliable, informative, and unique mapping name would be luks-<uuid>, where <uuid> is replaced with the device's LUKS UUID (eg: luks-50ec957a-5b5a-47ee-85e6-f8085bbc97a8). This naming convention might seem unwieldy, but you should not need to type it often.

cryptsetup luksOpen <device> <name>

There should now be a device node, /dev/mapper/<name>, which represents the decrypted device. This block device can be read from and written to like any other unencrypted block device.

To see some information about the mapped device, use the following command:

dmsetup info <name>
Idea.png
Tip
For more information, read the dmsetup(8) man page.

Create filesystems on the mapped device, or continue to build complex storage structures using the mapped device

Just use the mapped device node (/dev/mapper/<name>) as you would use any other block device. To create an ext2 filesystem on the mapped device, use the following command:

mke2fs /dev/mapper/<name>

To mount this filesystem on /mnt/test, use the following command:

Important.png
Important
The directory /mnt/test must exist before executing this command.
mount /dev/mapper/<name> /mnt/test

Add the mapping information to /etc/crypttab

In order for the system to set up a mapping for the device, an entry must be present in the /etc/crypttab file. If you are creating the file it should be owned by root (root:root) and should have mode 0744. Add a line of the following form the the file:

<name>  <device>  none

The <device> field should be given in the form "UUID=<luks_uuid>", where <luks_uuid> is the LUKS uuid as given by the command cryptsetup luksUUID <device>. This ensures the correct device will be identified and used even if the device node (eg: /dev/sda5) changes.

Idea.png
Tip
For details on the format of the /etc/crypttab file, read the crypttab(5) man page.

Add an entry to /etc/fstab

Add an entry to /etc/fstab, if desired, to establish a persistent association between the device and a mountpoint. Be sure to use the decrypted device, /dev/mapper/<name>.

In many cases it is desirable to list devices in /etc/fstab by UUID or by a filesystem label. The main purpose of this is to provide a constant identifier in the even that the device name (eg: /dev/sda4) changes. Since the LUKS device names are based solely on the LUKS UUID, device names of the form /dev/mapper/luks-<luks_uuid> are guaranteed to remain constant, and are therefore suitable for use in /etc/fstab.

Idea.png
Tip
For details on the format of the /etc/fstab file, read the fstab(5) man page.

Common Post-Installation Tasks

Set a randomly generated key as an additional way to access an encrypted block device

Generate a key

This will generate a 256-bit key in the file $HOME/keyfile.

dd if=/dev/urandom of=$HOME/keyfile bs=32 count=1
chmod 600 $HOME/keyfile

Add the key to an available keyslot on the encrypted device

cryptsetup luksAddKey <device> ~/keyfile

Add a new passphrase to an existing device

cryptsetup luksAddKey <device>

After being prompted for any existing passprase for the device for authentication, you will be prompted to enter the new passphrase.

Remove a passphrase or key from a device

cryptsetup luksRemoveKey <device>

You will be prompted for the passphrase you wish to remove, and then for any remaining passphrase for authentication.