Gallery › Kubernetes › Azure built-in policies
Kubernetes cluster pod hostPath volumes should only use allowed host paths
Doesn't convert yet Policy Audit Deny Disabled Mode Microsoft.Kubernetes.Data Version 8.0.0
Limit pod HostPath volume mounts to the allowed host paths in a Kubernetes Cluster. This policy is generally available for Kubernetes Service (AKS), and Azure Arc enabled Kubernetes. For more information, see https://aka.ms/kubepolicydoc.
ConvertTo-Bylaw can't convert this policy yet:
- BYL6002 Its mode, Microsoft.Kubernetes.Data, is a resource provider mode, which language version 1.0 doesn't support.
Azure Policy JSONAllowedHostPaths.json · 300 lines
{
"properties": {
"displayName": "Kubernetes cluster pod hostPath volumes should only use allowed host paths",
"policyType": "BuiltIn",
"mode": "Microsoft.Kubernetes.Data",
"description": "Limit pod HostPath volume mounts to the allowed host paths in a Kubernetes Cluster. This policy is generally available for Kubernetes Service (AKS), and Azure Arc enabled Kubernetes. For more information, see https://aka.ms/kubepolicydoc.",
"metadata": {
"version": "8.0.0",
"category": "Kubernetes"
},
"version": "8.0.0",
"parameters": {
"source": {
"type": "String",
"metadata": {
"displayName": "Source",
"description": "The source k8s object for constraint evaluation. 'Original' means only evaluate against the specific GroupVersionKind specified in the policy definition. 'Generated' means only evaluate against k8s objects generated by Gatekeeper ExpansionTemplates. 'All' means evaluate against both the original object and any generated ones."
},
"defaultValue": "Original",
"allowedValues": [
"All",
"Generated",
"Original"
]
},
"warn": {
"type": "Boolean",
"metadata": {
"displayName": "Warn",
"description": "Whether or not to return warnings back to the user in the kubectl cli"
},
"defaultValue": false
},
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "'Audit' allows a non-compliant resource to be created or updated, but flags it as non-compliant. 'Deny' blocks the non-compliant resource creation or update. 'Disabled' turns off the policy.",
"portalReview": true
},
"allowedValues": [
"audit",
"Audit",
"deny",
"Deny",
"disabled",
"Disabled"
],
"defaultValue": "Audit"
},
"excludedNamespaces": {
"type": "Array",
"metadata": {
"displayName": "Namespace exclusions",
"description": "List of Kubernetes namespaces to exclude from policy evaluation. System namespaces \"kube-system\", \"gatekeeper-system\" and \"azure-arc\" are always excluded by design. \"azure-extensions-usage-system\" is optional to remove."
},
"defaultValue": [
"kube-system",
"gatekeeper-system",
"azure-arc",
"azure-extensions-usage-system"
]
},
"namespaces": {
"type": "Array",
"metadata": {
"displayName": "Namespace inclusions",
"description": "List of Kubernetes namespaces to only include in policy evaluation. An empty list means the policy is applied to all resources in all namespaces."
},
"defaultValue": []
},
"labelSelector": {
"type": "object",
"metadata": {
"displayName": "Kubernetes label selector",
"description": "Label query to select Kubernetes resources for policy evaluation. An empty label selector matches all Kubernetes resources."
},
"defaultValue": {},
"schema": {
"description": "A label selector is a label query over a set of resources. The result of matchLabels and matchExpressions are ANDed. An empty label selector matches all resources.",
"type": "object",
"properties": {
"matchLabels": {
"description": "matchLabels is a map of {key,value} pairs.",
"type": "object",
"additionalProperties": {
"type": "string"
},
"minProperties": 1
},
"matchExpressions": {
"description": "matchExpressions is a list of values, a key, and an operator.",
"type": "array",
"items": {
"type": "object",
"properties": {
"key": {
"description": "key is the label key that the selector applies to.",
"type": "string"
},
"operator": {
"description": "operator represents a key's relationship to a set of values.",
"type": "string",
"enum": [
"In",
"NotIn",
"Exists",
"DoesNotExist"
]
},
"values": {
"description": "values is an array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty.",
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"key",
"operator"
],
"additionalProperties": false
},
"minItems": 1
}
},
"additionalProperties": false
}
},
"allowedHostPaths": {
"type": "Object",
"metadata": {
"displayName": "Allowed host paths",
"description": "The host paths allowed for pod hostPath volumes to use. Provide an empty paths list to block all host paths.",
"portalReview": true
},
"defaultValue": {
"paths": []
},
"schema": {
"type": "object",
"properties": {
"paths": {
"type": "array",
"items": {
"type": "object",
"properties": {
"pathPrefix": {
"type": "string"
},
"readOnly": {
"type": "boolean"
}
},
"required": [
"pathPrefix",
"readOnly"
],
"additionalProperties": false
}
}
},
"required": [
"paths"
],
"additionalProperties": false
}
},
"windowsAllowedHostPaths": {
"type": "Object",
"metadata": {
"displayName": "Allowed host paths for windows containers",
"description": "The host paths allowed for windows pod hostPath volumes to use. Provide an empty paths list to block all host paths. Use \"C:\\\" to allow all windows host paths.",
"portalReview": true
},
"defaultValue": {
"paths": []
},
"schema": {
"type": "object",
"properties": {
"paths": {
"type": "array",
"items": {
"type": "object",
"properties": {
"pathPrefix": {
"type": "string"
},
"readOnly": {
"type": "boolean"
}
},
"required": [
"pathPrefix",
"readOnly"
],
"additionalProperties": false
}
}
},
"required": [
"paths"
],
"additionalProperties": false
}
},
"blockSocketMountPaths": {
"type": "Boolean",
"metadata": {
"displayName": "Block container runtime socket host paths",
"description": "Block hostPath volumes and 'Socket' type volumes that expose container runtime sockets, even when the path is allowed and mounted read-only. Set to false only when access to container runtime sockets is intentionally required."
},
"defaultValue": true
},
"requireRecursiveReadOnly": {
"type": "Boolean",
"metadata": {
"displayName": "Require recursive read-only for read-only host paths",
"description": "When enabled, a host path allowed with readOnly must be mounted with recursiveReadOnly set to 'Enabled' (Kubernetes 1.30+). A plain readOnly mount only makes the top-level mount read-only and leaves nested submounts writable. Only 'Enabled' is accepted because it is the only value that guarantees recursive read-only. Defaults to false to preserve behavior and avoid breaking workloads or nodes without recursive read-only support."
},
"defaultValue": false
},
"excludedContainers": {
"type": "Array",
"metadata": {
"displayName": "Containers exclusions",
"description": "The list of InitContainers and Containers to exclude from readonly evaluation. It will not exclude the disallowed host path. The identify is the name of container. Use an empty list to apply this policy to all containers in all namespaces."
},
"defaultValue": []
},
"excludedImages": {
"type": "Array",
"metadata": {
"displayName": "Image exclusions",
"description": "The list of InitContainers and Containers to exclude from policy evaluation. The identifier is the image of container. Prefix-matching can be signified with `*`. For example: `myregistry.azurecr.io/istio:*`. It is recommended that users use the fully-qualified Docker image name (e.g. start with a domain name) in order to avoid unexpectedly exempting images from an untrusted repository.",
"deprecated": true
},
"defaultValue": []
},
"excludedWorkloads": {
"type": "Array",
"metadata": {
"displayName": "Workload exclusions",
"description": "The list of InitContainers and Containers to exclude from policy evaluation. Each entry is an object with `image`, `namespace` and `serviceAccount`; a container is excluded only when all three match. Prefix-matching on the image can be signified with `*`. For example: `myregistry.azurecr.io/istio:*`. It is recommended that users use the fully-qualified Docker image name (e.g. start with a domain name) in order to avoid unexpectedly exempting images from an untrusted repository. The namespace and service account scope the exclusion to a specific workload identity, so that naming an excluded image is not on its own sufficient to skip evaluation. In public-cloud policy version 8.0.0 and later, excludedImages is retained only for assignment compatibility and is ignored. Before upgrading, migrate each image exclusion to an entry here with an explicitly approved namespace and service account, and validate in Audit before enabling Deny.",
"portalReview": true
},
"defaultValue": []
}
},
"policyRule": {
"if": {
"field": "type",
"in": [
"Microsoft.Kubernetes/connectedClusters",
"Microsoft.ContainerService/managedClusters"
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"source": "[parameters('source')]",
"warn": "[parameters('warn')]",
"templateInfo": {
"sourceType": "PublicURL",
"url": "https://store.policy.core.windows.net/kubernetes/allowed-host-paths/v7/template.yaml"
},
"apiGroups": [
""
],
"kinds": [
"Pod"
],
"excludedNamespaces": "[parameters('excludedNamespaces')]",
"namespaces": "[parameters('namespaces')]",
"labelSelector": "[parameters('labelSelector')]",
"values": {
"allowedHostPaths": "[parameters('allowedHostPaths').paths]",
"windowsAllowedHostPaths": "[parameters('windowsAllowedHostPaths').paths]",
"blockSocketMountPaths": "[parameters('blockSocketMountPaths')]",
"requireRecursiveReadOnly": "[parameters('requireRecursiveReadOnly')]",
"excludedContainers": "[parameters('excludedContainers')]",
"excludedWorkloads": "[parameters('excludedWorkloads')]"
}
}
}
},
"versions": [
"8.0.0",
"7.0.0",
"6.4.0",
"6.3.0",
"6.2.0",
"6.1.1"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/098fc59e-46c7-4d99-9b16-64990e543d75",
"name": "098fc59e-46c7-4d99-9b16-64990e543d75"
}Source: built-in-policies/policyDefinitions/Kubernetes/AllowedHostPaths.json in Azure/azure-policy, under the MIT licence.
Bylaw