Bylaw

Gallery › Container Apps › Azure built-in policies

Container App environments should use network injection

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.2

Container Apps environments should use virtual network injection to: 1.Isolate Container Apps from the public internet 2.Enable network integration with resources on-premises or in other Azure virtual networks 3.Achieve more granular control over network traffic flowing to and from the environment.

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

Azure Policy JSONInjectVNet_Audit.json · 58 lines
{
  "properties": {
    "displayName": "Container App environments should use network injection",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Container Apps environments should use virtual network injection to: 1.Isolate Container Apps from the public internet 2.Enable network integration with resources on-premises or in other Azure virtual networks 3.Achieve more granular control over network traffic flowing to and from the environment.",
    "metadata": {
      "version": "1.0.2",
      "category": "Container Apps"
    },
    "version": "1.0.2",
    "parameters": {
      "effect": {
        "type": "String",
        "defaultValue": "Audit",
        "allowedValues": [
          "Audit",
          "Disabled",
          "Deny"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.App/managedEnvironments"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.App/managedEnvironments/vnetConfiguration.infrastructureSubnetId",
                "exists": false
              },
              {
                "field": "Microsoft.App/managedEnvironments/vnetConfiguration.infrastructureSubnetId",
                "equals": ""
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.2"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/8b346db6-85af-419b-8557-92cee2c0f9bb",
  "name": "8b346db6-85af-419b-8557-92cee2c0f9bb"
}
Bylaw8b346db6-85af-419b-8557-92cee2c0f9bb.bylaw.ps1 · 32 lines
# Converted from InjectVNet_Audit.json by ConvertTo-Bylaw.
Policy '8b346db6-85af-419b-8557-92cee2c0f9bb' {

    Properties @{
        DisplayName   = 'Container App environments should use network injection'
        Description   = 'Container Apps environments should use virtual network injection to: 1.Isolate Container Apps from the public internet 2.Enable network integration with resources on-premises or in other Azure virtual networks 3.Achieve more granular control over network traffic flowing to and from the environment.'
        Version       = '1.0.2'
        Category      = 'Container Apps'
        PolicyVersion = '1.0.2'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.App/managedEnvironments' {

        Require 'vnetConfiguration.infrastructureSubnetId exists' {
            Field vnetConfiguration.infrastructureSubnetId | Must -Exist
        }

        Require 'vnetConfiguration.infrastructureSubnetId is not' {
            Field vnetConfiguration.infrastructureSubnetId | Must -Not -Be '' -IfPresent
        }
    }

    Effect (Param Effect)
}

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