Commit Graph

2 Commits (master)

Author SHA1 Message Date
Nir Soffer 5d4d03623b
drivers: Extract drivers/common package (#21266)
Move all files and packages which are not a driver to the drivers/common
package. This helps to understand the structure of the code.

While moving, move the iso_test.iso into testdata/test.iso to separate
code and test data.

While fixing the test iso path fix few bugs in the tests using wrong iso
path. The test failed because the iso path was wrong instead of issue
with source or destination path.

New directory structure:

    % tree -L1 pkg/drivers
    pkg/drivers
    ├── common
    ├── hyperkit
    ├── kic
    ├── krunkit
    ├── kvm
    ├── none
    ├── qemu
    ├── ssh
    └── vfkit
2025-08-08 22:50:57 -07:00
Nir Soffer e4bdba7e5d
vmnet: Support running without sudoers configuration (#20719)
* vmnet: Improve --network vmnet-shared validation

Previously we did not check that the helper can run with the
--close-from=4 option, so the command could succeed when incorrect
sudoers configuration. For example a user with liberal NOPASSWD rule,
but without the closefrom_override option.

When the check failed, we log unhelpful log:

    libmachine: Failed to run vmnet-helper:
    %!w(*exec.ExitError=&{0x14000135e30 [115 117 100 111 58 32 97 ... 101 100 10]})

And we returned a bool, so the caller could not provide a suggestion how
to resolve the issue.

Fix by:

- Rename vment.HelperAvaialble to vment.ValidateHelper
- Return an error describing the issue, including a reason.Kind that can
  be used to provide a suggestion for resolving the issue.
- Include the ExitError.Stderr int the error. This includes helpful
  error messages from sudo.
- Add new reason.NotConfiguredVmnetHelper error
- Improve log when vment.ValidateHelper() succeeded

Example error flow - vment-helper not installed:

    % minikube start --driver vfkit --network vmnet-shared
    😄  minikube v1.35.0 on Darwin 15.4.1 (arm64)
      Using the vfkit (experimental) driver based on user configuration

    🙈  Exiting due to NOT_FOUND_VMNET_HELPER: failed to validate vmnet-shared network:
    stat /opt/vmnet-helper/bin/vmnet-helper: no such file or directory
    💡  Suggestion:

        vmnet-helper was not found on the system, resolve by:

        Option 1) Installing vmnet-helper:

        https://github.com/nirs/vmnet-helper#installation

        Option 2) Using the nat network:

        minikube start<no value> --driver vfkit --network nat

I resolved the issue by installing vmnet-helper but I did not configured
the sudoers rule:

    % minikube start --driver vfkit --network vmnet-shared
    😄  minikube v1.35.0 on Darwin 15.4.1 (arm64)
      Using the vfkit (experimental) driver based on user configuration

    🙈  Exiting due to NOT_CONFIGURED_VMNET_HELPER: failed to validate vmnet-shared network:
    exit status 1: sudo: you are not permitted to use the -C option
    💡  Suggestion:

        Configure vmnet-helper to run without a password.

        Please install a vmnet-helper sudoers rule using these instructions:

        https://github.com/nirs/vmnet-helper#granting-permission-to-run-vmnet-helper

After installing the sudoers rule minikube could start.

* vfkit: Use helper --socket instead of --fd

The --fd option avoids the need to manage a bound unix sockets, in
particular the limit on unix socket length. It is also more secure;
only the process inheriting the socket can access the helper. However it
requires the sudo --close-from= option, which may not work for some
users. We don't understand why it does not work, and debugging it is
hard since users are not happy to share their local sudoers
configuration.

Avoid the trouble by switching to the --socket option. In this case we
pass a unix socket path to the helper and vfkit. The helper creates a
bound unix datagram socket in the specified path, and waits until vfkit
connects to the socket. When vfkit connects to the unix socket the
programs are connected in the same way they are connected by passing
file descriptors.

When running minikube we will see 3 new files in the machine directory:

- `vfkit-fb64-7802.sock`: vfkit unix datagram socket
- `vmnet-helper.sock`: vmnet-helper unix datagram socket
- `vmnet-helper.sock.lock`: lockfile for vment-helper socket

The files are deleted when vmnet-helper and vfkit are terminated
gracefully. If they are killed the stale files are replaced on the next
start.

Issues:
- If the path exceeds the limit (104 characters), opening the socket
  will fail. We have the sames issue with vfkit management socket.

* vment: Fallback to interactive sudo

If vmnet-helper sudoers rule is not configured or does not work for the
user, maybe because the user has disabled the NOPASSWD option, we used
to fail, recommending to configure vmnet sudoers rule. This does not
help a user that cannot fix the sudoers configuration.

Since we switched to --socket mode, we can work without a sudoers rule.
If we can interact with the user, we fall back to interactive sudo. The
user can enter a password to start the machine.

Example run with --interactive=false:

    % minikube start --driver vfkit --network vmnet-shared --interactive=false
    😄  minikube v1.35.0 on Darwin 15.4.1 (arm64)
      Using the vfkit (experimental) driver based on user configuration

    🙈  Exiting due to NOT_CONFIGURED_VMNET_HELPER: failed to validate vmnet-shared network:
    exit status 1: sudo: a password is required
    💡  Suggestion:

        Configure vmnet-helper to run without a password.

        Please install a vmnet-helper sudoers rule using these instructions:

        https://github.com/nirs/vmnet-helper#granting-permission-to-run-vmnet-helper

Example run with --interactive (default):

    % minikube start --driver vfkit --network vmnet-shared
    😄  minikube v1.35.0 on Darwin 15.4.1 (arm64)
      Using the vfkit (experimental) driver based on user configuration
    💡  Unable to run vmnet-helper without a password
        To configure vment-helper to run without a password, please check the documentation:
        https://github.com/nirs/vmnet-helper/#granting-permission-to-run-vmnet-helper
    Password:
    👍  Starting "minikube" primary control-plane node in "minikube" cluster
    🔥  Creating vfkit VM (CPUs=2, Memory=6000MB, Disk=20000MB) ...
    🐳  Preparing Kubernetes v1.33.0 on Docker 27.4.0 ...
        ▪ Generating certificates and keys ...
        ▪ Booting up control plane ...
        ▪ Configuring RBAC rules ...
    🔗  Configuring bridge CNI (Container Networking Interface) ...
    🔎  Verifying Kubernetes components...
        ▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
    🌟  Enabled addons: storage-provisioner, default-storageclass
    🏄  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
2025-05-12 16:44:32 -07:00