Azure Policy for Guardrails

July 10, 2023 ยท View on GitHub

Table of Contents

Overview

Guardrails in Azure are deployed through Azure Policy. Azure Policy helps to enforce organizational standards and to assess compliance at-scale. Through its compliance dashboard, it provides an aggregated view to evaluate the overall state of the environment, with the ability to drill down to the per-resource, per-policy granularity. It also helps to bring your resources to compliance through bulk remediation for existing resources and automatic remediation for new resources.

Common use cases for Azure Policy include implementing governance for resource consistency, regulatory compliance, security, cost, and management. Policy definitions for these common use cases are already available in your Azure environment as built-ins to help you get started.

Azure Policy Compliance

Azure Landing Zones for Canadian Public Sector is configured with a set of built-in Azure Policy Sets based on Regulatory Compliance. Custom policy sets have been designed to increase compliance for logging, networking & tagging requirements. These can be further extended or removed as required by the department through automation.


Built-In Policy Sets Assignments

Note: The built-in policy sets are used as-is to ensure future improvements from Azure Engineering teams are automatically incorporated into the Azure environment.

All built-in policy set assignments are located in policy/builtin/assignments folder.

  • Deployment templates can be customized for additional policy parameters & role assignments for policy remediation.
  • Configuration files are used to define runtime parameters during policy set assignment.

Azure DevOps Pipeline (.pipelines/policy.yml) is used for policy set assignment automation. Assigned policy sets can be customized through pipeline configuration.

Pipeline Step

    - template: templates/steps/assign-policy.yml
      parameters:
        description: 'Assign Policy Set'
        deployTemplates: [asb, cis-msft-130, location, nist80053r4, nist80053r5, pbmm, hitrust-hipaa, fedramp-moderate]
        deployOperation: ${{ variables['deployOperation'] }}
        policyAssignmentManagementGroupScope: $(var-topLevelManagementGroupName)
        workingDir: $(System.DefaultWorkingDirectory)/policy/builtin/assignments

All policy set assignments are at the pubsec top level management group. This top level management group is retrieved from configuration parameter var-topLevelManagementGroupName. See the Azure DevOps Pipelines onboarding guide for instructions to setting up management groups & policy pipeline.

Policy SetDescriptionDeployment TemplateConfiguration
Canada Federal PBMMThis initiative includes audit and virtual machine extension deployment policies that address a subset of Canada Federal PBMM controls.pbmm.biceppbmm.parameters.json
NIST SP 800-53 Revision 4This initiative includes policies that address a subset of NIST SP 800-53 Rev. 4 controls.nist80053r4.bicepnist80053r4.parameters.json
NIST SP 800-53 Revision 5This initiative includes policies that address a subset of NIST SP 800-53 Rev. 5 controls.nist80053r5.bicepnist80053r5.parameters.json
Azure Security BenchmarkThe Azure Security Benchmark initiative represents the policies and controls implementing security recommendations defined in Azure Security Benchmark, see https://aka.ms/azsecbm. This also serves as the Microsoft Defender for Cloud default policy initiative.asb.bicepasb.parameters.json
CIS Microsoft Azure Foundations Benchmark 1.3.0This initiative includes policies that address a subset of CIS Microsoft Azure Foundations Benchmark recommendations.cis-msft-130.bicepcis-msft-130.parameters.json
FedRAMP ModerateThis initiative includes policies that address a subset of FedRAMP Moderate controls.fedramp-moderate.bicepfedramp-moderate.parameters.json
HIPAA / HITRUST 9.2This initiative includes audit and virtual machine extension deployment policies that address a subset of HITRUST/HIPAA controls.hitrust-hipaa.bicephitrust-hipaa.parameters.json
LocationRestrict deployments to Canadian regions.location.biceplocation.parameters.json

Custom Policies and Policy Sets

Note: The custom policies & policy sets are used when built-in alternative does not exist. Automation is regularly revised to use built-in policies and policy sets as new options are made available.

All policies and policy set definitions & assignments are at the pubsec top level management group. This top level management group is retrieved from configuration parameter var-topLevelManagementGroupName. See the Azure DevOps Pipelines onboarding guide for instructions to setting up management groups & policy pipeline.

Custom Policy Definitions

All custom policy definitions are located in policy/custom/definitions/policy folder.

Each policy is organized into it's own folder. The folder name must not have any spaces nor special characters. Each folder contains 3 files:

  1. azurepolicy.config.json - metadata used by Azure DevOps Pipeline to configure the policy.
  2. azurepolicy.parameters.json - contains parameters used in the policy.
  3. azurepolicy.rules.json - the policy rule definition.

See step-by-step instructions on Azure Policy Authoring Guide for more information.

Azure DevOps Pipeline (.pipelines/policy.yml) is used for policy definition automation. The automation enumerates the policy definition directory (policy/custom/definitions/policy) and creates/updates policies that it identifies.

Pipeline Step

    - template: templates/steps/define-policy.yml
      parameters:
        description: 'Define Policies'
        workingDir: $(System.DefaultWorkingDirectory)/policy/custom/definitions/policy

Custom Policy Set Definitions

All custom policy set definitions are located in policy/custom/definitions/policyset folder. Custom policy sets contain built-in and custom policies.

Azure DevOps Pipeline (.pipelines/policy.yml) is used for policy set definition automation. Defined policy sets can be customized through pipeline configuration.

