Skip to content
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

qemu_use_session triggers polkit action to acquire access to qemu:///system #1808

Open
dev-zero opened this issue Feb 17, 2024 · 4 comments
Open

Comments

@dev-zero
Copy link

When setting qemu_use_session = true I get an error about polkit being unavailable (on a minimal headless machine) to acquire root privileges to access qemu:///system.

Checking the driver it comes from this part of the code:

def list_all_networks
client = if @machine.provider_config.qemu_use_session
system_connection
else
connection.client
end

In fact, switching the lines as per

         client = if @machine.provider_config.qemu_use_session
-                   system_connection
-                else
                   connection.client
+                else
+                   system_connection
                 end

makes the machine come up as an unprivileged user with networking working.

A Vagrantfile to reproduce the issue:

Vagrant.configure("2") do |config|
  config.vm.define :test_vm do |test_vm|
    test_vm.vm.box = "opensuse/MicroOS.x86_64"
    test_vm.vm.synced_folder ".", "/vagrant", disabled: true
  end

  config.vm.provider :libvirt do |libvirt|
    libvirt.cpus = 2
    libvirt.qemu_use_session = true
  end
end

Full disclosure, afterwards vagrant kills the machine again due to this:

==> test_vm: Waiting for machine to boot. This may take a few minutes...




==> test_vm: Removing domain...
==> test_vm: Deleting the machine folder
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.

But I was able to connect to the VM via VNC and check the network.

@dev-zero
Copy link
Author

Follow up on the virtual machine bring-up: it seems that get_ipaddress_from_system_domain is not working either.
Simply commenting out the following helped in getting a machine up with qemu_use_session = true:

return get_ipaddress_from_system domain.mac if @machine.provider_config.qemu_use_session

@dev-zero
Copy link
Author

dev-zero commented Feb 19, 2024

This is with libvirt-10 on openSUSE Leap 15.5 (with a fix for https://bugzilla.opensuse.org/show_bug.cgi?id=1219986 applied). Will soon try with libvirt-9.

dev-zero added a commit to opencube-horizon/vagrant-libvirt that referenced this issue Feb 21, 2024
Detection of network connections via system is broken, but directly querying libvirt is working properly. Using the system connection with qemu_use_session is enabled will lead to polkit trying to acquire root privileges, which is unavailable in some setups. The client is nowadays capable of enumerating the network devices as unprivileged user.
Fixes vagrant-libvirt#1808.
@electrofelix
Copy link
Contributor

It should be possible to get read-only access to the system connection to read network information as a user. This sounds more like opensuse polkit is broken, as removing the opening of read-only system connection to read the network when session is used will simply break for all other distros.

@dev-zero
Copy link
Author

@electrofelix unfortunately not, polkit is working:

muellert@o184i163:~> virsh -r -c qemu:///system iface-list
==== AUTHENTICATING FOR org.libvirt.unix.monitor ====
System policy prevents monitoring of local virtualized systems
Authenticating as: root
Password:

If the user is not a member of libvirt, the system is asking for root permissions to access the system-wide libvirt socket, whether in read-only mode or not (see above the -r).
In particular, as soon as polkit gets involved, we are not in user-session mode anymore.
I will see whether I can test the change on other distros.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants