GithubHelp home page GithubHelp logo

coredns / alternate Goto Github PK

View Code? Open in Web Editor NEW
21.0 21.0 19.0 273 KB

Plugin Alternate is able to selectively forward the query to another upstream server, depending the error result provided by the initial resolver

License: Apache License 2.0

Makefile 4.64% Go 95.36%

alternate's Introduction

CoreDNS

Documentation CodeQL Go Tests CircleCI Code Coverage Docker Pulls Go Report Card CII Best Practices

CoreDNS is a DNS server/forwarder, written in Go, that chains plugins. Each plugin performs a (DNS) function.

CoreDNS is a Cloud Native Computing Foundation graduated project.

CoreDNS is a fast and flexible DNS server. The key word here is flexible: with CoreDNS you are able to do what you want with your DNS data by utilizing plugins. If some functionality is not provided out of the box you can add it by writing a plugin.

CoreDNS can listen for DNS requests coming in over:

Currently CoreDNS is able to:

  • Serve zone data from a file; both DNSSEC (NSEC only) and DNS are supported (file and auto).
  • Retrieve zone data from primaries, i.e., act as a secondary server (AXFR only) (secondary).
  • Sign zone data on-the-fly (dnssec).
  • Load balancing of responses (loadbalance).
  • Allow for zone transfers, i.e., act as a primary server (file + transfer).
  • Automatically load zone files from disk (auto).
  • Caching of DNS responses (cache).
  • Use etcd as a backend (replacing SkyDNS) (etcd).
  • Use k8s (kubernetes) as a backend (kubernetes).
  • Serve as a proxy to forward queries to some other (recursive) nameserver (forward).
  • Provide metrics (by using Prometheus) (prometheus).
  • Provide query (log) and error (errors) logging.
  • Integrate with cloud providers (route53).
  • Support the CH class: version.bind and friends (chaos).
  • Support the RFC 5001 DNS name server identifier (NSID) option (nsid).
  • Profiling support (pprof).
  • Rewrite queries (qtype, qclass and qname) (rewrite and template).
  • Block ANY queries (any).
  • Provide DNS64 IPv6 Translation (dns64).

And more. Each of the plugins is documented. See coredns.io/plugins for all in-tree plugins, and coredns.io/explugins for all out-of-tree plugins.

Compilation from Source

To compile CoreDNS, we assume you have a working Go setup. See various tutorials if you don’t have that already configured.

First, make sure your golang version is 1.21 or higher as go mod support and other api is needed. See here for go mod details. Then, check out the project and run make to compile the binary:

$ git clone https://github.com/coredns/coredns
$ cd coredns
$ make

This should yield a coredns binary.

Compilation with Docker

CoreDNS requires Go to compile. However, if you already have docker installed and prefer not to setup a Go environment, you could build CoreDNS easily:

docker run --rm -i -t \
    -v $PWD:/go/src/github.com/coredns/coredns -w /go/src/github.com/coredns/coredns \
        golang:1.21 sh -c 'GOFLAGS="-buildvcs=false" make gen && GOFLAGS="-buildvcs=false" make'

The above command alone will have coredns binary generated.

Examples

When starting CoreDNS without any configuration, it loads the whoami and log plugins and starts listening on port 53 (override with -dns.port), it should show the following:

.:53
CoreDNS-1.6.6
linux/amd64, go1.16.10, aa8c32

The following could be used to query the CoreDNS server that is running now:

dig @127.0.0.1 -p 53 www.example.com

Any query sent to port 53 should return some information; your sending address, port and protocol used. The query should also be logged to standard output.

The configuration of CoreDNS is done through a file named Corefile. When CoreDNS starts, it will look for the Corefile from the current working directory. A Corefile for CoreDNS server that listens on port 53 and enables whoami plugin is:

.:53 {
    whoami
}

Sometimes port number 53 is occupied by system processes. In that case you can start the CoreDNS server while modifying the Corefile as given below so that the CoreDNS server starts on port 1053.

.:1053 {
    whoami
}

If you have a Corefile without a port number specified it will, by default, use port 53, but you can override the port with the -dns.port flag: coredns -dns.port 1053, runs the server on port 1053.

