Skip to content

fix(azure): keyvault_logging_enabled false-fails on explicit AuditEvent category#11657

Open
m-khan-97 wants to merge 2 commits into
prowler-cloud:masterfrom
m-khan-97:fix/azure-keyvault-logging-auditevent-category
Open

fix(azure): keyvault_logging_enabled false-fails on explicit AuditEvent category#11657
m-khan-97 wants to merge 2 commits into
prowler-cloud:masterfrom
m-khan-97:fix/azure-keyvault-logging-auditevent-category

Conversation

@m-khan-97

@m-khan-97 m-khan-97 commented Jun 21, 2026

Copy link
Copy Markdown

Context

Fixes #11656.

keyvault_logging_enabled only recognized Key Vault audit logging when the diagnostic setting log used the audit category group. Azure can also represent the same audit logging via an explicit log category named AuditEvent with a null category group, which the check did not account for, producing a false FAIL.

Description

In prowler/providers/azure/services/keyvault/keyvault_logging_enabled/keyvault_logging_enabled.py, the has_audit condition now also accepts log.category == "AuditEvent" (in addition to the existing log.category_group == "audit"), both gated on log.enabled. The allLogs category-group condition is unchanged.

Added test_diagnostic_setting_with_explicit_auditevent_category to tests/providers/azure/services/keyvault/keyvault_logging_enabled/keyvault_logging_enabled_test.py, mirroring the existing test style, covering a diagnostic setting with category="AuditEvent"/category_group=None plus category_group="allLogs" and asserting PASS.

Added a CHANGELOG.md entry under ### 🐞 Fixed.

Steps to review

  • uv run pytest -q tests/providers/azure/services/keyvault/keyvault_logging_enabled/ — all 7 tests pass, including the new regression test.
  • uv run pytest -q tests/providers/azure/services/keyvault/ — full keyvault service suite (52 tests) still passes.

Checklist

SDK/CLI

  • Are there new checks included in this PR? No — this is a bug fix to an existing check's logic, no permission changes needed.

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed the Azure Key Vault audit logging check to correctly recognize audit logging when diagnostic settings use an explicitly configured AuditEvent log category, preventing false-negative results.
  • Tests

    • Added unit test coverage for diagnostic configurations that enable audit logging via an explicit AuditEvent category.

@m-khan-97 m-khan-97 requested a review from a team as a code owner June 21, 2026 14:50
@github-actions github-actions Bot added the provider/azure Issues/PRs related with the Azure provider label Jun 21, 2026
@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 400759aa-8c0b-44bc-8e3b-57c4867192ba

📥 Commits

Reviewing files that changed from the base of the PR and between 7260440 and 4442778.

📒 Files selected for processing (1)
  • prowler/CHANGELOG.md

📝 Walkthrough

Walkthrough

The Azure keyvault_logging_enabled check now treats AuditEvent diagnostic logs as compliant when enabled. The PR also adds unit coverage for that case and records the fix in the changelog.

Changes

keyvault_logging_enabled AuditEvent fix

Layer / File(s) Summary
Audit-log condition fix and AuditEvent test coverage
prowler/providers/azure/services/keyvault/keyvault_logging_enabled/keyvault_logging_enabled.py, tests/providers/azure/services/keyvault/keyvault_logging_enabled/keyvault_logging_enabled_test.py, prowler/CHANGELOG.md
execute now accepts enabled logs with category_group == "audit" or category == "AuditEvent". A new test asserts PASS for an AuditEvent diagnostic setting, and the changelog notes the fix.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested reviewers

  • danibarranqueroo
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main fix for the Azure Key Vault audit logging false failure.
Description check ✅ Passed The PR description includes context, fix summary, review steps, and checklist items, matching the template well.
Linked Issues check ✅ Passed The code and test address #11656 by treating explicit AuditEvent logging as compliant while preserving existing audit handling.
Out of Scope Changes check ✅ Passed The changes stay focused on the Key Vault logging bug fix, its regression test, and the changelog note.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the community Opened by the Community label Jun 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Conflict Markers Resolved

