From ebe3f395bdfa77b81af02fad4b99d2c872c09fb7 Mon Sep 17 00:00:00 2001 From: Brent Baude Date: Mon, 25 Mar 2024 10:43:48 -0500 Subject: [PATCH] hyperv: error if not admin creating vsocks in windows requires admin privileges. there could be some workarounds made in the future,but the general deal has always been, you need to be admin. lets enforce this with an error until those work-arounds can be implemented. Signed-off-by: Brent Baude --- pkg/machine/provider/platform_windows.go | 3 +++ pkg/machine/wsl/machine.go | 2 +- pkg/machine/wsl/util_windows.go | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/machine/provider/platform_windows.go b/pkg/machine/provider/platform_windows.go index 943a66926c..4287f1c5f4 100644 --- a/pkg/machine/provider/platform_windows.go +++ b/pkg/machine/provider/platform_windows.go @@ -32,6 +32,9 @@ func Get() (vmconfigs.VMProvider, error) { case define.WSLVirt: return new(wsl.WSLStubber), nil case define.HyperVVirt: + if !wsl.HasAdminRights() { + return nil, fmt.Errorf("hyperv machines require admin authority") + } return new(hyperv.HyperVStubber), nil default: return nil, fmt.Errorf("unsupported virtualization provider: `%s`", resolvedVMType.String()) diff --git a/pkg/machine/wsl/machine.go b/pkg/machine/wsl/machine.go index 18593e9fa3..20afee2dc4 100644 --- a/pkg/machine/wsl/machine.go +++ b/pkg/machine/wsl/machine.go @@ -308,7 +308,7 @@ func checkAndInstallWSL(reExec bool) (bool, error) { return true, nil } - admin := hasAdminRights() + admin := HasAdminRights() if !IsWSLFeatureEnabled() { return false, attemptFeatureInstall(reExec, admin) diff --git a/pkg/machine/wsl/util_windows.go b/pkg/machine/wsl/util_windows.go index 7b24a39b1d..c6d9d1ab71 100644 --- a/pkg/machine/wsl/util_windows.go +++ b/pkg/machine/wsl/util_windows.go @@ -96,7 +96,7 @@ func winVersionAtLeast(major uint, minor uint, build uint) bool { return true } -func hasAdminRights() bool { +func HasAdminRights() bool { var sid *windows.SID // See: https://coolaj86.com/articles/golang-and-windows-and-admins-oh-my/