Google Cloud HTTP(S) load balancing is deployed at the edge of Google's network in Google points of presence (POP) around the world. User traffic directed to an HTTP(S) load balancer enters the POP closest to the user and is then load balanced over Google's global network to the closest backend that has sufficient capacity available.
Cloud Armor is Google's distributed denial of service and web application firewall (WAF) detection system. Cloud Armor is tightly coupled with the Google Cloud HTTP Load Balancer and safeguards applications of Google Cloud customers from attacks from the internet.
reCAPTCHA Enterprise is a service that builds on the reCAPTCHA API and protects your site from spam and abuse using advanced risk analysis techniques to tell humans and bots apart. Cloud Armor Bot Management provides an end-to-end solution integrating reCAPTCHA Enterprise bot detection and scoring with enforcement by Cloud Armor at the edge of the network to protect downstream applications.
In this lab, you configure an HTTP Load Balancer with a backend, as shown in the diagram below. You set up a reCAPTCHA session token site key and embed it in your website. You also set up redirection to reCAPTCHA Enterprise manual challenge. You then configure a Cloud Armor bot management policy to see how bot detection protects your application from malicious bot traffic.
What you'll learn
In this lab, you learn how to:
Set up a HTTP Load Balancer with appropriate health checks
Create a reCAPTCHA WAF challenge-page site key and associated it with Cloud Armor security policy
Create a reCAPTCHA session token site key and install it on your web pages
Create a Cloud Armor bot management policy
Validate that the bot management policy is handling traffic based on the rules configured
Setup and requirements
Before you click the Start Lab button
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito (recommended) or private browser window to run this lab. This prevents conflicts between your personal account and the student account, which may cause extra charges incurred to your personal account.
Time to complete the lab—remember, once you start, you cannot pause a lab.
Note: Use only the student account for this lab. If you use a different Google Cloud account, you may incur charges to that account.
How to start your lab and sign in to the Google Cloud console
Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method.
On the left is the Lab Details pane with the following:
The Open Google Cloud console button
Time remaining
The temporary credentials that you must use for this lab
Other information, if needed, to step through this lab
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
Note: If you see the Choose an account dialog, click Use Another Account.
If necessary, copy the Username below and paste it into the Sign in dialog.
{{{user_0.username | "Username"}}}
You can also find the Username in the Lab Details pane.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
{{{user_0.password | "Password"}}}
You can also find the Password in the Lab Details pane.
Click Next.
Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials.
Note: Using your own Google Cloud account for this lab may incur extra charges.
Click through the subsequent pages:
Accept the terms and conditions.
Do not add recovery options or two-factor authentication (because this is a temporary account).
Do not sign up for free trials.
After a few moments, the Google Cloud console opens in this tab.
Note: To access Google Cloud products and services, click the Navigation menu or type the service or product name in the Search field.
Task 1. Configure firewall rules to allow HTTP and SSH traffic to backends
For this lab, you use the default VPC network created in your project when the lab spun up.
In this section, you configure firewall rules to allow HTTP traffic to the backends from the Google Cloud health checks and the Load Balancer. You then configure a firewall rule to allow SSH into the instances.
Create a firewall rule to allow HTTP traffic to the backends.
Health checks determine which instances of a load balancer can receive new connections. For HTTP load balancing, the health check probes to your load balanced instances come from addresses in the ranges 130.211.0.0/22 and 35.191.0.0/16. Your VPC firewall rules must allow these connections. Also, the load balancers talk to the backend on the same IP range.
To create a firewall rule to allow HTTP traffic to the backends:
In the console, navigate to Navigation menu () > VPC network > Firewall.
Notice the existing ICMP, internal, RDP, and SSH firewall rules. Each Google Cloud project starts with the default network and these firewall rules.
Click Create Firewall Rule.
Set the following values, leave all other values at their defaults:
Property
Value (type value or select option as specified)
Name
default-allow-health-check
Network
default
Targets
Specified target tags
Target tags
allow-health-check
Source filter
IPv4 Ranges
Source IPv4 ranges
130.211.0.0/22, 35.191.0.0/16
Protocols and ports
Specified protocols and ports, and then check tcp. Type 80 for the port number
Note: Be sure to enter the two Source IPv4 ranges one-by-one and press SPACE in between them.
Click Create.
Alternatively, in the gCloud command line, use the following command:
Click Check my progress to verify the objective.
Configure firewall rules to allow HTTP and SSH traffic to backends
Task 2. Configure instance templates and create managed instance groups
A managed instance group uses an instance template to create a group of identical instances. Use these to create the backend of the HTTP Load Balancer.
Configure the instance templates
An instance template is a resource that you use to create VM instances and managed instance groups. Instance templates define the machine type, boot disk image, subnet, labels, and other instance properties.
To create an instance template:
In the console, navigate to Navigation menu () > Compute Engine > Instance templates, and then click Create instance template.
For Name, type lb-backend-template.
For Location, Select Global.
For Series, select N1.
Click Networking, Disks, Security, Management, Sole-Tenancy under Advanced options.
Go to the Management section and insert the following script into the Startup script field:
The load balancing service forwards traffic to the named port.
Click Check my progress to verify the objective.
Configure instance templates and create managed instance groups
Task 3. Configure the HTTP Load Balancer
In this section, you configure the HTTP Load Balancer to send traffic to your backend lb-backend-example.
Start the configuration
In the console, click Navigation menu () > click Network Services > Load balancing, and then click Create load balancer.
Select Application Load Balancer (HTTP/HTTPS) and Next.
Select Public facing (external) and Next.
Select Best for global workloads and Next.
Select Global external Application Load Balancer and Next.
Select Configure.
Set the Name to http-lb.
Configure the frontend
Click Frontend configuration.
Specify the following, leaving all other values at their defaults:
Property
Value (type value or select option as specified)
Protocol
HTTP
IP version
IPv4
IP address
Ephemeral
Port
80
Click Done.
Configure the backend
Backend services direct incoming traffic to one or more attached backends. Each backend is composed of an instance group and additional serving capacity metadata.
Click on Backend configuration.
For Backend services & backend buckets, click Create a backend service.
Set the following values, leave all other values at their defaults:
Property
Value (select option as specified)
Name
http-backend
Protocol
HTTP
Named Port
http
Instance group
lb-backend-example
Port numbers
80
Click Done.
For Cloud CDN, set the Cache mode to Use origin settings based on Cache-Control headers.
For Health Check, select Create a health check.
Set the following values, leave all other values at their defaults:
Property
Value (select option as specified)
Name
http-health-check
Protocol
TCP
Port
80
Note: Health checks determine which instances receive new connections.
This HTTP health check polls instances every 5 seconds, waits up to 5 seconds for a response and treats 2 successful or 2 failed attempts as healthy or unhealthy, respectively.
Click Save.
Check the Enable Logging box.
Set the Sample rate to 1.
Click Create to create the backend service and click ok.
Review and create the HTTP Load Balancer
Host and path rules determine how your traffic is directed. For example, you could direct video traffic to one backend and static traffic to another backend. However, you are not configuring the Host and path rules in this lab.
Click on Review and finalize.
Review the Backend services and Frontend.
Click on Create.
Wait for the load balancer to be created.
Click on the name of the load balancer (http-lb).
Note the IPv4 address of the load balancer for the next task. In this lab, refer to it as [LB_IP_v4].
Click Check my progress to verify the objective.
Configure the HTTP Load Balancer
Test the HTTP Load Balancer
Now that you created the HTTP Load Balancer for your backends, verify that traffic is forwarded to the backend service.
To test IPv4 access to the HTTP Load Balancer, open a new tab in your browser and navigate to http://[LB_IP_v4]. Be sure to replace [LB_IP_v4] with the IPv4 address of the load balancer.
Note: It might take up to 5 minutes to access the HTTP Load Balancer. In the meantime, you might get a 404 or 502 error. Keep trying until you see the page load.
Task 4. Create and deploy reCAPTCHA session token and challenge-page site key
Create reCAPTCHA session token and WAF challenge-page site key
Before you create the session token site key and challenge page site key, double-check that you've enabled the reCAPTCHA Enterprise API as indicated in the previous Enable API section.
The reCAPTCHA JavaScript sets a reCAPTCHA session-token as a cookie on the end-user's browser after the assessment. The end-user's browser attaches the cookie and refreshes the cookie as long as the reCAPTCHA JavaScript remains active.
Create the reCAPTCHA session token site key and enable the WAF feature for the key:
The output of the above command gives you the session token site key you created. Record it to use later in this task.
You also set the WAF service to Cloud Armor to enable the Cloud Armor integration.
Note: You are using the integration type score which is leveraged in the Cloud Armor policy. You can alternatively use checkbox and invisible.
You also set a testing score when you create the key to validate that the bot management policies created with Cloud Armor are working as intended. Replicating bot traffic is not easy, so this is a good way to test the feature.
Create the reCAPTCHA WAF challenge-page site key and enable the WAF feature for the key. You can use the reCAPTCHA challenge page feature to redirect incoming requests to reCAPTCHA Enterprise to determine whether each request is potentially fraudulent or legitimate. Later, you associate this key with the Cloud Armor security policy to enable the manual challenge. This lab refers to this key as CHALLENGE-PAGE-KEY in the later steps.
Navigate to Navigation menu () > Security > reCAPTCHA Enterprise. You should see the keys you created in the reCAPTCHA Keys list:
Implement reCAPTCHA session token site key
Navigate to Navigation menu () > Compute Engine > VM Instances. Locate the VM in your instance group and SSH to it.
Go to the webserver root directory and change user to root:
cd /var/www/html/
sudo su
Update the landing index.html page and embed the reCAPTCHA session token site key. The session token site key (that you recorded earlier) is set in the head section of your landing page as below:
Create three other sample pages to test out the bot management policies:
good-score.html
echo '<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"></head><body><h1>Congrats! You have a good score!!</h1></body></html>' > good-score.html
bad-score.html
echo '<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"></head><body><h1>Sorry, You have a bad score!</h1></body></html>' > bad-score.html
median-score.html
echo '<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"></head><body><h1>You have a median score that we need a second verification.</h1></body></html>' > median-score.html
Validate that you are able to access all the webpages by opening them in your browser. Be sure to replace [LB_IP_v4] with the IPv4 address of the load balancer:
Open http://[LB_IP_v4]/index.html. You verify that the reCAPTCHA implementation is working when you see "protected by reCAPTCHA" at the bottom right corner of the page:
Click into each of the links.
Validate you are able to access all the pages.
Click Check my progress to verify the objective.
Deploy reCAPTCHA session token and challenge-page site key
To use reCAPTCHA Enterprise manual challenge to distinguish between human and automated clients, associate the reCAPTCHA WAF challenge site key (CHALLENGE-PAGE-KEY) you previously created for a manual challenge with the security policy. In the following script, remember to replace "CHALLENGE-PAGE-KEY" with the key you previously created:
In the console, navigate to Navigation menu > Network Security > Cloud Armor policies.
Click recaptcha-policy.
Your policy should resemble the following:
Click Check my progress to verify the objective.
Create Cloud Armor security policy rules for Bot Management
Task 6. Validate Bot Management with Cloud Armor
Open up a browser and enter the url http://[LB_IP_v4]/index.html. Navigate to "Visit allowed link".
Open a new window in Incognito mode to ensure you have a new session.
Enter the url http://[LB_IP_v4]/index.html and navigate to "Visit blocked link". You should receive a HTTP 403 error:
Note: If you are not shown a 403 Forbidden error you may need to wait long for recaptcha rules to take effect. Please wait 5 minutes then try this step again. Ensure you are using a new Incognito Window for testing each link.
Open a new window in Incognito mode to ensure you have a new session.
Enter the url http://[LB_IP_v4]/index.html and navigate to "Visit redirect link". You should see the redirection to Google reCAPTCHA and the manual challenge page as below:
Note: If the user interaction passes the assessment, reCAPTCHA Enterprise issues an exemption cookie. The browser attaches this exemption cookie to the user's subsequent requests to the same site until the cookie expires. By default, the exemption cookie expires after three hours.
Note: To prevent automated software from participating in abusive actions on your site, reCAPTCHA uses an advanced risk analysis engine and adaptive CAPTCHAs. It accomplishes this while allowing your valid users to pass through with ease. If the algorithm believes you are a human, it will validate the reCaptcha without additional action from you. If not, it will display a variety of images that you must categorize before proceeding. Only the most suspect traffic will be requested to solve a captcha by default.
If you are not served with a challenge to solve, you can still check the policy logs and verify that you were exempted from solving a challenge.
Verify Cloud Armor logs
Explore the security policy logs to validate bot management worked as expected.
In the console, navigate to Navigation menu > Network Security > Cloud Armor.
Click recaptcha-policy.
Click Logs.
Click View policy logs.
Below is the MQL(monitoring query language) query, copy and paste into the query editor:
resource.type:(http_load_balancer) AND jsonPayload.enforcedSecurityPolicy.name:(recaptcha-policy)
Now click Run Query.
Look for a log entry in Query results where the request is for http://[LB_IP_v4]/good-score.html. Expand jsonPayload.Expand enforcedSecurityPolicy.
Note: If you are not seeing log entries, wait a couple of minutes for the policy to propagate, refresh the URLs you used earlier, then check the logs again.
Repeat the same for http://[LB_IP_v4]/bad-score.html and http://[LB_IP_v4]/median-score.html.
Notice that the configuredAction is set to ALLOW, DENY or GOOGLE_RECAPTCHA with the name recaptcha-policy.
Note: Cloud Armor security policies create logs that can be explored to determine when traffic is denied and when it is allowed, along with the source of the traffic.
Click Check my progress to verify the objective.
Validate bot management with Cloud Armor
Congratulations!
You successfully implemented bot management with Cloud Armor. You configured an HTTP Load Balancer. Then, you created and implemented reCAPTCHA session token site key on a webpage. You also created a challenge-page site key. You set up Cloud Armor Bot management policy and validated how they handle requests based on the rules. You explored the security policy logs to identify why the traffic was allowed, blocked or redirected.
Manual Last Updated: July 04, 2024
Lab Last Tested: July 22, 2024
Copyright 2025 Google LLC. All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
Labs create a Google Cloud project and resources for a fixed time
Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
On the top left of your screen, click Start lab to begin
Use private browsing
Copy the provided Username and Password for the lab
Click Open console in private mode
Sign in to the Console
Sign in using your lab credentials. Using other credentials might cause errors or incur charges.
Accept the terms, and skip the recovery resource page
Don't click End lab unless you've finished the lab or want to restart it, as it will clear your work and remove the project
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one
Use private browsing to run the lab
Use an Incognito or private browser window to run this lab. This
prevents any conflicts between your personal account and the Student
account, which may cause extra charges incurred to your personal account.
Use Google Cloud Armor bot management to mitigate bot risk and to control access from automated clients