Off CoreDNS, then back to it with two plugins compiled in

Replacing a partner's DNS redirector containers took three attempts, and the middle one was a fourteen-week detour through BIND.

Infra

The thing being replaced was a pair of redirector containers supplied by Partner D, one per roaming partner. The replacement had two jobs: serve APN zones (apn.epc.mnc210.mcc311.3gppnetwork.org and four more) to an external partner, and advertise its own service address by BGP. That is an unusual pairing for a DNS container. It explains the base image — a DNS container that speaks BGP needs a routing daemon beside it. The first version (October 2024, CW-1689) put CoreDNS on top of the FRR image the DRA containers already use.

ARG BASE_IMAGE=registry.internal/infra/cr-frr:frr-stable-jammy@sha256:5e23a0dc8271…
FROM ${BASE_IMAGE} AS prod

ENV CONTAINER_ROUTER_SKIP_SET_HOSTNAME=true
ENV CONTAINER_ROUTER_SKIP_IP_ADD=true

Two environment flags disable the base image's own hostname and address handling; this container does both itself. Cutover was done by octet — the only coordination the two generations needed. The new containers took .109 and .110 on the bridge while the legacy redirectors kept .106 and .107, so both ran at once and the rollback was a route change.

The detour

In November 2025 the service moved off CoreDNS and onto BIND. That is one commit in the history (CW-2938 Migrate from coredns to bind for service), and it was right at the time for one reason. The zones hand out NAPTR records that steer traffic across several PGWs; stock CoreDNS returns a NAPTR set in a fixed order. Clients cache the whole set and use the first entry until the TTL expires, so the second PGW gets nothing. BIND could shuffle; CoreDNS, at that point, could only answer in file order.

BIND also brought a second image, a second configuration language, and a second way of doing everything (two zone formats for the same five zones). Fourteen weeks later (CW-3445, February 2026) the answer turned out to be smaller than either option: keep CoreDNS and compile the missing behaviour in.

Building CoreDNS from source, in the right order

CoreDNS is vendored under coredns/ with git subtree. The image builds it with two out-of-tree plugins: naptr_loadbalance, which I wrote, and upstream rrl (response rate limiting). The build order is worth writing down. Getting it wrong fails in a way that reads as a dependency problem (a missing module, not a missing file).

RUN go generate && go mod tidy && \
    CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o /coredns-binary

go generate runs directives_generate.go, which reads plugin.cfg and writes core/plugin/zplugin.go with an import line for every plugin including the two out-of-tree ones. Only after that file exists can go mod tidy resolve those modules and update go.sum. Run tidy first and it prunes the modules nothing imports yet; the build then fails on the imports generate was about to add. CGO_ENABLED=0 matters for a separate reason — the binary is copied out of golang:1.26-alpine into a jammy-based image, and a dynamically linked one would not load.

Plugin ordering inside plugin.cfg is the other non-obvious constraint. naptr_loadbalance sits at line 53 and cache at line 55, so the shuffle wraps the ResponseWriter before cache runs and applies to cached answers too. Reverse them and cache would serve one frozen order for the whole TTL — the exact failure the plugin exists to prevent. That ordering gets re-checked on every git subtree pull. The pull brings upstream's plugin.cfg back, and the two plugin lines go in by hand each time (documented in the README, because nothing enforces it).

naptr_loadbalance single   # one randomly chosen NAPTR per query
rrl . {
    responses-per-second 20
    slip-ratio 2
}

single is what production runs (one NAPTR per answer, chosen per query). slip-ratio 2 sends every second rate-limited response truncated (TC bit set) instead of dropping it. A real client then retries over TCP; an amplification attempt gets very little back.

The CI part was mostly about tags

Moving the build off Jenkins (CW-3385) took four days of small commits. Almost none of them were about Docker. A shared reusable workflow does the build, so this repository's own workflow file is twenty-five lines. One field in it is interesting (the tag list, two entries):

    with:
      image_additional_tags: |
        red
        coredns

Three commits went to the shape of that value alone (single value, then multiline, then multiline again); one removed secondary_maintainer; one removed a semgrep step to retrigger CI after a repository visibility change. The useful addition came later, in CW-3434 — paths-ignore for deployments/** and *.md. The deployment configuration lives in this same repository, and editing it should not produce a new image. A rebuilt image is a different image even when the Dockerfile has not changed.

What it cost, and what still needs doing

The image pins a base digest by sha256. It also carries dnsutils, tcpdump, net-tools and mtr-tiny, so a broken resolution can be reproduced from inside the container that served it. Bumps happen for CVEs instead of on a schedule. CoreDNS 1.14.3 on Go 1.26 went in to close a gRPC advisory; Dependabot raised the quic-go and OpenTelemetry ones separately (three PRs, March to June 2026).

What the history does not contain is a measurement (of anything). No before-and-after query latency, no memory comparison against the redirectors, no deployment-time figure. The honest summary is narrow. One image replaced two vendor containers; one plugin replaced a whole migration to BIND and back. What I would do differently is read the plugin interface before concluding the server cannot do what I need.