Repository navigation
fix(arm): read database firewall rules from child and top-level resources #11664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
9bb9757
73d9176
aac527c
ac45435
8f6c907
f9b673f
670e8ba
7b94476
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,17 +3,42 @@ package database | |
| import ( | ||
| "github.com/aquasecurity/trivy/pkg/iac/providers/azure/database" | ||
| "github.com/aquasecurity/trivy/pkg/iac/scanners/azure" | ||
| iacTypes "github.com/aquasecurity/trivy/pkg/iac/types" | ||
| ) | ||
|
|
||
| // TODO: This is the "Microsoft.Sql/servers/firewallRules" resource | ||
| const firewallRuleType = "firewallRules" | ||
|
|
||
| // adaptFirewallRules collects the firewall rules of a database server from its | ||
| // firewallRules child resources, e.g. "Microsoft.Sql/servers/firewallRules". | ||
| // https://learn.microsoft.com/en-us/azure/templates/microsoft.sql/servers/firewallrules?pivots=deployment-language-arm-template | ||
| func addFirewallRule(resource azure.Resource) []database.FirewallRule { | ||
| func adaptFirewallRules(server azure.Resource, deployment azure.Deployment) []database.FirewallRule { | ||
| return adaptFirewallRuleResources(deployment.GetChildResources(server, firewallRuleType)) | ||
| } | ||
|
|
||
| // orphanFirewallRules returns the top-level firewall rules of serverType whose | ||
| // server is unknown. | ||
| func orphanFirewallRules(deployment azure.Deployment, serverType string) []database.FirewallRule { | ||
| return adaptFirewallRuleResources(deployment.GetOrphanResources(serverType, firewallRuleType)) | ||
| } | ||
|
|
||
| // orphanage holds firewall rules whose server is unknown. | ||
| func orphanage(metadata iacTypes.Metadata, rules []database.FirewallRule) database.Server { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
mysqlDbServers = append(mysqlDbServers, database.MySQLServer{
Metadata: iacTypes.NewUnmanagedMetadata(),
Server: orphanage(rules),
})MSSQL and PostgreSQL then keep a local
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return database.Server{ | ||
| Metadata: metadata, | ||
| EnableSSLEnforcement: iacTypes.BoolDefault(false, metadata), | ||
| MinimumTLSVersion: iacTypes.StringDefault("", metadata), | ||
| EnablePublicNetworkAccess: iacTypes.BoolDefault(false, metadata), | ||
| FirewallRules: rules, | ||
| } | ||
| } | ||
|
|
||
| func adaptFirewallRuleResources(resources []azure.Resource) []database.FirewallRule { | ||
| var rules []database.FirewallRule | ||
| for _, rule := range resource.Properties.GetMapValue("firewallRules").AsMap() { | ||
| for _, resource := range resources { | ||
| rules = append(rules, database.FirewallRule{ | ||
| Metadata: rule.GetMetadata(), | ||
| StartIP: rule.GetMapValue("startIpAddress").AsStringValue("", rule.GetMetadata()), | ||
| EndIP: rule.GetMapValue("endIpAddress").AsStringValue("", rule.GetMetadata()), | ||
| Metadata: resource.Metadata, | ||
| StartIP: resource.Properties.GetMapValue("startIpAddress").AsStringValue("", resource.Metadata), | ||
| EndIP: resource.Properties.GetMapValue("endIpAddress").AsStringValue("", resource.Metadata), | ||
| }) | ||
| } | ||
| return rules | ||
|
|
||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.