Skip to content

Instantly share code, notes, and snippets.

@denji
Last active December 5, 2022 23:12
Show Gist options
  • Save denji/bdb54a436015efd938640dc9913e6c63 to your computer and use it in GitHub Desktop.
Save denji/bdb54a436015efd938640dc9913e6c63 to your computer and use it in GitHub Desktop.
Allow access to anyone in the libvirt group to run virt-manager without sudo. Tested on Ubuntu 18.04. #Polkit #PolicyKit #pkaction #qemu #kvm #sudo #linux
# Ubuntu/Debian
# New rules files are written in JavaScript unsupported. (need pkaction 0.106+)
# /etc/polkit-1/localauthority/50-local.d/libvirt-manage.pkla
[libvirt Management Access]
Identity=unix-group:libvirt
Action=org.libvirt.unix.manage
ResultActive=yes
ResultInactive=yes
ResultAny=yes
// CentOS/Fedora/RHEL
// /etc/polkit-1/rules.d/80-libvirt.rules
// https://libvirt.org/auth.html
// https://wiki.archlinux.org/index.php/Polkit
// https://gist.github.com/grawity/3886114
// sudo systemctl restart polkit
polkit.addRule(function(action, subject) {
if (action.id == "org.libvirt.unix.manage" && subject.local && subject.isInGroup("libvirt")) {
return polkit.Result.YES;
}
});
// https://www.freedesktop.org/software/polkit/docs/latest/polkit.8.html
// sudo systemctl restart polkit
// allow user denji
polkit.addRule(function(action, subject) {
if (action.id == "org.libvirt.unix.manage" && subject.local && subject.user == "denji") {
return polkit.Result.YES;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment