Bug 2159728

Summary: clevis_devices_to_unlock() doesn't skip comments, causing clevis-luks-askpass.service to always run
Product: Red Hat Enterprise Linux 9 Reporter: Martin Zelený <mzeleny>
Component: clevisAssignee: Sergio Arroutbi <sarroutb>
Status: CLOSED ERRATA QA Contact: Martin Zelený <mzeleny>
Severity: medium Docs Contact: Petr Hybl <phybl>
Priority: medium    
Version: 9.2CC: dapospis, jafiala, mjahoda, phybl, qe-baseos-security, rmetrich, sarroutb
Target Milestone: rcKeywords: Triaged
Target Release: ---Flags: pm-rhel: mirror+
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: clevis-18-108.el9 Doc Type: Bug Fix
Doc Text:
.Clevis now correctly skips commented-out devices in `crypttab` Previously, Clevis tried to unlock commented-out devices in the `crypttab` file, causing the `clevis-luks-askpass` service to run even if the device was not valid. This caused unnecessary service runs and made it difficult to troubleshoot. With this fix, Clevis ignores commented-out devices. Now, if an invalid device is commented out, Clevis does not attempt to unlock it, and `clevis-luks-askpass` finishes appropriately. This makes it easier to troubleshoot and reduces unnecessary service runs.
Story Points: ---
Clone Of: 2159440 Environment:
Last Closed: 2023-05-09 07:46:11 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 2159440    
Bug Blocks:    

Description Martin Zelený 2023-01-10 14:07:35 UTC
+++ This bug was initially created as a clone of Bug #2159440 +++

Description of problem:

When commenting out an entry in /etc/crypttab but the LUKS device still exists on the system, I can see clevis-luks-askpass.service never exiting and looping listing keys, etc., e.g.:

/etc/crypttab:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
#luks-64193b0a-fb00-4982-8a15-536813d3fba1 UUID=64193b0a-fb00-4982-8a15-536813d3fba1 none discard
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

Disks:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
# lsblk -f
NAME   FSTYPE LABEL            UUID                                   MOUNTPOINT
...
├─vda3 crypto                  64193b0a-fb00-4982-8a15-536813d3fba1   
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

This happens because clevis_devices_to_unlock() doesn't skip comments (but ignores the first field instead in while() loop on line 411):
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
 403 clevis_devices_to_unlock() {
 :
 411     while read -r _ crypt_device _; do
 :
 436     done < /etc/crypttab
 :
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

This causes the function to return "64193b0a-fb00-4982-8a15-536813d3fba1" even though it's to be skipped.

This was fixed with Upstream commit below:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
commit 0589c149b2b7036752fc8cf0b18d851eb997ed60
Author: Todd Zullinger <tmz>
Date:   Wed Nov 3 03:39:02 2021 -0400

    luks: ignore empty & comment lines in crypttab
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

Version-Release number of selected component (if applicable):

clevis-luks-15-8.el8 (8.6) and clevis-luks-15-11.el8 (8.7)

How reproducible:

Always

Comment 10 errata-xmlrpc 2023-05-09 07:46:11 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (clevis bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2023:2321