From 812003eb457237a8110f2f2e16c8ae6b25a46d9f Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Tue, 6 Jul 2021 12:52:32 +0530 Subject: [PATCH] util: fix bug in DeviceEncryptionStatus() With Luks1 device: $ cryptsetup status /dev/mapper/crypto-rbd0 /dev/mapper/crypto-rbd0 is active and is in use. type: LUKS1 cipher: aes-xts-plain64 keysize: 512 bits key location: dm-crypt device: /dev/rbd0 sector size: 512 offset: 4096 sectors size: 4190208 sectors mode: read/write With Luks2 device: $ cryptsetup status /dev/mapper/crypto-rbd0 /dev/mapper/crypto-rbd0 is active and is in use. type: LUKS2 cipher: aes-xts-plain64 keysize: 512 bits key location: dm-crypt device: /dev/rbd0 sector size: 512 offset: 32768 sectors size: 4161536 sectors mode: read/write This could lead to failures with unmap in the NodeUnstageVolume path for the encrypted volumes. Signed-off-by: Prasanna Kumar Kalever --- internal/util/crypto.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/util/crypto.go b/internal/util/crypto.go index 75a5f9c80..59a2d3f47 100644 --- a/internal/util/crypto.go +++ b/internal/util/crypto.go @@ -294,7 +294,8 @@ func DeviceEncryptionStatus(ctx context.Context, devicePath string) (mappedDevic if len(lines) < 1 { return "", "", fmt.Errorf("device encryption status returned no stdout for %s", devicePath) } - if !strings.HasSuffix(lines[0], " is active.") { + // The line will look like: "/dev/mapper/xxx is active and is in use." + if !strings.Contains(lines[0], " is active") { // Implies this is not a LUKS device return devicePath, "", nil }