Issue: Alias "Microsoft.ApiManagement/service/customProperties" doesn't return an array or string
I am tying to audit API Management Resources "protocol settings" for client side and back end settings being changed using the alias "Microsoft.ApiManagement/service/customProperties" however I believe it is returning an object instead of an array or string.
I believe it is an object being returned because it returns a value in side curly brackets {}. The Azure Resource Manager template functions that should convert an object to an array (createArray, array) returns "******" so I am not sure if those functions work for Azure Policy.
Below are the 4 questions I have about this Alias:
-
Is the Alias "Microsoft.ApiManagement/service/customProperties" returning an object?
-
If an object is being returned what are the ARM template functions that will work for handling an object correctly? Are there examples of an object being used in policies?
-
Should the Alias "Microsoft.ApiManagement/service/customProperties.additionalProperties" return the details about the protocol settings but its not working correctly? If so at this time it is only returning a "--".
-
Can someone identify what data types are returned or error messages we will see in the "Current value" when viewing the "Compliance details" of a none compliant resource in the portal? Below are my best guesses but I haven't seen them documented:
-
- Current value: {} = Object
-
- Current value: [] = Array
-
- Current value: "" = String
-
- Current value: "******" = ?????? (seen when trying ARM functions on an Alias)
-
- Current value: -- = ??????
Below are is an example of the return of "Microsoft.ApiManagement/service/customProperties" that I am seeing:
Reason for non-compliance Current value must be equal to the target value. Field Microsoft.ApiManagement/service/customProperties Path properties.customProperties Current value {"Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls10":"false","Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls11":"false","Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Ssl30":"false","Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls10":"false","Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls11":"true","Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Ssl30":"false","Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TripleDes168":"false","Microsoft.WindowsAzure.ApiManagement.Gateway.Protocols.Server.Http2":"False"} Target value
- The alias returns whatever the resource provider returns on that path of the applicable type. The fact that this one is named customObject implies there is no schema. IOW, it could be anything.
- There isn't a good way of parsing an arbitrary object and making policy decisions based on property values. The only related function I can find is containsKey
- The additionalProperties alias can never have a value and should not be an alias. It was generated incorrectly and will be removed.
- Correct, generally this is just the JSON returned by the resource provider. The ******* indicates the field might contain secrets, and has been masked accordingly. I think -- is what is shown when the alias path doesn't exist in the response.
When trying to use the "containsKey" function I get an error about it not being a valid function while contains is however it returns:
The inner exception 'The function 'containsKey' defined in policy is invalid. Please see https://aka.ms/policy-functions for usage details.'."}}
Is the "containsKey" function not valid? Below is the example of the function I am trying to retrieve a value with.
"value": "[containsKey(field('Microsoft.ApiManagement/service/customProperties'),'Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls11')]"
Is this Alias usable as it is today? Are there examples of how this could be used correctly? I do want to audit the properties below but as of right now I am not seeing how this Alias can be used:
- "Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls10": "false",
- "Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls11": "false",
- "Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Ssl30": "false",
- "Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls10": "false",
- "Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls11": "true",
- "Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Ssl30": "false",
- "Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TripleDes168": "false",
- "Microsoft.WindowsAzure.ApiManagement.Gateway.Protocols.Server.Http2": "False"
Below is an image of the error I get when trying to use the containsKey function in the portal:

