From 960eab060649d5f1447185c2f28bd1186af0c2fd Mon Sep 17 00:00:00 2001 From: Lanze Liu <86434077+liulanze@users.noreply.github.com> Date: Wed, 14 Aug 2024 17:17:00 -0700 Subject: [PATCH] ImageCustomizer: Bugfix Verity dependency handling in Azl3. (#10150) Co-authored-by: lanzeliu --- .../pkg/imagecustomizerlib/customizeverity.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/toolkit/tools/pkg/imagecustomizerlib/customizeverity.go b/toolkit/tools/pkg/imagecustomizerlib/customizeverity.go index 228b5ee4f9..a8e8abbe14 100644 --- a/toolkit/tools/pkg/imagecustomizerlib/customizeverity.go +++ b/toolkit/tools/pkg/imagecustomizerlib/customizeverity.go @@ -25,6 +25,11 @@ func enableVerityPartition(buildDir string, verity *imagecustomizerapi.Verity, i logger.Log.Infof("Enable verity") + err = validateVerityDependencies(imageChroot) + if err != nil { + return false, fmt.Errorf("failed to validate package dependencies for verity:\n%w", err) + } + // Integrate systemd veritysetup dracut module into initramfs img. systemdVerityDracutModule := "systemd-veritysetup" dmVerityDracutDriver := "dm-verity" @@ -247,3 +252,17 @@ func systemdFormatCorruptionOption(corruptionOption imagecustomizerapi.Corruptio return "", fmt.Errorf("invalid corruptionOption provided (%s)", string(corruptionOption)) } } + +func validateVerityDependencies(imageChroot *safechroot.Chroot) error { + requiredRpms := []string{"lvm2"} + + // Iterate over each required package and check if it's installed. + for _, pkg := range requiredRpms { + logger.Log.Debugf("Checking if package (%s) is installed", pkg) + if !isPackageInstalled(imageChroot, pkg) { + return fmt.Errorf("package (%s) is not installed:\nthe following packages must be installed to use Verity: %v", pkg, requiredRpms) + } + } + + return nil +}