Skip to content

Conversation

@cx-andre-pereira
Copy link
Contributor

@cx-andre-pereira cx-andre-pereira commented Nov 26, 2025

Reason for Proposed Changes

  • Currently there is no query to ensure that resources of type "azurerm_kubernetes_cluster" has proper audit logging enabled.

  • Quoting CIS_Azure_Kubernetes_Service_(AKS)_Benchmark_V1.8.0 page 17: "2.1.1 Enable audit Logs (Manual) ... Exporting logs and metrics to a dedicated, persistent datastore ensures availability of audit data following a cluster security event, and provides a central location for analysis of log and metric data collated from multiple sources.".

Proposed Changes

  • Implemented the missing query.

  • To ensure audit logging is enabled the cluster must be associated with a "azurerm_monitor_diagnostic_setting" resource that includes either the "kube-audit" and/or "kube-audit-admin" categories.

  • The association is set through the target_resource_id, the log categories included must be set with the "enabled_log" blocks. Support for legacy "log" blocks was also included. The enabled_log/log blocks should include the audit category in their "category" field.

  • In the case of a "azurerm_kubernetes_cluster" being associated with a "azurerm_monitor_diagnostic_setting" where the legacy "log" blocks are used with the right category/ies but set "enabled" to false the query will point to the lines where enabled is set and point out it should be set to true to fix the issue.

  • NOTE this is my own interpretation given the CIS Benchmark and the entry's name. In truth the "Remediation" from the Benchmark is not particularly explicit/restrictive with which particular categories must be included. All there is to go off is the following remediation step (6) : In the list of available logs, select the logs you wish to enable. For this example, enable the kube-audit and kube-audit-admin logs. Common logs include the kube-apiserver, kube-controller-manager, and kube-scheduler. You can return and change the collected logs once Log Analytics workspaces are enabled.; additionally it is suggested that not every single cluster must have these logs enabled but it seems like a manual decision that has to be done based on real world use context and cannot be done through static analysis.

  • The official documentation puts extra emphasis on thekube-apiserver, kube-audit and kube-audit-admin categories over the kube-controller-manager and kube-scheduler. It could be argued if the kube-apiserver flag being included should be enough to prevent the query from flagging.

I submit this contribution under the Apache-2.0 license.

@github-actions github-actions bot added feature New feature query New query feature labels Nov 26, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 26, 2025

kics-logo

KICS version: v2.1.17

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 kubernetes Kubernetes query labels Nov 26, 2025
@cx-andre-pereira cx-andre-pereira marked this pull request as ready for review November 26, 2025 12:28
@cx-andre-pereira cx-andre-pereira requested a review from a team as a code owner November 26, 2025 12:28
Copy link
Contributor

@cx-eduardo-semanas cx-eduardo-semanas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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 kubernetes Kubernetes query query New query feature terraform Terraform query

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants