last sync: 2021-May-10 15:04:35 UTC

Azure Policy definition

Deploy - Configure diagnostic settings for Azure Kubernetes Service to Log Analytics workspace

Name Deploy - Configure diagnostic settings for Azure Kubernetes Service to Log Analytics workspace
Azure Portal
Id 6c66c325-74c8-42fd-a286-a74b0e2939d8
Version 1.0.0
details on versioning
Category Kubernetes
Microsoft docs
Description Deploys the diagnostic settings for Azure Kubernetes Service to stream resource logs to a Log Analytics workspace.
Mode Indexed
Type BuiltIn
Preview FALSE
Deprecated FALSE
Effect Default: DeployIfNotExists
Allowed: (DeployIfNotExists, Disabled)
Used RBAC Role
Role Name Role Id
Monitoring Contributor 749f88d5-cbae-40b8-bcfc-e573ddc772fa
Log Analytics Contributor 92aaf0da-9dab-42b6-94a3-d43ce8d16293
History
Date/Time (UTC ymd) (i) Change type Change detail
2021-02-23 16:24:42 add 6c66c325-74c8-42fd-a286-a74b0e2939d8
Used in Initiatives none
JSON
{
  "properties": {
    "displayName": "Deploy - Configure diagnostic settings for Azure Kubernetes Service to Log Analytics workspace",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Deploys the diagnostic settings for Azure Kubernetes Service to stream resource logs to a Log Analytics workspace.",
    "metadata": {
      "version": "1.0.0",
      "category": "Kubernetes"
    },
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "DeployIfNotExists",
          "Disabled"
        ],
        "defaultValue": "DeployIfNotExists"
      },
      "diagnosticsSettingNameToUse": {
        "type": "String",
        "metadata": {
          "displayName": "Setting name",
          "description": "Name of the diagnostic settings."
        },
        "defaultValue": "AzureKubernetesDiagnosticsLogsToWorkspace"
      },
      "logAnalytics": {
        "type": "String",
        "metadata": {
          "displayName": "Log Analytics workspace",
          "description": "Specify the Log Analytics workspace the Azure Kubernetes Service should be connected to",
          "strongType": "omsWorkspace",
          "assignPermissions": true
        }
      },
      "AllMetrics": {
        "type": "String",
        "metadata": {
          "displayName": "AllMetrics - Enabled",
          "description": "Whether to stream AllMetrics logs to the Log Analytics workspace - True or False"
        },
        "allowedValues": [
          "True",
          "False"
        ],
        "defaultValue": "True"
      },
      "kube-apiserver": {
        "type": "String",
        "metadata": {
          "displayName": "kube-apiserver - Enabled",
          "description": "Whether to stream kube-apiserver logs to the Log Analytics workspace - True or False"
        },
        "allowedValues": [
          "True",
          "False"
        ],
        "defaultValue": "True"
      },
      "kube-audit": {
        "type": "String",
        "metadata": {
          "displayName": "kube-audit - Enabled",
          "description": "Whether to stream kube-audit logs to the Log Analytics workspace - True or False"
        },
        "allowedValues": [
          "True",
          "False"
        ],
        "defaultValue": "True"
      },
      "kube-controller-manager": {
        "type": "String",
        "metadata": {
          "displayName": "kube-controller-manager - Enabled",
          "description": "Whether to stream kube-controller-manager logs to the Log Analytics workspace - True or False"
        },
        "allowedValues": [
          "True",
          "False"
        ],
        "defaultValue": "True"
      },
      "kube-scheduler": {
        "type": "String",
        "metadata": {
          "displayName": "kube-scheduler - Enabled",
          "description": "Whether to stream kube-scheduler logs to the Log Analytics workspace - True or False"
        },
        "allowedValues": [
          "True",
          "False"
        ],
        "defaultValue": "True"
      },
      "cluster-autoscaler": {
        "type": "String",
        "metadata": {
          "displayName": "cluster-autoscaler - Enabled",
          "description": "Whether to stream cluster-autoscaler logs to the Log Analytics workspace - True or False"
        },
        "allowedValues": [
          "True",
          "False"
        ],
        "defaultValue": "True"
      },
      "kube-audit-admin": {
        "type": "String",
        "metadata": {
          "displayName": "kube-audit-admin - Enabled",
          "description": "Whether to stream kube-audit-admin logs to the Log Analytics workspace - True or False"
        },
        "allowedValues": [
          "True",
          "False"
        ],
        "defaultValue": "True"
      },
      "guard": {
        "type": "String",
        "metadata": {
          "displayName": "guard - Enabled",
          "description": "Whether to stream guard logs to the Log Analytics workspace - True or False"
        },
        "allowedValues": [
          "True",
          "False"
        ],
        "defaultValue": "True"
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "equals": "Microsoft.ContainerService/managedClusters"
      },
      "then": {
      "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Insights/diagnosticSettings",
          "roleDefinitionIds": [
            "/providers/microsoft.authorization/roleDefinitions/749f88d5-cbae-40b8-bcfc-e573ddc772fa",
            "/providers/microsoft.authorization/roleDefinitions/92aaf0da-9dab-42b6-94a3-d43ce8d16293"
          ],
          "existenceCondition": {
            "allOf": [
              {
                "field": "Microsoft.Insights/diagnosticSettings/logs.enabled",
                "equals": "True"
              },
              {
                "field": "Microsoft.Insights/diagnosticSettings/metrics.enabled",
                "equals": "True"
              },
              {
                "field": "Microsoft.Insights/diagnosticSettings/workspaceId",
              "equals": "[parameters('logAnalytics')]"
              }
            ]
          },
          "deployment": {
            "properties": {
              "mode": "incremental",
              "template": {
                "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                  "diagnosticsSettingNameToUse": {
                    "type": "string"
                  },
                  "resourceName": {
                    "type": "string"
                  },
                  "logAnalytics": {
                    "type": "string"
                  },
                  "location": {
                    "type": "string"
                  },
                  "AllMetrics": {
                    "type": "string"
                  },
                  "kube-apiserver": {
                    "type": "string"
                  },
                  "kube-audit": {
                    "type": "string"
                  },
                  "kube-controller-manager": {
                    "type": "string"
                  },
                  "kube-scheduler": {
                    "type": "string"
                  },
                  "cluster-autoscaler": {
                    "type": "string"
                  },
                  "kube-audit-admin": {
                    "type": "string"
                  },
                  "guard": {
                    "type": "string"
                  }
                },
                "variables": {
                  
                },
                "resources": [
                  {
                    "type": "Microsoft.ContainerService/managedClusters/providers/diagnosticSettings",
                    "apiVersion": "2017-05-01-preview",
                  "name": "[concat(parameters('resourceName'), '/', 'Microsoft.Insights/', parameters('diagnosticsSettingNameToUse'))]",
                  "location": "[parameters('location')]",
                    "dependsOn": [
                      
                    ],
                    "properties": {
                    "workspaceId": "[parameters('logAnalytics')]",
                      "metrics": [
                        {
                          "category": "AllMetrics",
                        "enabled": "[parameters('AllMetrics')]"
                        }
                      ],
                      "logs": [
                        {
                          "category": "kube-apiserver",
                        "enabled": "[parameters('kube-apiserver')]"
                        },
                        {
                          "category": "kube-audit",
                        "enabled": "[parameters('kube-audit')]"
                        },
                        {
                          "category": "kube-controller-manager",
                        "enabled": "[parameters('kube-controller-manager')]"
                        },
                        {
                          "category": "kube-scheduler",
                        "enabled": "[parameters('kube-scheduler')]"
                        },
                        {
                          "category": "cluster-autoscaler",
                        "enabled": "[parameters('cluster-autoscaler')]"
                        },
                        {
                          "category": "kube-audit-admin",
                        "enabled": "[parameters('kube-audit-admin')]"
                        },
                        {
                          "category": "guard",
                        "enabled": "[parameters('guard')]"
                        }
                      ]
                    }
                  }
                ],
                "outputs": {
                  
                }
              },
              "parameters": {
                "diagnosticsSettingNameToUse": {
                "value": "[parameters('diagnosticsSettingNameToUse')]"
                },
                "logAnalytics": {
                "value": "[parameters('logAnalytics')]"
                },
                "location": {
                "value": "[field('location')]"
                },
                "resourceName": {
                "value": "[field('name')]"
                },
                "guard": {
                "value": "[parameters('guard')]"
                },
                "AllMetrics": {
                "value": "[parameters('AllMetrics')]"
                },
                "kube-apiserver": {
                "value": "[parameters('kube-apiserver')]"
                },
                "kube-audit": {
                "value": "[parameters('kube-audit')]"
                },
                "kube-scheduler": {
                "value": "[parameters('kube-scheduler')]"
                },
                "kube-controller-manager": {
                "value": "[parameters('kube-controller-manager')]"
                },
                "cluster-autoscaler": {
                "value": "[parameters('cluster-autoscaler')]"
                },
                "kube-audit-admin": {
                "value": "[parameters('kube-audit-admin')]"
                }
              }
            }
          }
        }
      }
    }
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/6c66c325-74c8-42fd-a286-a74b0e2939d8",
  "type": "Microsoft.Authorization/policyDefinitions",
  "name": "6c66c325-74c8-42fd-a286-a74b0e2939d8"
}