Hierarchical firewall policy examples (original) (raw)

This page shows examples of hierarchical firewall policies. These examples help you understand how hierarchical firewall policies work and how to use them to provide consistent security across your Google Cloud resource hierarchy. To understand these examples, familiarize yourself withhierarchical firewall policies concepts.

Example 1: Allow a prober to access all VMs

This example describes how to set up a firewall rule at the organization level and allow a prober to access all virtual machines (VMs). A prober is a special program that automatically checks your VMs to determine their contents or configuration.

Scenario

You're a security administrator who needs to ensure your security scanning tool can connect to all your VM instances. The tool sends probes from IP address 10.100.0.1 to destination port 123. You need to ensure that no network or security administrator accidentally blocks this connection at any level within your organization.

The following diagram shows the configuration for this scenario:

Firewall policy to allow probes on all VMs

Firewall policy to allow probes on all VMs

How the policy applies to VMs

After evaluating all rules, the firewall policy applies to your VMs as follows:

Ingress connections

Egress connections

How to configure

To create a policy rule and associate it with an organization, do the following:

  1. Create a firewall policy to contain the rule:
    gcloud compute firewall-policies create \
    --organization ORG_ID \
    --short-name SHORT_NAME \
    --description DESCRIPTION
  2. Add the rule to the firewall policy:
    gcloud compute firewall-policies rules create 1000 \
    --action=allow \
    --description DESCRIPTION \
    --layer4-configs=tcp:123 \
    --firewall-policy SHORT_NAME \
    --organization ORG_ID \
    --src-ip-ranges=10.100.0.1/32
  3. Associate the firewall policy with the organization:
    gcloud compute firewall-policies associations create \
    --firewall-policy SHORT_NAME\
    --organization ORG_ID
    Replace the following:
    • ORG_ID: your organization's ID
      Specify an organization ID to create a policy whose parent is an organization. The policy can be associated with the organization or a folder within the organization.
    • SHORT_NAME: a name for the policy
      A policy created by using the Google Cloud CLI has two names: a system-generated name and a short name provided by you. When using the gcloud CLI to update an existing policy, you can provide either the system-generated name or the short name and the organization ID. When using the API to update the policy, you must provide the system-generated name.
    • DESCRIPTION: description of the firewall policy

Example 2: Deny all external connections except to certain ports

This example describes how to set up policies to deny ingress connections from a specific ports.

Scenario

You're a security administrator who wants to block all incoming internet traffic to secure your organization, except for specific services, such as web traffic (ports 80 and 443) and SSH access (port 22). You must block all incoming internet traffic on ports other than80, 443, or 22, regardless of existing VPC network rules. For connections on those allowed ports, you delegate to the VPC security administrator the ability to decide what happens in their specific VPC network.

The following diagram shows the configuration for this scenario:

Deny all external connections except certain destination ports

Deny all external connections except certain destination ports

How the policy applies to VMs

After evaluating the rules across the hierarchy, the VM firewall policy applies as follows:

Ingress connections

Egress connections

How to configure

