-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Execute add/remove registry entries in elevated mode with hyperv #24813
base: main
Are you sure you want to change the base?
Conversation
pkg/machine/hyperv/vsock/vsock.go
Outdated
"strings" | ||
|
||
"github.com/Microsoft/go-winio" | ||
"github.com/containers/podman/v5/pkg/machine/sockets" | ||
"github.com/containers/podman/v5/pkg/machine/wsl/wutil" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we do this in other places in WSL? I dont like mixing providers by calling into each other when possible. would you consider pkg/machine/windows
instead (apple does this)
func NewHVSockRegistryEntry(machineName string, purpose HVSockPurpose) (*HVSockRegistryEntry, error) { | ||
// CreateHVSockRegistryEntry is a constructor to make an instance of a registry entry in Windows. After making the new | ||
// object, you must call the add() method or AddHVSockRegistryEntries(...) to *actually* add it to the Windows registry. | ||
func CreateHVSockRegistryEntry(machineName string, purpose HVSockPurpose) (*HVSockRegistryEntry, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this and associated funcs go into libhvee?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Up to you, i can move it if you want. I checked libhvee and it looks like it's dedicated to hyperv but this funcs allow to add/rm entries to/from the Windows registry which are not tight to hyper-v. We use them for hyper-v here but they could be useful in other cases.
pkg/machine/hyperv/vsock/vsock.go
Outdated
return err | ||
} | ||
|
||
d, _ := os.Getwd() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we eating the error? i know it is done elsewhere too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, i copied the existing code. Updated 👍
you will need to document this change somewhere as well as add a release note about running elevated once. you also will need a test and to make sure this passes all current tests obviously. |
Sure, wanted some early feedback to know if i was doing something wrong or if it was an acceptable solution 👍 Gonna update it with all the rest!! |
does this approach require the user to be in a specific group on windows then ? |
AFAIK you still need to be in the hyper-v admin group. Not sure if we can do some change to libhvee to reduce the privileges on that front as well. |
bc58a14
to
369163b
Compare
@baude I only found one place where it was mentioned that podman needed to be run as admin when using hyper-v, so i updated that doc. Need to add something else? The tests seem to be running only on linux or i'm wrong? What tests should i add? Unit tests to verify the scripts are generate as expected? Any other idea/request? |
369163b
to
6709178
Compare
re: groups, what i was thinking more about is whether we now have to check for that instread. |
you mean adding a check to verify if the user is in the hyper-v admin group? |
correct |
6709178
to
ed47c52
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lstocchi The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Done, i followed the logic that was in place for the admin check |
Ephemeral COPR build failed. @containers/packit-build please check. |
@lstocchi thank you for submitting this PR. Requiring an admin terminal for HyperV machine commands is painful, and your help is appreciated. Here are some thoughts after reviewing and testing this PR:
|
ed47c52
to
02cbb6e
Compare
Thanks for the review @l0rd and sorry for the slow response. I've been busy on other things.
I re-added the check to verify that the user is admin.
The drawback from my pov is that if we use gsudo or another tool we are adding an extra dependency/complexity. All windows users (or i would say 99%) have the powershell installed. This is not true for gsudo or other tools. So, if we start depending on them we need to bundle it with podman and also make sure to keep it updated/verify it works with new releases. I'll try to see if by using the .NET framework (Microsoft.Win32.Registry) we can remove the powershell scripts.
What do you mean? Having a hyper-v windows guest machine, connecting to it from the host and executing the
The explanation is that adding/removing things on the HKLM registry is only allowed to admin users. Should i add this somewhere on the doc or you mean something else?
Good idea, done 👍 Thanks!! |
02cbb6e
to
574d243
Compare
@l0rd feel free to add more info if i missed something |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @lstocchi for the updates. I have tested it and it works fine. Well done. I have added some comments, probably the most important one is to add a test for the new AddHVSocketRegistryEntries
.
"golang.org/x/sys/windows" | ||
) | ||
|
||
func HasHyperVAdminRights() bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's not too hard, it would be helpful to add a test for this (that's not a blocker).
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]>
38f41e8
to
bff1257
Compare
@l0rd i should have fixed all your concerns (except the tests to verify if the user is in the hyperv admin, maybe it requires some e2e test). Please give it a look |
bff1257
to
c47b6e4
Compare
Signed-off-by: lstocchi <[email protected]>
Signed-off-by: lstocchi <[email protected]>
c47b6e4
to
1bbd5d2
Compare
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.
This will also be leveraged by podman desktop so users could switch from wsl to hyperv without restarting desktop in elevated mode.
Does this PR introduce a user-facing change?
Not sure what you mean by user-facing change but i would say yes.
Now the user who init a hyperv machine is asked to give elevated rights to execute the script to add registry entries to the Windows registry