Multi-Provider DNS Pointing & Failover Design
OpenFlare idempotently reconciles explicit and wildcard hostnames (of_zone_domains) to external DNS providers—Cloudflare, Alibaba Cloud DNS, and Tencent Cloud DNSPod—using unified DNS accounts and pointing groups. It supports node-backed A records with automated failover, custom A/AAAA/CNAME records, and SmartDNS CNAME delegation without turning Zones into a general-purpose DNS control plane.
1. Unified DNS Accounts & Scope Routing
- Provider adapters (
internal/openflare/dnsprovider): Supportscloudflare(with proxy toggle and one-click delegation),alidns(Alibaba Cloud DNS, with one-click delegation), andtencentcloud(Tencent Cloud DNSPod). - Credential & zone discovery (
internal/apps/openflare/dnsaccount): Encrypted credentials reside inof_dns_accounts. Verification and scheduled daily refreshes populate authorizedscopes,verification_status(ready/error), andlast_checked_at. - Longest-suffix routing (
dnsaccount.Resolve): Selects the account owning the most specific matching zone for a hostname; when multiple accounts match at equal specificity, preference follows the member'sdns_account_idor migrated connection account. - Legacy credential migration: Migration
202611280002imports legacy standalone Cloudflare credentials fromof_cf_connectionsintoof_dns_accounts, retaining a fallback path until the linked account runs scope verification.
2. Target Modes & Data Model
Group Target Modes (of_cf_pointing_groups.target_mode)
| Mode | Record Created | Behavior |
|---|---|---|
node | Single A record | Points to active_node_id IPv4 with primary/backup health failover and failback |
custom | A, AAAA, or CNAME | Writes the group's explicit record_type and record_content |
smartdns | DNS-only CNAME | Points to smartdns_target_host under the delegated zone, bound to smartdns_policy_id, with proxy forced off |
Proxy Flag & Group TTL
- Proxy (
proxied): Effective only on proxy-capable providers (Cloudflare) outsidesmartdnsmode.default_proxiedinitializes newly added members without overwriting existing ones; AliDNS and Tencent Cloud records forceproxied = false. - Group TTL: Supports
1(Cloudflare Auto; falls back to600s on AliDNS/Tencent Cloud) or manual integers60–86400seconds (legacy0resolves to300s). Proxied records always use automatic TTL.
3. Automated Node Failover & Quarantine Handoff
- Scheduled failover (
cloudflare:failover_check→CheckNodeFailover): Evaluates enablednodegroups against node health (not quarantined, notoffline, notunhealthy, emptylast_error,last_seen_atwithin 60 s):- Automatically fails back to
primary_node_idonce healthy; - Switches
active_node_idto a healthybackup_node_idwhen the primary becomes unhealthy and enqueues group reconciliation.
- Automatically fails back to
- Quarantine failover (
FailoverQuarantinedNode): Immediately switches affectednodegroups away from a quarantined node to a healthy peer and dispatches synchronization.
4. Idempotent Reconciliation & Concurrency
- 64-stripe member locking:
ReconcileMemberlocks bymemberID % 64to prevent concurrent duplicate record creation. - Cached update & single-record takeover: Updates cached
cf_record_iddirectly when account andcf_zone_idmatch (deleting and recreating if record type changed). Otherwise lists byname + type: creates on0matches, takes over on1match, and errors on multiple matches to avoid overwriting unmanaged load-balanced records. - Cleanup on removal:
DeleteManagedRecordremoves only the module-managed record when a member or group is deleted. - Async workers: Group, node-IP-change, and batch updates dispatch through Asynq (
cloudflare:sync_member,cloudflare:sync_group,cloudflare:sync_by_node), keeping node heartbeats non-blocking.