Professional Cloud Network Engineer
Integrating reCAPTCHA Enterprise with Google Cloud Armor allows you to protect web applications from automated bot traffic. This setup creates a workflow where Cloud Armor security policies check tokens generated by reCAPTCHA to decide if a user is human or a bot. Traffic flows from the user to your application, but Cloud Armor intercepts it at Google's network edge to perform this validation before the request ever reaches your backend servers.
A reCAPTCHA Enterprise key is the central resource that enables bot detection. You create this key within the reCAPTCHA Enterprise service and configure it for one of two main integration types. A challenge page key is used for user-facing interactions where a visual puzzle might be presented. A session token key is used for background validation that runs without directly interrupting the user. The key's configuration determines how the risk assessment is performed. After creating the key, you must link its identifier to a Cloud Armor security policy to establish the connection between the two services.
Linking a reCAPTCHA key to a Cloud Armor security policy is the essential step that activates the bot management workflow. You configure this link within a Cloud Armor rule by specifying the reCAPTCHA key and choosing an enforcement action, such as to allow, deny, or redirect traffic. When a user request arrives at the load balancer protected by this policy, Cloud Armor extracts the reCAPTCHA token from the request header. It then sends this token to the reCAPTCHA Enterprise service for a real-time risk analysis. The request's path depends entirely on the validation result: requests with valid, low-risk tokens proceed to the backend, while requests with failed or high-risk assessments trigger the policy's blocking action.
The token validation workflow defines the precise sequence of operations between all the components. First, your application's front-end must include the reCAPTCHA JavaScript API to generate a token for each user session or specific action. This token is then attached to subsequent requests sent to your backend, usually within a header. Cloud Armor, acting as the security gateway, is configured to look for this specific token. It passes the token to the reCAPTCHA Enterprise API, which returns a risk score. Cloud Armor then uses this score, along with your policy rules, to make an immediate enforcement decision, completing the automated threat mitigation loop.
Google Cloud Armor uses expression-based security rules to inspect incoming web traffic and decide how to handle potential bots. These rules can evaluate request details like the URL path and the validity of reCAPTCHA tokens. Based on this evaluation, Cloud Armor executes mitigation actions such as blocking, rate limiting, or redirecting the request, all before the traffic reaches your backend workloads. This offloads the complex work of token decryption and validation to Google's edge network, protecting your servers and reducing their processing load.
Cloud Armor evaluates custom rule expressions at the network edge to match incoming requests. Administrators write these expressions using a specific syntax to target elements like the request path, headers, or query parameters—for example, request.path.matches("/login.html"). When a request includes a reCAPTCHA token, Cloud Armor decodes it to check its validity and read its risk score. To prevent attacks using stolen tokens, policies can be configured to validate that the token was created with a specific, authorized reCAPTCHA key. If the token contains an unknown or mismatched key, Cloud Armor marks it as invalid and can block the request immediately.
reCAPTCHA Enterprise provides two primary token models for risk assessment: action-tokens and session-tokens. Both return a risk score indicating how likely an interaction is to be legitimate, but they operate differently. An action-token is attached by the client application to the header of a specific, high-value request, such as a login or purchase submission. Cloud Armor validates this single token at the edge before deciding to forward the request. A session-token is stored as a browser cookie after an initial assessment and provides continuous protection across a user's entire visit. The embedded JavaScript refreshes this session cookie automatically every 30 minutes while the page is active, offering protection with minimal user friction.
When Cloud Armor detects suspicious activity, it can execute mitigation actions like a standard URL redirect or by presenting an interactive reCAPTCHA challenge page. A standard redirect sends the client to a different external URL using an HTTP 302 response. For suspected bot traffic, a rule can use a redirect action configured with the GOOGLE_RECAPTCHA type to serve an inline challenge page directly.
The challenge page flow follows a defined sequence. First, Cloud Armor intercepts the client's initial request and redirects them to the reCAPTCHA challenge page. This page delivers HTML with reCAPTCHA JavaScript to assess the user and present a manual CAPTCHA if needed. If the user solves the challenge successfully, reCAPTCHA issues an exemption cookie valid for three hours by default. For GET and HEAD requests, the browser then automatically reloads the original target page with this cookie. For POST and PUT requests, the user must click a reload link. On all subsequent requests, Cloud Armor validates the exemption cookie and allows the traffic to pass directly to the backend without repeating the challenge.
Using a custom reCAPTCHA Web Application Firewall (WAF) site key, rather than a Google-managed key, allows administrators to view detailed, site-specific telemetry and train custom risk models. Google-managed keys provide baseline protection but do not grant access to these detailed assessment metrics in the Google Cloud console.
Effective bot management requires ongoing review of telemetry data to ensure policies are working correctly and not blocking legitimate users. You examine logs and metrics from Google Cloud Armor and reCAPTCHA Enterprise using Cloud Logging and Cloud Monitoring. This analysis helps you evaluate risk score distributions, verify that your policies are effective, and adjust threshold values to minimize false positives where real users are mistakenly challenged or blocked.
Cloud Armor produces detailed telemetry when it evaluates reCAPTCHA tokens, including the risk score, token attributes, and the final action taken. The score indicates the request's risk level, where higher scores suggest legitimate human traffic and lower scores suggest automated or fraudulent behavior. To access this crucial data for analysis, you must enable Cloud Logging for your Cloud Armor security policies. Without logging enabled, you cannot verify if your policies are correctly identifying bots or if they are inadvertently impacting legitimate user traffic.
Analyzing the distribution of reCAPTCHA risk scores across your traffic reveals the effectiveness of your bot detection setup. A healthy distribution typically shows a majority of requests receiving high scores (legitimate users) and a smaller cluster receiving low scores (automated traffic). If you see an unusually high percentage of low-score requests, your policies might be too aggressive or misclassifying real users. Conversely, if almost all requests receive high scores, your detection might be too permissive and allowing malicious bots. Regularly reviewing these distributions helps you understand your traffic patterns and guides adjustments to your confidence thresholds.
You verify policy effectiveness by checking the actions Cloud Armor takes on incoming requests. The workflow differs between token types. For action-tokens, the token is validated once for a specific request. For session-tokens, an initial assessment sets a cookie that is reused for later requests in the same session. You should confirm that traffic from known legitimate users passes through without challenge, while automated requests are correctly identified and subjected to blocking or a challenge page.
False positives occur when legitimate users are incorrectly flagged as bots, creating friction. To minimize this, create your own reCAPTCHA WAF site key and associate it with your security policy instead of using a Google-managed key. Your own key allows you to view site-specific metrics and train a security model tailored to your application's traffic patterns. Additionally, associating your reCAPTCHA keys with security policy rules adds an extra validation step: Cloud Armor checks that the token's key matches the keys authorized in the rule. This prevents token theft attacks but requires careful key management to avoid blocking users with tokens from different, legitimate key configurations.
Proper monitoring starts with enabling Cloud Logging for your Cloud Armor policies. Each request evaluation then generates log entries containing the reCAPTCHA score, the action taken, and the matched rule. You can filter these logs to analyze specific time periods, traffic sources, or action types. Key metrics to track include the count of requests challenged versus passed, the distribution of scores, and the rate of exemption cookie issuances. Regular review of these metrics helps you identify trends, spot anomalies, and make data-driven adjustments to your policies.
Threshold values are the score limits that determine when Cloud Armor takes action. Setting these thresholds involves a tradeoff between security and user experience. Stricter (lower) thresholds provide stronger protection but may inconvenience legitimate users. Looser (higher) thresholds improve usability but may allow more malicious traffic. If your analysis shows a high false positive rate, you can raise your thresholds, requiring stronger evidence of bot behavior before blocking. If too many bots are getting through, you can lower the thresholds to be more restrictive. Finding the optimal threshold is an iterative process that depends on your application's specific risk profile and user tolerance for authentication steps.
An action-token is attached to a specific, high-value request (like a login) and validated once by Cloud Armor at the edge. A session-token is stored as a browser cookie after an initial assessment and provides continuous protection for the entire user session, refreshing automatically every 30 minutes.
Use a custom reCAPTCHA WAF site key when you need to view detailed, site-specific assessment metrics in the Google Cloud console and want to train a security model tailored to your application's traffic patterns. Google-managed keys provide baseline protection but do not offer access to this granular telemetry.
Cloud Armor intercepts a suspicious request and redirects the user to a reCAPTCHA challenge page. After the user successfully completes the challenge, reCAPTCHA issues an exemption cookie. The browser then automatically reloads the original page (for GET/HEAD requests) or prompts a manual reload (for POST/PUT requests), and Cloud Armor validates the cookie on subsequent requests to allow passage.
Enabling Cloud Logging for Cloud Armor security policies is essential because it generates the detailed log entries containing reCAPTCHA scores and enforcement actions. Without these logs, you cannot analyze score distributions, verify if your policies are working correctly, or identify false positives blocking legitimate users.
Prepare and test your skills
Prepare and test your skills