fix(azure): Fix detecting logic for CIS Azure Benchmark v1.3.0 - 2.12 #7807
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
I found a bug in the logic of CIS Azure Benchmark v1.3.0 Section 2.12 (
policy_assignment_parameters.sqlanddefault_policy_disabled.sql).The current query takes json keys in the
propertycolumn of theazure_policy_assignmentstable to make a view. But, an actual value of the column is below.{ "scope": "/subscriptions/cc9a41f6-4e32-4f28-8326-a3c49e7036a3", "metadata": { "createdBy": "ae1999e6-b000-4f94-8e1c-ece7b864e35b", "createdOn": "2022-08-19T01:36:48.5129096Z", "updatedBy": "64fd25ee-36e3-44e9-bf7a-96e411ae909f", "updatedOn": "2023-02-08T03:00:27.2551198Z", "assignedBy": "Security Center", "parameterScopes": {}, "excludedOutOfTheBoxStandards": [ "PCI DSS 3.2.1", "ISO 27001", "SOC TSP" ] }, "notScopes": [], "parameters": { "sqlServerAuditingMonitoringEffect": { "value": "Disabled" }, "adaptiveApplicationControlsUpdateMonitoringEffect": { "value": "Disabled" } }, "description": "This is the default set of policies monitored by Azure Security Center. It was automatically assigned as part of onboarding to Security Center. The default assignment contains only audit policies. For more information please visit https://aka.ms/ascpolicies", "displayName": "ASC Default (subscription: cc9a41f6-4e32-4f28-8326-a3c49e7036a3)", "enforcementMode": "Default", "policyDefinitionId": "/providers/Microsoft.Authorization/policySetDefinitions/1f3afdf9-d0c9-4c3d-847f-89da613e70a8", "nonComplianceMessages": [] }Therefore, the result of taking keys is always the array
[scope, metadata, notStopes, parameters, description, displayName, enforcementMode, policyDefinitionId]. It is useless for checking the condition in the rule. The correct logic is taking json keys in theparametersfield.And then, when the policy sql writes in the result table, it only saves the
idcolumn on the table. But theidis always same among the result. We cannot identify which policies are disabled. That's way, I concatedidandparamfiled with/to do that.