TMAegis
More rules for aks-automatic

TMA-AKS-AUTOMATIC-4.2.2

Minimize the admission of containers wishing to share the host process ID namespace

HighLevel 1Automatedaks-automatic

Description

Minimize the admission of Pods that request spec.hostPID=true so that only tightly controlled, explicitly approved platform workloads can share the host process ID namespace in AKS. Users, groups, and service accounts with deployment rights should not be able to create or update workloads that use host PID sharing without an approved exception. Requires kubectl with cluster-wide read access (KUBECONFIG); system namespaces are excluded and listed resources must be remediated or documented as exceptions.

How it is checked

Audit method: Shell command

shell
out=$(kubectl get pods -A -o go-template='{{range .items}}{{.metadata.namespace}} {{.metadata.name}} {{.spec.hostPID}}{{"\n"}}{{end}}') || exit 1
bad=$(printf '%s\n' "$out" | awk -v ex='^(kube-system|kube-public|kube-node-lease|gatekeeper-system|azure-arc)$' 'NF && $1 !~ ex && ($3=="true")')
if [ -z "$bad" ]; then echo compliant; else printf '%s\n' "$bad" | head -n 25; fi
Expected output
compliant

How it is fixed

Fix method: Guidance or infrastructure patch

AKS Automatic already enforces baseline Pod Security Standards and Deployment Safeguards. Remove spec.hostPID: true from user workloads that do not have an approved exception. Where an exception is required, use an approved namespace exclusion and limit who can manage it. Deployment Safeguards are already enabled in Enforce mode. Use Azure Policy only when additional centralized policy requirements are needed. Validate required workloads after making changes.

Properties

Operating systems
Any
Tags
aks-automaticpoliciespod-security
Reference
CIS Azure Kubernetes Service Automatic (AKS Automatic) Benchmark v1.0.0 - 4.2.2 Minimize the admission of containers wishing to share the host process ID namespace

Check this host

Run this on a machine you are allowed to audit. The scan is read-only.

shell
tmaegis scan --target aks-automatic