To create a policy rule and allow external TCP 80 or 443 connections, do the following:

  1. Create a firewall policy to contain the rule:
    gcloud compute firewall-policies create \
    --organization ORG_ID \
    --short-name SHORT_NAME \
    --description DESCRIPTION
  2. Add a rule to delegate internal connections to the project owner:
    gcloud compute firewall-policies rules create 1000 \
    --action=goto_next \
    --description DESCRIPTION \
    --organization ORG_ID \
    --firewall-policy SHORT_NAME \
    --src-ip-ranges=10.0.0.0/8
  3. Add a rule to delegate external connections rules to ports 80or 443or 22 to the project owner:
    gcloud compute firewall-policies rules create 2000 \
    --action=goto_next \
    --description DESCRIPTION \
    --src-ip-ranges=0.0.0.0/0 \
    --layer4-configs=tcp:80,tcp:443,tcp:22 \
    --organization ORG_ID \
    --firewall-policy SHORT_NAME
  4. Add a rule to deny all other external connections:
    gcloud compute firewall-policies rules create 3000 \
    --action=deny \
    --description DESCRIPTION \
    --organization ORG_ID \
    --firewall-policy SHORT_NAME \
    --src-ip-ranges=0.0.0.0/0
  5. Associate the firewall policy with the organization:
    gcloud compute firewall-policies associations create \
    --organization ORG_ID \
    --firewall-policy SHORT_NAME
  6. In the project, add a firewall rule to allow internal connections from the designated subnet:
    gcloud compute firewall-rules create allow-internal-traffic \
    --action=allow \
    --priority=1000 \
    --source-ranges=10.2.0.0/16
  7. In the project, add a firewall rule to allow external TCP 80 or 443connections:
    gcloud compute firewall-rules create allow-external-traffic \
    --action=allow \
    --priority=2000 \
    --rules=tcp:80,tcp:443
    Replace the following:
    • ORG_ID: your organization's ID
      Specify an organization ID to create a policy whose parent is an organization. The policy can be associated with the organization or a folder within the organization.
    • SHORT_NAME: a name for the policy
      A policy created by using the Google Cloud CLI has two names: a system-generated name and a short name provided by you. When using the gcloud CLI to update an existing policy, you can provide either the system-generated name or the short name and the organization ID. When using the API to update the policy, you must provide the system-generated name.
    • DESCRIPTION: description of the firewall policy

Example 3: Deny egress connections except from a specific VPC network

This example describes how to set up policies to deny egress connections from specific VPC network.

Scenario

Your organization handles sensitive data and needs to restrict information leaving its network. By default, your organization prevents all VM instances from sending data to the internet. However, a project in the myvpcVPC network needs to communicate securely with a trusted partner's server at 203.0.113.1. To support this, you must implement the following:

The organization security administrator achieves this by blocking egress connections in all other VPC networks, except for connections originating in myvpc. The administrator specifically delegates the allowance of egress to public server 203.0.113.1 to the myvpc security administrator.

The following diagram shows the configuration for this scenario:

Deny egress connections except from a specific network

Deny egress connections except from a specific network

How the policy applies to VMs

After evaluating the rules across the hierarchy, the VM firewall policy applies as follows:

Ingress connections

Egress connections

How to configure

To create a policy rule and delegate certain egress connections to them, do the following:

  1. Create a firewall policy to contain the rule:
    gcloud compute firewall-policies create \
    --organization ORG_ID \
    --short-name SHORT_NAME \
    --description DESCRIPTION
  2. Add a rule to delegate certain egress connections:
    gcloud compute firewall-policies rules create 1000 \
    --action=goto_next \
    --description DESCRIPTION \
    --dest-ip-ranges=203.0.113.1/32
    --direction=egress
    --organization ORG_ID \
    --short-name SHORT_NAME \
    --target-resources=projects/PROJECT_ID/networks/myvpc
  3. Add a rule to deny all other egress connections:
    gcloud compute firewall-policies rules create 2000 \
    --action=deny \
    --description DESCRIPTION \
    --direction=egress \
    --dest-ip-ranges=0.0.0.0/0 \
    --organization ORG_ID \
    --short-name SHORT_NAME
  4. Associate the firewall policy with the organization:
    gcloud compute firewall-policies associations create \
    --organization ORG_ID \
    --short-name SHORT_NAME

Replace the following:

Specify an organization ID to create a policy whose parent is an  
organization. The policy can be associated with the organization or  
a folder within the organization.  
A policy created by using the Google Cloud CLI has two  
names: a system-generated name and a short name provided by you. When  
using the gcloud CLI to update an existing policy, you can  
provide either the system-generated name or the short name and the  
organization ID. When using the API to update the policy, you must  
provide the system-generated name.  

Example 4: Configure organization-wide and folder-specific rules

This example describes how to block ingress connections to all VMs in an organization, except for connections from an IP range.

Scenario

