-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
WIP: hyperv: Assert that the user has correct permissions #4745
WIP: hyperv: Assert that the user has correct permissions #4745
Conversation
… to a separate Util function.
Hi @blueelvis. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/assign medyagh |
Can one of the admins verify this patch? |
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.
Great work here! I hope you don't mind that I have a handful of minor suggestions.
pkg/util/utils.go
Outdated
@@ -291,3 +293,31 @@ func ContainsString(slice []string, s string) bool { | |||
} | |||
return false | |||
} | |||
|
|||
// ValidateUser validates minikube is run by the recommended user (privileged or regular) |
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.
I like the idea, but let's find a better home for it with a more appropriate function signature. What do you think about moving this to pkg/drivers/drivers.go so that the call can be `driver.ValidatePermissions()?
Since this function will no longer be in the main
package, it should return an error instead of exiting.
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.
I have moved this to the drivers
file. I was wondering, do we have any middleware setup? With this type of implementation, I really don't like how in some places, I need to check the commandline arguments and in some places, what is loaded from the config file. If we don't have it, I think it would be best to have a middleware setup which can validate config/permissions after arguments are saved to config file and we validate the config file only.
That way, in future, it would be easier to add more checks like validatePermissions
. What do you think?
pkg/util/utils.go
Outdated
// If Hyper-V, ensure we are having Administrator Privilleges. | ||
if driverName == constants.DriverHyperv { | ||
// This tries opening the first disk attached to the system for a direct I/O operation. This operation requires Administrator privileges and will fail without that. | ||
rawDisk, err := os.Open("\\\\.\\PHYSICALDRIVE0") |
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.
I just realized that this may break some users: Hyper-V has a separate set of ACL's, and in fact there is support for a Hyper-V administrators group. Rather than requiring full administrative access, I think we should:
- Make this check more specific so that HyperV admins can continue to use minikube. Perhaps there we could call
Get-VM
,Get-VMConnectAccess
or some other kind of command line instead to see if we have access to Hyper-V? - Add a
--force
flag so that these checks can be skipped.
We can start with one of those approaches, but both would be ideal in the long term.
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 you think we could track this in a separate bug/ work item? I fully agree with this and I think that we could check what other approaches could be in this case instead of running raw Powershell commands. Not sure if we already have a package to execute Powershell commands as part of golang. Pretty sure that there would be a native Windows API to check this.
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.
@tstromberg - I was browsing around and I see that what you are asking is already part of the machine library - https://github.com/docker/machine/blob/a555e4f7a8f518a8b1b174824c377e46cbfc4fe2/drivers/hyperv/powershell.go#L71
Let me add that and push a commit.
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.
@tstromberg - I noticed that these checks are private to the package for now. I am in the process of creating a PR to make those checks public and we can revisit this again. As of now, this PR will fix the issues with most of the client users. The very small user base which will be affected would be the ones running Hyper-V on Windows Server environments with that role.
WDYT?
@minikube-bot OK to test |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: blueelvis 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 |
@@ -136,3 +139,32 @@ func fixPermissions(path string) error { | |||
} | |||
return nil | |||
} | |||
|
|||
// ValidatePermissions validates minikube is run by the recommended user (privileged or regular) | |||
func ValidatePermissions(driverName string) 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.
I don't think this function should be in this package. This is related to what @afbjorklund was taking in the issue #4909. Anything under pkg/drivers
shouldn't be using minikube code directly, because the idea is that those drivers will be moved upstream. In this case, we have translations here. Drivers code related to minikube should be in pkg/minikube/drivers
.
wdyt?
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.
In one of the review comments above, Thomas mentioned that it would be better if we could place this function at this path.
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.
Gotcha! No strong feelings about it. Although I think pkg/drivers
should be drivers only, not using minikube code.
@tstromberg thoughts?
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.
SGTM. I think this should go in pkg/minikube/drivers/drivers.go
then?
@tstromberg - ping. The integration tests are failing because now more output is coming instead of just
I also cannot run the integration tests on my Windows box :( . Could you please guide me on where I need to make a fix for this? |
Is there a bug about integration tests on Windows? I'd like to make sure this gets sorted out. Presumably this should work even if
|
@tstromberg @medyagh - If I run that command, I am getting the following. This is happening even after cleaning the packages and getting them again.
Any other way, this can be fixed? |
@blueelvis: PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
sorry for the late reply, does this help ? https://minikube.sigs.k8s.io/docs/contributing/testing/ env TEST_ARGS="-minikube-start-args=--vm-driver=hyperv -test.run TestStartStop" make integration |
@medyagh - I tried running that in an Admin Git bash prompt but I am still not able to run the integration tests against Hyper-V :(
I am in the root folder of the project and I can see the file in the console but not sure why this is not able to find it. Any thoughts? |
@sharifelgamal has some experience here. |
Hey @blueelvis, we may have merged in a change that solves your issue ~3 weeks ago. Could you resolve your merge conflicts and try again? If you're still seeing issues, please ping @sharifelgamal. |
@priyawadhwa - Are you talking about the integration tests? Let me try again over the weekend and get back on this. |
@blueelvis yup I meant the integration tests, sorry for not clarifying! And sound great, thanks. |
// If Hyper-V, ensure we are having Administrator Privilleges. | ||
if driverName == constants.DriverHyperv { | ||
// This tries opening the first disk attached to the system for a direct I/O operation. This operation requires Administrator privileges and will fail without that. | ||
rawDisk, err := os.Open("\\\\.\\PHYSICALDRIVE0") |
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.
Alternatively: https://coolaj86.com/articles/golang-and-windows-and-admins-oh-my/
Also, we should perhaps be checking for membership to the hyperv admins group.
@priyawadhwa @tstromberg - I am closing this Pull Request. I will submit a new one after copying the functions from the machine-drivers fork. That would be really easy to achieve what is mentioned in the article as well. Discussion - machine-drivers/machine#20 |
validateUser()
so that it is effective even when cluster is already provisioned.Fixes #4511
-Pranav