In this section, you will use Cloud Armor bot management rules to allow, deny and redirect requests based on the reCAPTCHA score. Remember that when you created the session token site key, you set a testing score of 0.5.
In Cloud Shell, create a recaptcha security policy via gcloud with the description “policy for bot management”
Associate the reCAPTCHA WAF challenge site key created for manual challenge with the security policy using the tag
recaptcha-redirect: site-key
Add a bot management rule to the policy to allow traffic if the url path matches good-score.html and has a score greater than 0.4 using the following tags:
"request.path.matches('good-score.html') && token.recaptcha_session.score > 0.4" allowAdd a bot management rule to the policy to deny traffic if the url path matches bad-score.html and has a score less than 0.6 using the following tags:
deny-403Add a bot management rule to the policy to redirect traffic to Google reCAPTCHA if the url path matches median-score.html and has a score equal to 0.5 using the following tags:
redirectgoogle-recaptcharecaptcha-policyIn the Console, verify your policy resembles the following:

Open up a browser and go to http://{LoadBalance_IP_Here}/index.html. Click on “Visit allow link”. Verify you are allowed through.

Open a new window in Incognito mode to ensure we have a new session and go to http://{LoadBalance_IP_Here}/index.html. Click on “Visit blocked link”. Verify you receive a HTTP 403 error.

Open a new window in Incognito mode to ensure we have a new session and go to http://{LoadBalance_IP_Here}/index.html. Click on “Visit redirect link”. Verify you see the redirection to Google reCAPTCHA and the manual challenge page.

Explore the security policy logs to validate bot management worked as expected.
In the Console, navigate to the logs for the recaptcha policy you created.
Use the below MQL (Monitoring Query Language) query to view the request logs
resource.type:(http_load_balancer) AND jsonPayload.enforcedSecurityPolicy.name:(recaptcha-policy)
Verify 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.