Bylaw

Gallery › Container Registry › Azure built-in policies

Configure container registries to disable local admin account.

Converted Policy Disabled Modify Mode Indexed Version 1.0.1

Disable admin account for your registry so that it is not accessible by local admin. 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_AdminAccountDisabled_Modify.json · 62 lines
{
  "properties": {
    "displayName": "Configure container registries to disable local admin account.",
    "description": "Disable admin account for your registry so that it is not accessible by local admin. 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": "Indexed",
    "metadata": {
      "version": "1.0.1",
      "category": "Container Registry"
    },
    "version": "1.0.1",
    "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"
          },
          {
            "field": "Microsoft.ContainerRegistry/registries/adminUserEnabled",
            "equals": true
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "conflictEffect": "audit",
          "roleDefinitionIds": [
            "/providers/microsoft.authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
          ],
          "operations": [
            {
              "operation": "addOrReplace",
              "field": "Microsoft.ContainerRegistry/registries/adminUserEnabled",
              "value": false
            }
          ]
        }
      }
    },
    "versions": [
      "1.0.1"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/79fdfe03-ffcb-4e55-b4d0-b925b8241759",
  "name": "79fdfe03-ffcb-4e55-b4d0-b925b8241759"
}
Bylaw79fdfe03-ffcb-4e55-b4d0-b925b8241759.bylaw.ps1 · 30 lines
# Converted from ACR_AdminAccountDisabled_Modify.json by ConvertTo-Bylaw.
Policy '79fdfe03-ffcb-4e55-b4d0-b925b8241759' {

    Properties @{
        DisplayName   = 'Configure container registries to disable local admin account.'
        Description   = 'Disable admin account for your registry so that it is not accessible by local admin. 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.1'
        Category      = 'Container Registry'
        PolicyVersion = '1.0.1'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.ContainerRegistry/registries' {

        Require 'adminUserEnabled is not true' {
            Field adminUserEnabled | Must -Not -Be $true -IfPresent
        }
    }

    Modify -Role 'Contributor' -ConflictEffect Audit -Effect (Param Effect) {
        Field adminUserEnabled | AddOrReplace $false
    }
}

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