Skip to content

Commit

Permalink
hyperv: error if not admin
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
baude authored and openshift-cherrypick-robot committed Mar 26, 2024
1 parent c1a226a commit ebe3f39
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pkg/machine/provider/platform_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion pkg/machine/wsl/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func checkAndInstallWSL(reExec bool) (bool, error) {
return true, nil
}

admin := hasAdminRights()
admin := HasAdminRights()

if !IsWSLFeatureEnabled() {
return false, attemptFeatureInstall(reExec, admin)
Expand Down
2 changes: 1 addition & 1 deletion pkg/machine/wsl/util_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down

0 comments on commit ebe3f39

Please sign in to comment.