3 ways to configure robust firewall rules
Staff Software Engineer
If you administer firewall rules for Google Cloud VPCs, you want to ensure that the firewall rules you create can only be associated with correct VM instances by the developers in your organization. Without that assurance, it can be difficult to manage access to sensitive content hosted on VMs in your VPCs or allow these instances access to the internet, and you must carefully audit and monitor the instances to ensure that such unintentional access is not given through the use of tags. With Google VPC, there are now multiple ways to help achieve the required level of control, which we’ll describe here in detail.
As an example, imagine you want to create a firewall rule to restrict access to sensitive user billing information in a data store running on a set of VMs in your VPC. Further, you’d like to ensure that developers who can create VMs for applications other than the billing frontend cannot enable these VMs to be governed by firewall rules created to allow access to billing data.
The traditional approach here is to attach tags to VMs and create a firewall rule that allows access to specific tags, e.g., in the above example you could create a firewall rule that allows all VMs with the
billing-frontend tag to access to all VMs with the tag
billing-data. The drawback of this approach is that any developer with Compute InstanceAdmin role for the project can now attach
billing-frontend as a tag to their VM, and thus unintentionally gain access to sensitive data.
Configuring firewall rules with Service AccountsWith the general availability of firewall rules using service accounts, instead of using tags, you can block developers from enabling a firewall rule on their instances unless they have access to the appropriate centrally managed service accounts. Service accounts are special Google accounts that belong to your application or service running on a VM and can be used to authenticate the application or service for the resources it needs to access. In the above example, you can create a firewall rule to allow access to the
billing-data@service account only if the originating source service account of the traffic is
You can create this firewall rule using the following gcloud command:
If, in the above example, the billing frontend and billing data applications are autoscaled, you can specify the service accounts for the corresponding applications in the InstanceTemplate configured for creating the VMs.
The advantage of using this approach is that once you set it up, the firewall rules remain unchanged despite any changes to the underlying IAM permissions. However, you can currently only associate one service account with a VM and to change this service account, the instance must be in a stopped state.
Creating custom IAM role for InstanceAdminIf you want the flexibility of tags and the limitations of service accounts is a concern, you can create a custom role with more restricted permissions that disable the ability to set tags on VMs; do this by removing the
compute.instances.setTagpermission. This custom role can have other permissions present in the InstanceAdmin role and can then be assigned to developers in the organization. With this custom role, you can create your firewall rules using tags:
Note, however, that permissions assigned to a custom role are static in nature and must be updated with any new permissions that might be added to the InstanceAdmin role, as and when required.
Using subnetworks to partition workloads
You can also create firewall rules using source or destination IP CIDR ranges if the workloads can be partitioned into subnetworks of distinct ranges as shown in the example diagram below.
Here’s how to configure a firewall rule with source ranges using gcloud:
This method allows for better scalability with large VPCs and allows for changes in the service accounts associated with frontend VMs as long as the network topology remains unchanged. Note, however, that if a VM instance has can_ip_forward enabled, it may send traffic using the above source range and thus gain access to sensitive workloads.
As you can see, there’s a lot to consider when configuring firewall rules for your VPCs. We hope these tips help you configure firewall rules in a more secure and efficient manner. To learn more about configuring firewall rules, check out the documentation.
Note: This post was updated on September 10, 2018