Bylaw

Gallery › Container Registry › Azure built-in policies

Configure container registries to disable repository scoped access token.

Converted Policy Disabled Modify Mode All Version 1.0.0

Disable repository scoped access tokens for your registry so that repositories are not accessible by tokens. Disabling local authentication methods like admin user, repository scoped access tokens and anonymous pull improves security by ensuring that container registries exclusively require Azure Active Directory identities for authentication. Learn more at: https://aka.ms/acr/authentication.

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

Azure Policy JSONACR_TokenDisabled_Modify.json · 62 lines
{
  "properties": {
    "displayName": "Configure container registries to disable repository scoped access token.",
    "description": "Disable repository scoped access tokens for your registry so that repositories are not accessible by tokens. Disabling local authentication methods like admin user, repository scoped access tokens and anonymous pull improves security by ensuring that container registries exclusively require Azure Active Directory identities for authentication. Learn more at: https://aka.ms/acr/authentication.",
    "policyType": "BuiltIn",
    "mode": "All",
    "metadata": {
      "version": "1.0.0",
      "category": "Container Registry"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "String",
        "defaultValue": "Modify",
        "allowedValues": [
          "Modify",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.ContainerRegistry/registries/tokens"
          },
          {
            "field": "Microsoft.ContainerRegistry/registries/tokens/status",
            "notequals": "disabled"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "conflictEffect": "audit",
          "roleDefinitionIds": [
            "/providers/microsoft.authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
          ],
          "operations": [
            {
              "operation": "addOrReplace",
              "field": "Microsoft.ContainerRegistry/registries/tokens/status",
              "value": "disabled"
            }
          ]
        }
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/a9b426fe-8856-4945-8600-18c5dd1cca2a",
  "name": "a9b426fe-8856-4945-8600-18c5dd1cca2a"
}
Bylawa9b426fe-8856-4945-8600-18c5dd1cca2a.bylaw.ps1 · 30 lines
# Converted from ACR_TokenDisabled_Modify.json by ConvertTo-Bylaw.
Policy 'a9b426fe-8856-4945-8600-18c5dd1cca2a' {

    Properties @{
        DisplayName   = 'Configure container registries to disable repository scoped access token.'
        Description   = 'Disable repository scoped access tokens for your registry so that repositories are not accessible by tokens. Disabling local authentication methods like admin user, repository scoped access tokens and anonymous pull improves security by ensuring that container registries exclusively require Azure Active Directory identities for authentication. Learn more at: https://aka.ms/acr/authentication.'
        Version       = '1.0.0'
        Category      = 'Container Registry'
        PolicyVersion = '1.0.0'
        Mode          = 'All'
    }

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

    Resource 'Microsoft.ContainerRegistry/registries/tokens' {

        Require 'status is disabled' {
            Field status | Must -Be 'disabled'
        }
    }

    Modify -Role 'Contributor' -ConflictEffect Audit -Effect (Param Effect) {
        Field status | AddOrReplace 'disabled'
    }
}

Source: built-in-policies/policyDefinitions/Container Registry/ACR_TokenDisabled_Modify.json in Azure/azure-policy, under the MIT licence.