You may import other text files into the Corefile using the import directive. You can use globs to match multiple files with a single import directive.

.:53 {
    import example1.txt
}
import example2.txt

You can use environment variables in the Corefile with {$VARIABLE}. Note that each environment variable is inserted into the Corefile as a single token. For example, an environment variable with a space in it will be treated as a single token, not as two separate tokens.

.:53 {
    {$ENV_VAR}
}

A Corefile for a CoreDNS server that forward any queries to an upstream DNS (e.g., 8.8.8.8) is as follows:

.:53 {
    forward . 8.8.8.8:53
    log
}

Start CoreDNS and then query on that port (53). The query should be forwarded to 8.8.8.8 and the response will be returned. Each query should also show up in the log which is printed on standard output.

To serve the (NSEC) DNSSEC-signed example.org on port 1053, with errors and logging sent to standard output. Allow zone transfers to everybody, but specifically mention 1 IP address so that CoreDNS can send notifies to it.

example.org:1053 {
    file /var/lib/coredns/example.org.signed
    transfer {
        to * 2001:500:8f::53
    }
    errors
    log
}

Serve example.org on port 1053, but forward everything that does not match example.org to a recursive nameserver and rewrite ANY queries to HINFO.

example.org:1053 {
    file /var/lib/coredns/example.org.signed
    transfer {
        to * 2001:500:8f::53
    }
    errors
    log
}

. {
    any
    forward . 8.8.8.8:53
    errors
    log
}

IP addresses are also allowed. They are automatically converted to reverse zones:

10.0.0.0/24 {
    whoami
}

Means you are authoritative for 0.0.10.in-addr.arpa..

This also works for IPv6 addresses. If for some reason you want to serve a zone named 10.0.0.0/24 add the closing dot: 10.0.0.0/24. as this also stops the conversion.

This even works for CIDR (See RFC 1518 and 1519) addressing, i.e. 10.0.0.0/25, CoreDNS will then check if the in-addr request falls in the correct range.

Listening on TLS (DoT) and for gRPC? Use:

tls://example.org grpc://example.org {
    whoami
}

Similarly, for QUIC (DoQ):

quic://example.org {
    whoami
    tls mycert mykey
}

And for DNS over HTTP/2 (DoH) use:

https://example.org {
    whoami
    tls mycert mykey
}

in this setup, the CoreDNS will be responsible for TLS termination

you can also start DNS server serving DoH without TLS termination (plain HTTP), but beware that in such scenario there has to be some kind of TLS termination proxy before CoreDNS instance, which forwards DNS requests otherwise clients will not be able to communicate via DoH with the server

https://example.org {
    whoami
}

Specifying ports works in the same way:

grpc://example.org:1443 https://example.org:1444 {
    # ...
}

When no transport protocol is specified the default dns:// is assumed.

Community

We're most active on Github (and Slack):

More resources can be found:

Contribution guidelines

If you want to contribute to CoreDNS, be sure to review the contribution guidelines.

Deployment

Examples for deployment via systemd and other use cases can be found in the deployment repository.

Deprecation Policy

When there is a backwards incompatible change in CoreDNS the following process is followed:

  • Release x.y.z: Announce that in the next release we will make backward incompatible changes.
  • Release x.y+1.0: Increase the minor version and set the patch version to 0. Make the changes, but allow the old configuration to be parsed. I.e. CoreDNS will start from an unchanged Corefile.
  • Release x.y+1.1: Increase the patch version to 1. Remove the lenient parsing, so CoreDNS will not start if those features are still used.

E.g. 1.3.1 announce a change. 1.4.0 a new release with the change but backward compatible config. And finally 1.4.1 that removes the config workarounds.

Security

Security Audits

Third party security audits have been performed by:

Reporting security vulnerabilities

If you find a security vulnerability or any security related issues, please DO NOT file a public issue, instead send your report privately to [email protected]. Security reports are greatly appreciated and we will publicly thank you for it.

Please consult security vulnerability disclosures and security fix and release process document

alternate's People

Contributors

andrewloux avatar chrisohaver avatar dependabot[bot] avatar ekleiner avatar johnbelamaric avatar michaelbeaumont avatar miekg avatar mparamonau avatar rsvalerio avatar superq avatar yuewko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

