Bylaw

Gallery › Compute › Azure Community Policy

Audit SSH Auth on Existing Resources

Converted Policy Audit Disabled Mode all Version 1.0.0

This policy audits whether any Linux VMs use password-only authentication for SSH on existing resources.

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

Azure Policy JSONazurepolicy.json · 48 lines
{
  "name": "fa259b72-36b2-456f-9c7b-d6cc8e46d188",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Audit SSH Auth on Existing Resources",
    "description": "This policy audits whether any Linux VMs use password-only authentication for SSH on existing resources.",
    "metadata": {
      "version": "1.0.0",
      "category": "Compute"
    },
    "mode": "all",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allof": [
          {
            "field": "type",
            "equals": "Microsoft.Compute/virtualMachines"
          },
          {
            "field": "Microsoft.Compute/virtualMachines/osProfile.linuxConfiguration",
            "exists": "True"
          },
          {
            "field": "Microsoft.Compute/virtualMachines/osProfile.linuxConfiguration.disablePasswordAuthentication",
            "equals": "false"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylawfa259b72-36b2-456f-9c7b-d6cc8e46d188.bylaw.ps1 · 31 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'fa259b72-36b2-456f-9c7b-d6cc8e46d188' {

    Properties @{
        DisplayName = 'Audit SSH Auth on Existing Resources'
        Description = 'This policy audits whether any Linux VMs use password-only authentication for SSH on existing resources.'
        Version     = '1.0.0'
        Category    = 'Compute'
        Mode        = 'All'
    }

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

    Resource 'Microsoft.Compute/virtualMachines' {

        When {
            Field osProfile.linuxConfiguration | Must -Exist
        }

        Require 'osProfile.linuxConfiguration.disablePasswordAuthentication is not false' {
            Field osProfile.linuxConfiguration.disablePasswordAuthentication | Must -Not -Be 'false' -IfPresent
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Compute/audit-ssh-auth-on-existing-resources/azurepolicy.json in Azure/Community-Policy, under the MIT licence.