Protect sign-up with reCAPTCHA
A realm’s bot protection puts a challenge in front of the requests that anyone can make without signing in. With Google reCAPTCHA turned on, the sign-in pages get a token from Google for each of those requests, and the identity server verifies the token with Google before it does anything else, including its own rate limits.
The challenge guards four requests:
- signing up with a password;
- requesting a magic link;
- resending a magic link;
- resending a one-time code.
Signing in with a password isn’t challenged.
Before you begin
Section titled “Before you begin”- Identity server 1.89.0 or later. Google’s test key needs 1.91.1 or later.
- Login pages 0.33.0 or later. An install that serves its own login pages image must be on that version, or the pages show no challenge and every guarded request is refused.
- Console 0.55.0 or later,
awctl0.45.1 or later, or Terraform provider 0.35.0 or later. - A reCAPTCHA key from Google, with its site key and its legacy secret key. The identity server verifies tokens with the legacy secret key and uses no Google Cloud credential.
- The sign-in hostname allowed on the key. The identity server refuses a token that Google reports as solved on any hostname other than the one the request came in on.
- Billing turned on for the key’s Google Cloud project. See When verification fails.
Choose a key type
Section titled “Choose a key type”The realm must name the type of the key, as you created it at Google.
| Key type | Setting | What the person sees |
|---|---|---|
| Checkbox (v2) | CHECKBOX | The reCAPTCHA checkbox widget on the form. The form can’t be sent until the widget yields a token. |
| Score (v3) | SCORE | No widget. The page asks Google for a token when the form is sent, and shows the notice “This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.” |
With a score key, Google rates each request from 0 to 1. A request that scores below the realm’s lowest score is refused like a failed check. The default lowest score is 0.5.
Turn on reCAPTCHA
Section titled “Turn on reCAPTCHA”The site key is public and goes on the realm. The secret key is never a plain field: you store it as a tenant secret, and the realm names that secret.
In the console
Section titled “In the console”- In the console, go to Realms and open the realm.
- Open the Settings tab.
- Open Protection against abuse.
- Under Bot protection, in Challenge, select Always.
- In Provider, select Google reCAPTCHA.
- In Site key, enter the key’s site key.
- In Secret key, select the tenant secret that holds the key’s legacy secret key. To store it now, click Create a secret, enter a Display name and the secret key, and then click Create and select.
- In Key type, select Checkbox (v2) or Score (v3).
- For a score key, optionally enter a value from 0 to 1 in Lowest score let through. Blank means 0.5.
- Click Save. The row then reads Bot check on.
With awctl
Section titled “With awctl”-
Store the secret key as a tenant secret. The material is read from standard input, never from a flag:
Terminal window printf %s "$RECAPTCHA_SECRET_KEY" | awctl identity secrets create \--tenant-id TENANT_ID --display-name "reCAPTCHA secret key" --data-file=- -
Set the realm’s
bot_protection:Terminal window awctl identity realms update REALM_ID --tenant-id TENANT_ID \--config '{"bot_protection": {"mode": "ALWAYS", "provider": "RECAPTCHA","site_key": "SITE_KEY", "secret_ref": {"name": "tenants/TENANT_ID/secrets/SECRET_ID"},"recaptcha_key_type": "SCORE", "min_score": 0.7}}'
Replace TENANT_ID with the tenant’s ID (t-…), REALM_ID with the
realm’s ID (r-…), SITE_KEY with the key’s site key, and SECRET_ID
with the ID of the secret you created (s-…).
With Terraform
Section titled “With Terraform”resource "authwise_secret" "recaptcha" { display_name = "reCAPTCHA secret key" payload_wo = var.recaptcha_secret_key payload_wo_version = 1}
data "authwise_realm_config" "customers" { bot_protection = { mode = "ALWAYS" provider = "RECAPTCHA" site_key = "SITE_KEY" secret_ref = { name = authwise_secret.recaptcha.name } recaptcha_key_type = "SCORE" min_score = 0.7 }}
resource "authwise_realm" "customers" { display_name = "Customers" config = data.authwise_realm_config.customers.json}Replace SITE_KEY with the key’s site key. payload_wo is a write-only
argument, which needs Terraform 1.11 or later. To send a new secret key,
change payload_wo and raise payload_wo_version.
Settings
Section titled “Settings”| Console | API and Terraform | Meaning |
|---|---|---|
| Challenge | mode | OFF, the default, or ALWAYS. ADAPTIVE is reserved and refused. |
| Provider | provider | RECAPTCHA for Google reCAPTCHA. |
| Site key | site_key | The key’s public site key. The sign-in pages use it to load reCAPTCHA. |
| Secret key | secret_ref | The tenant secret that holds the key’s legacy secret key. |
| Key type | recaptcha_key_type | CHECKBOX or SCORE. Required for reCAPTCHA. |
| Lowest score let through | min_score | For a score key only, from 0 to 1. Unset means 0.5. |
| Time out after | timeout | How long one verification can take. Unset means 3 seconds. |
| When the verifier does not answer | fail_mode | CLOSED, the default, refuses the request. OPEN lets it through. |
A write that can’t work as written is refused, and the message names
every problem: ALWAYS with no provider, a missing site key or secret, a
missing key type, or a lowest score on anything but a score key.
When verification fails
Section titled “When verification fails”A request fails the check when it carries no token, when Google refuses the token, when the token was solved on another hostname, or when a score key’s score is below the realm’s lowest score.
| Request | What the person sees | What is recorded |
|---|---|---|
| Sign-up | The message “verification failed; complete the challenge and try again”. No account is created. | An authn.signup event, denied, with the reason bot_suspected. |
| Magic-link request or resend | The same answer as a request that was sent. Nothing is sent. | A security.rate_limited event, denied, with the limiter botcheck and the reason bot_suspected. |
| One-time code resend | No code is sent. | A security.rate_limited event, denied, with the limiter botcheck and the reason bot_suspected. |
If Google’s script doesn’t load in the person’s browser, the form shows “We couldn’t load the check that keeps this form safe. Reload the page to try again.”
When Google doesn’t answer
Section titled “When Google doesn’t answer”If the identity server can’t reach Google, or Google doesn’t answer within the timeout, the result depends on When the verifier does not answer:
- Fail closed, the default, refuses the request, with the reason
upstream_unavailable. - Fail open lets the request through.
When the free quota is spent
Section titled “When the free quota is spent”A Google Cloud project without billing that passes Google’s free monthly
quota answers every token as passed. The identity server treats that
answer as a failed check, whatever the fail mode, and records the reason
bot_vendor_over_quota. Every guarded request then fails until you turn
on billing for the project.
Check that it works
Section titled “Check that it works”- Open the realm’s sign-up page in a private browser window. For a checkbox key, the form shows the reCAPTCHA widget. For a score key, the form shows the reCAPTCHA notice under its fields.
- Sign up with a new address. The account is created.
- In the console, go to Activity. A refused sign-up appears as a
denied
authn.signupevent with the reasonbot_suspected. A sign-up that passed the check has no such event.
To exercise the pages without a real check, a realm can use Google’s
published test site key, 6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI, with
Google’s published test secret.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Cause and fix |
|---|---|
| Every sign-up fails with “verification failed; complete the challenge and try again” | The identity server’s log says why Google’s answer was refused. A hostname that isn’t the sign-in hostname means the key doesn’t allow that hostname. invalid-input-secret among the error codes means the tenant secret doesn’t hold the key’s legacy secret key. A score below the floor means the lowest score is too high for your traffic. |
Every guarded request fails, and events carry bot_vendor_over_quota | The key’s Google Cloud project is past its free quota. Turn on billing for the project. |
| The form shows no reCAPTCHA, and guarded requests are refused | The login pages are older than 0.33.0. Upgrade them. |
Saving is refused with bot_protection.recaptcha_key_type is required for recaptcha | Set the key type to CHECKBOX or SCORE. |
Saving is refused with bot_protection.min_score applies only to a reCAPTCHA SCORE key | Remove the lowest score, or set the key type to SCORE. |
Events carry upstream_unavailable | The identity server couldn’t reach Google within the timeout. Check its outbound access to www.google.com. |
What’s next
Section titled “What’s next”- Realms for how people get an account in a realm.
- Sign in with a magic link, whose requests the bot check also guards.