Skip to content

Commit d1bf8fd

Browse files
authored
https plugin (#1)
This pull request adds https plugin that performs DNS-over-HTTPS proxying.
1 parent f0d335a commit d1bf8fd

File tree

12 files changed

+2047
-0
lines changed

12 files changed

+2047
-0
lines changed

README.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# https
2+
3+
**https** is a [CoreDNS](https://github.com/coredns/coredns) plugin that proxies DNS messages to upstream resolvers using DNS-over-HTTPS protocol. See [RFC 8484](https://tools.ietf.org/html/rfc8484).
4+
5+
## Installation
6+
7+
External CoreDNS plugins can be enabled in one of two ways:
8+
1. [Build with compile-time configuration file](https://coredns.io/2017/07/25/compile-time-enabling-or-disabling-plugins/#build-with-compile-time-configuration-file)
9+
2. [Build with external golang source code](https://coredns.io/2017/07/25/compile-time-enabling-or-disabling-plugins/#build-with-external-golang-source-code)
10+
11+
## Syntax
12+
13+
In its most basic form:
14+
15+
~~~
16+
https FROM TO...
17+
~~~
18+
19+
* **FROM** is the base domain to match for the request to be proxied.
20+
* **TO...** are the destination endpoints to proxy to. The number of upstreams is
21+
limited to 15.
22+
23+
Multiple upstreams are randomized (see `policy`) on first use. When a proxy returns an error
24+
the next upstream in the list is tried.
25+
26+
Extra knobs are available with an expanded syntax:
27+
28+
~~~
29+
https FROM TO... {
30+
except IGNORED_NAMES...
31+
tls CERT KEY CA
32+
tls_servername NAME
33+
policy random|round_robin|sequential
34+
}
35+
~~~
36+
37+
* **FROM** and **TO...** as above.
38+
* **IGNORED_NAMES** in `except` is a space-separated list of domains to exclude from proxying.
39+
Requests that match none of these names will be passed through.
40+
* `tls` **CERT** **KEY** **CA** define the TLS properties for TLS connection. From 0 to 3 arguments can be
41+
provided with the meaning as described below
42+
43+
* `tls` - no client authentication is used, and the system CAs are used to verify the server certificate (by default)
44+
* `tls` **CA** - no client authentication is used, and the file CA is used to verify the server certificate
45+
* `tls` **CERT** **KEY** - client authentication is used with the specified cert/key pair.
46+
The server certificate is verified with the system CAs
47+
* `tls` **CERT** **KEY** **CA** - client authentication is used with the specified cert/key pair.
48+
The server certificate is verified using the specified CA file
49+
50+
* `policy` specifies the policy to use for selecting upstream servers. The default is `random`.
51+
52+
53+
## Metrics
54+
55+
If monitoring is enabled (via the *prometheus* plugin) then the following metric are exported:
56+
57+
* `coredns_https_request_duration_seconds{to}` - duration per upstream interaction.
58+
* `coredns_https_requests_total{to}` - query count per upstream.
59+
* `coredns_https_responses_total{to, rcode}` - count of RCODEs per upstream.
60+
and we are randomly (this always uses the `random` policy) spraying to an upstream.
61+
62+
## Examples
63+
64+
Proxy all requests within `example.org.` to a DoH nameserver:
65+
66+
~~~ corefile
67+
example.org {
68+
https . cloudflare-dns.com/dns-query
69+
}
70+
~~~
71+
72+
Forward everything except requests to `example.org`
73+
74+
~~~ corefile
75+
. {
76+
https . dns.quad9.net/dns-query {
77+
except example.org
78+
}
79+
}
80+
~~~
81+
82+
Load balance all requests between multiple upstreams
83+
84+
~~~ corefile
85+
. {
86+
https . dns.quad9.net/dns-query cloudflare-dns.com:443/dns-query dns.google/dns-query
87+
}
88+
~~~
89+
90+
Internal DoH server:
91+
92+
~~~ corefile
93+
. {
94+
https . 10.0.0.10:853/dns-query {
95+
tls ca.crt
96+
tls_servername internal.domain
97+
}
98+
}
99+
~~~

go.mod

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module github.com/v-byte-cpu/coredns-https
2+
3+
go 1.19
4+
5+
require (
6+
github.com/coredns/caddy v1.1.1
7+
github.com/coredns/coredns v1.9.3
8+
github.com/miekg/dns v1.1.50
9+
github.com/prometheus/client_golang v1.13.0
10+
github.com/stretchr/testify v1.8.0
11+
)
12+
13+
require (
14+
github.com/apparentlymart/go-cidr v1.1.0 // indirect
15+
github.com/beorn7/perks v1.0.1 // indirect
16+
github.com/cespare/xxhash/v2 v2.1.2 // indirect
17+
github.com/davecgh/go-spew v1.1.1 // indirect
18+
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect
19+
github.com/golang/protobuf v1.5.2 // indirect
20+
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 // indirect
21+
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
22+
github.com/opentracing/opentracing-go v1.2.0 // indirect
23+
github.com/pmezard/go-difflib v1.0.0 // indirect
24+
github.com/prometheus/client_model v0.2.0 // indirect
25+
github.com/prometheus/common v0.37.0 // indirect
26+
github.com/prometheus/procfs v0.8.0 // indirect
27+
golang.org/x/mod v0.4.2 // indirect
28+
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 // indirect
29+
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
30+
golang.org/x/text v0.3.7 // indirect
31+
golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2 // indirect
32+
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect
33+
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd // indirect
34+
google.golang.org/grpc v1.46.2 // indirect
35+
google.golang.org/protobuf v1.28.1 // indirect
36+
gopkg.in/yaml.v3 v3.0.1 // indirect
37+
)

0 commit comments

Comments
 (0)