↓ Skip to main content
Security

Cloudflare Part 4: an introduction to zero trust

Cloudflare, plainly - This article is part of a series.
Part 4: This Article
The old way to protect a network was a castle: a strong wall, a moat, and everyone inside trusted. Then people started working from cafés, apps moved to the cloud, and one phished VPN password could open the gate to the whole castle. Zero trust drops the castle. There is no “inside” any more, only one question asked on every request: who are you, and should you get this right now?
Left, castle and moat: a moat around a network where everything inside is trusted, so one stolen VPN login reaches everything. Right, zero trust with Cloudflare One: a person passes Access (a policy and a one-time PIN that expires in 10 minutes), then a Tunnel that only connects outwards, to an app with no open port. Access denies by default; the free plan covers 50 users.
From a trusted inside to a check on every request

The first three parts were about public websites: the front desk, what it did for my domains and the free-tier checklist. This one is about the things that should not be public: an admin page, a home dashboard, a family photo area. It’s also the part I haven’t built yet, so it ends with a plan rather than a trophy.

Words used in this post
#

TermMeaning here
PerimeterThe boundary of a network (the castle wall): firewall, VPN
Identity provider (IdP)The service that proves who you are: Google, GitHub, Microsoft, or a code sent by email
PolicyA rule saying who may reach what, under which conditions
Least privilegeGive each person access to what they need, and nothing else
ZTNAZero trust network access: reaching an app through an identity check instead of a VPN
TunnelAn encrypted connection that your server opens outwards to Cloudflare, so nothing needs to connect in
One-time PIN (OTP)A short code emailed to you at login; proving you own the mailbox proves who you are

What zero trust actually means
#

The standard reference is NIST’s SP 800-207, Zero Trust Architecture. Its abstract describes zero trust as moving defences “from static, network-based perimeters to focus on users, assets, and resources”, and states the core idea in one line: there is “no implicit trust granted to assets or user accounts based solely on their physical or network location”.

In practice, that comes down to three habits:

  1. Check every request, not just the first. A login gives you a short-lived session, not a permanent pass.
  2. Check the person, not the network. Being on the office Wi-Fi or the VPN proves nothing by itself.
  3. Give the least access that works. Reaching the wiki doesn’t mean reaching the database.
Castle and moatZero trust
Trust is based onWhere you connect fromWho you are, on which device, right now
A stolen login opensThe whole networkOne app, until the session expires
Apps are reachableBy anyone insideOnly through the identity check
Typical toolVPNAn identity-aware proxy in front of each app

Zero trust isn’t a product you buy. It’s a way of designing access. Products only make it easier.

How Cloudflare does it
#

Cloudflare’s version is called Cloudflare One. For a small setup, two pieces matter:

  • Access sits in front of an app and asks for identity first. It’s deny by default: anyone who doesn’t match an Allow policy is blocked, whether or not a Block policy names them.
  • Tunnel connects the app’s machine to Cloudflare. A small program, cloudflared, makes outbound-only connections to the nearest Cloudflare data centre, so you can close every inbound port on the firewall. The server doesn’t need a public address at all.

Put the two together and an app has no open port to scan and no login page anyone can reach. The only way in is through Cloudflare, after a policy says yes.

The free plan covers up to 50 users, with logs kept for up to 24 hours. That’s far more than a household needs.

Policies, plainly
#

An Access policy has an action (Allow, Block, Bypass or Service Auth) and rules that combine like logic:

RuleWorks likeExample
IncludeOR: any one is enoughemails ending in @example.com, or friend@example.org
RequireAND: all must holdand the person is in the group family
ExcludeNOT: any one blocksbut not old-laptop@example.com

Two warnings from the documentation are worth repeating. Bypass “does not enforce any Access security controls”, so don’t use it as a shortcut for internal apps. And an Include rule of “login method: one-time PIN” lets in anyone with a working email address. Name the people instead.

What logging in looks like
#

With one-time PIN login, you don’t need Google or GitHub set up at all:

  1. You open the app’s address and Cloudflare shows its login page.
  2. You type your email. If a policy allows that address, a code arrives. The page says “A code has been emailed to you” either way, so nobody can use it to test which addresses are allowed.
  3. You enter the code. It’s single-use and expires 10 minutes after it was requested.

