> ## Documentation Index
> Fetch the complete documentation index at: https://docs.codeant.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Azure Source Manager

<AccordionGroup>
  <Accordion title="Dont use allowedValues for a location parameter">
    <div class="paragraph">
      <p>In Azure Resource Manager (ARM) templates, it is possible to set allowedValues for various parameters to limit the options and maintain control.
      However, when it comes to a parameter defining the location of a resource, this practice can lead to a code smell.
      Specifically, setting allowedValues for a location parameter can cause issues because the locations list might not be exhaustive or suitable for all users.
      Users may be unable to deploy such a template if their desired location is not included in the allowedValues, causing inconvenience and potential delays in their work.</p>
    </div>

    <CodeGroup>
      ```azureresourcemanager Bad theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
        "location": {
            "type": "string",
            "metadata": {
                "description": "The location in which the resources should be deployed."
            },
            "defaultValue": "[resourceGroup().location]",
            "allowedValues": [
                "eastus",
                "westus",
                "northeurope",
                "westeurope",
                "southeastasia"
            ]
        }
      }
      }
      ```

      ```azureresourcemanager Fix theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
        "location": {
            "type": "string",
            "metadata": {
                "description": "The location in which the resources should be deployed."
            },
            "defaultValue": "[resourceGroup().location]"
        }
      }
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Use a hard-coded value for the apiVersion">
    <div class="paragraph">
      <p>In Azure, different API versions of a resource can have different properties and values.</p>
    </div>

    <div class="paragraph">
      <p>Using a variable or parameter for the apiVersion for a resource is not an optimal way to always stay up to date with
      the latest version.
      This can lead to unexpected behaviors like deployment failures,
      when the API version you set for a resource doesn’t match the properties in your template.</p>
    </div>

    <CodeGroup>
      ```azureresourcemanager Bad theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "parameters": {
      "customApiVersion": {
        "type": "string"
      }
      },
      "resources": [
      {
        "apiVersion": "[parameters('customApiVersion')]",
        "type": "Microsoft.Compute/virtualMachines",
        "name": "nonCompliantResource",
        "location": "[resourceGroup().location]"
      }
      ]
      }
      ```

      ```azureresourcemanager Fix theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "variables": {
      "customApiVersion": "[first(providers(‘Microsoft.Compute’,’virtualMachines’).apiVersions)]"
      },
      "resources": [
      {
        "apiVersion": "[variables('customApiVersion')]",
        "type": "Microsoft.Compute/virtualMachines",
        "name": "nonCompliantResource",
        "location": "[resourceGroup().location]"
      }
      ]
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Elements should not be empty or null">
    <div class="paragraph">
      <p>Empty or null elements are usually introduced by mistake.
      They are useless and prevent readability of the code.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```azureresourcemanager Bad theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "resources": [
      {
        "type": "Microsoft.Storage/storageAccounts",
        "apiVersion": "2023-01-01",
        "sku": "Standard_GRS",
        "name": null,
        "kind": "",
        "tags": {},
        "dependsOn": []
      }
      ]
      }
      ```

      ```azureresourcemanager Fix theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "resources": [
      {
        "type": "Microsoft.Storage/storageAccounts",
        "apiVersion": "2023-01-01",
        "sku": "Standard_GRS",
        "name": "myStorage",
        "kind": "BlobStorage"
      }
      ]
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Redundant explicit dependencies between resources should be removed">
    <div class="paragraph">
      <p>In Azure Resource Manager (ARM) templates, dependencies between resources can be defined in two ways: implicitly or explicitly.
      An implicit dependency is set when you use the reference function and pass in the resource name.
      An explicit dependency is defined when you add a dependsOn element.
      However, a code smell arises when these dependencies are used simultaneously for the same resources.
      This redundancy is unnecessary and can lead to confusion.
      Therefore, to maintain clarity and efficiency in your code, it is best to omit explicit dependencies when they are already defined implicitly.</p>
    </div>

    <CodeGroup>
      ```azureresourcemanager Bad theme={null}
      {
      "apiVersion": "2019-04-01",
      "type": "Microsoft.Network/networkInterfaces",
      "name": "exampleNic",
      "location": "[resourceGroup().location]",
      "dependsOn": [
      "[resourceId('Microsoft.Network/virtualNetworks', 'exampleVNet')]"
      ],
      "properties": {
      "ipConfigurations": [
        {
          "name": "ipconfig1",
          "properties": {
            "subnet": {
              "id": "[reference('Microsoft.Network/virtualNetworks/exampleVNet/subnets/exampleSubnet').id]"
            }
          }
        }
      ]
      }
      }
      ```

      ```azureresourcemanager Fix theme={null}
      {
      "apiVersion": "2019-04-01",
      "type": "Microsoft.Network/networkInterfaces",
      "name": "exampleNic",
      "location": "[resourceGroup().location]",
      "properties": {
      "ipConfigurations": [
        {
          "name": "ipconfig1",
          "properties": {
            "subnet": {
              "id": "[reference('Microsoft.Network/virtualNetworks/exampleVNet/subnets/exampleSubnet').id]"
            }
          }
        }
      ]
      }
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Dont hardcode resource locations">
    <div class="paragraph">
      <p>When deploying an Azure Resource Manager template (ARM template), you must provide a location for each resource. This can be done directly in the template or by passing parameters. However, hardcoding locations in the template can limit flexibility and potentially create deployment challenges, restricting users from choosing their preferred deployment location.</p>
    </div>

    <div class="paragraph">
      <p>It is therefore recommended to use a parameter to specify the location for resources, with the default value set to resourceGroup().location. This practice ensures consistency in resource allocation and provides users of the template the flexibility to specify a location where they have the necessary permissions to deploy resources. This approach helps avoid hardcoding locations, which can lead to potential deployment issues and restrictions.</p>
    </div>

    <CodeGroup>
      ```azureresourcemanager Bad theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "resources": [
      {
        "type": "Microsoft.Storage/storageAccounts",
        "apiVersion": "2022-09-01",
        "name": "[parameters('storageAccountName')]",
        "location": "westus",
        "sku": {
          "name": "Standard_LRS"
        },
        "kind": "StorageV2"
      }
      ]
      }
      ```

      ```azureresourcemanager Fix theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
      "location": {
        "type": "string",
        "defaultValue": "[resourceGroup().location]",
        "metadata": {
          "description": "Location for all resources."
        }
      }
      },
      "resources": [
      {
        "type": "Microsoft.Storage/storageAccounts",
        "apiVersion": "2022-09-01",
        "name": "[parameters('storageAccountName')]",
        "location": "[parameters('location')]",
        "sku": {
          "name": "Standard_LRS"
        },
        "kind": "StorageV2"
      }
      ]
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="The properties should appear in the recommended order">
    <div class="paragraph">
      <p>According to the best practices defined by Azure, a consistent order of properties and elements in a templates is recommended.
      This makes it easier to read and understand the template.</p>
    </div>

    <div class="paragraph">
      <p>Not following this convention has no technical impact,
      but will reduce the template’s readability because most developers are used to the standard order.</p>
    </div>

    <div class="paragraph">
      <p>Sorting the resources according to deployment order is recommended as well, as this will convey the intent of the orchestration.</p>
    </div>

    <CodeGroup>
      ```azureresourcemanager Bad theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/...",
      "contentVersion": "1.0.0.0",
      "apiProfile": "...",
      "parameters": {},
      "functions": {},
      "variables": {},
      "resources": [],
      "outputs": {}
      }
      ```

      ```azureresourcemanager Fix theme={null}
      {
      "resources": [
      {
        "comments": "if any",
        "condition": true,
        "scope": "% parent scope %",
        "type": "Microsoft.Compute/virtualMachines",
        "apiVersion": "2023-09-01",
        "name": "resourceName",
        "location": "[parameters('location')]",
        "zones": [],
        "sku": {},
        "kind": "",
        "scale": "",
        "plan": {},
        "identity": {},
        "copy": {
          "name": "vmLoop",
          "count": "[parameters('numberOfVMs')]"
        },
        "dependsOn": [
          "nicLoop"
        ],
        "tags": {},
        "properties": {}
      }
      ]
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Unused parameters should be removed">
    <div class="paragraph">
      <p>An unused parameter is a parameter that has been declared but is not used anywhere in the block of code where it is defined.
      It is dead code, contributing to unnecessary complexity and leading to confusion when reading the code.
      Therefore, it should be removed from your code to maintain clarity and efficiency.</p>
    </div>

    <div class="paragraph" />

    <CodeGroup>
      ```azureresourcemanager Bad theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "parameters": {
        "unusedParameter": {
            "type": "string"
        },
        "virtualMachinesName": {
            "type": "string"
        }
      },
      "resources": [
      {
        "type": "Microsoft.Compute/virtualMachines",
        "name": "[parameters('virtualMachinesName')]",
        "apiVersion": "2023-09-01",
        "location": "[resourceGroup().location]"
      }
      ]
      }
      ```

      ```azureresourcemanager Fix theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "parameters": {
        "virtualMachinesName": {
            "type": "string"
        }
      },
      "resources": [
      {
        "type": "Microsoft.Compute/virtualMachines",
        "name": "[parameters('virtualMachinesName')]",
        "apiVersion": "2023-09-01",
        "location": "[resourceGroup().location]"
      }
      ]
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Authorizing anonymous access to Azure resources is security-sensitive">
    <div class="paragraph">
      <p>Allowing anonymous access can reduce an organization’s ability to protect itself against attacks on its Azure resources.</p>
    </div>

    <div class="paragraph">
      <p>Security incidents may include disrupting critical functions, data theft, and additional Azure subscription costs due to resource overload.</p>
    </div>

    <div class="paragraph">
      <p>Using authentication coupled with fine-grained authorizations helps bring defense-in-depth and bring traceability to investigators of security incidents.</p>
    </div>

    <div class="paragraph">
      <p>Depending on the affected Azure resource, multiple authentication choices are possible: Active Directory Authentication, OpenID implementations (Google, Microsoft, etc.) or native Azure mechanisms.</p>
    </div>

    <CodeGroup>
      ```azureresourcemanager Bad theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "resources": [
          {
              "type": "Microsoft.Web/sites",
              "apiVersion": "2022-03-01",
              "name": "example"
          }
      ]
      }
      ```

      ```azureresourcemanager Fix theme={null}
      resource appService 'Microsoft.Web/sites@2022-09-01' = {
      name: 'example'
      // Sensitive: no authentication defined
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Allowing public network access to cloud resources is security-sensitive">
    <div class="paragraph">
      <p>Enabling public network access to cloud resources can affect an organization’s
      ability to protect its data or internal operations from data theft or
      disruption.</p>
    </div>

    <div class="paragraph">
      <p>Depending on the component, inbound access from the Internet can be enabled
      via:</p>
    </div>

    <div class="ulist">
      <ul>
        <li>
          <p>a boolean value that explicitly allows access to the public network.</p>
        </li>

        <li>
          <p>the assignment of a public IP address.</p>
        </li>

        <li>
          <p>database firewall rules that allow public IP ranges.</p>
        </li>
      </ul>
    </div>

    <div class="paragraph">
      <p>Deciding to allow public access may happen for various reasons such as for
      quick maintenance, time saving, or by accident.</p>
    </div>

    <div class="paragraph">
      <p>This decision increases the likelihood of attacks on the organization, such as:</p>
    </div>

    <div class="ulist">
      <ul>
        <li>
          <p>data breaches.</p>
        </li>

        <li>
          <p>intrusions into the infrastructure to permanently steal from it.</p>
        </li>

        <li>
          <p>and various malicious traffic, such as DDoS attacks.</p>
        </li>
      </ul>
    </div>

    <CodeGroup>
      ```azureresourcemanager Bad theme={null}
      resource exampleSite 'Microsoft.Web/sites@2020-12-01' = {
      name: 'example-site'
      properties: {
      publicNetworkAccess: 'Enabled'
      }
      }
      ```

      ```azureresourcemanager Fix theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "resources": [
      {
        "type": "Microsoft.Web/sites",
        "apiVersion": "2020-12-01",
        "name": "example-site",
        "properties": {
          "siteConfig": {
            "publicNetworkAccess": "Enabled"
          }
        }
      }
      ]
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Delivering code in production with debug features activated is security-sensitive">
    <div class="paragraph">
      <p>Development tools and frameworks usually have options to make debugging easier for developers. Although these features are useful during development, they should never be enabled for applications deployed in production. Debug instructions or error messages can leak detailed information about the system, like the application’s path or file names.</p>
    </div>

    <CodeGroup>
      ```azureresourcemanager Bad theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "resources": [
        {
            "type": "Microsoft.Resources/deployments",
            "apiVersion": "2022-09-01",
            "name": "templateDebug",
            "properties": {
                "debugSetting": { "detailLevel": "RequestContent, ResponseContent" }
            }
        }
      ]
      }
      ```

      ```azureresourcemanager Fix theme={null}
      resource templateDebug 'Microsoft.Resources/deployments@2022-09-01' = {
      name: 'templateDebug'
      properties: {
      debugSetting: {  // Noncompliant
        detailLevel: 'RequestContent, ResponseContent'
      }
      }
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Assigning high privileges Azure Resource Manager built-in roles is security-sensitive">
    <div class="paragraph">
      <p>Azure Resource Manager offers built-in roles that can be assigned to users, groups, or service principals.
      Some of these roles should be carefully assigned as they grant sensitive permissions like the ability to reset passwords for all users.</p>
    </div>

    <div class="paragraph">
      <p>An Azure account that fails to limit the use of such roles has a higher risk of being breached by a compromised owner.</p>
    </div>

    <div class="paragraph">
      <p>This rule raises an issue when one of the following roles is assigned:</p>
    </div>

    <div class="ulist">
      <ul>
        <li>
          <p>Contributor (b24988ac-6180-42a0-ab88-20f7382dd24c)</p>
        </li>

        <li>
          <p>Owner (8e3af657-a8ff-443c-a75c-2fe8c4bcb635)</p>
        </li>

        <li>
          <p>User Access Administrator (18d7d88d-d35e-4fb5-a5c3-7773c20a72d9)</p>
        </li>
      </ul>
    </div>

    <CodeGroup>
      ```azureresourcemanager Bad theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "resources": [
      {
        "name": "example",
        "type": "Microsoft.Authorization/roleAssignments",
        "apiVersion": "2022-04-01",
        "properties": {
          "description": "Assign the contributor role",
          "principalId": "string",
          "principalType": "ServicePrincipal",
          "roleDefinitionId": "[resourceId('Microsoft.Authorization/roleDefinitions', 'b24988ac-6180-42a0-ab88-20f7382dd24c')]"
        }
      }
      ]
      }
      ```

      ```azureresourcemanager Fix theme={null}
      resource symbolicname 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
      scope: tenant()
      properties: {
      description: 'Assign the contributor role'
      principalId: 'string'
      principalType: 'ServicePrincipal'
      roleDefinitionId: resourceId('Microsoft.Authorization/roleAssignments', 'b24988ac-6180-42a0-ab88-20f7382dd24c') // Sensitive
      }
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Using clear-text protocols is security-sensitive">
    <div class="paragraph">
      <p>Clear-text protocols such as \`ftp, telnet, or http lack
      encryption of transported data, as well as the capability to build an
      authenticated connection. It means that an attacker able to sniff traffic from
      the network can read, modify, or corrupt the transported content. These
      protocols are not secure as they expose applications to an extensive range of
      risks:</p>
    </div>

    <div class="ulist">
      <ul>
        <li>
          <p>sensitive data exposure</p>
        </li>

        <li>
          <p>traffic redirected  to a malicious endpoint</p>
        </li>

        <li>
          <p>malware-infected software update or installer</p>
        </li>

        <li>
          <p>execution of client-side code</p>
        </li>

        <li>
          <p>corruption of critical information</p>
        </li>
      </ul>
    </div>

    <div class="paragraph">
      <p>Even in the context of isolated networks like offline environments or segmented
      cloud environments, the insider threat exists. Thus, attacks involving
      communications being sniffed or tampered with can still happen.</p>
    </div>

    <div class="paragraph">
      <p>For example, attackers could successfully compromise prior security layers by:</p>
    </div>

    <div class="ulist">
      <ul>
        <li>
          <p>bypassing isolation mechanisms</p>
        </li>

        <li>
          <p>compromising a component of the network</p>
        </li>

        <li>
          <p>getting the credentials of an internal IAM account (either from a service
          account or an actual person)</p>
        </li>
      </ul>
    </div>

    <div class="paragraph">
      <p>In such cases, encrypting communications would decrease the chances of attackers
      to successfully leak data or steal credentials from other network components.
      By layering various security practices (segmentation and encryption, for
      example), the application will follow the <em>defense-in-depth</em> principle.</p>
    </div>

    <div class="paragraph">
      <p>Note that using the http\` protocol is being deprecated by
      <a href="https://blog.mozilla.org/security/2015/04/30/deprecating-non-secure-http">major web browsers</a>.</p>
    </div>

    <div class="paragraph">
      <p>In the past, it has led to the following vulnerabilities:</p>
    </div>

    <div class="ulist">
      <ul>
        <li>
          <p><a href="https://nvd.nist.gov/vuln/detail/CVE-2019-6169">CVE-2019-6169</a></p>
        </li>

        <li>
          <p><a href="https://nvd.nist.gov/vuln/detail/CVE-2019-12327">CVE-2019-12327</a></p>
        </li>

        <li>
          <p><a href="https://nvd.nist.gov/vuln/detail/CVE-2019-11065">CVE-2019-11065</a></p>
        </li>
      </ul>
    </div>

    <CodeGroup>
      ```azureresourcemanager Bad theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "resources": [
      {
        "type": "Microsoft.Web/sites",
        "name": "example",
        "apiVersion": "2022-09-01",
        "properties": {
          "httpsOnly": false
        }
      }
      ]
      }
      ```

      ```azureresourcemanager Fix theme={null}
      resource symbolicname 'Microsoft.Web/sites@2022-03-01' = {
      properties: {
      httpsOnly: false // Sensitive
      }
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Enabling Azure resource-specific admin accounts is security-sensitive">
    <div class="paragraph">
      <p>Enabling Azure resource-specific admin accounts can reduce an organization’s ability to protect itself against account or service account thefts.</p>
    </div>

    <div class="paragraph">
      <p>Full Administrator permissions fail to correctly separate duties and create potentially critical attack vectors on the impacted resources.</p>
    </div>

    <div class="paragraph">
      <p>In case of abuse of elevated permissions, both the data on which impacted resources operate and their access traceability are at risk.</p>
    </div>

    <CodeGroup>
      ```azureresourcemanager Bad theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "resources": [
      {
        "name": "example",
        "type": "Microsoft.Batch/batchAccounts/pools",
        "apiVersion": "2022-10-01",
        "properties": {
          "startTask": {
            "userIdentity": {
              "autoUser": {
                "elevationLevel": "Admin"
              }
            }
          }
        }
      }
      ]
      }
      ```

      ```azureresourcemanager Fix theme={null}
      resource AdminBatchPool 'Microsoft.Batch/batchAccounts/pools@2022-10-01' = {
      properties: {
      startTask: {
        userIdentity: {
          autoUser: {
            elevationLevel: 'Admin' // Sensitive
          }
        }
      }
      }
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Defining a short backup retention duration is security-sensitive">
    <div class="paragraph">
      <p>Reducing the backup retention duration can reduce an organization’s ability to re-establish service in case of a security incident.</p>
    </div>

    <div class="paragraph">
      <p>Data backups allow to overcome corruption or unavailability of data by recovering as efficiently as possible from a security incident.</p>
    </div>

    <div class="paragraph">
      <p>Backup retention duration, coverage, and backup locations are essential criteria regarding functional continuity.</p>
    </div>

    <CodeGroup>
      ```azureresourcemanager Bad theme={null}
      resource webApp 'Microsoft.Web/sites@2022-03-01' = {
      name: 'webApp'
      }

      resource backup 'config@2022-03-01' = {
      name: 'backup'
      parent: webApp
      properties: {
      backupSchedule: {
        frequencyInterval: 1
        frequencyUnit: 'Day'
        keepAtLeastOneBackup: true
        retentionPeriodInDays: 2  // Sensitive
      }
      }
      }
      ```

      ```azureresourcemanager Fix theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "resources": [
      {
        "type": "Microsoft.Web/sites",
        "apiVersion": "2022-03-01",
        "name": "webApp",
      },
      {
        "type": "Microsoft.Web/sites/config",
        "apiVersion": "2022-03-01",
        "name": "webApp/backup",
        "properties": {
          "backupSchedule": {
            "frequencyInterval": 1,
            "frequencyUnit": "Day",
            "keepAtLeastOneBackup": true,
            "retentionPeriodInDays": 2
          }
        },
        "dependsOn": [
          "[resourceId('Microsoft.Web/sites', 'webApp')]"
        ]
      }
      ]
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="String literals should not be duplicated">
    <div class="paragraph">
      <p>Duplicated string literals make the process of refactoring complex and error-prone, as any change would need to be propagated on all occurrences.</p>
    </div>

    <CodeGroup>
      ```azureresourcemanager Bad theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "variables": {},
      "resources": [
      {
        "type": "Microsoft.Storage/storageAccounts",
        "apiVersion": "2021-01-01",
        "name": "appSuperStorage",
        "tags": {
          "displayName": "appSuperStorage",
          "shortName" : "appSuperStorage"
        }
      }
      ]
      }
      ```

      ```azureresourcemanager Fix theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "variables": {
      "storageAccountName": "appSuperStorage"
      },
      "resources": [
      {
        "type": "Microsoft.Storage/storageAccounts",
        "apiVersion": "2021-01-01",
        "name": "[variables('storageAccountName')]",
        "tags": {
          "displayName": "[variables('storageAccountName')]",
          "shortName" : "[variables('storageAccountName')]"
        }
      }
      ]
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Disabling Managed Identities for Azure resources is security-sensitive">
    <div class="paragraph">
      <p>Disabling Managed Identities can reduce an organization’s ability to protect itself against configuration faults and credential leaks.</p>
    </div>

    <div class="paragraph">
      <p>Authenticating via managed identities to an Azure resource solely relies on an API call with a non-secret token. The process is inner to Azure: secrets used by Azure are not even accessible to end-users.</p>
    </div>

    <div class="paragraph">
      <p>In typical scenarios without managed identities, the use of credentials can lead to mistakenly leaving them in code bases. In addition, configuration faults may also happen when storing these values or assigning them permissions.</p>
    </div>

    <div class="paragraph">
      <p>By transparently taking care of the Azure Active Directory authentication, Managed Identities allow getting rid of day-to-day credentials management.</p>
    </div>

    <CodeGroup>
      ```azureresourcemanager Bad theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "resources": [
          {
              "type": "Microsoft.ApiManagement/service",
              "apiVersion": "2022-09-01-preview",
              "name": "apiManagementService"
          }
      ]
      }
      ```

      ```azureresourcemanager Fix theme={null}
      resource sensitiveApiManagementService 'Microsoft.ApiManagement/service@2022-09-01-preview' = {
      name: 'apiManagementService'
      // Sensitive: no Managed Identity is defined
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Defining a short log retention duration is security-sensitive">
    <div class="paragraph">
      <p>Defining a short log retention duration can reduce an organization’s ability to backtrace the actions of malicious actors in case of a security incident.</p>
    </div>

    <div class="paragraph">
      <p>Logging allows operational and security teams to get detailed and real-time feedback on an information system’s events. The logging coverage enables them to quickly react to events, ranging from the most benign bugs to the most impactful security incidents, such as intrusions.</p>
    </div>

    <div class="paragraph">
      <p>Apart from security detection, logging capabilities also directly influence future digital forensic analyses. For example, detailed logging will allow investigators to establish a timeline of the actions perpetrated by an attacker.</p>
    </div>

    <CodeGroup>
      ```azureresourcemanager Bad theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "resources": [
      {
        "name": "example",
        "type": "Microsoft.Network/firewallPolicies",
        "apiVersion": "2022-07-01",
        "properties": {
          "insights": {
            "isEnabled": true,
            "retentionDays": 7
          }
        }
      }
      ]
      }
      ```

      ```azureresourcemanager Fix theme={null}
      resource firewallPolicy 'Microsoft.Network/firewallPolicies@2022-07-01' = {
      properties: {
      insights: {
        isEnabled: true
        retentionDays: 7  // Sensitive
      }
      }
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Track uses of TODO tags">
    <div class="paragraph">
      <p>Developers often use TODO tags to mark areas in the code where additional work or improvements are needed but are not implemented immediately.
      However, these TODO tags sometimes get overlooked or forgotten, leading to incomplete or unfinished code.
      This rule aims to identify and address unattended TODO tags to ensure a clean and maintainable codebase.
      This description explores why this is a problem and how it can be fixed to improve the overall code quality.</p>
    </div>

    <CodeGroup>
      ```azureresourcemanager Bad theme={null}
      resource Microsoft_ApiManagement_service_apis_Raise_issue_because_protocols_contains_http 'Microsoft.ApiManagement/service/apis@2022-08-01' = {
      properties: {
      protocols: [
        // TODO change to secure protocol
        'http'
      ]
      }
      }
      ```

      ```azureresourcemanager Fix theme={null}
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Disabling Role-Based Access Control on Azure resources is security-sensitive">
    <div class="paragraph">
      <p>Disabling Role-Based Access Control (RBAC) on Azure resources can reduce an
      organization’s ability to protect itself against access controls being compromised.</p>
    </div>

    <div class="paragraph">
      <p>To be considered safe, access controls must follow the principle of
      least privilege and correctly segregate duties amongst users.
      RBAC helps enforce these practices by adapting the organization’s access control
      needs into explicit role-based policies: It helps keeping access controls maintainable
      and sustainable.</p>
    </div>

    <div class="paragraph">
      <p>Furthermore, RBAC allows operations teams to work faster during a security
      incident. It helps to mitigate account theft or intrusions by quickly shutting down
      accesses.</p>
    </div>

    <CodeGroup>
      ```azureresourcemanager Bad theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "resources": [
      {
        "name": "example",
        "type": "Microsoft.ContainerService/managedClusters",
        "apiVersion": "2023-03-01",
        "properties": {
          "aadProfile": {
            "enableAzureRBAC": false
          },
          "enableRBAC": false
        }
      }
      ]
      }
      ```

      ```azureresourcemanager Fix theme={null}
      resource aks 'Microsoft.ContainerService/managedClusters@2023-03-01' = {
      properties: {
      aadProfile: {
        enableAzureRBAC: false    // Sensitive
      }
      enableRBAC: false           // Sensitive
      }
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Azure role assignments that grant access to all resources of a subscription are security-sensitive">
    <div class="paragraph">
      <p>Azure RBAC roles can be assigned to users, groups, or service principals. A role assignment grants permissions on a predefined set of resources called "scope".</p>
    </div>

    <div class="paragraph">
      <p>The widest scopes a role can be assigned to are:</p>
    </div>

    <div class="ulist">
      <ul>
        <li>
          <p>Subscription: a role assigned with this scope grants access to all resources of this Subscription.</p>
        </li>

        <li>
          <p>Management Group: a scope assigned with this scope grants access to all resources of all the Subscriptions in this Management Group.</p>
        </li>
      </ul>
    </div>

    <div class="paragraph">
      <p>In case of security incidents involving a compromised identity (user, group, or service principal), limiting its role assignment to the narrowest scope possible helps separate duties and limits what resources are at risk.</p>
    </div>

    <CodeGroup>
      ```azureresourcemanager Bad theme={null}
      targetScope = 'subscription' // Sensitive

      resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
      name: guid(subscription().id, 'exampleRoleAssignment')
      }
      ```

      ```azureresourcemanager Fix theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "resources": [
      {
        "name": "example",
        "type": "Microsoft.Authorization/roleAssignments",
        "apiVersion": "2022-04-01",
        "name": "[guid(subscription().id, 'exampleRoleAssignment')]"
      }
      ]
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Administration services access should be restricted to specific IP addresses">
    <div class="paragraph">
      <p>Cloud platforms such as AWS, Azure, or GCP support virtual firewalls that can be used to restrict access to services by controlling inbound and outbound traffic.
      Any firewall rule allowing traffic from all IP addresses to standard network ports on which administration services traditionally listen, such as 22 for SSH, can expose these services to exploits and unauthorized access.</p>
    </div>

    <CodeGroup>
      ```azureresourcemanager Bad theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "resources": [
      {
        "name": "networkSecurityGroups/example",
        "type": "Microsoft.Network/networkSecurityGroups/securityRules",
        "apiVersion": "2022-11-01",
        "properties": {
          "protocol": "*",
          "destinationPortRange": "*",
          "sourceAddressPrefix": "*",
          "access": "Allow",
          "direction": "Inbound"
        }
      }
      ]
      }
      ```

      ```azureresourcemanager Fix theme={null}
      resource securityRules 'Microsoft.Network/networkSecurityGroups/securityRules@2022-11-01' = {
      name: 'securityRules'
      properties: {
      direction: 'Inbound'
      access: 'Allow'
      protocol: '*'
      destinationPortRange: '*'
      sourceAddressPrefix: '*'
      }
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Unused local variables should be removed">
    <div class="paragraph">
      <p>An unused local variable is a variable that has been declared but is not used anywhere in the block of code where it is defined. It is dead code, contributing to unnecessary complexity and leading to confusion when reading the code. Therefore, it should be removed from your code to maintain clarity and efficiency.</p>
    </div>

    <CodeGroup>
      ```azureresourcemanager Bad theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "variables": {
        "unusedVariable": "unusedValue",
        "virtualMachinesName": "[uniqueString(resourceGroup().id)]"
      },
      "resources": [
      {
        "type": "Microsoft.Compute/virtualMachines",
        "name": "[variables('virtualMachinesName')]",
        "apiVersion": "2023-09-01",
        "location": "[resourceGroup().location]"
      }
      ]
      }
      ```

      ```azureresourcemanager Fix theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "variables": {
        "virtualMachinesName": "[uniqueString(resourceGroup().id)]"
      },
      "resources": [
      {
        "type": "Microsoft.Compute/virtualMachines",
        "name": "[variables('virtualMachinesName')]",
        "apiVersion": "2023-09-01",
        "location": "[resourceGroup().location]"
      }
      ]
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Parameter and variable names should comply with a naming convention">
    <div class="paragraph">
      <p>A naming convention in software development is a set of guidelines for naming code elements like variables, functions, and classes.
      \{identifier\_capital\_plural} hold the meaning of the written code. Their names should be meaningful and follow a consistent and easily recognizable pattern.
      Adhering to a consistent naming convention helps to make the code more readable and understandable, which makes it easier to maintain and debug.
      It also ensures consistency in the code, especially when multiple developers are working on the same project.</p>
    </div>

    <div class="paragraph">
      <p>This rule checks that \{identifier} names match a provided regular expression.</p>
    </div>

    <CodeGroup>
      ```azureresourcemanager Bad theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
      "storage_account_name": {
        "type": "string"
      }
      },
      "variables": {
      "string_variable": "example value"
      }
      }
      ```

      ```azureresourcemanager Fix theme={null}
      {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
      "storageAccountName": {
        "type": "string"
      }
      },
      "variables": {
      "stringVariable": "example value"
      }
      }
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>
