Skip to content
ProHomeLab
RU

SSO

Cloudflare Turnstile in Authentik - Setting Up Login Form Protection

Stilicho2011Updated 6 min read16 views

Also available in: RU

Part 7 of 9 in the series Authentik
  1. Authentik Overview - Architecture, Features, and Comparison with Keycloak
  2. OIDC, OAuth2, and Proxy Provider in Authentik - How to Protect Any Application
  3. Authentik - Initial Setup After Installation
  4. Setting Up Password Recovery in Authentik
  5. Setting Up User Enrollment and Invitation Processes in Authentik
  6. Setting Up Two-Factor Authentication in Authentik
  7. Cloudflare Turnstile in Authentik - Setting Up Login Form Protection
  8. Setting Up Email Notifications in Authentik
  9. Authentik - Setting Up a Reputation Policy
Contents
Warning

Update, October 10, 2026: this method no longer works in Russia. The Turnstile widget is loaded from Cloudflare's servers (challenges.cloudflare.com), and access to them is restricted by Russian ISPs. For a user in Russia the widget simply never shows up, the check can't be passed - and the login form won't let them through. So instead of bot protection, you end up locking yourself out. If your users (or you) access Authentik from Russia, don't enable Turnstile. What you can use instead:

  • the Reputation Policy - built-in protection against password guessing that doesn't call out to anything external;
  • Cap - a CAPTCHA you can host on your own server; Authentik supports it in the same Captcha Stage (see the docs).

The article is still relevant if your users are outside Russia.

I'm assuming you already have Authentik installed and configured (see the initial setup article, and also OIDC, OAuth2, and Proxy Provider if you're protecting a third-party app). Cloudflare Turnstile is a modern alternative to CAPTCHA that lets you protect authentication forms from bots and brute-force attacks without forcing users to decipher images or type in characters.

Tip

If you enjoyed this article, you can become a sponsor on Boosty.

Note

Cloudflare Turnstile is an analog of Captcha technology, but for Cloudflare users. If you specifically need to set up Captcha, you can read more in the official documentation

Note

As of July 1, 2025, changes to Russian personal data legislation (Federal Law No. 152) came into effect, under which using Google reCAPTCHA or its analogs on sites that transfer data abroad becomes a violation. Keep this restriction in mind if you plan to use this service for commercial activity.


Why use Cloudflare Turnstile in Authentik

By default, Authentik already has decent protection against:

  • brute-force attacks;
  • username enumeration;
  • automated login attempts.

However, when exposing your IdP to the internet, this is often not enough.

Cloudflare Turnstile lets you:

  • filter out bots before they even get to the password;
  • reduce the load on Authentik;
  • improve the user experience compared to classic CAPTCHAs;
  • raise the overall security level without complicating your flow logic.

In other words, in addition to the authentication and authorization methods we already set up in previous articles, we're adding one more verification method.

Visually, it looks something like this

Authentik login screen with the Cloudflare Turnstile widget


Requirements

Before you start, make sure you have a Cloudflare account - a free one is enough.

The domain Authentik runs on doesn't have to be moved to Cloudflare: Turnstile works on any website, and you just enter the domain name when creating the widget. The exception is Pre-Clearance mode, covered below.


Creating a Turnstile widget in Cloudflare

  1. Go to the Cloudflare dashboard.
  2. Open the Security > Turnstile section (Cloudflare periodically moves menu items between sections - at the time of writing this was under "Protect & Connect", now it's moved to "Security". If you still can't find it, just search for "Turnstile" in the dashboard search).
  3. Click Add Widget (in some UI versions the button is already called Add site).
  4. Specify:
    • Widget name - any name you like (e.g. authentik-login);
    • Add Hostname > Domains - the domain where Authentik runs;
    • Widget mode - Managed (recommended for home use).
    • Pre-Clearance Mode - Yes
    • Level of pre-clearance - interactive
Note

Change the last two settings however you see fit, depending on your needs and level of paranoia. Pre-Clearance only makes sense when the domain itself is served through Cloudflare and has protection rules set up there. If your domain isn't on Cloudflare, set it to No.

Turnstile widget creation form in Cloudflare

Once created, you'll receive:

  • Site Key
  • Secret Key

You can copy them, but Cloudflare kindly notes that you'll always be able to access them again later.

Site Key and Secret Key of the Turnstile widget in Cloudflare

Creating a Captcha Stage in Authentik

Configuring the stage in Authentik

Now let's move on to the configuration in Authentik.

  1. Open the Authentik admin panel.
  2. Go to Flows and Stages → Stages.
  3. Click Create.
  4. Select Captcha Stage.

Selecting the Captcha Stage type in Authentik

  1. Give the stage a name.
  2. For the verification type, select Cloudflare Turnstile.
  3. In the Public key and Private Key fields, enter the values we got from Cloudflare.
  4. You can leave the Interactive toggle enabled if your Turnstile is configured as Invisible or Managed. Configuring Public key, Private key, and Interactive in the Captcha Stage

Don't touch anything in the Advanced Settings section. In the version of Authentik current as of writing, the correct values are already filled in automatically. Previously you had to enter them manually. You can read more in the official documentation

Advanced Settings of the Captcha Stage in Authentik

  1. Finish

Integrating the Turnstile stage into the main authentication and authorization flow

  1. Open the Authentik admin panel.
  2. Go to Flows and Stages → Flows → default-authentication-flow.
  3. Select Stage Bindings → Bind Existing Stage
  4. Select the stage we just created.
  5. Choose the processing order for the Turnstile stage - after the identification stage (where the username is entered), but before the password entry stage.
  6. Select evaluate when flow is planned.
  7. Create

Binding the Turnstile stage to default-authentication-flow

We've now integrated the "captcha" stage into Authentik's authentication process.

Turnstile stage in the Stage Bindings list of the authentication flow

Note

Set up this way, the captcha is shown to every user on every login. If you'd rather show it only to suspicious requests - say, after a few failed login attempts from the same IP - attach a Reputation Policy to this stage binding (without Negate the result) and switch the binding to evaluate when stage is run. I covered how that policy works in Authentik - Setting Up a Reputation Policy.

Warning

Test the login in a separate incognito window without closing your admin session. If the widget fails to load, you won't be able to get from the login form into the admin panel to turn the stage off. For that case there's an emergency way in: docker exec authentik_server ak create_recovery_key 10 <admin_username> prints a link that's valid for 10 minutes and logs you in as the given user, bypassing the login form. After that you can unbind the Turnstile stage from the flow.

Tip

In the Turnstile panel on the Cloudflare site, you can view analytics for this widget

Turnstile widget analytics in the Cloudflare dashboard

Turnstile analytics charts in Cloudflare