← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Runs With an Unconfined AppArmor Profile

initcontainer-apparmor-profile

severityModerate resourceInitContainers productKubernetes bundles2

An Unconfined AppArmor profile strips the mandatory access controls over file, capability and mount operations in the init container, widening what a compromised process can reach on the host.

Rejects unless

!has(object.spec.initContainers) || object.spec.initContainers.all(ic,
  !has(ic.securityContext) ||
  !has(ic.securityContext.appArmorProfile) ||
  !has(ic.securityContext.appArmorProfile.type) ||
  variables.allowedAppArmorTypes.exists(t, t == ic.securityContext.appArmorProfile.type)
)

spec.initContainers[*].securityContext.appArmorProfile.type must be undefined, RuntimeDefault, or Localhost.

Variables

allowedAppArmorTypes

["RuntimeDefault","Localhost"]

Remediation

Replace Unconfined with RuntimeDefault, or with Localhost naming a profile loaded on the node. Field: spec.initContainers[*].securityContext.appArmorProfile.type.

Applies to

  • pods · v1 · CREATE, UPDATE

Manifest

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: initcontainer-apparmor-profile
  annotations:
    kubeapt.io/uuid: "52a53ccc-78d2-4650-b761-ba691fe4d9cd"
    security.kubeapt.io/displayName: "Runs With an Unconfined AppArmor Profile"
    security.kubeapt.io/description: "An Unconfined AppArmor profile strips the mandatory access controls over file, capability and mount operations in the init container, widening what a compromised process can reach on the host."
    security.kubeapt.io/resource: "InitContainers"
    security.kubeapt.io/severity: "Moderate"
    security.kubeapt.io/remediation: "Replace Unconfined with RuntimeDefault, or with Localhost naming a profile loaded on the node. Field: spec.initContainers[*].securityContext.appArmorProfile.type."
    security.kubeapt.io/product: "Kubernetes"
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
    - apiGroups:
      - ''
      apiVersions:
      - v1
      operations:
      - CREATE
      - UPDATE
      resources:
      - pods
  variables:
  - name: allowedAppArmorTypes
    expression: |
      ["RuntimeDefault","Localhost"]
  validations:
  - expression: |
      !has(object.spec.initContainers) || object.spec.initContainers.all(ic,
        !has(ic.securityContext) ||
        !has(ic.securityContext.appArmorProfile) ||
        !has(ic.securityContext.appArmorProfile.type) ||
        variables.allowedAppArmorTypes.exists(t, t == ic.securityContext.appArmorProfile.type)
      )
    message: |
      spec.initContainers[*].securityContext.appArmorProfile.type must be undefined, RuntimeDefault, or Localhost.

Save it as initcontainer-apparmor-profile.yaml — the commands below assume that name.

Validate with kubeapt

Check a workload against this one policy, before anything is installed on a cluster.

$ kubeapt validate -p ./initcontainer-apparmor-profile.yaml -r ./workload.yaml

Or without the file, from the published policy set — -r takes a directory too:

$ kubeapt policies download && kubeapt validate --policy-name initcontainer-apparmor-profile -r ./manifests

Or against every namespace in the cluster your kubeconfig points at:

$ kubeapt validate --policy-name initcontainer-apparmor-profile -A