<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>AppArmor &#8211; Johnny Morano&#039;s Tech Articles</title>
	<atom:link href="https://jmorano.moretrix.com/tag/apparmor/feed/" rel="self" type="application/rss+xml" />
	<link>https://jmorano.moretrix.com</link>
	<description>Ramblings of an old-fashioned space cowboy</description>
	<lastBuildDate>Sun, 10 Apr 2022 09:44:36 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.2</generator>

<image>
	<url>https://jmorano.moretrix.com/wp-content/uploads/2022/04/cropped-jmorano_emblem-32x32.png</url>
	<title>AppArmor &#8211; Johnny Morano&#039;s Tech Articles</title>
	<link>https://jmorano.moretrix.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Libvirt guest startup issue with AppArmor</title>
		<link>https://jmorano.moretrix.com/2022/04/libvirt-guest-startup-issue-with-apparmor/</link>
					<comments>https://jmorano.moretrix.com/2022/04/libvirt-guest-startup-issue-with-apparmor/#respond</comments>
		
		<dc:creator><![CDATA[Johnny Morano]]></dc:creator>
		<pubDate>Sun, 10 Apr 2022 09:37:48 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[AppArmor]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[DevOps]]></category>
		<category><![CDATA[Libvirt]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[SysAdmin]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<guid isPermaLink="false">https://jmorano.moretrix.com/?p=1487</guid>

					<description><![CDATA[With AppArmor enabled on Debian/ Ubuntu systems, starting up virtual machines with libvirt can cause startup failures if&#8230;]]></description>
										<content:encoded><![CDATA[
<p>With <a href="https://apparmor.net/" data-type="URL" data-id="https://apparmor.net/" target="_blank" rel="noreferrer noopener">AppArmor</a> enabled on Debian/ Ubuntu systems, starting up virtual machines with <a href="https://libvirt.org/" data-type="URL" data-id="https://libvirt.org/" target="_blank" rel="noreferrer noopener">libvirt</a> can cause startup failures if not AppArmor is not properly configured.</p>



<p>AppArmor will write messages to the kernel log (visible with either the <code>dmesg</code> command or in <code>kernel.log</code> if available) regarding its actions.</p>



<p>If your libvirt guests are not starting up or failing, have a look at <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">dmesg</mark></code>. Example:</p>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="82" src="https://jmorano.moretrix.com/wp-content/uploads/2022/04/Screenshot-from-2022-04-10-11-09-15-1024x82.png" alt="" class="wp-image-1488" srcset="https://jmorano.moretrix.com/wp-content/uploads/2022/04/Screenshot-from-2022-04-10-11-09-15-1024x82.png 1024w, https://jmorano.moretrix.com/wp-content/uploads/2022/04/Screenshot-from-2022-04-10-11-09-15-300x24.png 300w, https://jmorano.moretrix.com/wp-content/uploads/2022/04/Screenshot-from-2022-04-10-11-09-15-768x62.png 768w, https://jmorano.moretrix.com/wp-content/uploads/2022/04/Screenshot-from-2022-04-10-11-09-15-850x68.png 850w, https://jmorano.moretrix.com/wp-content/uploads/2022/04/Screenshot-from-2022-04-10-11-09-15.png 1242w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>In the above example AppArmor has <mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">denied</mark> (<code>apparmor="DENIED"</code>) read access (<code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">requested_mask=r</mark></code>) to the file <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">/data/vms/cluster_storage/base-os-ubuntu-focal.qcow2</mark></code>. This blocks of course the startup guest machines we have previously created in the article: <a href="https://jmorano.moretrix.com/2022/03/terraform-and-libvirtd-nodes/" data-type="post" data-id="1302">Terraform and libvirtd nodes</a>.</p>



<p>To fix the issue, edit the file: <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">/etc/apparmor.d/libvirt/TEMPLATE.qemu</mark></code></p>



<p>By default it has the following content:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#
# This profile is for the domain whose UUID matches this file.
#

#include &lt;tunables/global>

profile LIBVIRT_TEMPLATE flags=(attach_disconnected) {
  #include &lt;abstractions/libvirt-qemu>
}
</pre>



<p>In order to allow <code>libvirt</code> to use the guest image files, change the content to (or add a similar line if your file path is different):</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#
# This profile is for the domain whose UUID matches this file.
#

#include &lt;tunables/global>

profile LIBVIRT_TEMPLATE flags=(attach_disconnected) {
  #include &lt;abstractions/libvirt-qemu>
  /data/vms/cluster_storage/**.qcow2 rwk,
}
</pre>



<p>The added line (<mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">line 9</mark>) will allow read (<code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">r</mark></code>), write (<code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">w</mark></code>) and lock (<code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">k</mark></code>) access to all <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">qcow2</mark></code> files in the directory <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">/data/vms/cluster_storage</mark></code>.</p>



<p>Once added, all libvirt guests will start up again without any (AppArmor) issues.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://jmorano.moretrix.com/2022/04/libvirt-guest-startup-issue-with-apparmor/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
