Encryption and Security: Travis Michette
Encryption and Security: Travis Michette
Travis Michette
Version 1.3
Table of Contents
1. System Security Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2. Data Encryption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2. Using Clevis and Tang to have Network Bound Disk Encryption (NBDE) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3. Using LUKS, Clevis, and Tang to have NBDE (Putting it all Together) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
The above items are the starting points for system security. This guide will focus mainly on data security and providing some
hands-on labs which will demonstrate encrypting and decrypting of disks using LUKS. The guide will also provide a recap and
overview of system security with OpenSCAP and have a hands-on lab for generating Ansible remediation playbooks based on
SCAP compliance scans.
◦ Locked room
◦ On person
◦ etc.
◦ Password
◦ Encryption
◦ etc.
Most of the system integrity and security concepts will not be discussed as part of this demonstration. We will mainly be focusing
on the data security portion of encryption and a brief review of OpenSCAP as well as showing a hands-on demo of extending the
SCAP presentation from a previous MeetUp.
One of the most valuable portions of a system is the actual data it contains. There are many things that can be done to protect
both the system and the data. In addition to a solid backup procedure, there should be steps taken for protecting data should
someone get unauthorized access to a computer. Most newer computer systems allow for encrypting. Windows has Bitlocker,
MacOS allows for filesystem security, and Linux provides LUKS for disk encryption. There are also several other multi-platform,
third-party utilities for disk and file encryption. An older open-source encryption utility, TrueCrypt has been forked and is now
released under several names, one of which is VeraCrypt.
With the portability of thumb drives, laptops, and other devices, it is critical to have personal and private information protected
should the device become comprimised, stolen, or lost.
2. Data Encryption
LUKS uses dmcrypt in Linux as part of the kernel to interact with block storage devices and allow encryption. The
application/utility that will be used as part of the hands-on exercise is cryptsetup. The diagram in Figure 1 shows the basic
layers involved with LUKS. Fortunately, Linux has all the pieces needed to complete end-to-end encryption of block devices using
LUKS.
In the first portion of the encryption lab, we will be creating a partition and utilizing cryptsetup to prepare our disk partition to be
encryped with LUKS.
The next diagram gives shows what is contained in the LUKS header on an encrypted volume/disk. It is important to note that in
addition to the header, there are key slots which allow for multiple encryption/decryption keys to be stored.
After the creation of the LUKS volume, we will use the cryptsetup command to dump the LUKS information for the encrypted
volume to the screen.
It is a good practice to have a backup of LUKS header information in the event a volume gets damaged or
something happens to the original header. Without LUKS header backup and metadata, if something goes
wrong, the data becomes lost.
The diagram below shows a typical LUKS encryption setup in which the password and parameters can be provided all as part of
the /etc/crypttab file or have human intervention in which the end-user is prompted for a password.
For laptops or personal devices, it makes sense to prompt end-users for passwords as the device is typically easily accessible
and there are typically few devices in use. For servers, the use of LUKS prompting for passwords can present challenges as
typically servers reside in DataCenters with no keyboard/monitor. Security professionals generally frown on keeping the
decryption key on the local drive which can be accessed by anyone, but allows for the system to be booted without prompting for
a decryption password. Because of these scenarios, Network Bound Disk Encryption (NBDE) is often used as a solution for
servers in a DataCenter environment.
The first portion of the lab will be to create the encrypted volume. For the sake of time, the virtual HDDs have been already
applied to the systems and these will be used as part of the partition creation process and LUKS creation process.
Servers to Use
• servera
[root@servera ~]#
# parted /dev/vdb \
mklabel msdos \
mkpart primary xfs 1M 1G
WARNING!
========
This will overwrite data on /dev/vdb1 irrevocably.
# mkfs.xfs /dev/mapper/Encrypted_Disk
meta-data=/dev/mapper/Encrypted_Disk 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
# mkdir /EncryptedDrive
# cat /EncryptedDrive/TestFile.txt
This is a test on encrypted filesystem
# umount /EncryptedDrive
Version: 1
Cipher name: aes
Cipher mode: xts-plain64
Hash spec: sha256
Payload offset: 4096
MK bits: 256
MK digest: 5d f5 d6 77 40 25 6e d8 b8 d7 b8 34 9a d7 37 48 c4 4f a0 41
MK salt: 7e ac e3 68 3c 52 12 f5 ca cd 3d ef 42 96 cd 7e
61 52 17 c0 2e 4a ba 46 5d 4d ed c7 0a 1e 1e 72
MK iterations:
UUID:
75250
21e34e9f-0142-44ad-a628-b9934d8c2225
2.2. Using Clevis and Tang to have Network Bound Disk Encryption (NBDE)
Clevis and Tang are two complimentary services that are provided to allow Network Bound Disk Encryption (NBDE). Clevis is
considered the client while Tang is considered the server.
Terms
Clevis: Clevis is a plugable framework for automated decryption. It can be used to provide automated decryption of data or even
automated unlocking of LUKS volumes.
Tang: Server side service that Clevis connects to in order to receive a decryption key and allow the NBDE service connection.
The diagram below depicts the Clevis and Tang framework on a high-level. As seen the cryptographic interface used between the
two applications is the JOSE Crypto Library.
As part of the second portion of disk encryption labs, we will be setting up three (3) Tang servers and configuring the Clevis client
to decrypt the volume created in the first portion of the encryption lab. We will be using Shamir’s Secret Sharing (SSS) with Clevis
to have a threshold of two (2) across the three (3) Tang servers.
The threshold is how many Tang servers must supply the LUKS key before the disk can be decrypted.
The Tang packages and services must be setup and configured. As part of the demonstration and hands-on lab, you will be
installing the Tang packages and configuring servers for the service along with the Linux firewall service. In the hands-on lab
below, you will be configuring three (3) Tang servers so that Clevis can be setup to require responses from any two (2) Tang
servers.
Servers to Configure
• serverb
• serverc
• serverd
Packages to Install
• tang
# firewall-cmd --reload
Before proceeding, please repeat steps 1-3 on the remaining servers (serverc and serverd).
The Clevis client packages must be installed and setup on the server containing the encrypted LUKS device. This service allows
the server to connect to the Tang server for obtaining the network-based decryption keys.
Servers to Configure
• servera
Packages to Install
• clevis
• clevis-luks
• clevis-dracut
For this step, we are wanting to use a TANG configuration of 3 servers noting that at least two (2) of the TANG servers need to
be contacted. You could just as easily have a threshold of 1 or 3.
cfg='{"t":1,"pins":{"tang":[{"url":...},{"url":...}]}}'
Clevis can be used to bind an existing LUKS volume to its automation policy. This is accomplished with a simple
command:
# man clevis-encrypt-sss
# man clevis-luks-bind
The threshold specifies how many TANG servers must provide a key to decrypt a given LUKS volume. If
one (1) is specified as the threshold value, then as long as a single TANG server can be reached and
provides a valid key, the volume can be decrypted.
Example 14. Associate the LUKS partition and Configure Clevis to use Tang Servers
# cfg=$'{"t":2,"pins":{"tang":[\
{"url":"http://serverb.lab.example.com"},\
{"url":"http://serverc.lab.example.com"},\
{"url":"http://serverd.lab.example.com"}]}}'
9B65OW9ly08QrYjGZ5CgMv2H7XM
-IGeEyKKphOqu3-1DPtP7CN_ESw
LDGB1B4_Va1skLi7npgv-uQPryg
[root@servera ~]#
Version: 1
Cipher name: aes
Cipher mode: xts-plain64
Hash spec: sha256
Payload offset: 4096
MK bits: 256
MK digest: 12 5b 60 00 1a 90 d6 69 10 75 4d df a5 e8 f9 85 bd 22 72 1a
MK salt: 1e fd 23 69 3f a3 6d 45 82 ba 93 bc 37 dd db 33
a3 93 63 43 29 49 60 a7 ab 10 8c fd 29 a3 4b f2
MK iterations: 73500
UUID: c2ef1b5a-7c1d-4a22-be9d-4728fe9a9975
2.3. Using LUKS, Clevis, and Tang to have NBDE (Putting it all Together)
Once all the preliminary setup is done, you can setup the /etc/crypttab on the client machine as well as the /etc/fstab file to
mount the filesystem upon boot using the Clevis client and the Tang server. This is the main purpose of setting up NBDE as it
prevents the system from prompting for a password providing that the proper network requirements are met.
Servers to Configure
• servera
The /etc/crypttab file describes encrypted block devices that are set up during system boot.
# vi /etc/crypttab
Encrypted_Disk /dev/vdb1 none _netdev
# vi /etc/fstab
...output omitted...
# reboot
# ssh root@servera
System is booting up. See pam_nologin(8)
Last login: Thu Sep 6 19:40:06 2018 from 172.25.250.250
[root@servera ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10474476 1744372 8730104 17% /
devtmpfs 486060 0 486060 0% /dev
tmpfs 507768 0 507768 0% /dev/shm
tmpfs 507768 13188 494580 3% /run
tmpfs 507768 0 507768 0% /sys/fs/cgroup
/dev/mapper/Encrypted_Disk 1042084 32948 1009136 4% /EncryptedDrive
tmpfs 101556 0 101556 0% /run/user/0
Red Hat includes the SCAP Workbench application as a GUI application which allows scanning, customizing, and saving SCAP
scans and results. The SCAP Workbench can be used to perform scans of remote systems over an SSH connection or it can be
utilized to scan the local system. Since the SCAP Workbench is a GUI application, it must run on a system with X-Windows
installed.
Servers to Configure
• workstation
Packages to Install
• scap-workbench
Since we are using an application on a VM that requires a GUI, we can use X11 forwarding with the SSH
connection by specifying a -X on the command line.
The fist step is to connect to the workstation and forward X11 traffic back to the local system.
# ssh root@workstation -X
After connecting to the Workstation VM, you will need to install the SCAP Workbench and its dependencies.
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
scap-workbench x86_64 1.1.6-1.el7 rhel--server-dvd 1.8 M
Installing for dependencies:
openscap-containers noarch 1.2.16-8.el7_5 rhel_updates 27 k
openscap-scanner x86_64 1.2.16-8.el7_5 rhel_updates 61 k
openscap-utils x86_64 1.2.16-8.el7_5 rhel_updates 27 k
scap-security-guide noarch 0.1.36-9.el7_5 rhel_updates 2.6 M
Transaction Summary
================================================================================
Install 1 Package (+4 Dependent packages)
Some things might already be installed for you, if SCAP Workbench is already installed, please move
on to the next step. Also note the dependencies for SCAP Workbench as they are automatically
installed.
In order to run a scan or customize SCAP content, you will need to launch the SCAP Workbench application.
You must use SCAP Workbench from a GUI, so it will need to run either locally or through an SSH
connection with X11 forwarded.
# scap-workbench
Once SCAP Workbench has been launched, select the content to load. For this lab, we will be using the RHEL7 content.
1. For Select content to load: select "RHEL7", then click "Load Content"
3. Click "Customize" to create custom SCAP content based on the chosen profile, and give it a name.
4. Click "Deselect All" so that you can select the items you wish to include in your custom scan profile. NOTE: we are
doing this to also limit it to a few checks for the example.
For this lab, we will be setting the minimum password length and PAM Password quality settings
5. Search for Password to set minimum password length and set the values in login.defs. Check Set Password
Minimum Length in login.defs and click on the minimum password legnth and set the value to 18
6. Set password quality reqirements with PAM. Search for the minlen and set it to 18. Also, place a checkbox in Set
Password Quality Requirements with pam_quality. Then click "OK"
7. At this point, we have taken the default settings from the STIG profile with only the tailored pieces that we selected.
The next step is to click "File ⇒ Save Customization Only" to save the custom content
8. Copy the custom tailoring file to the server(s) being scanned. In this case, we will want to copy the file to serverc
Servers to Configure
• serverc
Packages to Install
• openscap-scanner
• scap-security-guide
# ssh root@serverc
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
scap-security-guide noarch 0.1.36-7.el7 rhel--server-dvd 2.6 M
Installing for dependencies:
openscap x86_64 1.2.16-6.el7 rhel--server-dvd 3.8 M
openscap-scanner x86_64 1.2.16-6.el7 rhel--server-dvd 61 k
xml-common noarch 0.6.3-39.el7 rhel--server-dvd 26 k
Transaction Summary
================================================================================
Install 1 Package (+3 Dependent packages)
Installed:
scap-security-guide.noarch 0:0.1.36-7.el7
Dependency Installed:
openscap.x86_64 0:1.2.16-6.el7 openscap-scanner.x86_64 0:1.2.16-6.el7
xml-common.noarch 0:0.6.3-39.el7
# man scap-security-guide
NAME
SCAP Security Guide - Delivers security guidance, baselines, and asso‐
ciated validation mechanisms utilizing the Security Content Automation
Protocol (SCAP).
EXAMPLES
To scan your system utilizing the OpenSCAP utility against the ospp-
rhel7 profile:
# man oscap
NAME
oscap - OpenSCAP command line tool
SYNOPSIS
oscap [general-options] module operation [operation-options-and-argu‐
ments]
DESCRIPTION
oscap is Security Content Automation Protocol (SCAP) toolkit based on
OpenSCAP library. It provides various functions for different SCAP
specifications (modules).
EXAMPLES
Evaluate XCCDF content using CPE dictionary and produce html report. In
this case we use United States Government Configuration Baseline
(USGCB) for Red Hat Enterprise Linux 5 Desktop.
We will run the oscap utility to generate a report and a results file that can be sent back to the workstation system so that we
can create an Ansible playbook for remediation and view the results of the report.
Be very careful about the name of the profile as this was selected during the creation of the custom
profile/tailoring file portion when doing SCAP Workbench customizations.
Listing 33. Using oscap and the tailoring profile to scan serverc
WARNING: This content points out to the remote resources. Use `--fetch-remote-resources' option to download them.
Title Set Password to Maximum of Consecutive Repeating Characters from Same Character Class
Rule xccdf_org.ssgproject.content_rule_accounts_password_pam_maxclassrepeat
Ident CCE-27512-3
Result fail
Rule xccdf_org.ssgproject.content_rule_accounts_password_pam_lcredit
Ident CCE-27345-8
Result fail
[root@serverc ~]#
You can create a results report file from the results file so you have a nice HTML file that is easy to ready with the results from the
SCAP scan.
Need to Specify
• --results
• --report
Listing 35. Creating a Results File and Report During Custom Content Scan
--profile xccdf_org.ssgproject.content_profile_rhel7__stig_customized \
--tailoring-file ssg-rhel7-ds-tailoring.xml \
--results custom_scan_results_2.xml \
--report Custom_Scan_Report_2.html \
/usr/share/xml/scap/ssg/content/ssg-rhel7-ds.xml
WARNING: This content points out to the remote resources. Use `--fetch-remote-resources' option to download them.
Title Set Password to Maximum of Consecutive Repeating Characters from Same Character Class
Rule xccdf_org.ssgproject.content_rule_accounts_password_pam_maxclassrepeat
Ident CCE-27512-3
Result fail
[root@serverc ~]#
After you have the results files and the report, you should transfer it to your graphical workstation (workstation) for further
analysis.
After you have transferred the results file to workstation you can open the HTML report in a web browser. In this case we will
use firefox to open the file.
Firefox may not open the file based on SELinux context triggers. In order to get around this you can
use the command prompt and do setenforce 0 to allow you to open the report.
The OpenSCAP project and content created by Red Hat can automatically remediate findings from OpenSCAP scans. The
findings can be remediated in many ways (BASH, Ansible, etc.). While things are mostly complete, there are some automated
remediations that have not yet been developed.
There are multiple automatic remediation methods developed, but at this time, there isn’t a script to fix
everything.
Servers to Configure
• serverc
We will continue to use workstation as our master SCAP system as it should have Ansible and SCAP
Workbench installed.
The first step will be to generate an Ansible playbook from the SCAP scan results for system remediation.
Version: 1.3 Encryption and Security 36
Chapter 3. System Security Policy and Compliance
- hosts: all
vars:
var_accounts_password_minlen_login_defs: 18
var_password_pam_maxrepeat: 2
var_password_pam_maxclassrepeat: 4
var_password_pam_dcredit: -1
var_password_pam_minlen: 18
var_password_pam_ucredit: -1
var_password_pam_ocredit: -1
var_password_pam_lcredit: -1
var_password_pam_difok: 8
var_password_pam_minclass: 4
tasks:
[root@workstation ~]# ansible-playbook Custom_Scan_Fix.yml
[WARNING]: provided hosts list is empty, only localhost is available. Note
that the implicit localhost does not match 'all'
This step is needed so that our Ansible system can be configured with various configuration options and the inventory files so we
can run the given playbook.
100%[======================================>] 24 --.-K/s in 0s
[root@workstation ~]#
serverc.lab.example.com
[privilege_escalation]
become=True
[root@workstation ~]#
This step will utilize the workstation system which is configured as your Ansible management node and will run the playbook to
remediate the results on the serverc system.
[root@workstation ~]#
After running the playbook, you can see that there were 10 changes that were made to the system
and exactly which parameters were changed. The next thing to do is perform another scan of the
system to ensure that it is now fully compliant.