@mylameaccount containsKey is a condition, not a function. There's an example of it's use with tags here: https://docs.microsoft.com/en-us/azure/governance/policy/concepts/definition-structure#logical-operators
That makes sense. I must have misinterpreted an earlier response. That said the question still remains how can we use this alias? The data it returns in the "view compliance details" has the values I want to audit for however there is no useful way to pull it out to audit the key value in the object. Is there a useful example of how this alias can be used? Right now it seems to have zero value no matter what approach is used.
Should I be requesting an alias for each of the following under "Microsoft.ApiManagement/service/customProperties"?
-
"Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls10": "false",
-
"Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls11": "false",
-
"Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Ssl30": "false",
-
"Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls10": "false",
-
"Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls11": "true",
-
"Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Ssl30": "false",
-
"Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TripleDes168": "false",
-
"Microsoft.WindowsAzure.ApiManagement.Gateway.Protocols.Server.Http2": "False"
These all seem like something other organizations would want to audit at some point. Please give some guidance.
I earlier incorrectly identified containsKey as a function rather than a condition. That was my mistake, not yours.
As I mentioned earlier, due to the way the Microsoft.ApiManagement resource provider implemented its customProperties field, there isn't any good way to analyze its contents in a policy. The alias is created during generation because the field is defined in the swagger both in PUT and GET requests, but the contents below that is not defined. Since Azure Policy is not designed to apply rules to arbitrary JSON, there really isn't very much you can do with this field.
I'm sorry I don't have better news for you. We won't be able to fulfill the alias requests you listed above for the same reason: it's a current limitation.
Hi team, 2 years later, is there any feature available to validate json objects ?
Closest thing I've gotten sort of working is something like this:
{
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.ApiManagement/service"
},
{
"anyOf": [
{
"value": "[indexof(toLower(string(field('Microsoft.ApiManagement/service/customProperties'))), '\"microsoft.windowsazure.apimanagement.gateway.security.protocols.tls10\":\"true\"')]",
"greater": -1
},
{
"value": "[indexof(toLower(string(field('Microsoft.ApiManagement/service/customProperties'))), '\"microsoft.windowsazure.apimanagement.gateway.security.protocols.tls11\":\"true\"')]",
"greater": -1
},
{
"value": "[indexof(toLower(string(field('Microsoft.ApiManagement/service/customProperties'))), '\"microsoft.windowsazure.apimanagement.gateway.security.backend.protocols.tls10\":\"true\"')]",
"greater": -1
},
{
"value": "[indexof(toLower(string(field('Microsoft.ApiManagement/service/customProperties'))), '\"microsoft.windowsazure.apimanagement.gateway.security.backend.protocols.tls11\":\"true\"')]",
"greater": -1
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
}
Closest thing I've gotten sort of working is something like this:
{ "if": { "allOf": [ { "field": "type", "equals": "Microsoft.ApiManagement/service" }, { "anyOf": [ { "value": "[indexof(toLower(string(field('Microsoft.ApiManagement/service/customProperties'))), '\"microsoft.windowsazure.apimanagement.gateway.security.protocols.tls10\":\"true\"')]", "greater": -1 }, { "value": "[indexof(toLower(string(field('Microsoft.ApiManagement/service/customProperties'))), '\"microsoft.windowsazure.apimanagement.gateway.security.protocols.tls11\":\"true\"')]", "greater": -1 }, { "value": "[indexof(toLower(string(field('Microsoft.ApiManagement/service/customProperties'))), '\"microsoft.windowsazure.apimanagement.gateway.security.backend.protocols.tls10\":\"true\"')]", "greater": -1 }, { "value": "[indexof(toLower(string(field('Microsoft.ApiManagement/service/customProperties'))), '\"microsoft.windowsazure.apimanagement.gateway.security.backend.protocols.tls11\":\"true\"')]", "greater": -1 } ] } ] }, "then": { "effect": "[parameters('effect')]" } }
Thanks, it looks like doing the job !
{
"mode": "Indexed",
"parameters": {},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.ApiManagement/service"
},
{
"anyOf": [
{
"value": "[indexof(toLower(string(field('Microsoft.ApiManagement/service/customProperties'))), '\"microsoft.windowsazure.apimanagement.gateway.security.protocols.tls10\":\"true\"')]",
"greater": 0
},
{
"value": "[indexof(toLower(string(field('Microsoft.ApiManagement/service/customProperties'))), '\"microsoft.windowsazure.apimanagement.gateway.security.protocols.tls10\":true')]",
"greater": 0
}
]
}
]
},
"then": {
"effect": "deny"
}
}
}
This policy also works to deny on resource creation because at creation the value of custom properties are either true or false WITHOUT any quotes. After the resource is created the values have quotes. So this policy example works to deny when APIM gets created with TLS 1.0 and also properly audits existing resources.
Leaving this here in case anyone else runs into this issue.