Azure / azure-policy

Repository for Azure Resource Policy built-in definitions and samples
MIT License
1.49k stars 1.08k forks source link

Azure Cognitive Search services should use customer-managed keys to encrypt data at rest: Does not function with Deny Effect #1263

Open cmurrayjr opened 8 months ago

cmurrayjr commented 8 months ago

Details of the scenario you tried and the problem that is occurring

Initial observation of mis-match between filename and defined parameters.effect.allowedValues

It is worth noting that the name of this policies file indicates the author intended Audit-Only use of the policy, however parameters.effect.allowedValues lists Deny and Disabled Effects as well. This is further documented in #118467 on the azure-docs repo

Condition

When using this policy with a "Deny" effect.

Cause

The rule located at properties.policyrule.if.allof.anyof.field specifies that "Microsoft.Search/searchServices/encryptionWithCmk.encryptionComplianceStatus" must have the value of compliant. This works perfectly with Audit, however it poses an issue with Deny because this value is ReadOnly value that is added to the resource by the Azure service fabric post-deployment. Not by the user, and there for is not present when the policy engine assesses deny effects. You will note the documentation for ARM templates for this resource does not list encryptionComplianceStatus as a user-configurable setting.

Effect

When you attempt to deploy a search services resource with this policy in effect you will be denied as the policy cannot validate the value of the missing ReadOnly parameter

Verbose logs showing the problem

Search Service Name: "srch-corp-demo-dev-use2-test"): performing CreateOrUpdate: unexpected status 403 with error: RequestDisallowedByPolicy: Resource 'srch-corp-demo-dev-use2-test' was disallowed by policy. Policy identifiers: '[{"policyAssignment":{"name":"Azure Cognitive Search services should use customer-managed keys to encrypt data at rest - Deny","id":"/providers/Microsoft.Management/managementGroups/REDACTED/providers/Microsoft.Authorization/policyAssignments/REDACTED"},"policyDefinition":{"name":"Azure Cognitive Search services should use customer-managed keys to encrypt data at rest","id":"/providers/Microsoft.Authorization/policyDefinitions/REDACTED"}}]'.

Suggested solution to the issue

There are a few plausible solutions,