Skip to content

fix(arm): read database firewall rules from child and top-level resources - #11664

Open
aneviaro wants to merge 8 commits into
aquasecurity:mainfrom
aneviaro:fix/arm-sql-firewall-rules
Open

aneviaro wants to merge 8 commits into
aquasecurity:mainfrom
aneviaro:fix/arm-sql-firewall-rules

Conversation

@aneviaro

@aneviaro aneviaro commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Description

The database adapter read only properties.firewallRules, which isn't an ARM property of the server, so AVD-AZU-0029 never fired. Firewall rules are separate resources (Microsoft.Sql/servers/firewallRules, and the MySQL, MariaDB and PostgreSQL equivalents), declared as children or at the top level.

Now each server gets its firewallRules children, nested or top-level with a <server name>/<rule name> name, through GetChildResources. The properties.firewallRules read is removed.

A top-level rule whose name or server name is an expression goes to a server with unmanaged metadata of the same kind. AZU-0029 reads only managed servers, so it stays silent for these rules until aquasecurity/trivy-checks#672 makes it read rules from all servers.

Before and after, scanning the template from #11655 (trivy config --skip-check-update .):

main:      Failures: 10
this PR:   Failures: 11
+ AZU-0029 (HIGH): Firewall rule allows public internet access to a database server.

Related issues

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

🤖 Generated with Claude Code

@aneviaro
aneviaro requested a review from nikpivkin as a code owner November 17, 2026 13:39
@aneviaro
aneviaro force-pushed the fix/arm-sql-firewall-rules branch 4 times, most recently from e6cac47 to eb18754 Compare November 18, 2026 13:31
@aneviaro

Copy link
Copy Markdown
Contributor Author

@nikpivkin could you please review this bugfix as well? 🙏

@nikpivkin

Copy link
Copy Markdown
Contributor

#11662 is merged, but this branch still has its commits, so the diff has extra changes. Please rebase onto main.

@aneviaro
aneviaro force-pushed the fix/arm-sql-firewall-rules branch from eb18754 to ac45435 Compare November 20, 2026 10:21
@aneviaro

Copy link
Copy Markdown
Contributor Author

@nikpivkin oh, yep, sorry, rebased this and #11663

@nikpivkin nikpivkin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the contribution!

Rules without a known server go to the placeholder server with unmanaged metadata. AZU-0029 reads servers through database.all_servers, which skips unmanaged servers, so these rules are not reported. In ARM the server name is usually a parameter, so this is the common case for top-level rules. Not for this PR. AZU-0029 in trivy-checks should read rules from all servers, and we will do it separately.

@aneviaro
aneviaro requested a review from nikpivkin November 25, 2026 09:35

@nikpivkin nikpivkin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The description says AZU-0029 stays silent for these rules "as it does for orphan rules in Terraform". In Terraform such rules never reach the model, because GetReferencingResources does not find them. The result is the same but the reason is different, so I'd reword this part.

}

// orphanage holds firewall rules whose server is unknown.
func orphanage(metadata iacTypes.Metadata, rules []database.FirewallRule) database.Server {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

orphanage can create the unmanaged metadata itself, as orphanage in the storage adapter does. The wrapper does not need the same metadata as Server, so MySQL and MariaDB can drop the variable.

mysqlDbServers = append(mysqlDbServers, database.MySQLServer{
	Metadata: iacTypes.NewUnmanagedMetadata(),
	Server:   orphanage(rules),
})

MSSQL and PostgreSQL then keep a local metadata only for the wrapper and its own fields.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

orphanage now creates the unmanaged metadata, and MySQL and MariaDB build the wrapper inline, in 670e8ba.

},
},
{
name: "firewall rules as child resources",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The tests have no MariaDB case. The code is shared, so one case with a nested rule is enough.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a MariaDB server with a nested rule to the child resources case in 7b94476.

@aneviaro

Copy link
Copy Markdown
Contributor Author

Reworded the description: it no longer compares with Terraform, and points to aquasecurity/trivy-checks#672.

@aneviaro
aneviaro requested a review from nikpivkin November 27, 2026 15:55

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(arm): adapter does not read database firewall rules

2 participants