A worked example: a private app with no open port
#

Here’s the shape of it, for a small web app running on a home machine at localhost:8000. The commands are cloudflared’s locally managed tunnel steps; names are placeholders.

cloudflared tunnel login                 # opens a browser; pick the zone
cloudflared tunnel create home-app       # prints a tunnel UUID and writes a credentials file
cloudflared tunnel route dns home-app app.example.com   # CNAME → <UUID>.cfargotunnel.com
# ~/.cloudflared/config.yml
tunnel: <Tunnel-UUID>
credentials-file: /home/user1/.cloudflared/<Tunnel-UUID>.json
ingress:
  - hostname: app.example.com
    service: http://localhost:8000
  - service: http_status:404             # the required catch-all: anything else gets a 404
cloudflared tunnel run home-app

At this point the app is reachable from the internet, but not yet protected. Before sharing the address, add an Access application for app.example.com in the Zero Trust dashboard, with one Allow policy:

Application:  app.example.com (self-hosted)
Policy:       Family   (Allow)
  Include:    Emails   you@example.com, partner@example.com
Login:        One-time PIN
Session:      24 hours

Then check it from a private window: you should get Cloudflare’s login page, not the app. And from outside your network, the machine itself should have no open port to find.

Where I’d use it
#

I haven’t set any of this up yet. In the bhanuni.in post I noted that a family-only area for photos and videos doesn’t belong in a public repository. It should be a private site behind Access. That’s the first job. The second is the old habit of opening a port “just for a weekend” to reach something at home. With a tunnel there’s no port to forget to close.

What I’ll be careful about:

  • The identity is now the key. If someone takes over the email account, the PIN goes to them. Protect those mailboxes with 2FA.
  • Cloudflare becomes the gate. If the account is compromised, so is every app behind it. That’s part 3, step 1, again.
  • Keep cloudflared updated, like any other software with a connection to the internet.

Takeaways
#

  • Zero trust means no trust from location: check the person and the device on every request, and give the least access that works.
  • Cloudflare Access puts an identity check in front of an app, and it’s deny by default.
  • Cloudflare Tunnel connects a server outwards, so the app needs no open port and no public address.
  • One-time PIN login needs no identity provider. Name the people in the policy; never allow “anyone with an email”.
  • The free plan covers 50 users, plenty for a family or a small team.

References
#

That’s the series. The next post on the shelf, when I’ve built it, will be the private family area behind Access.

Author
Samarthya
Engineer, learner, tinkerer. This is my trophy shelf of everyday work and leisure.
Cloudflare, plainly - This article is part of a series.
Part 4: This Article

Related

Cloudflare Part 3: the free tier, and what you should do with it

The free plan is where most personal sites start, and many never need anything else. The catch is that the useful parts are mostly switched off, or left at gentle defaults. This post lists what $0 buys, with the real limits, and then the settings I’d change on a Saturday morning, in order. What the free plan includes, in numbers Part 1 explained the front desk, and part 2 showed what it did for my domains, including what I haven’t done yet. This part is the general version, for your own domain.

Cloudflare Part 2: how it secured my two sites

After the blog was hacked, I had two jobs: get off the server that let it happen, and make sure whatever stayed there was hard to reach. Cloudflare did most of the second job, though not all of it. This post goes through each risk, the setting that answers it, and what’s still open. Two domains, every record with a job Part 1 covered the front desk in general. This post is about my own front desks. Earlier posts have the click-by-click detail; here I’m looking at what each step protects against.

Cloudflare Part 1: an introduction

Think of a hotel. Guests never walk straight to a room: they talk to the front desk, which checks who they are, answers what it can, and only calls up to the room when it has to. Cloudflare is a front desk for a website. This series is about what that desk does, how it protected my two domains, and what you get from it for free. Two ways to reach a site: through the front desk, or around it I’ve used Cloudflare for a month now, for samarthya.me since the blog moved after the hack and for bhanuni.in. Earlier posts showed single steps. This series puts them together, starting with the basics.