Laszlo Ersek
2022-Jun-30 12:20 UTC
[Libguestfs] [libguestfs PATCH v2 0/3] LUKS decryption with Clevis+Tang
v1: https://listman.redhat.com/archives/libguestfs/2022-June/029290.html Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1809453 Please see the Notes section on each patch for the updates in this version. (The documentation of the CVE fix has been merged: 99844660b48e.) Thanks Laszlo Laszlo Ersek (3): use local git repo for common submodule introduce the "clevis_luks_unlock" API guestfish, guestmount: enable networking for "--key ID:clevis" .gitmodules | 3 +- appliance/packagelist.in | 4 ++ common | 2 +- daemon/Makefile.am | 1 + daemon/clevis-luks.c | 58 ++++++++++++++++++++ fish/fish.c | 3 + fuse/guestmount.c | 4 ++ generator/actions_core.ml | 40 ++++++++++++++ generator/proc_nr.ml | 1 + lib/MAX_PROC_NR | 2 +- lib/guestfs.pod | 19 +++++-- 11 files changed, 130 insertions(+), 7 deletions(-) create mode 100644 daemon/clevis-luks.c -- 2.19.1.3.g30247aa5d201
Laszlo Ersek
2022-Jun-30 12:20 UTC
[Libguestfs] [libguestfs PATCH v2 1/3] use local git repo for common submodule
--- .gitmodules | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 1343142128f6..7b1a84418c2b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,4 @@ [submodule "common"] path = common - url = https://github.com/libguestfs/libguestfs-common + url = file:///home/lacos/src/v2v/libguestfs-common + branch = . -- 2.19.1.3.g30247aa5d201
Laszlo Ersek
2022-Jun-30 12:20 UTC
[Libguestfs] [libguestfs PATCH v2 2/3] introduce the "clevis_luks_unlock" API
Introduce a new guestfs API called "clevis_luks_unlock". At the libguestfs level, it is quite simple; it wraps the "clevis luks unlock" guest command (implemented by the "clevis-luks-unlock" executable, which is in fact a shell script). The complexity is instead in the network-based disk encryption (Clevis/Tang) scheme. Useful documentation: - https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html-single/security_hardening/index#configuring-automated-unlocking-of-encrypted-volumes-using-policy-based-decryption_security-hardening - https://github.com/latchset/clevis#clevis - https://github.com/latchset/tang#tang The package providing "clevis-luks-unlock" is usually called "clevis-luks", occasionally "clevis". Some distros don't package clevis at all. Add the new API under a new option group (which may not be available) called "clevisluks". Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1809453 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- Notes: v2: - rewrap clevis_luks_unlock longdesc [Rich] daemon/Makefile.am | 1 + generator/actions_core.ml | 40 ++++++++++++++ generator/proc_nr.ml | 1 + daemon/clevis-luks.c | 58 ++++++++++++++++++++ appliance/packagelist.in | 4 ++ lib/MAX_PROC_NR | 2 +- lib/guestfs.pod | 19 +++++-- 7 files changed, 120 insertions(+), 5 deletions(-) diff --git a/daemon/Makefile.am b/daemon/Makefile.am index bbd49f9ea1e0..f50faecd6930 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -96,10 +96,11 @@ guestfsd_SOURCES = \ btrfs.c \ caml-stubs.c \ cap.c \ checksum.c \ cleanups.c \ + clevis-luks.c \ cmp.c \ command.c \ command.h \ compress.c \ copy.c \ diff --git a/generator/actions_core.ml b/generator/actions_core.ml index 807150615426..d9696a7c8232 100644 --- a/generator/actions_core.ml +++ b/generator/actions_core.ml @@ -9718,6 +9718,46 @@ and I<not> the name of the underlying block device." }; style = RErr, [String (Pathname, "dir"); String (FileOut, "filename")], []; visibility = VInternal; shortdesc = "read directories entries"; longdesc = "Internal function for readdir." }; + { defaults with + name = "clevis_luks_unlock"; added = (1, 49, 3); + style = RErr, + [String (Device, "device"); String (PlainString, "mapname")], + []; + optional = Some "clevisluks"; + test_excuse = "needs networking and a configured Tang server"; + shortdesc = "open an encrypted LUKS block device with Clevis and Tang"; + longdesc = "\ +This command opens a block device that has been encrypted according to +the Linux Unified Key Setup (LUKS) standard, using network-bound disk +encryption (NBDE). + +C<device> is the encrypted block device. + +The appliance will connect to the Tang servers noted in the tree of +Clevis pins that is bound to a keyslot of the LUKS header. The Clevis +pin tree may comprise C<sss> (redudancy) pins as internal nodes +(optionally), and C<tang> pins as leaves. C<tpm2> pins are not +supported. The appliance unlocks the encrypted block device by +combining responses from the Tang servers with metadata from the LUKS +header; there is no C<key> parameter. + +This command will fail if networking has not been enabled for the +appliance. Refer to C<guestfs_set_network>. + +The command creates a new block device called F</dev/mapper/mapname>. +Reads and writes to this block device are decrypted from and encrypted +to the underlying C<device> respectively. Close the decrypted block +device with C<guestfs_cryptsetup_close>. + +C<mapname> cannot be C<\"control\"> because that name is reserved by +device-mapper. + +If this block device contains LVM volume groups, then calling +C<guestfs_lvm_scan> with the C<activate> parameter C<true> will make +them visible. + +Use C<guestfs_list_dm_devices> to list all device mapper devices." }; + ] diff --git a/generator/proc_nr.ml b/generator/proc_nr.ml index bdced51c9acd..edd9bd99d2da 100644 --- a/generator/proc_nr.ml +++ b/generator/proc_nr.ml @@ -512,10 +512,11 @@ let proc_nr = [ 507, "luks_uuid"; 508, "cryptsetup_open"; 509, "cryptsetup_close"; 510, "internal_list_rpm_applications"; 511, "internal_readdir"; +512, "clevis_luks_unlock" ] (* End of list. If adding a new entry, add it at the end of the list * above. Do not modify anything below this line. *---------------------------------------------------------------------- diff --git a/daemon/clevis-luks.c b/daemon/clevis-luks.c new file mode 100644 index 000000000000..d3d970d78098 --- /dev/null +++ b/daemon/clevis-luks.c @@ -0,0 +1,58 @@ +/* libguestfs - the guestfsd daemon + * Copyright (C) 2009-2022 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <config.h> + +#include "daemon.h" +#include "actions.h" +#include "optgroups.h" + +#define MAX_ARGS 8 + +int +optgroup_clevisluks_available (void) +{ + return prog_exists ("clevis-luks-unlock"); +} + +int +do_clevis_luks_unlock (const char *device, const char *mapname) +{ + const char *argv[MAX_ARGS]; + size_t i = 0; + int r; + CLEANUP_FREE char *err = NULL; + + ADD_ARG (argv, i, "clevis"); + ADD_ARG (argv, i, "luks"); + ADD_ARG (argv, i, "unlock"); + ADD_ARG (argv, i, "-d"); + ADD_ARG (argv, i, device); + ADD_ARG (argv, i, "-n"); + ADD_ARG (argv, i, mapname); + ADD_ARG (argv, i, NULL); + + r = commandv (NULL, &err, argv); + if (r == -1) { + reply_with_error ("%s: %s: %s", device, mapname, err); + return -1; + } + + udev_settle (); + return 0; +} diff --git a/appliance/packagelist.in b/appliance/packagelist.in index 77a07acc6ad0..0b79edcdd55d 100644 --- a/appliance/packagelist.in +++ b/appliance/packagelist.in @@ -21,10 +21,11 @@ dnl ./configure --with-extra-packages="gdb valgrind [etc]" dnl Basically the same with a few minor tweaks. ifelse(UBUNTU,1,`define(`DEBIAN',1)') ifelse(REDHAT,1, + clevis-luks cryptsetup cryptsetup-luks dnl old name used before Fedora 17 dhclient gfs-utils gfs2-utils @@ -51,10 +52,11 @@ ifelse(REDHAT,1, ifelse(DEBIAN,1, bsdmainutils dnl old name used in Jessie and earlier btrfs-tools + clevis-luks cryptsetup dash extlinux dnl gfs-tools, gfs2-tools have been renamed to gfs2-utils gfs-tools @@ -90,10 +92,11 @@ dnl iproute has been renamed to iproute2 ) ifelse(ARCHLINUX,1, cdrkit cdrtools + clevis cryptsetup dhclient dhcpcd gptfdisk grub @@ -117,10 +120,11 @@ ifelse(ARCHLINUX,1, ifelse(SUSE,1, dnl It seems no other augeas package depends on it. augeas-lenses btrfsprogs cdrkit-cdrtools-compat + clevis cryptsetup dhcpcd dhcp-client glibc-locale gptfdisk diff --git a/lib/MAX_PROC_NR b/lib/MAX_PROC_NR index c0556fb20f37..4d0e90cbcbaf 100644 --- a/lib/MAX_PROC_NR +++ b/lib/MAX_PROC_NR @@ -1 +1 @@ -511 +512 diff --git a/lib/guestfs.pod b/lib/guestfs.pod index 1ad44e7c2878..e10bf1fbec30 100644 --- a/lib/guestfs.pod +++ b/lib/guestfs.pod @@ -589,15 +589,26 @@ devices. For LUKS it returns the string C<crypto_LUKS>. For Windows BitLocker it returns C<BitLocker>. Then open these devices by calling L</guestfs_cryptsetup_open>. Obviously you will require the passphrase! +Passphrase-less unlocking is supported for LUKS (not BitLocker) +block devices that have been encrypted with network-bound disk +encryption (NBDE), using Clevis on the Linux guest side, and +Tang on a separate Linux server. Open such devices with +L</guestfs_clevis_luks_unlock>. The appliance will need +networking enabled (refer to L</guestfs_set_network>) and actual +connectivity to the Tang servers noted in the C<tang> Clevis +pins that are bound to the LUKS header. (This includes the +ability to resolve the names of the Tang servers.) + Opening an encrypted device creates a new device mapper device -called F</dev/mapper/mapname> (where C<mapname> is the -string you supply to L</guestfs_cryptsetup_open>). -Reads and writes to this mapper device are decrypted from and -encrypted to the underlying block device respectively. +called F</dev/mapper/mapname> (where C<mapname> is the string +you supply to L</guestfs_cryptsetup_open> or +L</guestfs_clevis_luks_unlock>). Reads and writes to this mapper +device are decrypted from and encrypted to the underlying block +device respectively. LVM volume groups on the device can be made visible by calling L</guestfs_vgscan> followed by L</guestfs_vg_activate_all>. The logical volume(s) can now be mounted in the usual way. -- 2.19.1.3.g30247aa5d201
Laszlo Ersek
2022-Jun-30 12:20 UTC
[Libguestfs] [libguestfs PATCH v2 3/3] guestfish, guestmount: enable networking for "--key ID:clevis"
Call the C-language helper key_store_requires_network() in guestfish and guestmount. (Short log for the "common" submodule, commit range 35467027f657..ab6f3b2cc7cb: Laszlo Ersek (12): options: fix UUID comparison logic bug in get_keys() mltools/tools_utils: remove unused function "key_store_to_cli" mltools/tools_utils: allow multiple "--key" options for OCaml tools too options: replace NULL-termination with number-of-elements in get_keys() options: wrap each passphrase from get_keys() into a struct options: add back-end for LUKS decryption with Clevis+Tang options: introduce selector type "key_clevis" options: generalize "--key" selector parsing for C-language utilities mltools/tools_utils-c: handle internal type error with abort() mltools/tools_utils: generalize "--key" selector parsing for OCaml utils options, mltools/tools_utils: parse "--key ID:clevis" options options, mltools/tools_utils: add helper for network dependency ). Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1809453 Signed-off-by: Laszlo Ersek <lersek at redhat.com> Reviewed-by: Richard W.M. Jones <rjones at redhat.com> --- Notes: v2: - refresh the submodule update (in the commit message too); need to do it again upon merge - pick up Rich's R-b v1: The submodule commit range 35b49ce142fb..0399dea30e63 needs to be refreshed in both the commit message and the "common" hunk, once the libguestfs-common series is upstream. fish/fish.c | 3 +++ fuse/guestmount.c | 4 ++++ common | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/fish/fish.c b/fish/fish.c index 23d9bb94f3a4..19e3d2799e84 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -474,10 +474,13 @@ main (int argc, char *argv[]) CHECK_OPTION_blocksize_consumed; /* If we've got drives to add, add them now. */ add_drives (drvs); + if (key_store_requires_network (ks) && guestfs_set_network (g, 1) == -1) + exit (EXIT_FAILURE); + /* If we've got mountpoints or prepared drives or -i option, we must * launch the guest and mount them. */ if (next_prepared_drive > 1 || mps != NULL || inspector) { /* RHBZ#612178: If --listen flag is given, then we will fork into diff --git a/fuse/guestmount.c b/fuse/guestmount.c index 77c534828fcd..3c6d57bde0d6 100644 --- a/fuse/guestmount.c +++ b/fuse/guestmount.c @@ -346,10 +346,14 @@ main (int argc, char *argv[]) if (guestfs_set_recovery_proc (g, !do_fork) == -1) exit (EXIT_FAILURE); /* Do the guest drives and mountpoints. */ add_drives (drvs); + + if (key_store_requires_network (ks) && guestfs_set_network (g, 1) == -1) + exit (EXIT_FAILURE); + if (guestfs_launch (g) == -1) exit (EXIT_FAILURE); if (inspector) inspect_mount (); mount_mps (mps); diff --git a/common b/common index 35467027f657..ab6f3b2cc7cb 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 35467027f657de76aca34b48a6f23e9608b23a57 +Subproject commit ab6f3b2cc7cbb0fa786e6faf633689a826cb0d9b -- 2.19.1.3.g30247aa5d201