All conflict markers have been successfully resolved in this pull request.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@tests/providers/azure/services/keyvault/keyvault_logging_enabled/keyvault_logging_enabled_test.py`:
- Around line 247-321: Add a new negative test case method to validate the FAIL
scenario for the new AuditEvent path. Create a test similar to
test_diagnostic_setting_with_explicit_auditevent_category but configure the
diagnostic setting so that category="AuditEvent" is enabled=False while
category_group="allLogs" is also not enabled or enabled=False. This test should
verify that the check returns a FAIL status and confirm that the new OR
condition in the keyvault_logging_enabled check logic properly handles the case
where neither audit logging mechanism is properly enabled.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 41668a11-c4f9-4d0d-9da8-81a69559e9cc

📥 Commits

Reviewing files that changed from the base of the PR and between a7917f7 and 7260440.

📒 Files selected for processing (3)
  • prowler/CHANGELOG.md
  • prowler/providers/azure/services/keyvault/keyvault_logging_enabled/keyvault_logging_enabled.py
  • tests/providers/azure/services/keyvault/keyvault_logging_enabled/keyvault_logging_enabled_test.py

Comment on lines +247 to +321
def test_diagnostic_setting_with_explicit_auditevent_category(self):
keyvault_client = mock.MagicMock
keyvault_client.subscriptions = {AZURE_SUBSCRIPTION_ID: AZURE_SUBSCRIPTION_NAME}

with (
mock.patch(
"prowler.providers.common.provider.Provider.get_global_provider",
return_value=set_mocked_azure_provider(),
),
mock.patch(
"prowler.providers.azure.services.monitor.monitor_service.Monitor",
new=mock.MagicMock(),
),
mock.patch(
"prowler.providers.azure.services.keyvault.keyvault_logging_enabled.keyvault_logging_enabled.keyvault_client",
new=keyvault_client,
),
):
from prowler.providers.azure.services.keyvault.keyvault_logging_enabled.keyvault_logging_enabled import (
keyvault_logging_enabled,
)
from prowler.providers.azure.services.keyvault.keyvault_service import (
KeyVaultInfo,
)
from prowler.providers.azure.services.monitor.monitor_service import (
DiagnosticSetting,
)

keyvault_client.key_vaults = {
AZURE_SUBSCRIPTION_ID: [
KeyVaultInfo(
id="id",
name="name_keyvault",
location="westeurope",
resource_group="resource_group",
properties=VaultProperties(
tenant_id="tenantid",
sku="sku",
enable_rbac_authorization=False,
),
keys=[],
secrets=[],
monitor_diagnostic_settings=[
DiagnosticSetting(
id="id/ds1",
logs=[
mock.MagicMock(
category_group=None,
category="AuditEvent",
enabled=True,
),
mock.MagicMock(
category_group="allLogs",
category=None,
enabled=True,
),
],
storage_account_name="sa1",
storage_account_id="sa_id1",
name="ds_compliant",
),
],
),
]
}
check = keyvault_logging_enabled()
result = check.execute()
assert len(result) == 1
assert result[0].status == "PASS"
assert (
result[0].status_extended
== f"Key Vault name_keyvault in subscription {AZURE_SUBSCRIPTION_DISPLAY} has a diagnostic setting with audit logging."
)
assert result[0].resource_name == "name_keyvault"
assert result[0].resource_id == "id"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial | 💤 Low value

Consider adding a negative test case for the new AuditEvent path.

The new test validates the PASS scenario when category="AuditEvent" is enabled alongside allLogs. For comprehensive coverage of the new OR condition, consider adding a FAIL test case where category="AuditEvent" is enabled but category_group="allLogs" is disabled. This would explicitly verify that the new condition doesn't inadvertently pass when it shouldn't.

Note: The existing test_diagnostic_setting_without_audit_logging already covers this pattern with category_group="audit", so this is an optional enhancement rather than a critical gap.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@tests/providers/azure/services/keyvault/keyvault_logging_enabled/keyvault_logging_enabled_test.py`
around lines 247 - 321, Add a new negative test case method to validate the FAIL
scenario for the new AuditEvent path. Create a test similar to
test_diagnostic_setting_with_explicit_auditevent_category but configure the
diagnostic setting so that category="AuditEvent" is enabled=False while
category_group="allLogs" is also not enabled or enabled=False. This test should
verify that the check returns a FAIL status and confirm that the new OR
condition in the keyvault_logging_enabled check logic properly handles the case
where neither audit logging mechanism is properly enabled.

…nt category

Azure diagnostic settings can represent Key Vault audit logging either
via the "audit" category group, or via an explicit log category named
"AuditEvent" with a null category group. The check only recognized the
former, causing false FAIL results for vaults that have audit logging
enabled through the explicit category.
@m-khan-97 m-khan-97 force-pushed the fix/azure-keyvault-logging-auditevent-category branch from 7260440 to 4442778 Compare June 25, 2026 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Opened by the Community provider/azure Issues/PRs related with the Azure provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Azure keyvault_logging_enabled false-fails with AuditEvent diagnostic category

1 participant