Skip to content

Conversation

@cx-andre-pereira
Copy link
Contributor

@cx-andre-pereira cx-andre-pereira commented Oct 23, 2025

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 :

    • 1- Without a single "enabled_log"/"log" block defined; (positive1_1)
    • 2- With a single "enabled_log" object inherently missing at least 3 of the required categories; (positive1_2)
    • 3- With multiple "enabled_log" objects missing one or more of the required categories; (positive1_3)
    • 4- With a single "log" object with "enabled" == true; (positive2_1)
    • 5- With a single "log" object with "enabled" != true; (positive2_2)
    • 6- With multiple "log" objects missing one or more of the required categories; (positive2_3)
    • 7- With multiple "log" objects missing none or some of the required categories and at least one with "enabled" != 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.

@github-actions github-actions bot added feature New feature query New query feature labels Oct 23, 2025
@github-actions
Copy link
Contributor

kics-logo

KICS version: v2.1.13

Category Results
CRITICAL CRITICAL 0
HIGH HIGH 0
MEDIUM MEDIUM 0
LOW LOW 0
INFO INFO 0
TRACE TRACE 0
TOTAL TOTAL 0
Metric Values
Files scanned placeholder 1
Files parsed placeholder 1
Files failed to scan placeholder 0
Total executed queries placeholder 47
Queries failed to execute placeholder 0
Execution time placeholder 0

@github-actions github-actions bot added terraform Terraform query azure PR related with Azure Cloud labels Oct 23, 2025
@cx-andre-pereira cx-andre-pereira marked this pull request as ready for review October 23, 2025 18:57
@cx-andre-pereira cx-andre-pereira requested a review from a team as a code owner October 23, 2025 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

azure PR related with Azure Cloud feature New feature query New query feature terraform Terraform query

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant