You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CLOUDFLAREAPI: Add per-record CNAME flattening support (#4020)
Add support for Cloudflare's per-record CNAME flattening feature using
CF_CNAME_FLATTEN_ON and CF_CNAME_FLATTEN_OFF modifiers, similar to the
existing CF_PROXY_ON/OFF pattern.
CNAME flattening resolves CNAME targets to their IP addresses at
Cloudflare's edge, which can improve performance and compatibility. This
feature requires a paid Cloudflare plan (Pro, Business, or Enterprise).
New record modifiers for CNAME records:
- CF_CNAME_FLATTEN_ON: Enable CNAME flattening for the record
- CF_CNAME_FLATTEN_OFF: Disable CNAME flattening (default)
Example usage:
```javascript
D("example.com", REG, DSP,
CNAME("cdn", "cdn.provider.com.", CF_CNAME_FLATTEN_ON),
CNAME("www", "www.example.com.", CF_CNAME_FLATTEN_OFF),
);
```
- Uses Cloudflare API's `settings.flatten_cname` field
- Stores state in record metadata as `cloudflare_cname_flatten`
- Only applies to CNAME record types
- Integrated with diff detection via genComparable()
- pkg/js/helpers.js: Add CF_CNAME_FLATTEN_ON/OFF constants
- commands/types/others.d.ts: Add TypeScript declarations for IDE
support
- providers/cloudflare/cloudflareProvider.go:
- Add metaCNAMEFlatten constant
- Add checkCNAMEFlattenVal() validation function
- Update preprocessConfig() to validate CNAME flatten setting
- Update nativeToRecord() to read settings.flatten_cname from API
- Update genComparable() to include flatten state in diff comparison
- providers/cloudflare/rest.go:
- Update createRecDiff2() to set Settings.FlattenCNAME
- Update modifyRecord() to set Settings.FlattenCNAME
- commands/getZones.go:
- Update TSV export to include cloudflare_cname_flatten metadata
- Update JS/DJS export to include CF_CNAME_FLATTEN_ON modifier
- pkg/prettyzone/prettyzone.go:
- Update zone file export to include CF_CNAME_FLATTEN_ON comment
Added gated integration tests that are disabled by default since CNAME
flattening requires a paid plan:
- integrationTest/helpers_test.go: Add -cfflatten flag (default false)
- integrationTest/helpers_integration_test.go: Add test helper functions
- integrationTest/integration_test.go: Add CF_CNAME_FLATTEN test groups
Run tests on paid zones with: go test -v -provider=CLOUDFLAREAPI
-cfflatten=true
Updated documentation/provider/cloudflareapi.md with:
- New CNAME flattening section with usage examples
- Warning about paid plan requirement
- Integration test flag documentation
If a domain does not exist in your Cloudflare account, DNSControl
202
205
will automatically add it when `dnscontrol push` is executed.
203
206
207
+
## CNAME flattening
208
+
209
+
Cloudflare supports [CNAME flattening](https://developers.cloudflare.com/dns/cname-flattening/), which resolves CNAME targets to their IP addresses at the edge. This can be enabled zone-wide (for zones on paid Cloudflare plans) or per-record.
210
+
211
+
DNSControl supports per-record CNAME flattening using the `CF_CNAME_FLATTEN_ON` modifier:
**Paid plans only:** Per-record CNAME flattening requires a Cloudflare paid subscription (Pro, Business, or Enterprise). Free plans do not support this feature. If you attempt to enable CNAME flattening on a free zone, the Cloudflare API will return an error.
231
+
{% endhint %}
232
+
233
+
For more information, see [Cloudflare's CNAME flattening documentation](https://developers.cloudflare.com/dns/cname-flattening/).
204
234
205
235
## Old-style vs new-style redirects
206
236
@@ -421,6 +451,18 @@ go test -v -verbose -profile CLOUDFLAREAPI -cfworkers=false
421
451
422
452
When `-cfworkers=false` is set, tests related to Workers are skipped. The Account ID is not required.
423
453
454
+
### CNAME flattening tests
455
+
456
+
Tests for per-record CNAME flattening (`CF_CNAME_FLATTEN_ON`/`CF_CNAME_FLATTEN_OFF`) are disabled by default
457
+
because they require a paid Cloudflare plan. To enable these tests, use the `-cfflatten=true` flag:
458
+
459
+
```shell
460
+
cd integrationTest
461
+
go test -v -verbose -profile CLOUDFLAREAPI -cfflatten=true
462
+
```
463
+
464
+
If you run with `-cfflatten=true` on a free zone, the tests will fail with an error from the Cloudflare API.
465
+
424
466
## Cloudflare special TTLs
425
467
426
468
Cloudflare plays tricks with TTLs. Cloudflare uses "1" to mean "auto-ttl";
0 commit comments