Azure Policy – VM password requirements

When creating a Virtual Machine in the Azure environment, you have to follow some requirements in terms of password lenght. By default Microsoft enforce 12 caracters. But what happens if your corporate policy requires 20 or 25 caracters ?

To achieve that, you can implement an Azure Policy that will ensure when a new VM is created, your corporate policy will be enforced (only if more restrictive that Microsoft default)

Here you will find the code to create your custom policy. This sample specify the requirement of 20 password characters or an SSH Public key for Linux machines.

Hope this will help you to achieve more !

 


   « policyRule »: {
      « if »: {
        « allof »: [
          {
            « field »: « type »,
            « equals »: « Microsoft.Compute/virtualMachines »
          },
          {
            « not »: {
« anyof »: [
                {
                  « value »: « [greaterOrEquals(length(field(‘Microsoft.Compute/virtualMachines/osProfile.adminPassword’)), 20)] »,
                  « equals »: true
                },
                {
                  « field »: « Microsoft.Compute/virtualMachines/osProfile.linuxConfiguration.disablePasswordAuthentication »,
                  « equals »: true
                }
              ]
            }
          }
        ]
      },
      « then »: {
        « effect »: « deny »
      }
    }

Laisser un commentaire