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

Unexpected results using "Microsoft.web/sites/config/web.ipSecurityRestrictions"

Open pbillany opened this issue 7 years ago • 3 comments

I'm trying to construct a policy to audit this setting.

I have two webapps, one with the setting populated:-

"ipSecurityRestrictions": [ { "ipAddress": "a.b.c.d/e", "action": "Allow", "tag": "Default", "priority": 10, "name": "allowip" } ],

And one without:-

"ipSecurityRestrictions": null,

I've tried querying the value in various ways including:-

"field": "Microsoft.web/sites/config/ipSecurityRestrictions", "notlike": "*"

and:-

"value": "[empty(field('Microsoft.web/sites/config/ipSecurityRestrictions'))] "equals": true

I seem to always get a compliant app regardless of the value.

Is there a particular way of assessing for a null value?

I've noticed that the portal populates greyed-out values as below, could this be impacting results? image

They do not appear when querying the values with the API.

Similar to issue #52 as commented by @Singh1612

pbillany avatar Jun 10 '19 20:06 pbillany

Just to clarify on my last comment... When IpSecurityRestrictions is null in the REST API - the portal shows the screen above (Priority 1 | Name Allow All | Source Any | | | Action Allow).

When I add a specific CIDR or unique address, a second rule appears (that again doesn't show in the REST API) - (Priority 2147483647 | Name Deny all | Source Any |   |   | Action Deny)

Can anyone tell me how I can account for this behaviour when constructing a policy?

pbillany avatar Jun 12 '19 20:06 pbillany

FYI @mylameaccount

pbillany avatar Jun 13 '19 16:06 pbillany

So solved by looking for the Deny using but with following logic

"existenceCondition": { "allOf": [ { "not": { "field": "Microsoft.web/sites/config/web.ipSecurityRestrictions[*].action", "notEquals": "Deny"

  • in essence the field is an array and when you create restirctions is creates array e.g. ["Allow", Allow", "Deny"]

if I use "Equals" then it doesn't resolve - I found this article to be the best explanation....

https://docs.microsoft.com/en-us/azure/governance/policy/how-to/author-policies-for-arrays

By looking for Deny I can see that some policy has been set. Could be improved by getting desired IPs and looking for those... next stage...

pbillany avatar Jun 19 '19 14:06 pbillany