You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 16, 2020. It is now read-only.
Repository navigation
This repository was archived by the owner on Oct 16, 2020. It is now read-only.
libvirt: apparmor denies reading from /var/lib/libvirt/images/ #2083
I get this error when I start vm
error: internal error: process exited while connecting to monitor: 2017-07-31T04:52:22.223191Z qemu-system-x86_64: -fw_cfg name=opt/com.coreos/config,file=/var/lib/libvirt/images/config.ign: can't load /var/lib/libvirt/images/config.ign
I also have this same issue. Ignition file exists and is valid. Here is version information from virsh. I'm on ubuntu 16.04
root@server:~/Documents/libvirt-3.7.0# virsh -c qemu:///system version
Compiled against library: libvirt 2.2.0
Using library: libvirt 2.2.0
Using API: QEMU 2.2.0
Running hypervisor: QEMU 2.6.2
My issue ended loading the file ended up up being with /etc/libvirt/libvirtd.conf and needing to turn security off and then restarting libvirtd service.
@funwun did you ever figure this out?
Could you check if it was an apparmor issue? It looks like their wiki has good information, and checking if temporarily disabling apparmor makes a difference could determine if it's causing this issue.
Seeing that the workaround was to add to /etc/apparmor.d/abstractions/libvirt-qemu implies that not libvirt but the guest (=qemu) wasn't able to access the file.
virt-aa-helper is allowed to read these paths:
$ grep image /etc/apparmor.d/usr.lib.libvirt.virt-aa-helper
# For backingstore, virt-aa-helper needs to peek inside the disk image, so
/var/lib/libvirt/images/ r,
/var/lib/libvirt/images/** r,
# nova base images (LP: #907269)
/var/lib/nova/images/** r,
/var/lib/uvtool/libvirt/images/** r,
Now when a guest is spawned and apparmor is set as the security modules two things happen:
the guest gets created a custom apparmor profile by virt-aa-helper
this includes the general allowance from /etc/apparmor.d/abstractions/libvirt-qemu
it has entries for disks and devices of all sorts matching the definition of the guest
later hotplug or other events call from libvirt to virt-aa-helper to append rules for these
the guest (=qemu) gets started under that profile
In case a user is reporting an apparmor deny against that I'd assume for their case virt-aa-helper was unable to add the rule.
In those cases (e.g. the one by @purplesrl above with node3.ign) report it upstream (or here for this particular case).
Feel free to CC me - for those cases one would want to look at:
the Deny from dmesg
the related apparmor files which would be
/etc/apparmor.d/abstractions/libvirt-qemu
per guest file /etc/apparmor.d/libvirt/libvirt-$(virsh dominfo | awk '/UUID/ {print $2}').files
the libvirt xml describing the guest virsh dumpxml <guestname>
To shortcut that for the case here this is a user/config error and not a libvirt bug, let me outline why.
At least the initial report had an xml with an .ign file and for now I assume that is how everyone does it.
Like:
That is a manual qemu commandline addition outside of the scope what libvirt manages.
That most likely is the reason you are failing.
virt-aa-helper doesn't care about those "out of scope" entries so nothing adds a rule for this path.
If one (or some automation) adds such a path out-of-scope it needs to add the path as well to the apparmor rules.
Unfortunately there are no per-guest overrides (yet - I'm working on it as soon as confidtional if works in apparmor). So for now one has to edit /etc/apparmor.d/abstractions/libvirt-qemu to match what one added to the guest cmdline.
But for that I'd strictly vote against: /var/lib/libvirt/images/* r,
This would allow ALL guests (until you can override per-guest) to read ALL files in there.
This is totally not what you want.
Until you have per guest overrides, at least make the rule a full path, so in this case /var/lib/libvirt/images/config.ign r,
Or if you like maybe /var/lib/libvirt/images/*.ign r,
That would mean a malicious attacker breaking out of a guest can at least only read those files instead of all other guests images.
To allow to fix that in libvirt we would need one of two things
per guest override (in progress - will allow to add the rule just for the right guest)
some generic tag that means, you don't want to let libvirt add any devices, but for consideration to e.g. the security modules to allow access
Thanks for highlighting the -fw_cfg parameter usage here.
I should point out that although this is exposed to the end user via -fw_cfg, and looks like a convenient way to get information into the guest OS, this is generally discouraged by QEMU developers. The principal purpose of the "fw_cfg" mechanism is communication between QEMU and the firmware. There are a fairly limited number of slots available for passing information, and so long term there's no guarantee that there will be spare slots available for end user application usage in this way. Thus we're not likely to expose '-fw_cfg' in libvirt XML explicitly.
Recognising the usefulness of this conceptual approach though, I recently made it possible to use the SMBIOS "OEM strings" facility in QEMU and libvirt (https://libvirt.org/formatdomain.html#elementsSysinfo) to pass data into the guest. This will be available in QEMU 2.12, and libvirt 4.1.0. We're encouraging applications to include an application specific name prefix in the OEM strings entry so they can co-exist eg
So I'd encourage support of "OEM strings" as an alternative option to "fw_cfg", with eventual discontinuation of fw_cfg, once support for OEM strings is widely available in distros (will take a few years to penetrate)
Thanks Daniel - good to know,
OEM strings are nice, but they are too generic to parse paths out of them right?
So virt-aa-helper still can't know when to derive a path to add it to the rules (let me know you think there is a reasonable way to detect a path is meant in those cases).
@cpaelzer nothing todo from security pov since the data is passed inline, no references to external files on disk, so there is nothing to grant access to.
@berrange we'll look into OEM strings for the future. "fw_cfg" is being used by ignition for passing provisioning configuration since some time.
@cpaelzer then I guess we'll suggest adding a wildcard rule for ignition files to our doc. If per-guest overrides are under work, it would be nice in the future to have some standardized path for user provided guest-read-only stuff (either generically or specific for fw_cfg).
@berrange I built qemu 2.12-rc3 and added a file to a vm with -smbios type=11,value=ignition:"$(sed -e 's/,/,,/g' ~/test.ign)", and accessed it via sudo dmidecode --oem-string 1, but it seems to be getting truncated to 1024 characters. Is this an expected limitation, or is dmidecode the one shortening it here?
Ignition configs definitely end up being bigger than 1 KB, so that's not really a workable replacement if we can't up that limit.
Also is there a chance of being able to reference a file (something like -smbios type=11,file=~/test.ign) in place of including the value on the command line? Ignition configs can have newlines and it would be great to be able to avoid the comma replacement step.
@dgonyeo thanks for testing that, you've uncovered a horrible bug in QEMU. While SMBIOS has no limit on string length, QEMU's command line option parser is arbitrarily truncating options at 1024 bytes, with no warning, silently discarding any further data. I'm going to fix that to actually report an error message instead of continuing to run with garbage data. So yeah, unfortunately this means you can't use SMBIOS right now :-( Your suggestion to allow reference to an external file is a useful one, so I'll look at that too.
Activity
euank commentedon Jul 31, 2017
Total shot in the dark, but if you have selinux enabled it might be denying it.
funwun commentedon Jul 31, 2017
Host: Ubuntu 17.04 x64
SELinux status: disabled
grep CONFIG_FW_CFG_SYSFS /boot/config-$(uname -r)
lucab commentedon Jul 31, 2017
Does
var/lib/libvirt/images/config.ignactually exist and is it a valid configuration?kudramh commentedon Aug 27, 2017
removed apparmor and kvm started properly
funwun commentedon Aug 28, 2017
@lucab sure, the hostname only
pfremm commentedon Sep 12, 2017
I also have this same issue. Ignition file exists and is valid. Here is version information from virsh. I'm on ubuntu 16.04
root@server:~/Documents/libvirt-3.7.0# virsh -c qemu:///system version
Compiled against library: libvirt 2.2.0
Using library: libvirt 2.2.0
Using API: QEMU 2.2.0
Running hypervisor: QEMU 2.6.2
pfremm commentedon Sep 12, 2017
My issue ended loading the file ended up up being with /etc/libvirt/libvirtd.conf and needing to turn security off and then restarting libvirtd service.
euank commentedon Oct 12, 2017
@funwun did you ever figure this out?
Could you check if it was an apparmor issue? It looks like their wiki has good information, and checking if temporarily disabling apparmor makes a difference could determine if it's causing this issue.
pfremm commentedon Oct 12, 2017
Yeah you are correct it is. If I check the app armor status I can see libvirt in enforcing mode:
purplesrl commentedon Oct 23, 2017
+1 apparmor
Fixed by adding
In
/etc/apparmor.d/abstractions/libvirt-qemu11 remaining items
cpaelzer commentedon Apr 11, 2018
Odd, let me outline how it is supposed to work.
Seeing that the workaround was to add to /etc/apparmor.d/abstractions/libvirt-qemu implies that not libvirt but the guest (=qemu) wasn't able to access the file.
virt-aa-helper is allowed to read these paths:
Now when a guest is spawned and apparmor is set as the security modules two things happen:
In case a user is reporting an apparmor deny against that I'd assume for their case virt-aa-helper was unable to add the rule.
In those cases (e.g. the one by @purplesrl above with node3.ign) report it upstream (or here for this particular case).
Feel free to CC me - for those cases one would want to look at:
virsh dumpxml <guestname>To shortcut that for the case here this is a user/config error and not a libvirt bug, let me outline why.
At least the initial report had an xml with an .ign file and for now I assume that is how everyone does it.
Like:
That is a manual qemu commandline addition outside of the scope what libvirt manages.
That most likely is the reason you are failing.
virt-aa-helper doesn't care about those "out of scope" entries so nothing adds a rule for this path.
If one (or some automation) adds such a path out-of-scope it needs to add the path as well to the apparmor rules.
Unfortunately there are no per-guest overrides (yet - I'm working on it as soon as confidtional if works in apparmor). So for now one has to edit /etc/apparmor.d/abstractions/libvirt-qemu to match what one added to the guest cmdline.
But for that I'd strictly vote against:
/var/lib/libvirt/images/* r,This would allow ALL guests (until you can override per-guest) to read ALL files in there.
This is totally not what you want.
Until you have per guest overrides, at least make the rule a full path, so in this case
/var/lib/libvirt/images/config.ign r,Or if you like maybe
/var/lib/libvirt/images/*.ign r,That would mean a malicious attacker breaking out of a guest can at least only read those files instead of all other guests images.
To allow to fix that in libvirt we would need one of two things
berrange commentedon Apr 11, 2018
Thanks for highlighting the -fw_cfg parameter usage here.
I should point out that although this is exposed to the end user via -fw_cfg, and looks like a convenient way to get information into the guest OS, this is generally discouraged by QEMU developers. The principal purpose of the "fw_cfg" mechanism is communication between QEMU and the firmware. There are a fairly limited number of slots available for passing information, and so long term there's no guarantee that there will be spare slots available for end user application usage in this way. Thus we're not likely to expose '-fw_cfg' in libvirt XML explicitly.
Recognising the usefulness of this conceptual approach though, I recently made it possible to use the SMBIOS "OEM strings" facility in QEMU and libvirt (https://libvirt.org/formatdomain.html#elementsSysinfo) to pass data into the guest. This will be available in QEMU 2.12, and libvirt 4.1.0. We're encouraging applications to include an application specific name prefix in the OEM strings entry so they can co-exist eg
So I'd encourage support of "OEM strings" as an alternative option to "fw_cfg", with eventual discontinuation of fw_cfg, once support for OEM strings is widely available in distros (will take a few years to penetrate)
cpaelzer commentedon Apr 11, 2018
Thanks Daniel - good to know,
OEM strings are nice, but they are too generic to parse paths out of them right?
So virt-aa-helper still can't know when to derive a path to add it to the rules (let me know you think there is a reasonable way to detect a path is meant in those cases).
berrange commentedon Apr 11, 2018
@cpaelzer nothing todo from security pov since the data is passed inline, no references to external files on disk, so there is nothing to grant access to.
lucab commentedon Apr 11, 2018
Thanks both for the detailed insights!
@berrange we'll look into OEM strings for the future. "fw_cfg" is being used by ignition for passing provisioning configuration since some time.
@cpaelzer then I guess we'll suggest adding a wildcard rule for ignition files to our doc. If per-guest overrides are under work, it would be nice in the future to have some standardized path for user provided guest-read-only stuff (either generically or specific for fw_cfg).
cpaelzer commentedon Apr 11, 2018
I was unsure on your suggestion, so I polled for opinions on the libvirt mailing list
cgonyeo commentedon Apr 12, 2018
@berrange I built qemu 2.12-rc3 and added a file to a vm with
-smbios type=11,value=ignition:"$(sed -e 's/,/,,/g' ~/test.ign)", and accessed it viasudo dmidecode --oem-string 1, but it seems to be getting truncated to 1024 characters. Is this an expected limitation, or isdmidecodethe one shortening it here?Ignition configs definitely end up being bigger than 1 KB, so that's not really a workable replacement if we can't up that limit.
Also is there a chance of being able to reference a file (something like
-smbios type=11,file=~/test.ign) in place of including the value on the command line? Ignition configs can have newlines and it would be great to be able to avoid the comma replacement step.berrange commentedon Apr 13, 2018
@dgonyeo thanks for testing that, you've uncovered a horrible bug in QEMU. While SMBIOS has no limit on string length, QEMU's command line option parser is arbitrarily truncating options at 1024 bytes, with no warning, silently discarding any further data. I'm going to fix that to actually report an error message instead of continuing to run with garbage data. So yeah, unfortunately this means you can't use SMBIOS right now :-( Your suggestion to allow reference to an external file is a useful one, so I'll look at that too.
bgilbert commentedon Apr 26, 2018
For the record, patch series removing length limits in QEMU command-line parsing. The changes did not make QEMU 2.12.
cgwalters commentedon Jul 27, 2018
I think libvirt should do what I did in https://github.com/cgwalters/playground/commit/f2b67e50bc7f44d4b2e76ac6f3e5bbfe070819da#diff-f1a5248af69a24af73c52a6b2e565df6R75 and pass the config as a file descriptor. Since libvirt uses C it could even use memfd or
O_TMPFILErather than an unlinked real file.bgilbert commentedon Oct 31, 2018
The length limits were removed in QEMU 3.0.
bgilbert commentedon Nov 1, 2018
Support for OEM strings filed as coreos/ignition#656.
fix nvme by disabling qemu security driver
fix nvme by disabling qemu security driver
add support to disable qemu security driver