This page describes some common Firewall Insights tasks for reviewing and optimizing your Virtual Private Cloud (VPC) firewall usage. Perform these tasks to optimize your firewall rule configurations and tighten security boundaries.
For example, you're a network administrator or a network security engineer that supports several large Shared VPC networks with many projects and applications. You want to review and optimize a large volume of firewall rules accumulated over time to ensure that they are consistent with the expected state of your network. You can use the following tasks to review and optimize your firewall rules.
Required roles and permissions
To get the permissions that you need to use Firewall Insights, ask your administrator to grant you the following IAM roles on your project:
-
Firewall Recommender Admin role (
roles/recommender.firewallAdmin
) -
Firewall Recommender Viewer role (
roles/recommender.firewallViewer
)
For more information about granting roles, see Manage access to projects, folders, and organizations.
These predefined roles contain the permissions required to use Firewall Insights. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
The following permissions are required to use Firewall Insights:
-
recommender.computeFirewallInsights.list
-
recommender.computeFirewallInsights.update
You might also be able to get these permissions with custom roles or other predefined roles.
View rules applied to a VM in the last 30 days
To review rules that help you avoid misconfigurations and unnecessary shadowed rules, do the following:
Console
In the Google Cloud console, go to the Compute Engine VM instances page.
In the
Filter field, filter the instances by entering one of the following key-value pairs to find relevant VMs.Network tags:TAG_NAME
Replace
TAG_NAME
with a tag assigned to a VPC network.Internal IP:INTERNAL_IP_ADDRESS
Replace
INTERNAL_IP_ADDRESS
with an internal IP address for a VM interface.External IP:EXTERNAL_IP_ADDRESS
Replace
EXTERNAL_IP_ADDRESS
with an external IP address for a VM interface.In the search results for a VM interface, select a VM and click the
more actions menu.On the menu, select View network details.
On the Network interface details page, complete the following steps:
- In the Firewall and routes details section, click Firewalls and then Filter.
Enter
last hit after:YYYY-MM-DD
to filter the firewall rules. This filter expression finds firewall rules with recent hits.For a firewall rule, click the number in the Hit count column to open the firewall log and review traffic details, as in the following example query. To enter a query, click Submit filter.
jsonPayload.rule_details.reference:("network:network1/firewall:allow-tcp") AND jsonPayload.instance.project_id:("p6ntest-firewall-intelligence") AND jsonPayload.instance.zone:("us-central1-c") AND jsonPayload.instance.vm_name:("instance2")
Add one or more additional Cloud Logging filters to further filter the firewall log detail. For example, the following example query adds an additional filter that filters by source IP address (
src_ip
). To enter a query, click Submit filter.jsonPayload.rule_details.reference:("network:network1/firewall:allow-tcp") AND jsonPayload.instance.project_id:("p6ntest-firewall-intelligence") AND jsonPayload.instance.zone:("us-central1-c") AND jsonPayload.instance.vm_name:("instance2") AND jsonPayload.connection.src_ip:("10.0.1.2")
Detect sudden increases in the hit count for deny
firewall rules
You can configure Cloud Monitoring to detect changes
in the hit count of your VPC deny
firewall rules.
For example, you can choose to be alerted when the hit count of a particular
rule increases by a certain percentage. Setting this alert
helps you detect possible attacks on your Google Cloud
resources.
To set an alert, do the following:
Console
In the Google Cloud console, go to the Monitoring page.
In the navigation pane, click
Alerting and then Create policy.On the Create alerting policy page, click
Add alert condition. A new condition is added.Expand the New condition section and select Configure trigger. The Configure alert trigger page opens.
Configure the alert conditions. For example, use the following values to trigger an alert when the hit count for the rule that you identified increases by 10% for six hours:
- Condition types: Set to
Threshold
. - Alert trigger: Set to
Any time series violates
. - Threshold position: Set to
Above threshold
. - Threshold value: Set to
10
.
- Condition types: Set to
In the Advanced options section, enter a name for the condition and click Next.
On the Multi-condition trigger page, specify the condition and click Next.
On the Configure notifications page, select Notification channels and then Manage notification channels.
In the Notification channels window, add the new notification channel—for example, an email address, and click Save.
In the Notification channels list, select the added notifications and then click OK.
In the Name the alert policy section, enter the name and click Next. The alert condition is added.
Clean up shadowed firewall rules
To clean up firewall rules that are shadowed by other rules, do the following:
Console
In the Google Cloud console, go to the Firewall policies page.
In the VPC firewall rules section, click > Shadowed rules.
Filter and then select Insight typeFor each rule in the search results, click the Name of the rule and view its details page. Review and clean up each rule as needed.
For more information about shadowed rules, see Examples of shadowed rules.
Remove an unused allow
rule
To evaluate and remove an unused allow
rule, do the following:
Console
In the Google Cloud console, go to the Firewall policies page.
In the VPC firewall rules section, click > Ingress > last hit before MM/DD/YYYY.
Filter, and then select TypeReplace
MM/DD/YYYY
with the date that you want to use. For example,08/31/2021
.For each rule in the search results, review the information in the Insights column. This column provides a percentage that indicates the likelihood that this rule will be hit in the future. If the percentage is high, you might want to keep this rule. However, if it is low, continue reviewing the information generated by the insight.
Click the insight link to display the Insight details pane.
In the Insight details pane, review the attributes of this rule and the attributes of any similar rules that are listed.
If the rule has a low probability of being hit in the future, and if that prediction is supported by the hit pattern of similar rules, consider removing the rule. To remove the rule, click Rule name. The Firewall rule details page opens.
Click Delete.
In the confirmation dialog, click Delete.
Remove an unused attribute from an allow
rule
To evaluate and remove an unused attribute, do the following:
Console
In the Google Cloud console, go to the Firewall Insights page.
On the card named Allow rules with unused attributes, click View full list. In response, the Google Cloud console displays the Allow rules with unused attributes page. This page lists all the rules that had unused attributes during the observation period.
Click the text that's displayed in the Insight column. The Insight Details page opens.
Review the details at the top of the page. The summary includes the following details:
- The name of the insight.
- The number of unused attributes that this rule has.
- The time that the insight was last updated.
- The names of other rules in the project that use similar attributes.
- The length of the observation period.
Assess whether you could remove the attribute:
- Review the Firewall rule with unhit attributes card. Look at the field labeled Attribute with no hit (with future hit prediction). This field provides a percentage that describes the likelihood of whether the attribute will be hit in the future.
- Review the Similar firewall rule in the same project card. Review the data displayed about whether this rule's attribute was used.
If the attribute has a low probability of being hit in the future, and if that prediction is supported by the hit pattern of similar rules, consider removing the attribute from the rule. To remove the attribute, click the name of the rule, which appears at the top of the Insight Detail page. The Firewall rule details page opens.
Click Edit, make the needed changes, and then click Save.
Narrow an allow
rule's IP address range
Be aware that your project might have firewall rules that allow access from certain IP address blocks for load balancer health checks or for other Google Cloud functionality. These IP addresses might not be hit, but they should not be removed from your firewall rules. For more information about these ranges, see the Compute Engine documentation.
To evaluate and tighten an overly permissive IP address range, do the following:
Console
In the Google Cloud console, go to the Firewall Insights page.
On the card named Allow rules with overly permissive IP address or port ranges, click View full list. In response, the Google Cloud console displays a list of all the rules that had overly permissive ranges during the observation period.
Find any rule in the list, and click the text that's displayed in the Insight column. The Insight Details page opens.
Review the details at the top of the page. The summary includes the following details:
- The name of the rule.
- The number of IP address ranges that could be narrowed.
- The time that the insight was last updated.
- The length of the observation period.
Assess whether you could narrow the IP address range: Review the Firewall rule with overly permissive IP address or port ranges card. Review the proposed list of new IP address ranges.
If appropriate, consider using the recommendations in the insight to make the IP address range more narrow. Click the name of the rule, which appears at the top of the Insight Detail page. The Firewall rule details page opens.
Click Edit, make the needed changes, and then click Save.