Gallery › Monitoring › Azure Community Policy
Deploy Linux Diagnostic Agent to Collect Security Related Events
Converted Policy AuditIfNotExists DeployIfNotExists Disabled Mode Indexed Version 1.0.0
This Policy will Deploy the Linux Diagnostic Agent and collect the following Logs: Syslog, Auth, AuthPriv; All logs are configured to collect informational detail. Additionaly, to account for VMs provisioned from custom images where the image SKU is blank this Policy is keyed to look for the storageProfile.osDisk.osType property of a VM. This property does not exist at provisioning time, but is populated by the VM agent after provisioining, and so will not trigger an automatic remediation task to be created
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
{
"name": "84601dde-6803-4174-96fe-7eb6c0e1216c",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Deploy Linux Diagnostic Agent to Collect Security Related Events",
"description": "This Policy will Deploy the Linux Diagnostic Agent and collect the following Logs: Syslog, Auth, AuthPriv; All logs are configured to collect informational detail. Additionaly, to account for VMs provisioned from custom images where the image SKU is blank this Policy is keyed to look for the storageProfile.osDisk.osType property of a VM. This property does not exist at provisioning time, but is populated by the VM agent after provisioining, and so will not trigger an automatic remediation task to be created",
"metadata": {
"version": "1.0.0",
"category": "Monitoring"
},
"mode": "Indexed",
"parameters": {
"storageAccountId": {
"type": "String",
"metadata": {
"strongType": "Microsoft.Storage/storageAccounts",
"assignPermissions": true,
"displayName": "Storage Account",
"description": "This is the Storage Account that all log data will be sent to."
}
},
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "DeployIfNotExists, AuditIfNotExists or Disabled the execution of the Policy"
},
"allowedValues": [
"DeployIfNotExists",
"AuditIfNotExists",
"Disabled"
],
"defaultValue": "DeployIfNotExists"
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Compute/virtualMachines"
},
{
"field": "Microsoft.Compute/virtualMachines/storageProfile.osDisk.osType",
"equals": "Linux"
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Compute/virtualMachines/extensions",
"roleDefinitionIds": [
"/providers/microsoft.authorization/roleDefinitions/92aaf0da-9dab-42b6-94a3-d43ce8d16293",
"/providers/microsoft.authorization/roleDefinitions/17d1049b-9a84-46fb-8f53-869881c3d3ab"
],
"existenceCondition": {
"allOf": [
{
"field": "Microsoft.Compute/virtualMachines/extensions/type",
"equals": "LinuxDiagnostic"
},
{
"field": "Microsoft.Compute/virtualMachines/extensions/publisher",
"equals": "Microsoft.Azure.Diagnostics"
},
{
"field": "Microsoft.Compute/virtualMachines/extensions/provisioningState",
"equals": "Succeeded"
}
]
},
"deployment": {
"properties": {
"mode": "incremental",
"template": {
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string"
},
"location": {
"type": "string"
},
"storageAccountId": {
"type": "string"
}
},
"variables": {
"vmExtensionName": "Microsoft.Insights.VMDiagnosticsSettings",
"vmExtensionPublisher": "Microsoft.Azure.Diagnostics",
"vmExtensionType": "LinuxDiagnostic",
"vmExtensionTypeHandlerVersion": "4.0",
"existingdiagnosticsStorageAccountName": "[last(split(parameters('storageAccountId'), '/'))]",
"wadmetricsresourceid": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', resourceGroup().name , '/providers/', 'Microsoft.Compute/virtualMachines/')]",
"accountSasProperties": {
"signedServices": "q",
"signedPermission": "rwc",
"signedExpiry": "2050-01-01T00:00:01Z",
"signedResourceTypes": "o"
}
},
"resources": [
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2020-06-01",
"location": "[parameters('location')]",
"name": "[concat(parameters('vmName'), '/', variables('vmExtensionName'))]",
"properties": {
"publisher": "[variables('vmExtensionPublisher')]",
"type": "[variables('vmExtensionType')]",
"autoUpgradeMinorVersion": true,
"typeHandlerVersion": "[variables('vmExtensionTypeHandlerVersion')]",
"protectedSettings": {
"storageAccountName": "[variables('existingdiagnosticsStorageAccountName')]",
"storageAccountSasToken": "[listAccountSas(parameters('storageAccountId'), '2018-07-01', variables('accountSasProperties')).accountSasToken]"
},
"settings": {
"StorageAccount": "[variables('existingdiagnosticsStorageAccountName')]",
"ladCfg": {
"diagnosticMonitorConfiguration": {
"eventVolume": "Medium",
"metrics": {
"metricAggregation": [
{
"scheduledTransferPeriod": "PT1M"
},
{
"scheduledTransferPeriod": "PT1H"
}
],
"resourceId": "[variables('wadmetricsresourceid')]"
},
"performanceCounters": {
"performanceCounterConfiguration": []
},
"syslogEvents": {
"syslogEventConfiguration": {
"LOG_AUTH": "LOG_INFO",
"LOG_AUTHPRIV": "LOG_INFO",
"LOG_SYSLOG": "LOG_INFO",
"LOG_CRON": "LOG_INFO",
"LOG_MAIL": "LOG_INFO"
}
}
},
"sampleRateInSeconds": 15
}
}
}
}
],
"outputs": {
"policy": {
"type": "string",
"value": "[concat('Enabled Linux diagnostic extension for VM', ': ', parameters('vmName'))]"
}
}
},
"parameters": {
"vmName": {
"value": "[field('name')]"
},
"location": {
"value": "[field('location')]"
},
"storageAccountId": {
"value": "[parameters('storageAccountId')]"
}
}
}
}
}
}
}
}
}# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '84601dde-6803-4174-96fe-7eb6c0e1216c' {
Properties @{
DisplayName = 'Deploy Linux Diagnostic Agent to Collect Security Related Events'
Description = 'This Policy will Deploy the Linux Diagnostic Agent and collect the following Logs: Syslog, Auth, AuthPriv; All logs are configured to collect informational detail. Additionaly, to account for VMs provisioned from custom images where the image SKU is blank this Policy is keyed to look for the storageProfile.osDisk.osType property of a VM. This property does not exist at provisioning time, but is populated by the VM agent after provisioining, and so will not trigger an automatic remediation task to be created'
Version = '1.0.0'
Category = 'Monitoring'
Mode = 'Indexed'
}
Parameter StorageAccountId @{
Type = 'String'
DisplayName = 'Storage Account'
Description = 'This is the Storage Account that all log data will be sent to.'
Metadata = [ordered]@{ strongType = 'Microsoft.Storage/storageAccounts'; assignPermissions = $true }
}
Parameter Effect @{
AllowedValues = @('DeployIfNotExists', 'AuditIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'DeployIfNotExists, AuditIfNotExists or Disabled the execution of the Policy'
}
Resource 'Microsoft.Compute/virtualMachines' {
Require 'storageProfile.osDisk.osType is not Linux' {
Field storageProfile.osDisk.osType | Must -Not -Be 'Linux' -IfPresent
}
}
DeployIfNotExists 'Microsoft.Compute/virtualMachines/extensions' -Role 'Log Analytics Contributor', 'Storage Account Contributor' -Effect (Param Effect) {
Require 'type is LinuxDiagnostic, publisher is Microsoft.Azure.Diagnostics and provisioningState is Succeeded' {
Field 'Microsoft.Compute/virtualMachines/extensions/type' | Must -Be 'LinuxDiagnostic'
Field publisher | Must -Be 'Microsoft.Azure.Diagnostics'
Field provisioningState | Must -Be 'Succeeded'
}
Deployment -TemplateFile './templates/84601dde-6803-4174-96fe-7eb6c0e1216c.json' -Parameters ([ordered]@{
vmName = (Arm '[field(''name'')]')
location = (Arm '[field(''location'')]')
storageAccountId = (Param StorageAccountId)
})
}
}Its deployment templates are written beside it:
templates/84601dde-6803-4174-96fe-7eb6c0e1216c.json
Source: policyDefinitions/Monitoring/deploy-linux-diagnostic-agent-to-collect-security-related-events/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw