Bug 2159440

Summary: clevis_devices_to_unlock() doesn't skip comments, causing clevis-luks-askpass.service to always run
Product: Red Hat Enterprise Linux 8 Reporter: Renaud Métrich <rmetrich>
Component: clevisAssignee: Sergio Arroutbi <sarroutb>
Status: CLOSED ERRATA QA Contact: Martin Zelený <mzeleny>
Severity: medium Docs Contact: Jan Fiala <jafiala>
Priority: medium    
Version: 8.7CC: dapospis, jafiala, mzeleny, sarroutb
Target Milestone: rcKeywords: Triaged
Target Release: ---Flags: pm-rhel: mirror+
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: clevis-15-12.el8 Doc Type: Bug Fix
Doc Text:
.Clevis ignores commented devices in `crypttab` Previously, Clevis tried to unlock commented 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 devices. Now, if an invalid device is commented, Clevis does not attempt to unlock it and `clevis-luks-askpass.service` finishes appropriately. This makes it easier to troubleshoot and reduces unnecessary service runs.
Story Points: ---
Clone Of:
: 2159728 (view as bug list) Environment:
Last Closed: 2023-05-16 08:39:14 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:    
Bug Blocks: 2159728    

Description Renaud Métrich 2023-01-09 15:33:15 UTC
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 12 Sergio Arroutbi 2023-01-19 11:18:16 UTC
@jafiala : Changes in doc text LGTM. Thanks

Comment 17 errata-xmlrpc 2023-05-16 08:39:14 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:2868