azure-policy icon indicating copy to clipboard operation
azure-policy copied to clipboard

Alias request: "Microsoft.ApiManagement/service/virtualNetworkType"

Open mylameaccount opened this issue 7 years ago • 5 comments

I am requesting that an alias be created for the “virtualNetworkType” property of the “Microsoft.ApiManagement/service” resource type.

The scenario we are looking to audit for is for any API Management resource that does not have the virtual network enabled (None) or set to External.

  • Resource Provider: Microsoft.ApiManagement
  • Resource Type: service
  • Property: “properties.virtualNetworkType” (may also be known as "properties.vpnType")
  • Alias Name: : "Microsoft.ApiManagement/service/virtualNetworkType"

Example policy definition

"policyRule": {
  "if": {
    "allOf": [
      {
        "field": "type",
        "equals": "Microsoft.ApiManagement/service"
      },
      {
        "field": "Microsoft.ApiManagement/service/virtualNetworkType",
        "Equals": "None"
      }
    ]
  },
  "then": {
    "effect": "Audit"
  }
}

mylameaccount avatar Apr 19 '19 02:04 mylameaccount

Please also make this available in Azure Gov as well as Azure Cloud.

RichShillingtonMSFT avatar Apr 22 '19 13:04 RichShillingtonMSFT

Full set of Microsoft.ApiManagement aliases (including this one) has been published in Azure Cloud and Azure Gov.

mentat9 avatar Apr 22 '19 21:04 mentat9

If it is published it may not be working correctly for me. I believe I see some issues with the API Management alias in general. Many seem to return just a "Current value: --". Just two hyphens and no value while I can see using powershell and rest api that there are settings.

That said the following are the indicators for the "virtualNetworkType" alias not working for me. Please give guidance if you see I am doing something wrong:

  1. Running the following powershell command does not show the Alias: "(Get-AzPolicyAlias -NamespaceMatch "Microsoft.ApiManagement" | Where-object {$_.ResourceType -eq "service"}).Aliases"

  2. Editing the Azure Policy Definition with the "virtualNetworkType" in the portal results in an error as seen in the picture below: virtualNetworkType-ErrorInGUI

  3. Using powershell results in an error similar to that in the portal:

New-AzPolicyDefinition : InvalidPolicyAlias : The policy definition 'blahblah-AzureAPIManagement.Networking.Delete' rule is invalid. The 'field' property 'Microsoft.ApiManagement/service/virtualNetworkType' of the policy rule doesn't exist as an alias under provider 'Microsoft.ApiManagement' and resource type 'service'. The supported aliases are 'Microsoft.ApiManagement/service/api-version-sets.displayName; Microsoft.ApiManagement/service/api-version-sets.versioningScheme; Microsoft.ApiManagement/service/caches.description; Microsoft.ApiManagement/service/caches.connectionString; Microsoft.ApiManagement/service/caches.resourceId; Microsoft.ApiManagement/service/publisherEmail; Microsoft.ApiManagement/service/publisherName; Microsoft.ApiManagement/service/sku.name.externalDocs; Microsoft.ApiManagement/service/sku.name; Microsoft.ApiManagement/service/sku.capacity; Microsoft.ApiManagement/service/sku; Microsoft.ApiManagement/service/provisioningState; Microsoft.ApiManagement/service/targetProvisioningState; Microsoft.ApiManagement/service/createdAtUtc; Microsoft.ApiManagement/service/runtimeUrl; Microsoft.ApiManagement/service/portalUrl; Microsoft.ApiManagement/service/managementApiUrl; Microsoft.ApiManagement/service/scmUrl; Microsoft.ApiManagement/service/addresserEmail; Microsoft.ApiManagement/service/hostnameConfigurations[].type; Microsoft.ApiManagement/service/hostnameConfigurations[].hostname; Microsoft.ApiManagement/service/hostnameConfigurations[].certificate.expiry; Microsoft.ApiManagement/service/hostnameConfigurations[].certificate.thumbprint; Microsoft.ApiManagement/service/hostnameConfigurations[].certificate.subject; Microsoft.ApiManagement/service/hostnameConfigurations[].certificate; Microsoft.ApiManagement/service/hostnameConfigurations[]; Microsoft.ApiManagement/service/hostnameConfigurations; Microsoft.ApiManagement/service/staticIPs[]; Microsoft.ApiManagement/service/staticIPs; Microsoft.ApiManagement/service/vpnconfiguration.vnetid; Microsoft.ApiManagement/service/vpnconfiguration.subnetname; Microsoft.ApiManagement/service/vpnconfiguration.subnetResourceId; Microsoft.ApiManagement/service/vpnconfiguration.location; Microsoft.ApiManagement/service/vpnconfiguration; Microsoft.ApiManagement/service/additionalLocations[].location; Microsoft.ApiManagement/service/additionalLocations[].skuType; Microsoft.ApiManagement/service/additionalLocations[].skuUnitCount; Microsoft.ApiManagement/service/additionalLocations[].staticIPs[]; Microsoft.ApiManagement/service/additionalLocations[].staticIPs; Microsoft.ApiManagement/service/additionalLocations[].vpnconfiguration.vnetid; Microsoft.ApiManagement/service/additionalLocations[].vpnconfiguration.subnetname; Microsoft.ApiManagement/service/additionalLocations[].vpnconfiguration.subnetResourceId; Microsoft.ApiManagement/service/additionalLocations[].vpnconfiguration.location; Microsoft.ApiManagement/service/additionalLocations[].vpnconfiguration; Microsoft.ApiManagement/service/additionalLocations[]; Microsoft.ApiManagement/service/additionalLocations; Microsoft.ApiManagement/service/customProperties.additionalProperties; Microsoft.ApiManagement/service/customProperties; Microsoft.ApiManagement/service/vpnType'. Please see https://github.com/Azure/azure-policy/blob/master/1-contribution-guide/request-alias.md to request new aliases. At C:\Users\blahblah-AzureAPIManagement.Networking.ApimIsVNetEnabled - Delete.ps1:134 char:19

  • ... efinition = New-AzPolicyDefinition -Name $NewPolicyDef_Name -DisplayN ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : CloseError: (:) [New-AzPolicyDefinition], ErrorResponseMessageException
    • FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzurePolicyDefinitionCmdlet

mylameaccount avatar Apr 22 '19 22:04 mylameaccount

You are correct. Somehow the update was incomplete. Sorry for the inconvenience: I've corrected it both public and government clouds.

mentat9 avatar Apr 24 '19 00:04 mentat9

This one works for me.

{ "mode": "All", "policyRule": { "if": { "allOf": [ { "field": "type", "equals": "Microsoft.ApiManagement/service" }, { "not": { "field": "Microsoft.ApiManagement/service/virtualNetworkType", "like": "Internal" } } ] }, "then": { "effect": "audit" } }, "parameters": {} }

RichShillingtonMSFT avatar Apr 24 '19 12:04 RichShillingtonMSFT