Skip to content

fix(query): fixed fn for "SQL Server Database With Unrecommended Retention Days" query#7670

Merged
cx-artur-ribeiro merged 6 commits intomasterfrom
AST-40746
Aug 22, 2025
Merged

fix(query): fixed fn for "SQL Server Database With Unrecommended Retention Days" query#7670
cx-artur-ribeiro merged 6 commits intomasterfrom
AST-40746

Conversation

@cx-ricardo-jesus
Copy link
Copy Markdown
Contributor

Closes #

Reason for Proposed Changes

  • Currently, the query doesn't take into consideration the situations where the server/database does not have a defined retention period for the auditing settings (Microsoft.Sql/servers/auditingSettings.retentionInDays).

Proposed Changes

  • To add support for the resource of type Microsoft.Sql/servers/, I added to the variable called types the name of its auditingSettings child resource(Microsoft.Sql/servers/auditingSettings).
  • Also, created another variable called dbTypes which has the names of the resource types that the "father" resources have("Microsoft.Sql/servers/databases", "Microsoft.Sql/servers").
  • This query, after the changes, still has two policies, one for the cases when the retentionDays field is not defined and the other one for the cases when it's defined but with a value under 90, which should also return a vulnerable result.
  • On the first policy, using the walk function, I iterated through the resources and, if the resource has a type equal to the types of the array dbTypes (represents the father resources), it is extracted is child resources using the helper function get_children which is a modification from the function get_children from the KICS arm_lib, that serves the purpose of this query.
  • So, the helper function basically returns an array that has the path to the child resource and the child resources itself.
  • It has three cases. The first one is for the resources that have the child resources nested within, which happens sometimes in JSON format. The second one, its for samples that have the bicep format, that does not have the resources nested, that's why I added the not common_lib.valid_key(parent, "resources") and for the child resources it does not have the field dependsOn(it's a field that appears on JSON format samples). The third case is for the samples in JSON format that has the resources defined sequentially.
  • After the helper function returns the values that it should return, it's checked for each child resource, if its type is one of the types present on the dbTypes array and, if it is and the resource is enabled, it checks if the field retentionDays is not defined.
  • For the second policy, I did the same but, the last check verifies if the field retentionDays is defined to a value under 90.
  • Also, added samples for the Microsoft.Sql/servers resource type.
    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 August 21, 2025 16:12
@github-actions github-actions bot added query New query feature arm Azure Resource Manager query labels Aug 21, 2025
@github-actions
Copy link
Copy Markdown
Contributor

kics-logo

KICS version: v2.1.11

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

Copy link
Copy Markdown
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.

LGTM

@cx-artur-ribeiro cx-artur-ribeiro merged commit c0669b2 into master Aug 22, 2025
27 checks passed
@cx-artur-ribeiro cx-artur-ribeiro deleted the AST-40746 branch August 22, 2025 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arm Azure Resource Manager query query New query feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants