Merge pull request #4318 from Tadas/fix-hyperv-admin

Check for 'Hyper-V Administrators' security group
This commit is contained in:
Matthew Hooker 2017-03-08 23:35:17 -08:00 committed by GitHub
commit c5ddbacb62
1 changed files with 18 additions and 6 deletions

View File

@ -64,7 +64,7 @@ func (d *HypervPS4Driver) Verify() error {
return err
}
if err := d.verifyElevatedMode(); err != nil {
if err := d.verifyHypervPermissions(); err != nil {
return err
}
@ -293,16 +293,28 @@ func (d *HypervPS4Driver) verifyPSHypervModule() error {
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 {
err := fmt.Errorf("%s", "Please restart your shell in elevated mode")
var ps powershell.PowerShellCmd
cmdOut, err := ps.Output(hypervAdminCmd)
if err != nil {
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
}