Chapter 3. Tutorial: Limit egress with Google Cloud Next Generation Firewall
Use this guide to implement egress restrictions for OpenShift Dedicated on Google Cloud by using Google Cloud’s Next Generation Firewall (NGFW). NGFW is a fully distributed firewall service that allows fully qualified domain name (FQDN) objects in firewall policy rules. This is necessary for many of the external endpoints that OpenShift Dedicated relies on.
The ability to restrict egress traffic using a firewall or other network device is only supported with OpenShift Dedicated clusters deployed using Private Service Connect (PSC). Clusters that do not use PSC require a support exception to use this functionality. For additional assistance, please open a support case.
3.1. Reviewing your prerequisites Copy linkLink copied to clipboard!
-
You have the Google Cloud Command Line Interface (
gcloud) installed. - You are logged into the Google Cloud CLI and have selected the Google Cloud project where you plan to deploy OpenShift Dedicated.
You have the minimum necessary permissions in Google Cloud, including:
-
Compute Network Admin -
DNS Administrator
-
You have enabled certain services by running the following commands in your terminal:
gcloud services enable networksecurity.googleapis.com
$ gcloud services enable networksecurity.googleapis.comCopy to Clipboard Copied! Toggle word wrap Toggle overflow gcloud services enable networkservices.googleapis.com
$ gcloud services enable networkservices.googleapis.comCopy to Clipboard Copied! Toggle word wrap Toggle overflow gcloud services enable servicenetworking.googleapis.com
$ gcloud services enable servicenetworking.googleapis.comCopy to Clipboard Copied! Toggle word wrap Toggle overflow
3.2. Setting up your environment Copy linkLink copied to clipboard!
In your terminal, configure the following environment variables:
This example uses us-east1 as the region to deploy into and the prefix osd-ngfw for the cluster’s resources. The default CIDR ranges are assigned for the service and pod networks. The machine CIDR is based on the subnet ranges that will be set later in this tutorial. Modify the parameters to meet your needs.
3.3. Creating the VPC and subnets Copy linkLink copied to clipboard!
Before you can deploy a Google Cloud NGFW, you must first create the Virtual Private Cloud (VPC) and subnets that you will use for OpenShift Dedicated:
Create the VPC by running the following command:
gcloud compute networks create ${prefix}-vpc --subnet-mode=custom$ gcloud compute networks create ${prefix}-vpc --subnet-mode=customCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create the worker subnets by running the following command:
gcloud compute networks subnets create ${prefix}-worker \ --range=10.0.2.0/23 \ --network=${prefix}-vpc \ --region=${region} \ --enable-private-ip-google-access$ gcloud compute networks subnets create ${prefix}-worker \ --range=10.0.2.0/23 \ --network=${prefix}-vpc \ --region=${region} \ --enable-private-ip-google-accessCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create the control plane subnets by running the following command:
gcloud compute networks subnets create ${prefix}-control-plane \ --range=10.0.0.0/25 \ --network=${prefix}-vpc \ --region=${region} \ --enable-private-ip-google-access$ gcloud compute networks subnets create ${prefix}-control-plane \ --range=10.0.0.0/25 \ --network=${prefix}-vpc \ --region=${region} \ --enable-private-ip-google-accessCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create the PSC subnets by running the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow These examples use the subnet ranges of 10.0.2.0/23 for the worker subnet, 10.0.0.0/25 for the control plane subnet, and 10.0.0.128/29 for the PSC subnet. Modify the parameters to meet your needs. Ensure the parameter values are contained within the machine CIDR you set earlier in this tutorial.
3.4. Deploying a global network firewall policy Copy linkLink copied to clipboard!
Create a global network firewall policy by running the following command:
gcloud compute network-firewall-policies create \ ${prefix} \ --description "OpenShift Dedicated Egress Firewall" \ --global$ gcloud compute network-firewall-policies create \ ${prefix} \ --description "OpenShift Dedicated Egress Firewall" \ --globalCopy to Clipboard Copied! Toggle word wrap Toggle overflow Associate the newly created global network firewall policy to the VPC you created above by running the following command:
gcloud compute network-firewall-policies associations create \ --firewall-policy ${prefix} \ --network ${prefix}-vpc \ --global-firewall-policy$ gcloud compute network-firewall-policies associations create \ --firewall-policy ${prefix} \ --network ${prefix}-vpc \ --global-firewall-policyCopy to Clipboard Copied! Toggle word wrap Toggle overflow
3.5. Creating a Cloud Router and a Cloud Network Address Translation gateway Copy linkLink copied to clipboard!
The Network Address Translation (NAT) gateway enables internet connectivity for your private VMs by masquerading all their traffic under a single public IP address. As the designated exit point, it translates their internal IPs for any outbound requests, such as fetching updates. This process effectively grants them access to the internet without ever exposing their private addresses.
Reserve an IP address for Cloud NAT by running the following command:
gcloud compute addresses create ${prefix}-${region}-cloudnatip \ --region=${region}$ gcloud compute addresses create ${prefix}-${region}-cloudnatip \ --region=${region}Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a Cloud Router by running the following command:
gcloud compute routers create ${prefix}-router \ --region=${region} \ --network=${prefix}-vpc$ gcloud compute routers create ${prefix}-router \ --region=${region} \ --network=${prefix}-vpcCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a Cloud NAT by running the following command:
gcloud compute routers nats create ${prefix}-cloudnat-${region} \ --router=${prefix}-router --router-region ${region} \ --nat-all-subnet-ip-ranges \ --nat-external-ip-pool=${prefix}-${region}-cloudnatip$ gcloud compute routers nats create ${prefix}-cloudnat-${region} \ --router=${prefix}-router --router-region ${region} \ --nat-all-subnet-ip-ranges \ --nat-external-ip-pool=${prefix}-${region}-cloudnatipCopy to Clipboard Copied! Toggle word wrap Toggle overflow
3.6. Creating private Domain Name System records for Private Google Access Copy linkLink copied to clipboard!
The private Domain Name System (DNS) zone optimizes how your resources connect to Google APIs by ensuring traffic never travels over the public internet. It functions by intercepting DNS requests for Google services and resolving them to private IP addresses, forcing the connection onto Google’s internal network for a faster, more secure data exchange.
Create a private DNS zone for the googleapis.com domain by running the following command:
gcloud dns managed-zones create ${prefix}-googleapis \ --visibility=private \ --networks=https://www.googleapis.com/compute/v1/projects/${project_id}/global/networks/${prefix}-vpc \ --description="Private Google Access" \ --dns-name=googleapis.com$ gcloud dns managed-zones create ${prefix}-googleapis \ --visibility=private \ --networks=https://www.googleapis.com/compute/v1/projects/${project_id}/global/networks/${prefix}-vpc \ --description="Private Google Access" \ --dns-name=googleapis.comCopy to Clipboard Copied! Toggle word wrap Toggle overflow Begin a record set transaction by running the following command:
gcloud dns record-sets transaction start \ --zone=${prefix}-googleapis$ gcloud dns record-sets transaction start \ --zone=${prefix}-googleapisCopy to Clipboard Copied! Toggle word wrap Toggle overflow Stage the DNS records for Google APIs under the googleapis.com domain by running the following commands:
gcloud dns record-sets transaction add --name="*.googleapis.com." \ --type=CNAME restricted.googleapis.com. \ --zone=${prefix}-googleapis \ --ttl=300$ gcloud dns record-sets transaction add --name="*.googleapis.com." \ --type=CNAME restricted.googleapis.com. \ --zone=${prefix}-googleapis \ --ttl=300Copy to Clipboard Copied! Toggle word wrap Toggle overflow gcloud dns record-sets transaction add 199.36.153.4 199.36.153.5 199.36.153.6 199.36.153.7 \ --name=restricted.googleapis.com. \ --type=A \ --zone=${prefix}-googleapis \ --ttl=300$ gcloud dns record-sets transaction add 199.36.153.4 199.36.153.5 199.36.153.6 199.36.153.7 \ --name=restricted.googleapis.com. \ --type=A \ --zone=${prefix}-googleapis \ --ttl=300Copy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the staged record set transaction you started above by running the following command:
gcloud dns record-sets transaction execute \ --zone=$prefix-googleapis$ gcloud dns record-sets transaction execute \ --zone=$prefix-googleapisCopy to Clipboard Copied! Toggle word wrap Toggle overflow
3.7. Creating the firewall rules Copy linkLink copied to clipboard!
Create a blanket allow rule for private IP (RFC 1918) address space by running the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create an allow rule for HTTPS (tcp/443) domains required for OpenShift Dedicated by running the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow ImportantIf there is not a matching rule that allows the traffic, it will be blocked by the firewall. To allow access to other resources, such as internal networks or other external endpoints, create additional rules with a priority of less than 1000. For more information on how to create firewall rules, see Use global network firewall policies and rules.
3.8. Creating your cluster Copy linkLink copied to clipboard!
You are now ready to create your OpenShift Dedicated on Google Cloud cluster. For more information, see Creating a cluster on Google Cloud with Workload Identity Federation authentication.
3.9. Deleting your cluster Copy linkLink copied to clipboard!
To delete your cluster, see Deleting an OpenShift Dedicated cluster on Google Cloud.
3.10. Cleaning up resources Copy linkLink copied to clipboard!
To prevent ongoing charges, after you delete your cluster you must manually delete the Google Cloud networking infrastructure you created as part of this tutorial. Deleting the cluster will not automatically remove these underlying resources. You can clean up these resources using a combination of gcloud CLI commands and actions within the Google Cloud console.
Before you begin the process of cleaning up the the resources you created for this tutorial, run the following commands and complete any prompts.
To authenticate your identity run the following command:
gcloud init
$ gcloud initCopy to Clipboard Copied! Toggle word wrap Toggle overflow To log in to your Google Cloud account, run the following command:
gcloud auth application-default login
$ gcloud auth application-default loginCopy to Clipboard Copied! Toggle word wrap Toggle overflow To log in to the OpenShift Cluster manager CLI tool, run the following command:
ocm login --use-auth-code
$ ocm login --use-auth-codeCopy to Clipboard Copied! Toggle word wrap Toggle overflow
You are now ready to clean up the resources you created as part of this tutorial. To respect resource dependencies, delete them in the reverse order of their creation.
Delete the firewall policy’s association with the VPC by running the following command:
gcloud compute network-firewall-policies associations delete \ --firewall-policy=${prefix} \ --network=${prefix}-vpc \ --global-firewall-policy$ gcloud compute network-firewall-policies associations delete \ --firewall-policy=${prefix} \ --network=${prefix}-vpc \ --global-firewall-policyCopy to Clipboard Copied! Toggle word wrap Toggle overflow Delete the global network firewall policy by running the following command:
gcloud compute network-firewall-policies delete ${prefix} --global$ gcloud compute network-firewall-policies delete ${prefix} --globalCopy to Clipboard Copied! Toggle word wrap Toggle overflow A managed DNS zone in Google Cloud cannot be deleted until all user-defined record sets are removed. Define variables to target the specific Google Cloud project and the managed DNS zone being cleaned up by running the following command:
cat /tmp/delete_records.sh PROJECT_ID=<your-project-id> ZONE_NAME=<your-managed-zone-name>
$ cat /tmp/delete_records.sh PROJECT_ID=<your-project-id> ZONE_NAME=<your-managed-zone-name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow List the record sets that are included within the Private DNS zone by running the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Delete the record sets that are included within that Private DNS Zone by running the following command:
gcloud --project=$PROJECT_ID dns record-sets delete "$name" --zone=$ZONE_NAME --type="$type"
$ gcloud --project=$PROJECT_ID dns record-sets delete "$name" --zone=$ZONE_NAME --type="$type"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Delete the Private DNS Zone by running the following command:
gcloud dns managed-zones delete ${prefix}-googleapis$ gcloud dns managed-zones delete ${prefix}-googleapisCopy to Clipboard Copied! Toggle word wrap Toggle overflow Delete the Cloud NAT gateway:
gcloud compute routers nats delete ${prefix}-cloudnat-${region} \ --router=${prefix}-router \ --router-region=${region}$ gcloud compute routers nats delete ${prefix}-cloudnat-${region} \ --router=${prefix}-router \ --router-region=${region}Copy to Clipboard Copied! Toggle word wrap Toggle overflow Delete the Cloud Router by running the following command:
gcloud compute routers delete ${prefix}-router --region=${region}$ gcloud compute routers delete ${prefix}-router --region=${region}Copy to Clipboard Copied! Toggle word wrap Toggle overflow Delete the reserved IP address by running the following command:
gcloud compute addresses delete ${prefix}-${region}-cloudnatip --region=${region}$ gcloud compute addresses delete ${prefix}-${region}-cloudnatip --region=${region}Copy to Clipboard Copied! Toggle word wrap Toggle overflow Delete the worker subnet by running the following command:
gcloud compute networks subnets delete ${prefix}-worker --region=${region}$ gcloud compute networks subnets delete ${prefix}-worker --region=${region}Copy to Clipboard Copied! Toggle word wrap Toggle overflow Delete the control plane subnet by running the following command:
gcloud compute networks subnets delete ${prefix}-control-plane --region=${region}$ gcloud compute networks subnets delete ${prefix}-control-plane --region=${region}Copy to Clipboard Copied! Toggle word wrap Toggle overflow Delete the PSC subnet by running the following command:
gcloud compute networks subnets delete ${prefix}-psc --region=${region}$ gcloud compute networks subnets delete ${prefix}-psc --region=${region}Copy to Clipboard Copied! Toggle word wrap Toggle overflow Delete the VPC by running the following command:
gcloud compute networks delete ${prefix}-vpc$ gcloud compute networks delete ${prefix}-vpcCopy to Clipboard Copied! Toggle word wrap Toggle overflow