alternate's Issues

Use a single alternate block to reduce repetition

In the use-case where you want to forward the query based on multiple rcodes; I currently have to do something like this:

alternate NXDOMAIN . 192.168.1.1:53
alternate SERVFAIL . 192.168.1.1:53

Would like to submit a pull-request to make a single block support multiple rcodes, but was looking for some insight into how the interface should look. As it is a non-optional argument, I think it should be inlined like so:

alternate NXDOMAIN,SERVFAIL . 192.168.1.1:53

Let me know what you folks think.

Support nested alternates

I'm interested in adding an alternate for an alternate. For example, something like this:
...
alternate NXDOMAIN . 8.8.8.8 {
alternate NXDOMAIN . 192.168.1.1:53
}

Is that possible? Let me know what you folks think.

Travis is failing

I think need a sync-up of vendor CoreDNS or Prometheus ...
(the same issue was fixed in CoreDNS recently)

see : https://travis-ci.org/coredns/alternate

github.com/coredns/coredns/coremain
github.com/coredns/coredns/plugin/metrics
# github.com/coredns/coredns/plugin/metrics
../coredns/plugin/metrics/metrics.go:43:49: too many arguments in call to prometheus.NewProcessCollector
	have (int, string)
	want (prometheus.ProcessCollectorOpts)
make: *** [get] Error 2
The command "make" exited with 2.

Unable to use this plugin

Hi,

I compiled the plugin with coredns.

My Corefile looks like this:

.:533 {
    forward . 8.8.8.8
    alternate NXDOMAIN . 127.0.0.1:5353
    log
}

Query to 127.0.0.1:533 for a domain that exist in 127.0.0.1:5353 returns NXDOMAIN. Also shutting down DNS server on 127.0.0.1:5353 and running the query again doesn't produce any error in coredns logs. Strange...

How I can see if alternate is running?

Regards.

CoreDNS issue under load

Hi,
I'm using CoreDNS with alternate plugin as high available DNS alongside Unbound DNS. the server is getting around 60K/s
My config is:

.:53 {
    debug
    loop
    bind 10.x.x.1
    bind 10.x.x.2
    bind 37.x.x.3
    bind 127.0.0.1

    forward . 127.0.0.1:9053

    alternate original SERVFAIL,REFUSED . 37.x.x.4 37.x.x.5

    reload 30s

    cache 300 {
        success 50000
        denial 25000
    }

    prometheus localhost:9253
}

If I kill the local Unbound instance :9053 CoreDNS displays messages like the following:

[DEBUG] Wrong reply for id: 42177, img.like.video. 1
debug: 000000 a4 c1 01 00 00 01 00 00 00 00 00 01 03 69 6d 67
debug: 000010 04 6c 69 6b 65 05 76 69 64 65 6f 00 00 01 00 01
debug: 000020 00 00 29 08 00 00 00 80 00 00 00
debug: 00002b
[DEBUG] Wrong reply for id: 52794, e1329.g.akamaiedge.net. 1
debug: 000000 ce 3a 01 00 00 01 00 00 00 00 00 01 05 65 31 33
debug: 000010 32 39 01 67 0a 61 6b 61 6d 61 69 65 64 67 65 03
debug: 000020 6e 65 74 00 00 01 00 01 00 00 29 08 00 00 00 80
debug: 000030 00 00 00
debug: 000033
[DEBUG] Wrong reply for id: 24443, me-du.shadow.igamecj.com. 1
debug: 000000 5f 7b 01 00 00 01 00 00 00 00 00 01 05 6d 65 2d
debug: 000010 64 75 06 73 68 61 64 6f 77 07 69 67 61 6d 65 63

Then the DNS queries start to get dropped, and after a minute or so, the container of CoreDNS exits.
The logs I shared were the last messages from CoreDNS before it crash.

Any hints on this?

EDIT: CoreDNS version is 1.8.6 and 1.8.7 same issue.

FeatureRequest: Redirect to alternate upstream in no data in ANSWER section

Hello,

Would it be possible to add condition to redirect if there are no data in ANSWER section of response from first upstream?

