This course is using an outdated version of the technology and is now considered to be Legacy content. It will be removed from our catalog on June 28, 2024. Please be sure to complete your course and finish any remaining labs before that date. We recommend moving to version 9.2, which is the latest version currently available.
Performance Checklist
In this lab, you will selectively control which USB devices may access or be accessed by the system, using USBGuard.
Outcomes
You should be able to:
Create a permanent USBGuard policy that allows a specific USB device to interact with the system.
Generate a base policy that will maintain currently defined policies and ignore any additional USB devices that attempt to connect to the system.
Use command-line tools such as usbguard, lsblk, and others to confirm USB device access policies.
Verify that the workstation and usbguard virtual machines are started.
Log in to workstation as student using student as the password.
On workstation, run lab usb-review setup to ensure that the environment is ready.
[student@workstation ~]$lab usb-review setup
On workstation, ensure that the usbguard virtual machine (VM) is running.
Open the usbguard VM console and log in as user student with student as the password.
On workstation, use the sudo -i command to switch identity to the root user.
Use student as the password.
[student@workstation ~]$sudo -i[sudo] password for student:student[root@workstation ~]#
Use the virsh list --all command to determine the usbguard VM status.
[root@workstation ~]#virsh list --allId Name State ---------------------------------------------------- - usbguard shut off
If the usbguard VM is not running, use the virsh start command with the VM name to start it.
[root@workstation ~]#virsh start usbguardDomain usbguard started
Allow the usbguard VM about two minutes to complete the startup process.
Use the virsh console command with the VM name to access its console interface.
If the console delays in displaying the login prompt, hit the Enter key to proceed to the prompt.
[root@workstation ~]#virsh console usbguardConnected to domain usbguard Escape character is ^]<Enter>Red Hat Enterprise Linux Server 7.5 (Maipo) Kernel 3.10.0-862.3.2.el7.x86_64 on an x86_64localhost login:studentPassword:student[student@localhost ~]$
On the usbguard VM, install the RPM packages used to configure, control, and manage USB device access.
Use the sudo -i command to switch identity to the root user.
Use student as the password.
[student@localhost ~]$sudo -i[sudo] password for student:student[root@localhost ~]#
Use YUM to install usbguard, usbutils, and udisks2 packages.
[root@localhost ~]#yum install usbguard usbutils udisks2...output omitted...Is this ok [y/d/N]:y...output omitted... Complete![root@localhost ~]#
Start the USBGuard service and configure it to persist across reboots. Run the usbguard list-devices command to list the default devices.
Configure the usbguard service to persist across reboots.
[root@localhost ~]#systemctl enable usbguard --nowCreated symlink from /etc/systemd/system/basic.target.wants/usbguard.service to /usr/lib/systemd/system/usbguard.service.
Use the usbguard list-devices command to list all USB devices recognized by USBGuard.
[root@localhost ~]#usbguard list-devices1: allow id 1d6b:0002 serial "0000:00:04.7" name "EHCI Host Controller" hash "CsKOZ6IY8v3eojsc1fqKDW84V+MMhD6HsjjojcZBjSg=" parent-hash "qiR4Ubbd7AIXLCz201hJYzaO9KIrOvqqRgqs2vM2NOY=" via-port "usb1" with-interface 09:00:00 2: allow id 1d6b:0001 serial "0000:00:04.0" name "UHCI Host Controller" hash "sKXn6PthDDlGgdxZHdnlUQ9DROkH/YSojkBlfpcnsaU=" parent-hash "VC8ZB6FZ51WMN42QA3CqGvK9+eLDu4jpdgzSwLFn+fs=" via-port "usb2" with-interface 09:00:00 3: allow id 1d6b:0001 serial "0000:00:04.1" name "UHCI Host Controller" hash "6t6CPSS/v2EqQwsw6CMq8DVfOhgUGO2f+bEBX7R2yz0=" parent-hash "0JRYS5mysCKe92s8So5WC7cbttP3haCBtScjU64BJs0=" via-port "usb3" with-interface 09:00:00 4: allow id 1d6b:0001 serial "0000:00:04.2" name "UHCI Host Controller" hash "BSaNQWADaBI31jUqbck0N56uRuh3uVT1Vk4rdoD0ghs=" parent-hash "prVi21GR+cpMC0ykIE8H9TC9QoaAkFrbmw2PLcWNGkw=" via-port "usb4" with-interface 09:00:00
Set a permanent USBGuard policy to allow the RED USB device access to the system.
From workstation, open a second terminal session and attach the RED USB device (usb-disk-red.img) to the usbguard VM and record its device ID number:
[student@workstation ~]$sudo virsh attach-device usbguard \>/home/student/RH415/labs/usb-controlling/usb-disk-red.xml[sudo] password for student:studentDevice attached successfully
On the virsh console terminal, connected to usbguard VM, you will see kernel messages indicating that the RED USB device is not authorized for usage.
Press Enter to return to the command prompt.
[13865.418288] usb 1-1: new high-speed USB device number 4 using ehci-pci [13865.544834] usb 1-1: New USB device found, idVendor=46f4, idProduct=0001 [13865.548156] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [13865.552218] usb 1-1: Product: QEMU USB HARDDRIVE [13865.554899] usb 1-1: Manufacturer: QEMU [13865.557623] usb 1-1:SerialNumber: RED[13865.560922] usb 1-1:Device is not authorized for usageEnter[root@localhost ~]#
From the usbguard VM, list the blocked USB devices and record the device number for the RED USB device.
The device number (5 on this system) may be different on your system.
[root@localhost ~]#usbguard list-devices --blocked5: block id 46f4:0001 serial "RED"name "QEMU USB HARDDRIVE" hash "AKmuakTNktSfF54t2IHFRMaukoUw47v3lu/9ZebOsNo=" parent-hash "CsKOZ6IY8v3eojsc1fqKDW84V+MMhD6HsjjojcZBjSg=" via-port "1-1" with-interface 08:06:50
On usbguard VM, use the usbguard allow-device -p 5 command to add a permanent allow rule target for the RED USB device.
[root@localhost ~]#usbguard allow-device -p 5[40641.494327] usb 1-1: authorized to connect ...output omitted...Enter[root@localhost ~]#
Restart the usbguard services to ensure the USBGuard daemon loads the /etc/usbguard/rules.conf file.
[root@localhost ~]#systemctl restart usbguard
Run the usbguard list-rules command to list persistent rules and ensure that the RED USB device is listed. Rule numbers may vary.
[root@localhost ~]#usbguard list-rules6: allow id 46f4:0001 serial "RED"name "QEMU USB HARDDRIVE" hash "AKmuakTNktSfF54t2IHFRMaukoUw47v3lu/9ZebOsNo=" parent-hash "CsKOZ6IY8v3eojsc1fqKDW84V+MMhD6HsjjojcZBjSg=" with-interface 08:06:50
List the devices to ensure that the RED USB device has a target policy of allow.
[root@localhost ~]#usbguard list-devices1: allow id 1d6b:0002 serial "0000:00:04.7" name "EHCI Host Controller" hash "CsKOZ6IY8v3eojsc1fqKDW84V+MMhD6HsjjojcZBjSg=" parent-hash "qiR4Ubbd7AIXLCz201hJYzaO9KIrOvqqRgqs2vM2NOY=" via-port "usb1" with-interface 09:00:00 2: allow id 1d6b:0001 serial "0000:00:04.0" name "UHCI Host Controller" hash "sKXn6PthDDlGgdxZHdnlUQ9DROkH/YSojkBlfpcnsaU=" parent-hash "VC8ZB6FZ51WMN42QA3CqGvK9+eLDu4jpdgzSwLFn+fs=" via-port "usb2" with-interface 09:00:00 3: allow id 1d6b:0001 serial "0000:00:04.1" name "UHCI Host Controller" hash "6t6CPSS/v2EqQwsw6CMq8DVfOhgUGO2f+bEBX7R2yz0=" parent-hash "0JRYS5mysCKe92s8So5WC7cbttP3haCBtScjU64BJs0=" via-port "usb3" with-interface 09:00:00 4: allow id 1d6b:0001 serial "0000:00:04.2" name "UHCI Host Controller" hash "BSaNQWADaBI31jUqbck0N56uRuh3uVT1Vk4rdoD0ghs=" parent-hash "prVi21GR+cpMC0ykIE8H9TC9QoaAkFrbmw2PLcWNGkw=" via-port "usb4" with-interface 09:00:005: allow id 46f4:0001 serial "RED"name "QEMU USB HARDDRIVE" hash "AKmuakTNktSfF54t2IHFRMaukoUw47v3lu/9ZebOsNo=" parent-hash "CsKOZ6IY8v3eojsc1fqKDW84V+MMhD6HsjjojcZBjSg=" via-port "1-1" with-interface 08:06:50
From workstation, open a second terminal session and attach the BLUE USB device to the usbguard VM.
Confirm that the BLUE USB device is blocked from interacting with the usbguard VM.
Attach the BLUE USB device (usb-disk-blue.img) to the usbguard VM.
[student@workstation ~]$sudo virsh attach-device usbguard \>/home/student/RH415/labs/usb-controlling/usb-disk-blue.xmlDevice attached successfully
On the virsh console terminal, connected to usbguard VM, you will see kernel messages indicating that the BLUE USB device is not authorized for usage.
Press Enter to return to the command prompt.
[16334.781286] usb 1-2: new high-speed USB device number 5 using ehci-pci [16334.908460] usb 1-2: New USB device found, idVendor=46f4, idProduct=0001 [16334.912567] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [16334.917532] usb 1-2: Product: QEMU USB HARDDRIVE [16334.921468] usb 1-2: Manufacturer: QEMU [16334.923748] usb 1-2:SerialNumber: BLUE[16334.927286] usb 1-2:Device is not authorized for usageEnter[root@localhost ~]#
From the usbguard VM, list the USB devices to confirm that the RED USB device has a rule target of allow and the BLUE USB device has a rule target of block.
The device numbers (5 and 7 on this system) may be different on your system.
[root@localhost ~]#usbguard list-devices1: allow id 1d6b:0002 serial "0000:00:04.7" name "EHCI Host Controller" hash "CsKOZ6IY8v3eojsc1fqKDW84V+MMhD6HsjjojcZBjSg=" parent-hash "qiR4Ubbd7AIXLCz201hJYzaO9KIrOvqqRgqs2vM2NOY=" via-port "usb1" with-interface 09:00:00 2: allow id 1d6b:0001 serial "0000:00:04.0" name "UHCI Host Controller" hash "sKXn6PthDDlGgdxZHdnlUQ9DROkH/YSojkBlfpcnsaU=" parent-hash "VC8ZB6FZ51WMN42QA3CqGvK9+eLDu4jpdgzSwLFn+fs=" via-port "usb2" with-interface 09:00:00 3: allow id 1d6b:0001 serial "0000:00:04.1" name "UHCI Host Controller" hash "6t6CPSS/v2EqQwsw6CMq8DVfOhgUGO2f+bEBX7R2yz0=" parent-hash "0JRYS5mysCKe92s8So5WC7cbttP3haCBtScjU64BJs0=" via-port "usb3" with-interface 09:00:00 4: allow id 1d6b:0001 serial "0000:00:04.2" name "UHCI Host Controller" hash "BSaNQWADaBI31jUqbck0N56uRuh3uVT1Vk4rdoD0ghs=" parent-hash "prVi21GR+cpMC0ykIE8H9TC9QoaAkFrbmw2PLcWNGkw=" via-port "usb4" with-interface 09:00:005: allow id 46f4:0001 serial "RED"name "QEMU USB HARDDRIVE" hash "AKmuakTNktSfF54t2IHFRMaukoUw47v3lu/9ZebOsNo=" parent-hash "CsKOZ6IY8v3eojsc1fqKDW84V+MMhD6HsjjojcZBjSg=" via-port "1-1" with-interface 08:06:507: block id 46f4:0001 serial "BLUE"name "QEMU USB HARDDRIVE" hash "GT0vx1ANtDVdOaekgV1a9GmXHc2Mwrx4o3w6gXae5Lo=" parent-hash "CsKOZ6IY8v3eojsc1fqKDW84V+MMhD6HsjjojcZBjSg=" via-port "1-2" with-interface 08:06:50
On workstation, use the second terminal session to detach the BLUE USB device from the usbguard VM:
[student@workstation ~]$sudo virsh detach-device usbguard \>/home/student/RH415/labs/usb-controlling/usb-disk-blue.xmlDevice detached successfully
Generate a new base policy with a reject rule target that will ignore any additional USB devices that try to interact with the system.
Using the reject rule target, additional USB devices will not be listed in command-line tool output, such as lsusb, lsblk, and other tools that provide disk information.
Generate a new base policy with a reject rule target.
Restart the usbguard service.
[root@localhost ~]#usbguard generate-policy -X \>-t reject > /etc/usbguard/rules.conf[root@localhost ~]#systemctl restart usbguard.service
Run the usbguard list-rules command to confirm an allow rule target for the RED USB device followed by a catch-all reject rule target that will apply to any additional USB devices.
[root@localhost ~]#usbguard list-rules1: allow id 1d6b:0002 serial "0000:00:04.7" name "EHCI Host Controller" with-interface 09:00:00 2: allow id 1d6b:0001 serial "0000:00:04.0" name "UHCI Host Controller" with-interface 09:00:00 3: allow id 1d6b:0001 serial "0000:00:04.1" name "UHCI Host Controller" with-interface 09:00:00 4: allow id 1d6b:0001 serial "0000:00:04.2" name "UHCI Host Controller" with-interface 09:00:005: allow id 46f4:0001 serial "RED"name "QEMU USB HARDDRIVE" with-interface 08:06:506: reject
From workstation, attach the BLUE USB device (usb-disk-blue.img) to the usbguard VM.
[student@workstation ~]$sudo virsh attach-device usbguard \>/home/student/RH415/labs/usb-controlling/usb-disk-blue.xmlDevice attached successfully
Although the command output indicates that the BLUE USB device was successfully attached, further investigation on the usbguard VM will confirm that the attempt to attach a USB device was not authorized.
A blocked USB device shows up in command-line tool listings but will not be allowed to mount.
A rejected USB device is ignored by the system and therefore does not display in command-line tool listings.
The journal records the kernel action as well as the USBGuard action.
[root@localhost ~]#journalctl -b -e...output omitted... Jul 17 23:42:10 localhost usbguard-daemon[1401]: uid=0 pid=1399 result='SUCCESS' Jul 17 23:44:34 localhost kernel: usb 1-2: new high-speed USB device number 5 us Jul 17 23:44:34 localhost kernel: usb 1-2: New USB device found, idVendor=46f4, Jul 17 23:44:34 localhost kernel: usb 1-2: New USB device strings: Mfr=1, Produc Jul 17 23:44:34 localhost kernel: usb 1-2: Product: QEMU USB HARDDRIVE Jul 17 23:44:34 localhost kernel: usb 1-2: Manufacturer: QEMU Jul 17 23:44:34 localhost kernel: usb 1-2:SerialNumber: BLUEJul 17 23:44:34 localhost kernel: usb 1-2:Device is not authorized for usageJul 17 23:44:34 localhost usbguard-daemon[1401]: uid=0 pid=1399 result='SUCCESS' Jul 17 23:44:34 localhost usbguard-daemon[1401]: uid=0 pid=1399 result='SUCCESS' Jul 17 23:44:34 localhost kernel: usb 1-2: USB disconnect, device number 5 Jul 17 23:44:34 localhost usbguard-daemon[1401]: uid=0 pid=1399 result='SUCCESS' ...output omitted...
Run the usbguard list-devices command to confirm that the RED USB device is listed but the BLUE USB device is ignored and therefore not listed.
[root@localhost ~]#usbguard list-devices7: allow id 1d6b:0002 serial "0000:00:04.7" name "EHCI Host Controller" hash "CsKOZ6IY8v3eojsc1fqKDW84V+MMhD6HsjjojcZBjSg=" parent-hash "qiR4Ubbd7AIXLCz201hJYzaO9KIrOvqqRgqs2vM2NOY=" via-port "usb1" with-interface 09:00:00 8: allow id 1d6b:0001 serial "0000:00:04.0" name "UHCI Host Controller" hash "sKXn6PthDDlGgdxZHdnlUQ9DROkH/YSojkBlfpcnsaU=" parent-hash "VC8ZB6FZ51WMN42QA3CqGvK9+eLDu4jpdgzSwLFn+fs=" via-port "usb2" with-interface 09:00:00 9: allow id 1d6b:0001 serial "0000:00:04.1" name "UHCI Host Controller" hash "6t6CPSS/v2EqQwsw6CMq8DVfOhgUGO2f+bEBX7R2yz0=" parent-hash "0JRYS5mysCKe92s8So5WC7cbttP3haCBtScjU64BJs0=" via-port "usb3" with-interface 09:00:00 10: allow id 1d6b:0001 serial "0000:00:04.2" name "UHCI Host Controller" hash "BSaNQWADaBI31jUqbck0N56uRuh3uVT1Vk4rdoD0ghs=" parent-hash "prVi21GR+cpMC0ykIE8H9TC9QoaAkFrbmw2PLcWNGkw=" via-port "usb4" with-interface 09:00:0011: allow id 46f4:0001 serial "RED"name "QEMU USB HARDDRIVE" hash "AKmuakTNktSfF54t2IHFRMaukoUw47v3lu/9ZebOsNo=" parent-hash "CsKOZ6IY8v3eojsc1fqKDW84V+MMhD6HsjjojcZBjSg=" via-port "1-1" with-interface 08:06:50
Log out from the usbguard VM and exit from the serial console.