Bylaw

Gallery › Backup › Azure built-in policies

Disable Cross Subscription Restore for Backup Vaults

Converted Policy Disabled Modify Mode Indexed Version 1.1.1

Disable or PermanentlyDisable Cross Subscription Restore for your Backup vault so that restore targets cannot be in different subscription from the vault subscription. Learn more at: https://aka.ms/csrstatechange.

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

Azure Policy JSONVaults_CrossSubscriptionRestore_Modify.json · 89 lines
{
  "properties": {
    "displayName": "Disable Cross Subscription Restore for Backup Vaults",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Disable or PermanentlyDisable Cross Subscription Restore for your Backup vault so that restore targets cannot be in different subscription from the vault subscription. Learn more at: https://aka.ms/csrstatechange.",
    "metadata": {
      "version": "1.1.1",
      "category": "Backup"
    },
    "version": "1.1.1",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Modify",
          "Disabled"
        ],
        "defaultValue": "Modify"
      },
      "crossSubscriptionRestoreState": {
        "type": "String",
        "metadata": {
          "displayName": "Cross Subscription Restore State",
          "description": "Settings to disable or permanently disable Cross Subscription Restore. Please note that Cross Subscription Restore once permanently disabled on a vault cannot be re-enabled.",
          "deprecated": true
        },
        "allowedValues": [
          "Disable",
          "PermanentlyDisable"
        ],
        "defaultValue": "Disable"
      },
      "crossSubscriptionRestoreStateParameter": {
        "type": "String",
        "metadata": {
          "displayName": "Cross Subscription Restore State",
          "description": "Settings to disable or permanently disable Cross Subscription Restore. Please note that Cross Subscription Restore once permanently disabled on a vault cannot be re-enabled."
        },
        "allowedValues": [
          "Disabled",
          "PermanentlyDisabled"
        ],
        "defaultValue": "Disabled"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.DataProtection/backupVaults"
          },
          {
            "field": "Microsoft.DataProtection/backupVaults/featureSettings.crossSubscriptionRestoreSettings.state",
            "notEquals": "[parameters('crossSubscriptionRestoreStateParameter')]"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "conflictEffect": "deny",
          "roleDefinitionIds": [
            "/providers/microsoft.authorization/roleDefinitions/5e467623-bb1f-42f4-a55d-6e525e11384b"
          ],
          "operations": [
            {
              "condition": "[greaterOrEquals(requestContext().apiVersion, '2022-12-01')]",
              "operation": "addOrReplace",
              "field": "Microsoft.DataProtection/backupVaults/featureSettings.crossSubscriptionRestoreSettings.state",
              "value": "[parameters('crossSubscriptionRestoreStateParameter')]"
            }
          ]
        }
      }
    },
    "versions": [
      "1.1.1",
      "1.1.0-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/4d479a11-f2b5-4f0a-bb1e-d2332aa95cda",
  "name": "4d479a11-f2b5-4f0a-bb1e-d2332aa95cda"
}
Bylaw4d479a11-f2b5-4f0a-bb1e-d2332aa95cda.bylaw.ps1 · 43 lines
# Converted from Vaults_CrossSubscriptionRestore_Modify.json by ConvertTo-Bylaw.
Policy '4d479a11-f2b5-4f0a-bb1e-d2332aa95cda' {

    Properties @{
        DisplayName   = 'Disable Cross Subscription Restore for Backup Vaults'
        Description   = 'Disable or PermanentlyDisable Cross Subscription Restore for your Backup vault so that restore targets cannot be in different subscription from the vault subscription. Learn more at: https://aka.ms/csrstatechange.'
        Version       = '1.1.1'
        Category      = 'Backup'
        PolicyVersion = '1.1.1'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('Modify', 'Disabled')
        Default       = 'Modify'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }
    Parameter CrossSubscriptionRestoreState @{
        AllowedValues = @('Disable', 'PermanentlyDisable')
        Default       = 'Disable'
        DisplayName   = 'Cross Subscription Restore State'
        Description   = 'Settings to disable or permanently disable Cross Subscription Restore. Please note that Cross Subscription Restore once permanently disabled on a vault cannot be re-enabled.'
        Metadata      = [ordered]@{ deprecated = $true }
    }
    Parameter CrossSubscriptionRestoreStateParameter @{
        AllowedValues = @('Disabled', 'PermanentlyDisabled')
        Default       = 'Disabled'
        DisplayName   = 'Cross Subscription Restore State'
        Description   = 'Settings to disable or permanently disable Cross Subscription Restore. Please note that Cross Subscription Restore once permanently disabled on a vault cannot be re-enabled.'
    }

    Resource 'Microsoft.DataProtection/backupVaults' {

        Require 'featureSettings.crossSubscriptionRestoreSettings.state is as required' {
            Field featureSettings.crossSubscriptionRestoreSettings.state | Must -Be (Param CrossSubscriptionRestoreStateParameter)
        }
    }

    Modify -Role 'Backup Contributor' -ConflictEffect Deny -Effect (Param Effect) {
        Field featureSettings.crossSubscriptionRestoreSettings.state | AddOrReplace (Param CrossSubscriptionRestoreStateParameter) -Condition (Arm '[greaterOrEquals(requestContext().apiVersion, ''2022-12-01'')]')
    }
}

Source: built-in-policies/policyDefinitions/Backup/Vaults_CrossSubscriptionRestore_Modify.json in Azure/azure-policy, under the MIT licence.