For example:
I am querying for TXT record of example.com
CoreDNS will query first backend and will got response with NOERROR, but no data in ANSWER section (there is no TXT record for this domain on first backend, but domain exists and has an A record for example).
But there is second backend, which does have TXT record for example.com.

go get fails

I am having an issue with "go get github.com/coredns/alternate" It looks like its failing to find the proxy plugin.

github.com/coredns/coredns/plugin/pkg/proxy: cannot find module providing package github.com/coredns/coredns/plugin/pkg/proxy

#12 [builder  8/12] RUN echo "alternate:github.com/coredns/alternate" >> /go/coredns/plugin.cfg
#12 DONE 0.3s

#13 [builder  9/12] RUN go get github.com/coredns/alternate
#13 1.962 go: downloading github.com/coredns/alternate v0.0.0-20230808153232-6204d80011e7
#13 74.71 go: downloading github.com/miekg/dns v1.1.55
#13 74.71 go: downloading golang.org/x/net v0.14.0
#13 74.72 go: downloading google.golang.org/grpc v1.57.0
#13 74.73 go: downloading github.com/prometheus/client_golang v1.16.0
#13 74.74 go: downloading github.com/dnstap/golang-dnstap v0.4.0
#13 75.29 go: downloading google.golang.org/protobuf v1.31.0
#13 75.49 go: downloading golang.org/x/sys v0.11.0
#13 75.49 go: downloading github.com/farsightsec/golang-framestream v0.3.0
#13 75.50 go: downloading golang.org/x/tools v0.9.1
#13 75.64 go: downloading github.com/cespare/xxhash/v2 v2.2.0
#13 75.64 go: downloading github.com/prometheus/client_model v0.4.0
#13 75.64 go: downloading github.com/prometheus/common v0.44.0
#13 75.86 go: downloading github.com/prometheus/procfs v0.10.1
#13 75.89 go: downloading google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130
#13 75.90 go: downloading github.com/matttproud/golang_protobuf_extensions v1.0.4
#13 75.99 go: downloading github.com/golang/protobuf v1.5.3
#13 76.07 go: downloading golang.org/x/text v0.12.0
#13 76.57 go: downloading golang.org/x/mod v0.10.0
#13 77.31 go: downloading google.golang.org/genproto/googleapis/rpc v0.0.0-20230720185612-659f7aaaa771
#13 82.04 go: github.com/coredns/alternate imports
#13 82.04       github.com/coredns/coredns/plugin/pkg/proxy: cannot find module providing package github.com/coredns/coredns/plugin/pkg/proxy
#13 82.43 go: downloading cloud.google.com/go/compute v1.20.1
#13 82.48 go: downloading github.com/Azure/azure-sdk-for-go v68.0.0+incompatible
#13 82.48 go: downloading github.com/Azure/go-autorest/autorest v0.11.29
#13 82.48 go: downloading github.com/Azure/go-autorest/autorest/adal v0.9.22
#13 82.48 go: downloading github.com/Azure/go-autorest/autorest/azure/auth v0.5.12
#13 82.60 go: downloading github.com/DataDog/datadog-agent/pkg/obfuscate v0.45.0-rc.1
#13 82.60 go: downloading github.com/DataDog/datadog-go/v5 v5.1.1
#13 82.60 go: downloading github.com/Microsoft/go-winio v0.5.2
#13 82.67 go: downloading github.com/antonmedv/expr v1.12.7
#13 82.67 go: downloading github.com/aws/aws-sdk-go v1.44.317
#13 82.68 go: downloading github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534
#13 82.69 go: downloading github.com/dustin/go-humanize v1.0.1
#13 82.73 go: downloading github.com/emicklei/go-restful/v3 v3.10.2
#13 82.75 go: downloading github.com/go-logr/logr v1.2.4
#13 82.76 go: downloading github.com/go-openapi/jsonpointer v0.19.6
#13 82.97 go: downloading github.com/go-openapi/jsonreference v0.20.1
#13 82.98 go: downloading github.com/go-openapi/swag v0.22.3
#13 83.04 go: downloading github.com/golang-jwt/jwt/v4 v4.5.0
#13 83.04 go: downloading github.com/golang/glog v1.1.0
#13 83.05 go: downloading github.com/google/go-cmp v0.5.9
#13 83.10 go: downloading github.com/googleapis/enterprise-certificate-proxy v0.2.5
#13 83.10 go: downloading github.com/googleapis/gax-go/v2 v2.12.0
#13 83.10 go: downloading github.com/kr/pretty v0.3.1
#13 83.12 go: downloading github.com/onsi/ginkgo/v2 v2.9.5
#13 83.17 go: downloading github.com/onsi/gomega v1.27.6
#13 83.18 go: downloading github.com/openzipkin-contrib/zipkin-go-opentracing v0.5.0
#13 83.25 go: downloading github.com/openzipkin/zipkin-go v0.4.1
#13 83.26 go: downloading github.com/oschwald/geoip2-golang v1.9.0
#13 83.27 go: downloading github.com/oschwald/maxminddb-golang v1.11.0
#13 83.28 go: downloading github.com/philhofer/fwd v1.1.2
#13 83.32 go: downloading github.com/stretchr/objx v0.5.0
#13 83.33 go: downloading github.com/stretchr/testify v1.8.4
#13 83.35 go: downloading github.com/tinylib/msgp v1.1.8
#13 83.38 go: downloading go.etcd.io/etcd/api/v3 v3.5.9
#13 83.42 go: downloading go.etcd.io/etcd/client/pkg/v3 v3.5.9
#13 83.44 go: downloading go.etcd.io/etcd/client/v3 v3.5.9
#13 83.45 go: downloading go.opencensus.io v0.24.0
#13 83.49 go: downloading go.uber.org/atomic v1.11.0
#13 83.53 go: downloading golang.org/x/crypto v0.12.0
#13 83.54 go: downloading golang.org/x/oauth2 v0.10.0
#13 83.57 go: downloading golang.org/x/sync v0.3.0
#13 83.59 go: downloading golang.org/x/term v0.11.0
#13 83.73 go: downloading golang.org/x/time v0.3.0
#13 83.74 go: downloading golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2
#13 83.74 go: downloading google.golang.org/api v0.134.0
#13 83.74 go: downloading gopkg.in/DataDog/dd-trace-go.v1 v1.53.0
#13 83.81 go: downloading inet.af/netaddr v0.0.0-20220811202034-502d2d690317
#13 83.81 go: downloading k8s.io/api v0.27.4
#13 83.95 go: downloading k8s.io/apimachinery v0.27.4
#13 84.06 go: downloading k8s.io/client-go v0.27.4
#13 84.38 go: downloading k8s.io/klog/v2 v2.100.1
#13 84.48 go: downloading k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f
#13 84.54 go: downloading k8s.io/utils v0.0.0-20230209194617-a36077c30491
#13 84.68 go: downloading sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd
#13 84.76 go: downloading sigs.k8s.io/yaml v1.3.0
#13 ERROR: process "/bin/sh -ec go get github.com/coredns/alternate" did not complete successfully: exit code: 1
------
 > [builder  9/12] RUN go get github.com/coredns/alternate:
83.74 go: downloading gopkg.in/DataDog/dd-trace-go.v1 v1.53.0
83.81 go: downloading inet.af/netaddr v0.0.0-20220811202034-502d2d690317
83.81 go: downloading k8s.io/api v0.27.4
83.95 go: downloading k8s.io/apimachinery v0.27.4
84.06 go: downloading k8s.io/client-go v0.27.4
84.38 go: downloading k8s.io/klog/v2 v2.100.1
84.48 go: downloading k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f
84.54 go: downloading k8s.io/utils v0.0.0-20230209194617-a36077c30491
84.68 go: downloading sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd
84.76 go: downloading sigs.k8s.io/yaml v1.3.0
------
Dockerfile:17
--------------------
  15 |     RUN go get github.com/cloud66-oss/coredns_mysql
  16 |     RUN echo "alternate:github.com/coredns/alternate" >> /go/coredns/plugin.cfg
  17 | >>> RUN go get github.com/coredns/alternate
  18 |     RUN go generate
  19 |     RUN CGO_ENABLED=1 go build
--------------------

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.