feat(query): implements "Beta - Diagnostic Settings Without Appropriate Logging" #7794
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.








Reason for Proposed Changes
Currently there is no query to ensure that a given "azurerm_monitor_diagnostic_setting" resource enables logging for the 4 main categories: 'Administrative', 'Alert', 'Policy', and 'Security'.
Quoting CIS_Microsoft_Azure_Foundations_Benchmark_v5.0.0 page 199: "
The diagnostic setting should be configured to log the appropriate activities from the control/management plane.and "Ensure the categories 'Administrative', 'Alert', 'Policy', and 'Security' set to: 'enabled: true'Proposed Changes
Implemented the missing query.
The query was implemented with support of legacy "log" blocks in mind, alongside from the newer "enabled_log" blocks.
As for the query implementation itself, the query can flag for 7 different scenarios, given a "azurerm_monitor_diagnostic_setting" resource :
true; (positive2_1)true; (positive2_2)true; (positive2_4)Having multiple vs a single object are considered different scenarios mostly because the payload generated will differ, merging objects into an array if there are 2 or more.
For scenario 4 vs 5 and 6 vs 7 the main difference in the results will be the fact that the "IssueType" will change from "MissingAttribute" on 4/6 to "IncorrectValue" on 5/7. Given that the "enabled" field is set to a value that is not "true" in scenarios 5 and 7, effectively being an explicit disabling of a main category rather than the implicit disabling when lacking a relevant "log" field, I prioritized the "IncorrectValue" issue type for those scenarios.
This way a scenario like 7 (positive2_4) will properly flag the issue as an "IncorrectValue" and not a "MissingAttribute", since all attributes are present and the issue is that the log for "Administrative" has the "enabled" field set to "false".
I submit this contribution under the Apache-2.0 license.