Unrecommended Log Profile Retention Policy

  • Query id: 25684eac-daaa-4c2c-94b4-8d2dbb627909
  • Query name: Unrecommended Log Profile Retention Policy
  • Platform: AzureResourceManager
  • Severity: Medium
  • Category: Observability
  • URL: Github

Description

Log Profile Retention Policy should be enabled and the recommended number of days for the retention should be higher than 365 or 0 (0 will retain the events indefinitely)
Documentation

Code samples

Code samples with security vulnerabilities

Positive test num. 1 - json file
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "2.0.0.0",
  "apiProfile": "2019-03-01-hybrid",
  "parameters": {},
  "variables": {},
  "functions": [],
  "resources": [
    {
      "name": "string",
      "type": "microsoft.insights/logprofiles",
      "apiVersion": "2016-03-01",
      "location": "location",
      "tags": {},
      "properties": {
        "storageAccountId": "storageAccountId",
        "serviceBusRuleId": "serviceBusRuleId",
        "locations": [
          "location1"
        ],
        "categories": [
          "Write"
        ],
        "retentionPolicy": {
          "enabled": true,
          "days": 300
        }
      }
    }
  ],
  "outputs": {}
}
Positive test num. 2 - json file
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "2.0.0.0",
  "apiProfile": "2019-03-01-hybrid",
  "parameters": {},
  "variables": {},
  "functions": [],
  "resources": [
    {
      "name": "string",
      "type": "microsoft.insights/logprofiles",
      "apiVersion": "2016-03-01",
      "location": "location",
      "tags": {},
      "properties": {
        "storageAccountId": "storageAccountId",
        "serviceBusRuleId": "serviceBusRuleId",
        "locations": [
          "location1"
        ],
        "categories": [
          "Write"
        ],
        "retentionPolicy": {
          "enabled": false,
          "days": 300
        }
      }
    }
  ],
  "outputs": {}
}
Positive test num. 3 - json file
{
  "properties": {
    "template": {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "2.0.0.0",
      "apiProfile": "2019-03-01-hybrid",
      "parameters": {},
      "variables": {},
      "functions": [],
      "resources": [
        {
          "name": "string",
          "type": "microsoft.insights/logprofiles",
          "apiVersion": "2016-03-01",
          "location": "location",
          "tags": {},
          "properties": {
            "storageAccountId": "storageAccountId",
            "serviceBusRuleId": "serviceBusRuleId",
            "locations": [
              "location1"
            ],
            "categories": [
              "Write"
            ],
            "retentionPolicy": {
              "enabled": true,
              "days": 300
            }
          }
        }
      ],
      "outputs": {}
    },
    "parameters": {}
  },
  "kind": "template",
  "type": "Microsoft.Blueprint/blueprints/artifacts",
  "name": "myTemplate"
}

Positive test num. 4 - json file
{
  "properties": {
    "template": {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "2.0.0.0",
      "apiProfile": "2019-03-01-hybrid",
      "parameters": {},
      "variables": {},
      "functions": [],
      "resources": [
        {
          "name": "string",
          "type": "microsoft.insights/logprofiles",
          "apiVersion": "2016-03-01",
          "location": "location",
          "tags": {},
          "properties": {
            "storageAccountId": "storageAccountId",
            "serviceBusRuleId": "serviceBusRuleId",
            "locations": [
              "location1"
            ],
            "categories": [
              "Write"
            ],
            "retentionPolicy": {
              "enabled": false,
              "days": 300
            }
          }
        }
      ],
      "outputs": {}
    },
    "parameters": {}
  },
  "kind": "template",
  "type": "Microsoft.Blueprint/blueprints/artifacts",
  "name": "myTemplate"
}

Code samples without security vulnerabilities

Negative test num. 1 - json file
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "2.0.0.0",
  "apiProfile": "2019-03-01-hybrid",
  "parameters": {},
  "variables": {},
  "functions": [],
  "resources": [
    {
      "name": "string",
      "type": "microsoft.insights/logprofiles",
      "apiVersion": "2016-03-01",
      "location": "location",
      "tags": {},
      "properties": {
        "storageAccountId": "storageAccountId",
        "serviceBusRuleId": "serviceBusRuleId",
        "locations": [
          "location1"
        ],
        "categories": [
          "Write"
        ],
        "retentionPolicy": {
          "enabled": true,
          "days": 400
        }
      }
    }
  ],
  "outputs": {}
}
Negative test num. 2 - json file
{
  "properties": {
    "template": {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "2.0.0.0",
      "apiProfile": "2019-03-01-hybrid",
      "parameters": {},
      "variables": {},
      "functions": [],
      "resources": [
        {
          "name": "string",
          "type": "microsoft.insights/logprofiles",
          "apiVersion": "2016-03-01",
          "location": "location",
          "tags": {},
          "properties": {
            "storageAccountId": "storageAccountId",
            "serviceBusRuleId": "serviceBusRuleId",
            "locations": [
              "location1"
            ],
            "categories": [
              "Write"
            ],
            "retentionPolicy": {
              "enabled": true,
              "days": 400
            }
          }
        }
      ],
      "outputs": {}
    },
    "parameters": {}
  },
  "kind": "template",
  "type": "Microsoft.Blueprint/blueprints/artifacts",
  "name": "myTemplate"
}