FS#63152 - [libvirt] dropping privileges via libvirt seclabel does not work
Attached to Project:
Community Packages
Opened by Thomas Krug (phragment) - Wednesday, 10 July 2019, 20:49 GMT
Last edited by Toolybird (Toolybird) - Thursday, 27 April 2023, 06:22 GMT
Opened by Thomas Krug (phragment) - Wednesday, 10 July 2019, 20:49 GMT
Last edited by Toolybird (Toolybird) - Thursday, 27 April 2023, 06:22 GMT
|
Details
Description:
Dropping privileges via libvirt seclabel does not work due to incorrect permissions. Additional info: package version: libvirt 5.4.0-1 Steps to reproduce: # $EDITOR /etc/libvirt/qemu.conf user = "root" group = "root" # virsh edit somedomain <seclabel type='static' model='dac' relabel='yes'> <label>nobody:kvm</label> </seclabel> Started virtual machine does not run as nobody:kvm. Further info: https://www.redhat.com/archives/libvir-list/2019-July/msg00511.html # ls -ld /var/lib/libvirt/qemu/ drwxrwx--- 9 nobody kvm 4096 19. Jun 17:05 /var/lib/libvirt/qemu/ # chmod a+x /var/lib/libvirt/qemu/ # ls -ld /var/lib/libvirt/qemu/ drwxr-x--x 9 nobody kvm 4096 19. Jun 17:05 /var/lib/libvirt/qemu/ |
This task depends upon
rm -rf \
..
"${pkgdir}"/var/lib/libvirt/qemu
Arch is deleting that dir and letting libvirt create it on first run of daemon which appears to work fine.
On my system the perms are correct:
drwxr-xr-x 8 zzz kvm 4096 Jul 11 12:43 /var/lib/libvirt/qemu
(Sidenote: I'm not sure what libvirt does when /etc/libvirt/qemu.conf is subsequently edited with different user/group.)
In summary, it looks like upstream bug reporter has somehow acquired wrong perms on /var/lib/libvirt/qemu
On the question of whether Arch should be touching that dir or not? Dunno.
The makefile from libvirt creates the path:
$(MKDIR_P) -m 0751 "$(DESTDIR)$(localstatedir)/lib/libvirt/qemu"
It is unclear for me why the path is deleted in the pkgbuild.
I could reproduce the issue on my system without modifying the permissions.
But my system is an "old" arch install (installed libvirt pkg around 2014) maybe this has changed a while ago?
I will look into it.
FS#54943do not hardcode kvm group number":https://git.archlinux.org/svntogit/community.git/commit/trunk?h=packages/libvirt&id=9f43c804cfea3ff39bb912f800202a542ffd210e
(git-svn-id: file:///srv/repos/svn-community/svn@274310 9fca08f4-af9d-4005-b8df-a31f2cc04f65)
I cannot find the reason therefore, I would propose the attached patch.
Edit:
In your patch why the need for the chmod? The permissions were already set in the Makefile.
Also how would you resolve the possible mismatch mismatches between the dynamically assigned GID for kvm and UID for nobody between the build machine and the target machine?
But libvirt will chmod them once and further config changes will silently fail, not dropping privileges.
This would avoid possible ID mismatches and I believe pacman will not change directory permissions on existing directories.
I still trying to understand how /var/lib/libvirt/qemu on your system became 0770.
Edit:
possibly a tmpfiles.d snippet such as
d /var/lib/libvirt/qemu 0751 kvm nobody
d /var/cache/libvirt/qemu 0750 kvm nobody
This explains why older libvirt installations (pre Dec 2017) will have the issue and newer ones won't.
I don't know much about tmpfiles.d but it sounds plausible.
@loqs, I concur with you.
I attached a proposed patch.
Off Topic:
zfs is missing in makedepends. And there is a problem with wireshark deps?
wireshark/src/plugin.c:17:10: fatal error: wireshark/config.h: No such file or directory
pacman -Ss wireshark
community/wireshark-cli 3.0.2-1 [installed]
changes from the official build in previous commits updated libvirt to version 6.1.0 and fix firewalld support.
PKGBUILD.diff (3.1 KiB)
virsh -c lxc:/// start mycontainer
error: Failed to start domain mycontainer
error: internal error: guest failed to start: free(): invalid size
FS#64789instead of this bug?Edit:
Are there any additional messages in libvirt's log [1] files when the container fails to start?
[1] https://libvirt.org/logging.html
But I could easily be wrong as I don't use seclabel. It would be good if someone affected by this bug could test latest 6.3.0.
True. But doesn't that mean we fail to fix up the already broken installations out there? That's why your earlier suggestion of using z was pure genius :)
The z line could be dropped at some future point after all users are expected to have updated.