Edge¶
This guide covers Cloudflare as the edge in front of your apps: checking DNS zones against their name servers, hardening zones through Cloudflare's API, checking the minimum TLS version, and issuing origin certificates. Set edge to cloudflare on an app to use it; see Fleet document. The host side, including the Caddyfile that serves the certificate, is in Hosts.
Commands that call Cloudflare read the API token from CLOUDFLARE_API_TOKEN. Zone commands read the zones document, zones.json by default. Use --zones <path> for another file.
The zones document¶
zones.json lists every DNS zone the fleet owns. Print its schema with deployforge zones schema.
{
"formatVersion": "1",
"zones": [
{
"name": "example.com",
"registrar": "example-registrar",
"dns": "cloudflare",
"records": [
{
"name": "app",
"type": "A",
"values": ["203.0.113.10"],
"proxied": true,
"purpose": "app",
"source": "example-app/prod",
"host": "web-1",
"status": "present",
"check": { "path": "/readyz", "status": 200 }
}
],
"hardening": {}
}
]
}
Zone fields: name, registrar, dns (cloudflare or registrar), records, hardening and notes.
Record fields:
name: the label under the zone, or@for the zone itself.type:A,AAAA,CNAME,MX,TXTorWORKER.values: the values. For a proxied record, the origin.proxied: whether Cloudflare proxies the record.purpose:static-site,app,redirect,mail,verificationorparked.source,host,notes: where it is served from, what serves it, and anything else to know.status:present, orplanned.verifyskips planned records.check: an HTTPS request to the host that must answer as given:path,statusand an optionallocationprefix.
Check zones¶
deployforge zones validate
deployforge zones verify
deployforge zones get https://app.example.com/readyz
deployforge zones page -o zones.md
zones validatechecks the document, and that every live host name of the fleet has a record.zones verify [zone...]asks each zone's name servers for every listed record and makes the records' HTTPS checks.zones get <https-url>resolves the host at its zone's own name servers, asverifydoes, so a record added moments ago is reached even while a resolver caches its absence. It exits non-zero unless the answer has--status(default 200), and aLocationstarting with--locationwhen you set it.zones pagewrites a Markdown page of the zones document, to-oor standard output.zones schemawrites the zones document's JSON Schema, to-oor standard output.
verify has two flags for staged changes. --records-only checks the records but not their HTTPS checks, as before a planned change while a host is down. --fail-planned fails a planned record instead of skipping it, as after a step that adds records.
Harden zones¶
zones harden sets each zone's TLS settings and writes its custom rules, rate limit, Free Managed Ruleset, cache rule and www redirect. The baseline is the same for every zone. Each zone's hardening section holds only what differs. The rules carry refs beginning with fleet-; other rules in a phase are kept.
deployforge zones harden plan
deployforge zones harden apply --confirm
deployforge zones harden verify
plan [zone...]says what differs from the baseline and whatapplywould do. It changes nothing.apply [zone...] --confirmchanges what differs, then verifies. It needs--confirm.verify [zone...]checks every zone matches and exits non-zero if not.
Name zones to act on them, or leave them out for every zone with hardening. The token needs Zone Read, Zone Settings Edit, Zone WAF Edit, Cache Rules Edit, Single Redirect Edit and Bot Management Edit. Zone Read is enough for plan and verify.
The hardening section¶
{
"hardening": {
"allowCountries": ["US", "CA"],
"countryHosts": ["app", "auth"],
"botFightModeOff": true,
"wwwRedirect": true,
"rateLimit": { "path": "/login-token", "requests": 5, "whenRecord": "auth" },
"noCachePrefixes": ["/api/"]
}
}
allowCountriesandcountryHosts: the only countries allowed (ISO 3166-1 alpha-2) on the listed labels under the zone.botFightModeOff: turn Bot Fight Mode off.wwwRedirect: redirectwwwto the apex with a 301, keeping the path and query.rateLimit: limit one exact path per client address.requestsis how many one address may make in 10 seconds; the default is 5.whenRecordnames a record label that must exist before the limit applies.noCachePrefixes: path prefixes never cached, besides/and.htmldocuments.
Check the minimum TLS version¶
zones tls [<host>...] checks from outside that each host refuses TLS 1.1 and accepts TLS 1.2. With no host it checks every live stack's host names.
Origin certificates¶
An app behind Cloudflare serves a Cloudflare Origin CA certificate for its zone and *.zone. The key is made on the host and never leaves it.
origin-cert install <zone> <host>makes a key and CSR on the host with openssl, has Cloudflare sign it, and installs the certificate and key as/etc/caddy/certs/<zone>.pemand.key, owned byroot:caddy, mode 0640. Reload Caddy to serve it.--ssh-keynames the host's key.origin-cert issue <zone>reads a PEM CSR on standard input and writes the signed certificate to-oor standard output. Its ID and expiry go to standard error.--dayssets the validity: 7, 30, 90, 365, 730, 1095 or 5475 (the default, fifteen years).origin-cert list <zone>lists the zone's certificates: ID, expiry and host names.origin-cert revoke <id> --confirmrevokes a certificate. Cloudflare then refuses an origin that still serves it, so revoke a certificate you replaced only once nothing serves it.
An example of issue with a CSR you made elsewhere: