Bylaw

Gallery › Kubernetes › Azure Community Policy

Control allowed Host Paths on volumes in a Kubernetes Cluster

Doesn't convert yet Policy Audit Deny Disabled Mode Microsoft.Kubernetes.Data Version 1.0.0 Preview

This policy controls valid host paths that are allowed to be used by hostPath volumes in a Kubernetes Cluster. For instructions on using this policy, please visit https://aka.ms/kubepolicydoc.

ConvertTo-Bylaw can't convert this policy yet:

Azure Policy JSONazurepolicy.json · 106 lines
{
  "properties": {
    "displayName": "Control allowed Host Paths on volumes in a Kubernetes Cluster",
    "policyType": "Custom",
    "mode": "Microsoft.Kubernetes.Data",
    "description": "This policy controls valid host paths that are allowed to be used by hostPath volumes in a Kubernetes Cluster. For instructions on using this policy, please visit https://aka.ms/kubepolicydoc.",
    "metadata": {
      "version": "1.0.0",
      "category": "Kubernetes",
      "preview": true
    },
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "defaultValue": "Audit"
      },
      "excludedNamespaces": {
        "type": "Array",
        "metadata": {
          "displayName": "Namespace exclusions",
          "description": "List of Kubernetes namespaces to exclude from policy evaluation."
        },
        "defaultValue": [
          "kube-system",
          "gatekeeper-system",
          "azure-arc"
        ]
      },
      "allowedHostPaths": {
        "type": "Object",
        "metadata": {
          "displayName": "Allowed host paths",
          "description": "Configure what hostPaths are valid for volumes to use. An empty list means there is no restriction on host paths used.",
          "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
          }
        },
        "defaultValue": {
          "paths": [
            {
              "pathPrefix": "/dev/null",
              "readOnly": true
            }
          ]
        }
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "in": [
          "AKS Engine",
          "Microsoft.Kubernetes/connectedClusters",
          "Microsoft.ContainerService/managedClusters"
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "constraintTemplate": "https://raw.githubusercontent.com/Azure/Community-Policy/master/policyDefinitions/Kubernetes/allowed-host-paths/template.yaml",
          "constraint": "https://raw.githubusercontent.com/Azure/Community-Policy/master/policyDefinitions/Kubernetes/allowed-host-paths/constraint.yaml",
          "values": {
            "excludedNamespaces": "[parameters('excludedNamespaces')]",
            "allowedHostPaths": "[parameters('allowedHostPaths').paths]"
          }
        }
      }
    }
  },
  "type": "Microsoft.Authorization/policyDefinitions",
  "name": "035822c0-0ab3-4622-8167-f3b9b8555c9c"
}

Source: policyDefinitions/Kubernetes/allowed-host-paths/azurepolicy.json in Azure/Community-Policy, under the MIT licence.