Bookmark this page

Lab: Protecting Data with LUKS and NBDE

In this lab, you will create an encrypted storage device with LUKS and configure it to automatically decrypt at boot time in a secure manner using NBDE.

Outcomes

You should be able to:

  • Encrypt a partition with LUKS.

  • Decrypt a LUKS partition with multiple Tang servers.

Verify that workstation, serverb, serverc, and serverd are started.

Log in to workstation as student using student as the password. From workstation, run lab luks-review setup to verify that the environment is ready, and the Tang servers on serverc and serverd are available.

[student@workstation ~]$ lab luks-review setup
  1. Verify that an additional disk is available on serverb. In this exercise, you use this disk to create an encrypted partition.

    1. Log in to serverb as student. You do not need to enter any password.

      [student@workstation ~]$ ssh student@serverb
      [student@serverb ~]$ 
    2. Use the sudo -i command to change to the root user. Use student as the password.

      [student@serverb ~]$ sudo -i
      [sudo] password for student: student
      [root@serverb ~]# 
    3. Verify that the vdb disk is available, and has no partition.

      [root@serverb ~]# parted -l
      ...output omitted...
      Error: /dev/vdb: unrecognised disk label
      Model: Virtio Block Device (virtblk)
      Disk /dev/vdb: 1074MB
      Sector size (logical/physical): 512B/512B
      Partition Table: unknown
      Disk Flags:
  2. Create a partition on the additional disk on serverb.

    1. Use the parted command to create a partition on the additional disk on serverb. Use the whole disk for the partition.

      [root@serverb ~]# parted /dev/vdb \
      > mklabel msdos \
      > mkpart primary xfs 1M 1G
      ...output omitted...
    2. Verify that the partition is available.

      [root@serverb ~]# parted /dev/vdb print
      Model: Virtio Block Device (virtblk)
      Disk /dev/vdb: 1074MB
      Sector size (logical/physical): 512B/512B
      Partition Table: msdos
      Disk Flags:
      
      Number  Start   End     Size    Type     File system  Flags
      1      1049kB  1074MB  1073MB  primary
      
  3. Encrypt the vdb1 partition with LUKS. Use redhatRHT as the encryption password.

    1. Use the cryptsetup luksFormat command to encrypt the vdb1 partition with LUKS.

      [root@serverb ~]# cryptsetup luksFormat /dev/vdb1
      
      WARNING!
      ========
      This will overwrite data on /dev/vdb1 irrevocably.
      
      Are you sure? (Type uppercase yes): YES
      Enter passphrase: redhatRHT
      Verify passphrase: redhatRHT
  4. Open the device with a map name of encryptedvdb1.

    1. Use the cryptsetup luksOpen command to name the encrypted partition encryptedvdb1.

      [root@serverb ~]# cryptsetup luksOpen /dev/vdb1 encryptedvdb1
      Enter passphrase for /dev/vdb1: redhatRHT
    2. Verify that the partition is now available at /dev/mapper/encryptedvdb1

      [root@serverb ~]# ls /dev/mapper/encryptedvdb1
      /dev/mapper/encryptedvdb1
      
  5. Create an XFS file system on the encrypted partition, and mount this file system on the /encrypted directory. When done, create a file in that directory.

    1. Create an XFS file system on /dev/mapper/encryptedvdb1.

      [root@serverb ~]# mkfs.xfs /dev/mapper/encryptedvdb1
      meta-data=/dev/mapper/encryptedvdb1 isize=512    agcount=4, agsize=65344 blks
               =                       sectsz=512   attr=2, projid32bit=1
               =                       crc=1        finobt=0, sparse=0
      data     =                       bsize=4096   blocks=261376, imaxpct=25
               =                       sunit=0      swidth=0 blks
      naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
      log      =internal log           bsize=4096   blocks=855, version=2
               =                       sectsz=512   sunit=0 blks, lazy-count=1
      realtime =none                   extsz=4096   blocks=0, rtextents=0
    2. Create the /encrypted directory.

      [root@serverb ~]# mkdir /encrypted
    3. Mount /dev/mapper/encryptedvdb1 on the /encrypted directory.

      [root@serverb ~]# mount -t xfs /dev/mapper/encryptedvdb1 /encrypted
    4. Verify that the /dev/vdb1 partition is correctly mounted.

      [root@serverb ~]# mount | grep /encrypted
      /dev/mapper/encryptedvdb1 on /encrypted type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
      
    5. Create a file in the /encrypted directory.

      [root@serverb ~]# touch /encrypted/testfile
  6. Unmount the file system and lock the encrypted partition.

    1. Unmount the file system from /encrypted.

      [root@serverb ~]# umount /encrypted
    2. Lock the encrypted partition.

      [root@serverb ~]# cryptsetup luksClose encryptedvdb1
  7. Associate the LUKS-encrypted partition available on /dev/vdb1 with the Tang servers on serverc and serverd. Configure SSS encryption so that at least two Tang servers must be available to decrypt the partition.

    1. Install the packages required to configure serverb as a Clevis client.

      [root@serverb ~]# yum install clevis clevis-luks clevis-dracut
      ...output omitted...
      Is this ok [y/d/N]: y
      ...output omitted...
      Installed:
        clevis.x86_64 0:7-4.el7               clevis-dracut.x86_64 0:7-4.el7
        clevis-luks.x86_64 0:7-4.el7
      ...output omitted...
      Complete!
    2. Associate the LUKS-encrypted partition available on /dev/vdb1 with the Tang servers on serverc, and serverd. Configure the SSS encryption so that the two Tang servers must be available to decrypt the partition.

      [root@serverb ~]# cfg=$'{"t":2,"pins":{"tang":[\n
      > {"url":"http://serverc.lab.example.com"},\n
      > {"url":"http://serverd.lab.example.com"}]}}'
      [root@serverb ~]# clevis luks bind -d /dev/vdb1 sss "$cfg"
      The advertisement contains the following signing keys:
      
      gks_IaVo1yog0KuQei95rg_yGns
      
      Do you wish to trust these keys? [ynYN] Y
      The advertisement contains the following signing keys:
      
      vA5xAeUiKPqvkg4UyR4TemzXoAw
      
      Do you wish to trust these keys? [ynYN] Y
      You are about to initialize a LUKS device for metadata storage.
      Attempting to initialize it may result in data loss if data was
      already written into the LUKS header gap in a different format.
      A backup is advised before initialization is performed.
      
      Do you wish to initialize /dev/vdb1? [yn] y
      Enter existing LUKS password: redhatRHT
  8. Enable clevis-luks-askpass.path to support non-root LUKS-encrypted partitions.

    1. Use the systemctl enable clevis-luks-askpass.path command to enable clevis-luks-askpass.path.

      [root@serverb ~]# systemctl enable clevis-luks-askpass.path
      Created symlink from /etc/systemd/system/remote-fs.target.wants/clevis-luks-askpass.path to /usr/lib/systemd/system/clevis-luks-askpass.path.
  9. Configure the encrypted partition to automatically decrypt and mount on the /encrypted directory at boot time.

    1. Modify the /etc/crypttab file to open the encrypted partition at boot time.

      [root@serverb ~]# vi /etc/crypttab
      encryptedvdb1       /dev/vdb1  none   _netdev
    2. Update the /etc/fstab file to mount the encrypted partition on the /encrypted directory. When done, log out from serverb.

      [root@serverb ~]# vi /etc/fstab
      ...output omitted...
      /dev/mapper/encryptedvdb1   /encrypted       xfs    _netdev        1 2
      [root@serverb ~]# logout
      [student@serverb ~]$ logout
      [student@workstation ~]$ 
  10. On serverb, verify that the LUKS-encrypted partition on /dev/vdb1 is decrypted and mounted automatically on the /encrypted directory.

    1. Click ActionsShutdown for serverb to stop that virtual machine, and wait until the status for serverb is STOPPED. When done, click ActionsStart for serverb to start that virtual machine, and wait until the status for serverb is STARTED.

    2. Log in to serverb as student. You do not need to enter any password.

      [student@workstation ~]$ ssh student@serverb
      [student@serverb ~]$ 
    3. Use the sudo -i command to change to the root user. Use student as the password.

      [student@serverb ~]$ sudo -i
      [sudo] password for student: student
      [root@serverb ~]# 
    4. Verify that the encrypted partition is mounted on the /encrypted directory.

      [root@serverb ~]# mount | grep /encrypted
      /dev/mapper/encryptedvdb1 on /encrypted type xfs (rw,relatime,seclabel,attr2,inode64,noquota,_netdev)
    5. Verify that the previously created file is still available in the /encrypted directory. When done, log out from serverb.

      [root@serverb ~]# ls /encrypted
      testfile
      [root@serverb ~]# logout
      [student@serverb ~]$ logout
      [student@workstation ~]$ 
      
  11. Rotate the keys for the Tang server on serverc. Name the appropriate keys signature.jwk and exchange.jwk.

    1. Log in to serverc as student. You do not need to enter any password.

      [student@workstation ~]$ ssh student@serverc
      [student@serverc ~]$ 
    2. Use the sudo -i command to change to the root user. Use student as the password.

      [student@serverc ~]$ sudo -i
      [sudo] password for student: student
      [root@serverc ~]# 
    3. Generate new signature and exchange keys in the directory for the Tang server key database, /var/db/tang. The Tang server uses the new keys automatically for new client bindings.

      [root@serverc ~]# cd /var/db/tang
      [root@serverc tang]# jose jwk gen -i '{"alg":"ES512"}' \
      > -o signature.jwk
      [root@serverc tang]# jose jwk gen -i '{"alg":"ECMR"}' \
      > -o exchange.jwk
    4. Rename the old keys with a . as a prefix. The names of your old keys may be different. When done, log out from serverc.

      [root@serverc tang]# mv gxB7oqYiEu3zrLayhymtD10sV9E.jwk \
      > .gxB7oqYiEu3zrLayhymtD10sV9E.jwk
      [root@serverc tang]# mv k25k6PbmgUu-pWWUb210xgBelhfQ.jwk \
      > .k25k6PbmgUu-pWWUb210xgBelhfQ.jwk
      [root@serverc tang]# logout
      [student@serverc ~]$ logout
      [student@workstation ~]$ 

Evaluation

On workstation, run the lab luks-review grade command to confirm success of this exercise.

[student@workstation ~]$ lab luks-review grade

Cleanup

On workstation, run the lab luks-review cleanup script to clean up this exercise.

[student@workstation ~]$ lab luks-review cleanup

This concludes the lab.

Revision: rh415-7.5-813735c