uvt-kvm list requires sudo on non-login shells

Bug #2002530 reported by Andrei Gherzan
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
uvtool
Fix Committed
Undecided
Unassigned

Bug Description

As per the current implementation, `uvtool list` is a wrapper over `virsh`.

def main_list(parser, args):
    # Hack for now. In time this should properly use the API and list
    # only instances created with this tool.
    subprocess.check_call('virsh -q list --all|awk \'{print $2}\'', shell=True)

In a non-login shell, listing VMs with virsh would require elevated permissions (sudo) when default configuration is used (at all levels: client configuration, env variables etc.):

┌─ ~
└─❯ sudo uvt-kvm list
test
┌─ ~
└─❯ uvt-kvm list
┌─ ~
└─❯

For default connection, libvirt uses the following rule to determine its value[1]:
1. The environment variable LIBVIRT_DEFAULT_URI
2. The client configuration file uri_default parameter
3. Probe each hypervisor in turn until one that works is found
`
So when none apply (configuration-wise) and qemu support is used, libvirt will use qemu:///system for root and qemu:///session for normal users[2].

libvirt-clients provides a profile.d script to default the connection to the system daemon but, obviously, that only applies for login shells:

┌─ ~
└─❯ shopt -q login_shell; echo $?
1
┌─ ~
└─❯ echo $LIBVIRT_DEFAULT_URI
┌─ ~
└─❯ bash -l
┌─ ~
└─❯ shopt -q login_shell; echo $?
0
┌─ ~
└─❯ echo $LIBVIRT_DEFAULT_URI
qemu:///system

There is also worth mentioning that this bug report assumes that the user is part of the libvirt system group. Otherwise not only listing but also other operations are affected due to a lack of permissions on the libvirt socket.

[1] https://libvirt.org/uri.html#default-uri-choice
[2] https://libvirt.org/uri.html#qemu-qemu-and-kvm-uris

Related branches

Robie Basak (racb)
Changed in uvtool:
status: New → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.