Pipeline Step

    - template: templates/steps/define-policyset.yml
      parameters:
        description: 'Define Policy Set'
        deployTemplates: [AKS, DefenderForCloud, LogAnalytics, Network, DNSPrivateEndpoints, Tags]
        deployOperation: ${{ variables['deployOperation'] }}
        policyAssignmentManagementGroupScope: $(var-topLevelManagementGroupName)
        workingDir: $(System.DefaultWorkingDirectory)/policy/custom/definitions/policyset
Policy SetDescriptionDeployment TemplateConfiguration
Azure Kubernetes ServiceAzure Policy Add-on to Azure Kubernetes Service clusters & Pod Security.AKS.bicepAKS.parameters.json
Microsoft Defender for CloudConfigures Microsoft Defender for Cloud, including Azure Defender for subscription and resources.DefenderForCloud.bicepDefenderForCloud.parameters.json
Private DNS Zones for Private EndpointsPolicies to configure DNS zone records for private endpoints. Policy set is assigned through deployment pipeline when private endpoint DNS zones are managed in the Hub Network.DNSPrivateEndpoints.bicepDNSPrivateEndpoints.parameters.json
Log Analytics for Azure Services (IaaS and PaaS)Configures monitoring agents for IaaS and diagnostic settings for PaaS to send logs to a central Log Analytics Workspace.LogAnalytics.bicepLogAnalytics.parameters.json
NetworkingConfigures policies for network resources.Network.bicepNetwork.parameters.json
Tag GovernanceConfigures required tags and tag propagation from resource groups to resources.Tags.bicepTags.parameters.json

Custom Policy Set Assignments

All custom policy set assignments are located in policy/custom/assignments folder.

  • Deployment templates can be customized for additional policy parameters & role assignments for policy remediation.
  • Configuration files are used to define runtime parameters during policy set assignment.

Azure DevOps Pipeline (.pipelines/policy.yml) is used for policy set assignment automation. Assigned policy sets can be customized through pipeline configuration.

Pipeline Step

    - template: templates/steps/assign-policy.yml
      parameters:
        description: 'Assign Policy Set'
        deployTemplates: [AKS, DefenderForCloud, LogAnalytics, Network, Tags]
        deployOperation: ${{ variables['deployOperation'] }}
        policyAssignmentManagementGroupScope: $(var-topLevelManagementGroupName)
        workingDir: $(System.DefaultWorkingDirectory)/policy/custom/assignments
Policy SetDescriptionDeployment TemplateConfiguration
Azure Kubernetes ServiceAzure Policy Add-on to Azure Kubernetes Service clusters & Pod Security.AKS.bicepAKS.parameters.json
Microsoft Defender for CloudConfigures Microsoft Defender for Cloud, including Azure Defender for subscription and resources.DefenderForCloud.bicepDefenderForCloud.parameters.json
Azure DDoSConfigures policy to automatically protect virtual networks with public IP addresses. Policy set is assigned through deployment pipeline when DDoS Standard is configured.DDoS.bicepDDoS.parameters.json
Private DNS Zones for Private EndpointsPolicies to configure DNS zone records for private endpoints. Policy set is assigned through deployment pipeline when private endpoint DNS zones are managed in the Hub Network.DNSPrivateEndpoints.bicepDNSPrivateEndpoints.parameters.json
Log Analytics for Azure Services (IaaS and PaaS)Configures monitoring agents for IaaS and diagnostic settings for PaaS to send logs to a central Log Analytics Workspace.LogAnalytics.bicepLogAnalytics.parameters.json
NetworkingConfigures policies for network resources.Network.bicepNetwork.parameters.json
Tag GovernanceConfigures required tags and tag propagation from resource groups to resources.Tags.bicepTags.parameters.json

Templated Parameters

Parameters can be templated using the syntax {{PARAMETER_NAME}}. Following parameters are supported:

Templated ParameterSource ValueExample
{{var-topLevelManagementGroupName}}Environment configuration file such as config/variables/CanadaPubSecALZ-main.ymlpubsec
{{var-logging-logAnalyticsWorkspaceResourceId}}Resource ID is inferred using Log Analytics settings in environment configuration file such as config/variables/CanadaPubSecALZ-main.yml/subscriptions/bc0a4f9f-07fa-4284-b1bd-fbad38578d3a/resourcegroups/pubsec-central-logging/providers/microsoft.operationalinsights/workspaces/log-analytics-workspace
{{var-logging-logAnalyticsWorkspaceId}}Workspace ID is inferred using Log Analytics settings in environment configuration file such as config/variables/CanadaPubSecALZ-main.ymlfcce3f30-158a-4561-a714-361623f42168
{{var-logging-logAnalyticsResourceGroupName}}Environment configuration file such as config/variables/CanadaPubSecALZ-main.ymlpubsec-central-logging
{{var-logging-logAnalyticsRetentionInDays}}Environment configuration file such as config/variables/CanadaPubSecALZ-main.yml730
{{var-logging-diagnosticSettingsforNetworkSecurityGroupsStoragePrefix}}Environment configuration file such as config/variables/CanadaPubSecALZ-main.ymlpubsecnsg
{{var-policyAssignmentManagementGroupId}}The management group scope for policy assignment.pubsec

Authoring Guide

See Azure Policy Authoring Guide for step-by-step instructions.