pod-apparmor-profile
An Unconfined AppArmor profile at pod level strips the mandatory access controls over file, capability and mount operations from every container that inherits it, widening what a compromised process can reach on the host.
!has(object.spec.securityContext) || !has(object.spec.securityContext.appArmorProfile) || !has(object.spec.securityContext.appArmorProfile.type) || variables.allowedAppArmorTypes.exists(t, t == object.spec.securityContext.appArmorProfile.type)
spec.securityContext.appArmorProfile.type must be undefined, RuntimeDefault, or Localhost.
allowedAppArmorTypes
["RuntimeDefault","Localhost"]
Replace Unconfined with RuntimeDefault, or with Localhost naming a profile loaded on the node. Field: spec.securityContext.appArmorProfile.type.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: pod-apparmor-profile
annotations:
kubeapt.io/uuid: "b71879ea-3051-4076-9040-e60c9606f4e5"
security.kubeapt.io/displayName: "Runs With an Unconfined AppArmor Profile"
security.kubeapt.io/description: "An Unconfined AppArmor profile at pod level strips the mandatory access controls over file, capability and mount operations from every container that inherits it, widening what a compromised process can reach on the host."
security.kubeapt.io/resource: "Pods"
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.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.securityContext) || !has(object.spec.securityContext.appArmorProfile) || !has(object.spec.securityContext.appArmorProfile.type) || variables.allowedAppArmorTypes.exists(t, t == object.spec.securityContext.appArmorProfile.type)
message: |
spec.securityContext.appArmorProfile.type must be undefined, RuntimeDefault, or Localhost.Save it as pod-apparmor-profile.yaml — the commands below assume that name.
Check a workload against this one policy, before anything is installed on a cluster.
$ kubeapt validate -p ./pod-apparmor-profile.yaml -r ./workload.yamlOr without the file, from the published policy set — -r takes a directory too:
$ kubeapt policies download && kubeapt validate --policy-name pod-apparmor-profile -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name pod-apparmor-profile -A