cnamefollow

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

cnamefollow

Name

cnamefollow - re-resolves CNAME targets through CoreDNS's own server blocks when the target falls within configured authoritative zones.

Description

In split-horizon DNS environments, an external domain may CNAME into an internal zone (e.g., app.example.com CNAME app.internal.corp.). When the upstream resolver chases this CNAME, it resolves the target against the upstream resolver DNS rather than the internal authoritative servers, returning either the wrong answer or NXDOMAIN.

CoreDNS does not natively re-evaluate CNAME targets across server blocks. The cnamefollow plugin solves this by intercepting responses from the upstream resolver, detecting CNAME targets that fall within configured authoritative zones, and re-resolving those targets through CoreDNS's own server.ServeDNS() — which routes to the correct server block for that zone.

The plugin preserves the full CNAME chain in the response. It does not flatten or strip CNAME records.

How It Works

  1. The upstream resolver (via forward) returns a response containing a CNAME
  2. The plugin checks if any CNAME target is a subdomain of the configured zones
  3. If matched, it calls upstream.Lookup() which re-enters CoreDNS's server routing, matching the appropriate server block for the target zone
  4. The re-resolved answer is appended to the original CNAME, producing a complete response
  5. If no CNAME targets match, or if the re-resolution fails, the original response is returned unmodified

Syntax

cnamefollow ZONE [ZONE...]
  • ZONE — one or more authoritative zone names to match CNAME targets against

Example

internal.example.com {
    forward . 10.0.0.1 10.0.0.2
    cache 300
}

corp.example.com {
    forward . 10.0.0.1 10.0.0.2
    cache 300
}

.:53 {
    forward . 169.254.169.253
    cnamefollow internal.example.com corp.example.com
    cache 300
}

Given the following DNS records:

app.external.net.              CNAME  app.internal.example.com.    (public)
app.internal.example.com.      CNAME  k8s-elb.amazonaws.com.      (internal, AD)
k8s-elb.amazonaws.com.         A      10.1.2.3                    (internal, AD)

A query for app.external.net will:

  1. Match the . server block, forward to 169.254.169.253 (VPC resolver)
  2. VPC resolver returns: CNAME app.internal.example.com. + NXDOMAIN (or wrong public answer)
  3. Plugin detects app.internal.example.com. is in internal.example.com zone
  4. Re-resolves through the internal.example.com server block → internal DNS servers
  5. Returns the complete chain:
app.external.net.              30 IN CNAME app.internal.example.com.
app.internal.example.com.      30 IN CNAME k8s-elb.amazonaws.com.
k8s-elb.amazonaws.com.         30 IN A     10.1.2.3

Behavior Notes

  • Only operates in the server block where it is configured (typically the . catch-all)
  • Only triggers when a CNAME target is a subdomain of a configured zone
  • Queries for type CNAME are passed through without retry (preserves CNAME-only responses for DCV and similar tooling)
  • If re-resolution fails or returns no answers, the original upstream response is returned unmodified
  • Queries with no CNAME records, or CNAMEs not targeting configured zones, pass through with zero overhead

Building

Add to CoreDNS plugin.cfg before forward:

cnamefollow:github.com/robertlestak/coredns-cnamefollow
forward:forward

Then:

go generate && go build

Why This Exists

See coredns/coredns#1864 — CoreDNS does not chase CNAMEs across server block boundaries. This is a known limitation with no upstream fix as of CoreDNS v1.14.2. In enterprise split-horizon DNS environments where external domains CNAME into internal zones, this causes resolution failures or incorrect answers.

Documentation

Overview

Package cnamefollow implements a CoreDNS plugin that re-resolves CNAME targets through CoreDNS's own server blocks when the target falls within configured authoritative zones. This solves cross-zone CNAME chasing in split-horizon DNS environments where the upstream resolver returns incorrect or incomplete answers for CNAME targets in internal zones.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CnameFollow

type CnameFollow struct {
	Next  plugin.Handler
	Zones []string
	// contains filtered or unexported fields
}

CnameFollow is a plugin that intercepts responses containing CNAME records whose targets fall within configured authoritative zones, and re-resolves those targets through CoreDNS's own server routing (which will match the appropriate server block for that zone).

func New

func New(zones []string) *CnameFollow

New creates a new CnameFollow plugin instance.

func (*CnameFollow) Name

func (c *CnameFollow) Name() string

Name implements the plugin.Handler interface.

func (*CnameFollow) ServeDNS

func (c *CnameFollow) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

ServeDNS implements the plugin.Handler interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址