-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Execute add/remove registry entries in elevated mode with hyperv
Adding/removing a key in the Windows registry requires elevated rights. For this reason, using podman with hyperv had the constraint to run it as admin otherwise it was not possible to init/rm a hyperv machine. This patch adds a couple of functions to add/remove registry entries in bulk in privileged mode. When creating/deleting a machine the user is asked only once to elevate the rights to perform the action. So now podman can be started without being admin. The only constraint is that you must be a member of the Hyper-V administratos group. This will also be leveraged by podman desktop so users could switch from wsl to hyperv without restarting desktop in elevated mode. Signed-off-by: lstocchi <[email protected]>
- Loading branch information
Showing
9 changed files
with
287 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//go:build windows | ||
|
||
package hyperv | ||
|
||
import ( | ||
"github.com/sirupsen/logrus" | ||
"golang.org/x/sys/windows" | ||
) | ||
|
||
// https://support.microsoft.com/en-us/help/243330/well-known-security-identifiers-in-windows-operating-systems | ||
// BUILTIN\Hyper-V Administrators => S-1-5-32-578 | ||
const hypervAdminGroupSid = "S-1-5-32-578" | ||
|
||
func HasHyperVAdminRights() bool { | ||
sid, err := windows.StringToSid(hypervAdminGroupSid) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
// From MS docs: | ||
// "If TokenHandle is NULL, CheckTokenMembership uses the impersonation | ||
// token of the calling thread. If the thread is not impersonating, | ||
// the function duplicates the thread's primary token to create an | ||
// impersonation token." | ||
token := windows.Token(0) | ||
member, err := token.IsMember(sid) | ||
|
||
if err != nil { | ||
logrus.Warnf("Token Membership Error: %s", err) | ||
return false | ||
} | ||
|
||
return member | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.