All articles
Cloudflare··7 min read

Lock a whole app behind a login in 20 minutes with Cloudflare

Cloudflare Access puts a real authentication gate in front of an entire app, free for 50 users, without touching your code. It also protects far less than the phrase implies, and four specific mistakes will leave it open while you think it is closed.

You can put a real login gate in front of an entire app in about twenty minutes, for free, without touching your code. It is the highest-value hour of security work available to most people building internal tools.

It also does far less than the phrase “secured with Cloudflare” suggests, and being clear about which half you have is the difference between being protected and feeling protected.

What Cloudflare Access actually does

Access sits at the edge and refuses to pass a request to your app until the visitor has authenticated. Your application code is not involved and does not need to change. For an internal dashboard, an admin panel, or a staging environment that should never have been public, this is close to ideal.

The free plan covers up to 50 users, which is more than enough for most internal tools.

Pricing above the free tier moves, and the figures quoted in tutorials go stale quickly. Check Cloudflare's current pricing page rather than trusting a number from a video, including this one.

The setup, in the order that works

  • Deploy the app to Cloudflare Workers, connected to your GitHub repository so commits deploy automatically.
  • Point your domain's DNS at Cloudflare, so traffic actually traverses their network. Without this there is nothing in front of your app to do the gating.
  • Create a Zero Trust organisation and pick a team name. This becomes your team domain, which your identity provider will need.
  • Add a self-hosted application under Access, set a session duration, and give it your app's hostname.
  • Reload the app. You should now be locked out of your own site. That is the gate working.
  • Add a login method, connect your identity provider, then create and apply a policy.

Getting blocked from your own app is the checkpoint that matters. If you can still reach it, nothing is protecting it yet.

Four mistakes that will cost you an evening

Creating a policy does not apply it. This is the one that leaves apps open while their owner believes otherwise. A policy exists independently of the application it governs. You must open the application, select the policy, confirm, and then save the application. Miss the final save and you have written a rule that enforces nothing.

Choose the right application type in your identity provider. Even when your app is a single-page application, register it as a regular web application. Access performs the authentication exchange on its servers rather than in the browser, so the single-page option produces a configuration that fails in a way the error messages do not explain.

Nothing configures the callback URL for you. The first login attempt always fails, because your identity provider has never heard of Cloudflare. The error page contains the exact callback URL it rejected. Copy that into the allowed callbacks list. For the logout and origin fields, trim it back to the bare domain.

Accepting every identity provider is the default. That means any login method you have ever configured, including abandoned experiments, remains a valid way in. Restrict the application to the one provider you intend, and delete connections you are not using.

Testing it without fooling yourself

You are signed into Cloudflare. Of course the app loads. Signing out of the app launcher is not enough either, because the session survives it. Use a completely fresh private window, and treat any other result as untested.

One tutorial author lost hours to a configuration error here and described the experience accurately:

Here's the error that I've gotten multiple times and this frustrates the crap out of me because I couldn't figure out what I was doing wrong. It says this account does not have access. I got so frustrated, I just shut my computer at like 4:00 a.m. I just went to bed.

· Dwain Browne, How to Secure a Vibe Coded App with Cloudflare

His theory was a synchronisation delay. The likelier explanation, and the first thing to check, is that no policy matches your identity: the rule names a different email, or the policy was never applied to the application. Work through the configuration before blaming propagation.

Policies are rules, and some of them are softer than they look

Access policies can require a particular email or domain, a country, or multi-factor authentication. Email rules are the dependable ones, since they key off a verified identity.

Country rules are worth understanding before you rely on one. They are based on the IP address a request arrives from, so anyone with a VPN presents as whichever country they prefer. Useful for reducing background noise, not for keeping out anyone who actually wants in. The same applies to hiding an app from the launcher: it affects what people are shown, not what they are allowed to reach.

What this does not protect

This is the important part, and the reason to be careful with the phrase “production grade security for free”. Putting Access in front of your app secures who can open it. It does nothing about:

  • Keys compiled into your front-end bundle, which remain readable by anyone who gets through the gate.
  • Database access rules, so any user who passes Access may still read everyone else's data.
  • API endpoints reachable on another hostname that Access does not cover.
  • Spending limits on the paid services behind your app.

An app behind Access with no row level security and a database URL in the browser bundle is not a secure app. It is an insecure app with a login screen, and the login screen is the part an attacker cares least about.

Use it for what it is excellent at, which is making sure an internal tool is not quietly public. Then go and fix the data layer, because that is where the actual risk lives.

Find out which of those apply to you

Fourteen questions, about three minutes, runs entirely in your browser. You get a ranked list of what's actually open, with the fix for each.

Run the free check

Sources

Quotations from the two interviews are transcribed from the published videos and lightly condensed for readability.