Bylaw

Gallery › Kubernetes › Azure built-in policies

Azure Kubernetes Clusters should enable Container Storage Interface(CSI)

Converted Policy Audit Disabled Mode Indexed Version 1.0.0

The Container Storage Interface (CSI) is a standard for exposing arbitrary block and file storage systems to containerized workloads on Azure Kubernetes Service. To learn more, https://aka.ms/aks-csi-driver

ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.

Azure Policy JSONAKS_CSI.json · 125 lines
{
  "properties": {
    "displayName": "Azure Kubernetes Clusters should enable Container Storage Interface(CSI)",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "The Container Storage Interface (CSI) is a standard for exposing arbitrary block and file storage systems to containerized workloads on Azure Kubernetes Service. To learn more, https://aka.ms/aks-csi-driver",
    "metadata": {
      "version": "1.0.0",
      "category": "Kubernetes"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "String",
        "defaultValue": "Audit",
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy",
          "portalReview": true
        }
      },
      "enableDiskCSI": {
        "type": "String",
        "defaultValue": "true",
        "allowedValues": [
          "true",
          "false"
        ],
        "metadata": {
          "displayName": "Enable Disk CSI Monitoring",
          "description": "Enable monitoring of disk CSI driver. 'false' will skip monitoring",
          "portalReview": true
        }
      },
      "enableFileCSI": {
        "type": "String",
        "defaultValue": "true",
        "allowedValues": [
          "true",
          "false"
        ],
        "metadata": {
          "displayName": "Enable File CSI Monitoring",
          "description": "Enable monitoring of file CSI driver. 'false' will skip monitoring",
          "portalReview": true
        }
      },
      "enableSnapshotCSI": {
        "type": "String",
        "defaultValue": "true",
        "allowedValues": [
          "true",
          "false"
        ],
        "metadata": {
          "displayName": "Enable Snapshot CSI Monitoring",
          "description": "Enable monitoring of snapshot CSI driver. 'false' will skip monitoring",
          "portalReview": true
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.ContainerService/managedClusters"
          },
          {
            "anyOf": [
              {
                "allOf": [
                  {
                    "field": "Microsoft.ContainerService/managedClusters/storageProfile.diskCSIDriver.enabled",
                    "equals": false
                  },
                  {
                    "value": "[parameters('enableDiskCSI')]",
                    "equals": "true"
                  }
                ]
              },
              {
                "allOf": [
                  {
                    "field": "Microsoft.ContainerService/managedClusters/storageProfile.fileCSIDriver.enabled",
                    "equals": false
                  },
                  {
                    "value": "[parameters('enableFileCSI')]",
                    "equals": "true"
                  }
                ]
              },
              {
                "allOf": [
                  {
                    "field": "Microsoft.ContainerService/managedClusters/storageProfile.snapshotController.enabled",
                    "equals": false
                  },
                  {
                    "value": "[parameters('enableSnapshotCSI')]",
                    "equals": "true"
                  }
                ]
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/c5110b6e-5272-4989-9935-59ad06fdf341",
  "name": "c5110b6e-5272-4989-9935-59ad06fdf341"
}
Bylawc5110b6e-5272-4989-9935-59ad06fdf341.bylaw.ps1 · 67 lines
# Converted from AKS_CSI.json by ConvertTo-Bylaw.
Policy 'c5110b6e-5272-4989-9935-59ad06fdf341' {

    Properties @{
        DisplayName   = 'Azure Kubernetes Clusters should enable Container Storage Interface(CSI)'
        Description   = 'The Container Storage Interface (CSI) is a standard for exposing arbitrary block and file storage systems to containerized workloads on Azure Kubernetes Service. To learn more, https://aka.ms/aks-csi-driver'
        Version       = '1.0.0'
        Category      = 'Kubernetes'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
        Metadata      = [ordered]@{ portalReview = $true }
    }
    Parameter EnableDiskCSI @{
        AllowedValues = @('true', 'false')
        Default       = 'true'
        DisplayName   = 'Enable Disk CSI Monitoring'
        Description   = 'Enable monitoring of disk CSI driver. ''false'' will skip monitoring'
        Metadata      = [ordered]@{ portalReview = $true }
    }
    Parameter EnableFileCSI @{
        AllowedValues = @('true', 'false')
        Default       = 'true'
        DisplayName   = 'Enable File CSI Monitoring'
        Description   = 'Enable monitoring of file CSI driver. ''false'' will skip monitoring'
        Metadata      = [ordered]@{ portalReview = $true }
    }
    Parameter EnableSnapshotCSI @{
        AllowedValues = @('true', 'false')
        Default       = 'true'
        DisplayName   = 'Enable Snapshot CSI Monitoring'
        Description   = 'Enable monitoring of snapshot CSI driver. ''false'' will skip monitoring'
        Metadata      = [ordered]@{ portalReview = $true }
    }

    Resource 'Microsoft.ContainerService/managedClusters' {

        Require 'storageProfile.diskCSIDriver.enabled is as required' {
            AnyOf {
                Field storageProfile.diskCSIDriver.enabled | Must -Not -Be $false -IfPresent
                Param EnableDiskCSI | Must -Not -Be 'true'
            }
        }

        Require 'storageProfile.fileCSIDriver.enabled is as required' {
            AnyOf {
                Field storageProfile.fileCSIDriver.enabled | Must -Not -Be $false -IfPresent
                Param EnableFileCSI | Must -Not -Be 'true'
            }
        }

        Require 'storageProfile.snapshotController.enabled is as required' {
            AnyOf {
                Field storageProfile.snapshotController.enabled | Must -Not -Be $false -IfPresent
                Param EnableSnapshotCSI | Must -Not -Be 'true'
            }
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/Kubernetes/AKS_CSI.json in Azure/azure-policy, under the MIT licence.