From f5f15402deaa1376e6f3eeb90698977aa1e30daf Mon Sep 17 00:00:00 2001 From: Chris Gunn Date: Mon, 21 Oct 2024 13:29:03 -0700 Subject: [PATCH] Image Customizer: Remove "sudo" calls. You don't need to call "sudo" if the entire program is run as root already. --- toolkit/tools/pkg/imagecustomizerlib/customizeoverlays.go | 2 +- toolkit/tools/pkg/imagecustomizerlib/shrinkfilesystems.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/toolkit/tools/pkg/imagecustomizerlib/customizeoverlays.go b/toolkit/tools/pkg/imagecustomizerlib/customizeoverlays.go index 02544f08651..2ca52ce57d5 100644 --- a/toolkit/tools/pkg/imagecustomizerlib/customizeoverlays.go +++ b/toolkit/tools/pkg/imagecustomizerlib/customizeoverlays.go @@ -176,7 +176,7 @@ func addEquivalencyRules(selinuxMode imagecustomizerapi.SELinuxMode, for _, overlay := range overlays { err = imageChroot.UnsafeRun(func() error { - return shell.ExecuteLiveWithErr(1, "sudo", "semanage", "fcontext", "-a", "-e", overlay.MountPoint, overlay.UpperDir) + return shell.ExecuteLiveWithErr(1, "semanage", "fcontext", "-a", "-e", overlay.MountPoint, overlay.UpperDir) }) if err != nil { return fmt.Errorf("failed to add equivalency rule between %s and %s:\n%w", overlay.MountPoint, overlay.UpperDir, err) diff --git a/toolkit/tools/pkg/imagecustomizerlib/shrinkfilesystems.go b/toolkit/tools/pkg/imagecustomizerlib/shrinkfilesystems.go index 3e670221e06..aa058dcf422 100644 --- a/toolkit/tools/pkg/imagecustomizerlib/shrinkfilesystems.go +++ b/toolkit/tools/pkg/imagecustomizerlib/shrinkfilesystems.go @@ -79,13 +79,13 @@ func shrinkFilesystems(imageLoopDevice string, verityHashPartition *imagecustomi } // Check the file system with e2fsck - err = shell.ExecuteLive(true /*squashErrors*/, "sudo", "e2fsck", "-fy", partitionLoopDevice) + err = shell.ExecuteLive(true /*squashErrors*/, "e2fsck", "-fy", partitionLoopDevice) if err != nil { return fmt.Errorf("failed to check %s with e2fsck:\n%w", partitionLoopDevice, err) } // Shrink the file system with resize2fs -M - stdout, stderr, err := shell.Execute("sudo", "resize2fs", "-M", partitionLoopDevice) + stdout, stderr, err := shell.Execute("resize2fs", "-M", partitionLoopDevice) if err != nil { return fmt.Errorf("failed to resize %s with resize2fs:\n%v", partitionLoopDevice, stderr) } @@ -103,7 +103,7 @@ func shrinkFilesystems(imageLoopDevice string, verityHashPartition *imagecustomi } // Resize the partition with parted resizepart - _, stderr, err = shell.ExecuteWithStdin("yes" /*stdin*/, "sudo", "parted", "---pretend-input-tty", + _, stderr, err = shell.ExecuteWithStdin("yes" /*stdin*/, "parted", "---pretend-input-tty", imageLoopDevice, "resizepart", strconv.Itoa(partitionNumber), end) if err != nil { return fmt.Errorf("failed to resizepart %s with parted:\n%v", partitionLoopDevice, stderr) @@ -121,7 +121,7 @@ func shrinkFilesystems(imageLoopDevice string, verityHashPartition *imagecustomi // Get the start sectors of all partitions. // Ideally, we would use 'lsblk --output START' here. But that is only available in util-linux v2.38+. func getStartSectors(imageLoopDevice string, partitionCount int) (partitionStarts map[string]int, err error) { - stdout, stderr, err := shell.Execute("sudo", "fdisk", "--list", imageLoopDevice) + stdout, stderr, err := shell.Execute("fdisk", "--list", imageLoopDevice) if err != nil { return nil, fmt.Errorf("fdisk failed to list partitions:\n%v", stderr) }