Bylaw

Gallery › Kubernetes › Azure built-in policies

Azure Arc-enabled Kubernetes clusters should have the Strimzi Kafka extension installed

Converted Policy AuditIfNotExists DeployIfNotExists Disabled Mode Indexed Version 1.0.0

Strimzi Kafka extension provides the operators to install Kafka for building real-time data pipelines and streaming applications with security and observability capabilities. Learn more here: https://aka.ms/arc-strimzikafka-doc.

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

Azure Policy JSONArcStrimziKafkaExtension.json · 129 lines
{
  "properties": {
    "displayName": "Azure Arc-enabled Kubernetes clusters should have the Strimzi Kafka extension installed",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Strimzi Kafka extension provides the operators to install Kafka for building real-time data pipelines and streaming applications with security and observability capabilities. Learn more here: https://aka.ms/arc-strimzikafka-doc.",
    "metadata": {
      "category": "Kubernetes",
      "version": "1.0.0"
    },
    "version": "1.0.0",
    "parameters": {
      "ExtensionVersion": {
        "type": "String",
        "metadata": {
          "displayName": "Extension Version",
          "description": "Provide the extension version of Arc enabled Strimzi Kafka. The extension version 0.1.0 supports Strimzi version 0.33.0 and kafka version 3.3.2. Refer to https://aka.ms/arc-strimzikafka-doc for available releases."
        }
      },
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "DeployIfNotExists",
          "AuditIfNotExists",
          "Disabled"
        ],
        "defaultValue": "DeployIfNotExists"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Kubernetes/connectedClusters"
          },
          {
            "field": "Microsoft.Kubernetes/connectedClusters/connectivityStatus",
            "equals": "connected"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.KubernetesConfiguration/extensions",
          "existenceCondition": {
            "allOf": [
              {
                "field": "Microsoft.KubernetesConfiguration/extensions/extensionType",
                "equals": "microsoft.streamingforstrimzikafka"
              },
              {
                "field": "Microsoft.KubernetesConfiguration/extensions/provisioningState",
                "equals": "Succeeded"
              }
            ]
          },
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/8e3af657-a8ff-443c-a75c-2fe8c4bcb635"
          ],
          "deployment": {
            "properties": {
              "mode": "incremental",
              "parameters": {
                "ExtensionVersion": {
                  "value": "[parameters('ExtensionVersion')]"
                },
                "clusterRegion": {
                  "value": "[field('location')]"
                },
                "clusterResourceId": {
                  "value": "[field('id')]"
                }
              },
              "template": {
                "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                  "ExtensionVersion": {
                    "type": "string"
                  },
                  "clusterRegion": {
                    "type": "string"
                  },
                  "clusterResourceId": {
                    "type": "string"
                  }
                },
                "resources": [
                  {
                    "type": "Microsoft.KubernetesConfiguration/extensions",
                    "apiVersion": "2021-09-01",
                    "name": "strimzikafka",
                    "location": "[parameters('clusterRegion')]",
                    "version": "[parameters('ExtensionVersion')]",
                    "identity": {
                      "type": "SystemAssigned"
                    },
                    "properties": {
                      "extensionType": "microsoft.streamingforstrimzikafka",
                      "autoUpgradeMinorVersion": true,
                      "releaseTrain": "Stable",
                      "scope": {
                        "Cluster": {
                          "releaseNamespace": "streamingforstrimzikafka"
                        }
                      }
                    },
                    "scope": "[concat('Microsoft.Kubernetes/connectedClusters/', split(parameters('clusterResourceId'),'/')[8])]"
                  }
                ]
              }
            }
          }
        }
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/a8e653d9-b5d4-48a0-afe6-14d881f9ee9a",
  "name": "a8e653d9-b5d4-48a0-afe6-14d881f9ee9a"
}
Bylawa8e653d9-b5d4-48a0-afe6-14d881f9ee9a.bylaw.ps1 · 44 lines
# Converted from ArcStrimziKafkaExtension.json by ConvertTo-Bylaw.
Policy 'a8e653d9-b5d4-48a0-afe6-14d881f9ee9a' {

    Properties @{
        DisplayName   = 'Azure Arc-enabled Kubernetes clusters should have the Strimzi Kafka extension installed'
        Description   = 'Strimzi Kafka extension provides the operators to install Kafka for building real-time data pipelines and streaming applications with security and observability capabilities. Learn more here: https://aka.ms/arc-strimzikafka-doc.'
        Category      = 'Kubernetes'
        Version       = '1.0.0'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

    Parameter ExtensionVersion @{
        Type        = 'String'
        DisplayName = 'Extension Version'
        Description = 'Provide the extension version of Arc enabled Strimzi Kafka. The extension version 0.1.0 supports Strimzi version 0.33.0 and kafka version 3.3.2. Refer to https://aka.ms/arc-strimzikafka-doc for available releases.'
        JsonName    = 'ExtensionVersion'
    }
    Parameter Effect @{
        AllowedValues = @('DeployIfNotExists', 'AuditIfNotExists', 'Disabled')
        Default       = 'DeployIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource 'Microsoft.Kubernetes/connectedClusters' {

        Require 'connectivityStatus is not connected' {
            Field connectivityStatus | Must -Not -Be 'connected' -IfPresent
        }
    }

    DeployIfNotExists 'Microsoft.KubernetesConfiguration/extensions' -Role 'Owner' -Effect (Param Effect) {
        Require 'extensionType is microsoft.streamingforstrimzikafka and provisioningState is Succeeded' {
            Field extensionType | Must -Be 'microsoft.streamingforstrimzikafka'
            Field provisioningState | Must -Be 'Succeeded'
        }
        Deployment -TemplateFile './templates/a8e653d9-b5d4-48a0-afe6-14d881f9ee9a.json' -Parameters ([ordered]@{
                ExtensionVersion  = (Param ExtensionVersion)
                clusterRegion     = (Arm '[field(''location'')]')
                clusterResourceId = (Arm '[field(''id'')]')
            })
    }
}

Its deployment templates are written beside it:

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