Your organization includes multiple folders, such as Folder1 and Folder2. The organization security team configures an organization-level policy to allow ingress traffic exclusively from the 203.0.113.0/24 IP range across all folders.

After the traffic enters the network, different folders have different needs:

In this example, a security administrator blocks ingress connections to any VMs in the organization except those from the allowed IP range 203.0.113.0/24. The administrator delegates further decisions regarding connections from203.0.113.0/24 to security administrators at the folder levels.

The following diagram shows the configuration for this scenario:

Organization-wide and folder-specific rules

Organization-wide and folder-specific rules

How the policy applies to VMs

After evaluating the rules across the hierarchy, the VM firewall policy applies as follows:

For VMs in VPC network my-vpc

For VMs in VPC network vpc2

How to configure

To configure organization-wide and folder-specific rules, do the following:

  1. Create a firewall policy for Org_A:
    gcloud compute firewall-policies create \
    --organization ORG_ID \
    --short-name SHORT_NAME \
    --description DESCRIPTION
  2. Add a rule to delegate ingress from 203.0.113.0/24 to the project owner:
    gcloud compute firewall-policies rules create 1000 \
    --action=goto_next \
    --description DESCRIPTION \
    --organization ORG_ID \
    --short-name SHORT_NAME \
    --src-ip-ranges=203.0.113.0/24
  3. Add a rule to deny all other external connections:
    gcloud compute firewall-policies rules create 2000 \
    --action=deny \
    --description DESCRIPTION \
    --organization ORG_ID \
    --short-name SHORT_NAME \
    --src-ip-ranges=0.0.0.0/0
  4. Associate the firewall policy with the organization:
    gcloud compute firewall-policies associations create \
    --organization ORG_ID \
    --short-name SHORT_NAME
  5. Create a firewall policy to contain the rules for Folder1:
    gcloud compute firewall-policies create \
    --organization ORG_ID \
    --short-name SHORT_NAME \
    --description DESCRIPTION
  6. Add a rule to allow all HTTP(S) ingress:
    gcloud compute firewall-policies rules create 1000 \
    --action=allow \
    --description DESCRIPTION \
    --layer4-configs=tcp:80,tcp:443 \
    --organization ORG_ID \
    --short-name SHORT_NAME
  7. Add a rule to deny ingress on all other ports or protocols:
    gcloud compute firewall-policies rules create 2000 \
    --action=deny \
    --description DESCRIPTION \
    --organization ORG_ID \
    --short-name SHORT_NAME \
    --src-ip-ranges=0.0.0.0/0
  8. Associate the firewall policy with Folder1:
    gcloud compute firewall-policies associations create \
    --organization ORG_ID \
    --short-name SHORT_NAME \
    --folder FOLDER_ID
  9. Create a firewall policy to contain the rules for Folder2:
    gcloud compute firewall-policies create \
    --organization ORG_ID \
    --short-name SHORT_NAME \
    --description DESCRIPTION
  10. Add a rule to allow ingress from 203.0.113.1:
    gcloud compute firewall-policies rules create 1000 \
    --action=allow \
    --description DESCRIPTION \
    --organization ORG_ID \
    --short-name SHORT_NAME \
    --src-ip-ranges=203.0.113.1/32
  11. Associate the firewall policy with Folder2:
    gcloud compute firewall-policies associations create \
    --organization ORG_ID \
    --short-name SHORT_NAME \
    --folder FOLDER_ID
  12. Add a firewall rule to allow HTTP(S) connection ingress:
    gcloud compute firewall-rules create allow-internal-traffic \
    --network=vpc2 \
    --action=allow \
    --rules=tcp:80,tcp:443,tcp:22

Replace the following:

Specify an organization ID to create a policy whose parent is an  
organization. The policy can be associated with the organization or  
a folder within the organization.  
A policy created by using the Google Cloud CLI has two  
names: a system-generated name and a short name provided by you. When  
using the gcloud CLI to update an existing policy, you can  
provide either the system-generated name or the short name and the  
organization ID. When using the API to update the policy, you must  
provide the system-generated name.  

What's next