Open raoulbhatia opened 2 years ago
I am experiencing a nearly identical issue - My only difference is that the libvirtd host is running Debian 11 and the guest tries to start from an image whose backing volume is a Debian 11 image stored at the default '/var/lib/libvirt/images' location.
error: internal error: process exited while connecting to monitor: 2022-02-12T12:21:17.463372Z qemu-system-x86_64: -blockdev {"driver":"file","filename":"/var/lib/libvirt/images/debian11","node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}: Could not open '/var/lib/libvirt/images/debian11': Permission denied
As access to the default image store is also denied, I do not believe that the auto-magic configuration for non-standard paths would solve all the issues.
I'll continue my debugging and see if I can find a viable solution.
I don't think the provider should auto-configure this (and can't as we can't assume we run as root).
I'd accept a PR hinting at this in the README and also in the docs.
@dmacvicar
So what I have discovered now checking the bug within in the libvirt-apparmor thing and the behaviour of the terraform provider:
I'am using .qcow2 as my image formats. If I specifiy my volume as following the instance is able to start but not boot. This is because the provider sets the disk format to raw by default. Changing the disk format manually to qcow2 afterwards resolves the boot issue.
Terraform code:
disk { file = libvirt_volume.terminal.id }
Generated XML:
`
`
Apparmor can generate a allow rule for this because the attribute "source file" specifies the full path. The Apparmor virt-aa-helper reads the libvirt domain xml and adds it's image file path to the allow rules.
This is not working if you specifiy the following:
Terraform code:
disk { volume_id = libvirt_volume.terminal.id }
Generated XML:
`
`
Error after "terraform apply:
Error: error creating libvirt domain: internal error: process exited while connecting to monitor: 2023-02-09T21:19:11.930365Z qemu-system-x86_64: -blockdev {"driver":"file","filename":"***/terminal.qcow2","node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}: Could not open '***/terminal.qcow2': Permission denied
The Apparmor helper cannot generate a allow rule because it cannot read the dir path of the storage pool and therefore cannot generate the absolute path to the image file.
Unfortunately this issue is open since 2017 within libvirt. Therefore I would suggest to modify the disk block within libvirt_domain a litte bit as disabling the libvirt security mechanism should not be a prefered fix.
First: If you specifiy "file" as the disk source there should be a option to set the disk format to something other than raw. This would ensure that custom storage pools with a dir path and a file format other than raw are working with the provider even if apparmor is enabled. Apparmor can read the full disk path and generate a allow rule. So the domain XML should like this
`
`
Second: What I noticed after "terraform plan" and "terraform apply" with the disk specified as "file" when you do a new "terraform plan" the provider suggests a change:
disk { "- file = "/terminal.qcow2"" "+ volume_id = "/terminal.qcow2"" }
This should also be looked into. Don't know why terraform wants to change something here. If you apply nothing happens as far as I checked it. Non the less this change should not appear. This only occurs the first time after the instance as has been provisioned with the disk as "file.
Initial Libvirt Bug Discussion: https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/1677398
Libvirt Gitlab Upstream Bug: https://gitlab.com/libvirt/libvirt/-/issues/135
System Information
Linux distribution
Ubuntu 20.04.3 LTS
Terraform, provider and libvirt version
Description of Issue/Question
Setup
Base setup from https://blog.ruanbekker.com/blog/2020/10/08/using-the-libvirt-provisioner-with-terraform-for-kvm/ with the following change to the
libvirt_disk_path
variable.(Please provide the full main.tf file for reproducing the issue (Be sure to remove sensitive information)
Steps to Reproduce Issue
Use
Ubuntu 20.04
with standardapparmor
andlibvirt
packagesThe defined libvirtd domain
terraform-kvm-ansible
will fail to start with the following output:This can also be reproduced by running
virsh start terraform-kvm-ansible
on the KVM hypervisor.apparmor
error indmesg
Solution
Add the non-standard path to
/etc/apparmor.d/local/abstractions/libvirt-qemu
, i.e.Proposal
Perhaps there would be an option to either
Related upstream bug reports:
Thanks, Raoul