Skip to content

Conversation

@cx-ricardo-jesus
Copy link
Contributor

@cx-ricardo-jesus cx-ricardo-jesus commented Oct 21, 2025

Reason for Proposed Changes

  • Currently, there is no query for Terraform/Azure that checks if the purge protection is enabled for an Azure Key Vault.
  • Quoting CIS_Microsoft_Azure_Foundations_Benchmark_v5.0.0: "`Key vaults contain object keys, secrets, and certificates. Deletion of a key vault can cause immediate data loss or loss of security functions (authentication, validation, verification, non-repudiation, etc.) supported by the key vault objects. It is recommended that the key vault be made recoverable by enabling the "purge protection" function.
  • Currently, when running the remediate KICS command, an error occurs due to the variable ActualRemediationDoneNumber not being incremented for Beta queries(with the flag experimental set to true).

Proposed Changes

  • Implemented the query that returns a positive result when the field purge_protection_enabled is not defined or not set to true.
  • Regarding the metadata information, I took inspiration from a similar query implemented for the AzureResourceManager platform, which covers an analogous resource for AzureResourceManager, and also checks for the soft delete part.
  • Taking into account the information stated on the previous point, I think the most appropriate CWE is 530 and set the severity to High, taking into account that the similar query mentioned above, also has a HIGH severity.
  • Regarding the remediation fix, basically, changed the Query struct on the remediation.go, to also store a boolean variable called experimental, which is extracted from the results file.
  • Also, added the boolean Experimental variable on the Remediation structure.
  • Basically, now, the remediationSet, which stores a set of Remediation structs, will also store the Experimental bool, which will be true or false, taking into account the value present on the experimental field on the results file.
  • After these changes, the Beta queries will be capable of running the remediations, but, as expected, will not present any result.

I submit this contribution under the Apache-2.0 license.

@cx-ricardo-jesus cx-ricardo-jesus requested a review from a team as a code owner October 21, 2025 11:26
@github-actions github-actions bot added feature New feature query New query feature terraform Terraform query azure PR related with Azure Cloud labels Oct 21, 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

@cx-ricardo-jesus cx-ricardo-jesus marked this pull request as draft October 21, 2025 11:39
@cx-ricardo-jesus cx-ricardo-jesus marked this pull request as ready for review October 21, 2025 11:57
@cx-ricardo-jesus cx-ricardo-jesus changed the title feat(query): implemented query Beta - Key Vault Purge Protection Is Enabled for terraform/azure feat(query): implemented query Beta - Key Vault Purge Protection Is Enabled for terraform/azure and fixed remediation problems Oct 28, 2025
Copy link
Contributor

@cx-artur-ribeiro cx-artur-ribeiro left a comment

Choose a reason for hiding this comment

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

Insane job fixing the remediation for experimental queries!
The new query also looks well done, nothing to point out.

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.

2 participants