<p>I am trying to load an apparmor profile I created using GKE and some of the following instructions.</p>
<p>To apply the created app armor profile I followed this instructions:</p>
<p><a href="https://cloud.google.com/container-optimized-os/docs/how-to/secure-apparmor#creating_a_custom_security_profile" rel="nofollow noreferrer">https://cloud.google.com/container-optimized-os/docs/how-to/secure-apparmor#creating_a_custom_security_profile</a></p>
<p>which is just the apparmor parser applied to the node[s], and some follow up instructions to apply this same profile creation during restart of the node.
Basically is running the following line:</p>
<pre><code>/sbin/apparmor_parser --replace --write-cache /etc/apparmor.d/no_raw_net
</code></pre>
<p>and testing that a container with this profile is secured as expected.</p>
<p>As a second step I defined an environment variable with the apparmor profile name inside of an environment variable of the pod. As explained in here:</p>
<p><a href="https://cloud.google.com/migrate/anthos/docs/troubleshooting/app-armor-profile" rel="nofollow noreferrer">https://cloud.google.com/migrate/anthos/docs/troubleshooting/app-armor-profile</a></p>
<p>Basically is defining the pod in this way:</p>
<pre><code>spec:
  containers:
  - image: gcr.io/my-project/my-container:v1.0.0
    name: my-container
    env:
    - name: HC_APPARMOR_PROFILE
      value: &quot;apparmor-profile-name&quot;
    securityContext:
      privileged: true
</code></pre>
<p>Inside of the host the apparmor profile works as expected. But I cannot provide this profile.</p>
<p>Also tried removing the security context section of the pod that is defined as true in the documentation for gke.</p>
<p>Last but not least I tried with k8s pod annotation which is a feature of k8s to set a profile to a given container as explained here:</p>
<p><a href="https://kubernetes.io/docs/tutorials/security/apparmor/" rel="nofollow noreferrer">https://kubernetes.io/docs/tutorials/security/apparmor/</a></p>
<p>with this the pod looks like this:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: hello-apparmor-2
  annotations:
    container.apparmor.security.beta.kubernetes.io/hello: localhost/k8s-apparmor-example-allow-write
spec:
  containers:
  - name: hello
    image: busybox
    command: [ &quot;sh&quot;, &quot;-c&quot;, &quot;echo 'Hello AppArmor!' &amp;&amp; sleep 1h&quot; ]
</code></pre>
<p>but also had no good luck to apply the given profile.</p>
<p>Also tried to apply user-data config as a custom metadata for the cloud-init of the node instance, so it can add also the profile I created to app armor, and double check that the creation matters is not an issue but the edition of the cluster matadata is disable post creation of the cluster, and the creation of a new cluster node with the user-data is not allowed due to the fact that user-data is reserved for the container optimized os user data that will be defined by google.</p>
<p>No matter what I do I always end up either having unconfined profile for the current container or &quot;cri-containerd.apparmor.d (enforce)&quot; depending if the security context is set to true or not...</p>
<p>Do you have any advice on how can I provide the given profile to a pod in GKE?</p>

juan garcia
<p>If I understood the question correctly, seems like you are mixing the profile's filename with the profile name.</p>
<pre><code>annotations:
    container.apparmor.security.beta.kubernetes.io/&lt;container-name&gt;: localhost/&lt;profile-name&gt;
</code></pre>
<p>Here, <code>&lt;profile-name&gt;</code> is the name of the profile, it's not the same as the filename of the profile. Eg: in the below example filename is <code>no_raw_net</code> and <strong>profile name is</strong> <code>no-ping</code>.</p>
<pre><code>cat &gt; /etc/apparmor.d/no_raw_net &lt;&lt;EOF
#include &lt;tunables/global&gt;

profile no-ping flags=(attach_disconnected,mediate_deleted) {
  #include &lt;abstractions/base&gt;

  network inet tcp,
  network inet udp,
  network inet icmp,

  deny network raw,
  deny network packet,
  file,
  mount,
}
EOF
</code></pre>
