↓ Skip to main content
Security

Cloudflare Part 1: an introduction

Cloudflare, plainly - This article is part of a series.
Part 1: This Article
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.
A visitor reaches the origin two ways. Orange cloud, proxied: through the Cloudflare edge, present in 348 cities, which answers DNS and handles TLS, cache, rules and the WAF. Grey cloud, DNS only: straight to the origin.
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.

Words used in this post
#

TermMeaning here
DNSThe internet’s phone book: turns a name such as example.com into the address of a machine
NameserverThe server that answers DNS questions for a domain
OriginThe server that really holds the site’s files
EdgeCloudflare’s servers close to the visitor, which answer first
ProxyA middleman that receives a request and decides what to do with it, instead of the origin
TLSThe encryption behind https://, with a certificate proving who the server is
CDNContent delivery network: copies of files kept near visitors so they load fast

What Cloudflare is
#

Cloudflare runs one large network and sells (or gives away) many services on top of it. The network is the important part: its network page lists data centres in 348 cities, and says 95% of the world’s internet-connected population is within 50 milliseconds of one of them.

For a small site the services fall into four groups:

GroupWhat it doesI use it for
DNSAnswers “where is this name?”Both domains
Proxy and CDNAnswers as your site: TLS, cache, redirectswww, about, the old blog name, bhanuni.in
SecurityDDoS protection, a firewall for web requests (WAF), bot detectionWhatever is proxied
Zero TrustLogins in front of private apps, tunnels to machines with no open portNext on my list (part 4)

There are also developer products (Workers, Pages, storage). They’re useful, but they’re not the subject here.

Step 1: Cloudflare becomes your phone book
#

Everything starts with DNS. You add your domain to Cloudflare, and Cloudflare gives you two nameservers. At your registrar (the shop you rent the name from) you replace the old nameservers with those two. From then on, when anyone asks “where is example.com?”, Cloudflare answers.

That step alone changes nothing visible. The answers are the same; only who gives them has changed. That’s why it’s the safe first step, and why I took it on its own (Rebuilding, part 4).

Step 2: orange cloud or grey cloud
#

Every address record in Cloudflare (A, AAAA, CNAME) has a switch with two positions, drawn as a cloud:

Grey cloud: DNS onlyOrange cloud: Proxied
What a lookup returnsThe origin’s real addressCloudflare’s own addresses
Who the visitor talks toThe origin, directlyCloudflare, which then talks to the origin (or doesn’t)
Cloudflare’s TLS, cache, rules, WAFNot appliedApplied
Works for mail?YesNo: Cloudflare proxies only A, AAAA and CNAME

That switch is the whole idea. With the grey cloud, Cloudflare is a phone book. With the orange cloud, it’s the front desk: the visitor’s browser connects to the nearest Cloudflare server, which decides whether to answer from its cache, send a redirect, block the request, or forward it to the origin.

You can see which one you’re getting:

# Who answered? A proxied name says "server: cloudflare" and carries a cf-ray id.
curl -sI https://www.example.com/ | grep -i "^server\|^cf-ray"

For my blog itself the answer is Server: GitHub.com: it’s DNS only, on purpose (part 2 explains why). For www.samarthya.me it’s Server: cloudflare, because Cloudflare answers that name itself.

Step 3: what the front desk does
#

Once a name is proxied, a request goes through a fixed set of stations at the edge. Simplified:

  1. DDoS protection drops floods before they reach anything else. It’s on every plan, unmetered.
  2. TLS. Cloudflare presents a certificate to the visitor. Universal SSL gives a free one for the apex and first-level subdomains, renewed automatically.
  3. Rules and the WAF. Redirects, blocks and challenges, written as small expressions such as http.host eq "blog.example.com".
  4. Cache. If a stored copy is fresh, it’s served from the edge and the origin never hears about it.
  5. The origin, only if none of the above answered. Cloudflare connects to it with its own TLS connection, which you can make it verify (Full (strict), part 2).

The order is the point. Most of what reaches a small site is noise: scanners, old links, bots. Each station that answers first is one request your server never sees.

What it doesn’t do
#

The proxy doesn’t make a weak origin safe:

  • It doesn’t hide a server that’s public in other ways. My about host also runs mail, and mail records have to point at the real machine. Anyone who looks can find it.
  • It doesn’t fix the application. A vulnerable plugin is still vulnerable when the request is allowed through.
  • It adds a dependency. If Cloudflare has a bad day, so does every proxied site. And settings like strict TLS turn mistakes at the origin, such as an expired certificate, into an outage.

I treat it the way I’d treat a good receptionist: it cuts down the traffic and catches the obvious cases. Every room still needs a lock.

Where my two domains sit
#

NameCloudWhy
samarthya.me (this blog)GreyGitHub Pages already serves it fast and renews its own certificate
www, the old blog nameOrangeCloudflare answers with a redirect; GitHub is never asked
about.samarthya.meOrangeThe origin is the old host, so it gets a front desk
mail and friendsGreyMail can’t be proxied
bhanuni.inOrangeThere’s no server at all; Cloudflare answers every request with a redirect

Takeaways
#

  • Cloudflare is DNS first. Moving the nameservers is the safe step that changes nothing visible.
  • The orange/grey switch decides everything else: proxied names get Cloudflare’s TLS, rules, cache and WAF, and DNS-only names get none of it.
  • The edge answers in a fixed order (DDoS, TLS, rules, cache, origin), so every station that answers saves the origin a request.
  • A proxy cuts the noise reaching a weak server. It doesn’t make that server safe.

References
#

Next: part 2, what all this did for samarthya.me and bhanuni.in.

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 1: This Article

Related

Building about.samarthya.me, part 3: Cloudflare in front

The hub lives on an old server I no longer fully trust. So it gets a receptionist: every visitor talks to Cloudflare, and only Cloudflare talks to the server. This post is about setting up that front desk, record by record. One domain, four kinds of record, one front desk Part 1 and part 2 produced the data. Before the site can be published (part 6), it needs an address, a certificate and a sensible cache.

bhanuni.in: a domain, a redirect and a gallery that keeps her safe

In 2019 I booked a domain in my daughter’s name, bhanuni.in, and then did nothing with it for almost six years. It sat in a drawer like a gift card. She now draws every day (digitally & otherwise) (ponies - MLP, Sprunki, Rat-A-Tat, Sab Jholmaal hai and weekend sessions as part of a group), so the domain finally has a job: it opens her gallery. This post is all about how I wired it up, why I picked the boring option, and the precautions I take before any of her pictures go online. The redirect, and the importer every drawing goes through New to RDAP, SPF, DMARC or a proxied record? Every term in this post is explained in plain words in Keywords at the end. What I wanted # Three things, in this order:

Building about.samarthya.me, part 6: Shipping to a server I don't trust, and keeping it fresh

Imagine delivering furniture to a house that was burgled last month. You don’t just drop the boxes at the door: you check the locks, take away anything that isn’t yours, and photograph every room before you leave. That’s how this site gets published. Build, ship, prove, then stay fresh The site from part 5 is thirty files on my PC. The server they go to is the shared host whose WordPress site was compromised in October. It still runs my email and it can serve files; it’s the only server I have for this. So the rule for everything below is: treat the server as untrusted storage. It holds files; it never runs code; and I check what it serves.