Bylaw

Gallery › Cosmos DB › Azure built-in policies

Cosmos DB database accounts should have local authentication methods disabled

Converted Policy Audit Deny Disabled Mode Indexed Version 1.2.0

Disabling local authentication methods improves security by ensuring that Cosmos DB database accounts exclusively require Azure Active Directory identities for authentication. Learn more at: https://docs.microsoft.com/azure/cosmos-db/how-to-setup-rbac#disable-local-auth.

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

Azure Policy JSONCosmos_DisableLocalAuth_AuditDeny.json · 59 lines
{
  "properties": {
    "displayName": "Cosmos DB database accounts should have local authentication methods disabled",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Disabling local authentication methods improves security by ensuring that Cosmos DB database accounts exclusively require Azure Active Directory identities for authentication. Learn more at: https://docs.microsoft.com/azure/cosmos-db/how-to-setup-rbac#disable-local-auth.",
    "metadata": {
      "version": "1.2.0",
      "category": "Cosmos DB"
    },
    "version": "1.2.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.DocumentDB/databaseAccounts"
          },
          {
            "field": "Microsoft.DocumentDB/databaseAccounts/disableLocalAuth",
            "notEquals": true
          },
          {
            "field": "Microsoft.DocumentDB/databaseAccounts/capabilities[*].name",
            "notin": [
              "EnableMongo",
              "EnableCassandra",
              "EnableGremlin"
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.2.0",
      "1.1.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/5450f5bd-9c72-4390-a9c4-a7aba4edfdd2",
  "name": "5450f5bd-9c72-4390-a9c4-a7aba4edfdd2"
}
Bylaw5450f5bd-9c72-4390-a9c4-a7aba4edfdd2.bylaw.ps1 · 34 lines
# Converted from Cosmos_DisableLocalAuth_AuditDeny.json by ConvertTo-Bylaw.
Policy '5450f5bd-9c72-4390-a9c4-a7aba4edfdd2' {

    Properties @{
        DisplayName   = 'Cosmos DB database accounts should have local authentication methods disabled'
        Description   = 'Disabling local authentication methods improves security by ensuring that Cosmos DB database accounts exclusively require Azure Active Directory identities for authentication. Learn more at: https://docs.microsoft.com/azure/cosmos-db/how-to-setup-rbac#disable-local-auth.'
        Version       = '1.2.0'
        Category      = 'Cosmos DB'
        PolicyVersion = '1.2.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Deny', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource 'Microsoft.DocumentDB/databaseAccounts' {

        When {
            Field disableLocalAuth | Must -Not -Be $true
        }

        Require 'capabilities and name are as required' {
            Count 'capabilities[*]' -Where {
                Field name | Must -BeIn @('EnableMongo', 'EnableCassandra', 'EnableGremlin')
            } | Must -Not -Be 0
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/Cosmos DB/Cosmos_DisableLocalAuth_AuditDeny.json in Azure/azure-policy, under the MIT licence.