Merge pull request #4318 from Tadas/fix-hyperv-admin
Check for 'Hyper-V Administrators' security group
This commit is contained in:
commit
c5ddbacb62
|
@ -64,7 +64,7 @@ func (d *HypervPS4Driver) Verify() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := d.verifyElevatedMode(); err != nil {
|
if err := d.verifyHypervPermissions(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,16 +293,28 @@ func (d *HypervPS4Driver) verifyPSHypervModule() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *HypervPS4Driver) verifyElevatedMode() error {
|
func (d *HypervPS4Driver) verifyHypervPermissions() error {
|
||||||
|
|
||||||
log.Printf("Enter method: %s", "verifyElevatedMode")
|
log.Printf("Enter method: %s", "verifyHypervPermissions")
|
||||||
|
|
||||||
isAdmin, _ := powershell.IsCurrentUserAnAdministrator()
|
hypervAdminCmd := "([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole('Hyper-V Administrators')"
|
||||||
|
|
||||||
if !isAdmin {
|
var ps powershell.PowerShellCmd
|
||||||
err := fmt.Errorf("%s", "Please restart your shell in elevated mode")
|
cmdOut, err := ps.Output(hypervAdminCmd)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res := strings.TrimSpace(string(cmdOut))
|
||||||
|
|
||||||
|
if res == "False" {
|
||||||
|
isAdmin, _ := powershell.IsCurrentUserAnAdministrator()
|
||||||
|
|
||||||
|
if !isAdmin {
|
||||||
|
err := fmt.Errorf("%s", "Current user is not a member of 'Hyper-V Administrators' or 'Administrators' group")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue