Debian Codegraph @

cmd/atomdns/handlers/global/README.md

raw
1 # Name
2
3 _global_ - hold server properties
4
5 # Description
6
7 _global_ holds the server properties, like the prometheus metrics port, root directory, profiling settings,
8 and the server's configuration on how many and what type of servers to run.
9
10 It's not a proper handler and you can not use it as such: you can't use _global_ in the configuration, other than in the
11 global block, see the configuration examples below.
12
13 If no servers (also see below) are defined atomdns starts a (single, but one for TCP and one for UDP) DNS server on port 53.
14
15 # Syntax
16
17 ```txt
18 {
19 root DIRECTORY
20 log {
21 debug
22 json
23 quiet
24 disable
25 }
26 metrics [/N] [ADDRRES]
27 health [ADDRESS [LAMEDUCK]]
28 pprof [FILE|ADDRESS]
29 dns {
30 addr ADDRESS
31 limits {
32 tcp EXPR
33 run EXPR
34 }
35 }
36 dot {
37 addr ADDRESS
38 limits {
39 run EXPR
40 }
41 }
42 doh {
43 addr ADDRESS
44 limits {
45 run EXPR
46 inflight EXPR
47 }
48 }
49 dou {
50 addr SOCKET
51 }
52 tls ISSUER {
53 cert CERT KEY
54 ca URL
55 source IP|IFACE [IP|IFACE]...
56 contact EMAIL
57 directory DIRECTORY
58 rootca CA
59 }
60 }
61 ```
62
63 - with `root` **DIRECTORY** that directory to use as the root directory for the server. Any relative path names will
64 get this directory prefixed. If **DIRECTORY** itself is also relative, the current working directory (cwd) of the atomdns
65 process will be prefixed.
66 - `log` tells atomdns on how to, globally, log:
67 - `debug` sets the global log level to debug.
68 - `json` enables JSON logging.
69 - With `quiet` the banner is not shown. Query logging is not affected.
70 - And `disable` disables the logging so that it can be enabled with the SIGUSR1 signal, see atomdns-log(7).
71 To enable logging for specific zone you need to enable the _log_ handler in that handler block.
72 - The `metrics` property allows setting the listening **ADDRESS** for the prometheus metrics. This defaults to `localhost:9153`.
73 Without `metrics` no metrics can be scraped as the prometheus server isn't running, i.e. to allow for
74 metrics gathering `metrics` must be enabled in the global block.
75 The optional **/N** tells the metric handler to monitor 1 in **N** queries. The default is 10. This needs to
76 be a positive integer > 0. This is done to not impair performance too much.
77 With the `metrics` handler you can enable/disable metrics on a per server basis.
78 - With `health` you start a local web server that exports a /health endpoint on **ADDRESS** that returns 200 OK when
79 everything is OK. When **LAMEDUCK** which should be a time.Duration in string form is given, the server' shutdown will be
80 delayed for that duration. The default for **ADDRESS** is `:8080`. Every 2 seconds atomdns will query itself
81 to get its health so it can export the latency metrics.
82 - With `pprof` you can publish runtime profiling data at the endpoint on
83 **ADDRESS** under `/debug/pprof`. Alternatively it can be a path where the profiling output is written to.
84 The default is `localhost:6053`.
85
86 This is parsed in-order and some settings depend on `root` and/or `debug`, so set those two early in the file.
87
88 ## `dns`
89
90 With `dns` you set DNS (port (usually) 53, TCP and UDP) server options, defined are.
91
92 - `addr` **ADDRESS**: listen on this address, default is `[::]:53`.
93 - `limits` set further limits:
94 - `tcp` **LIMIT**, break off TCP connections after this many queries, default is 1024, -1 disables.
95 - `run` **EXPR**, run this many servers the default is `NumCPU()*3`, this can be a bare number,
96 like 5, or an expression like `NumCPU()*N`, where **N** is a whole number. `NumCPU()` may be spelled in
97 lowercase, i.e. `numcpu()*N` is OK. Note that adding more servers helps with lock contention when writing the DNS messages
98 back to the client. This number is again multiplied by 2 for 50% UDP, and 50% TCP server. So `run 5`, will
99 start 10 server instances. The maximum value is the number of CPUs \* 1024.
100
101 ## `dot`
102
103 With `dot` you control DNS TLS server options, defined are.
104
105 - `addr` **ADDRESS**: listen on this address, default is `[::]:853`.
106 - `limits` set further limits:
107 - `tcp` **LIMIT**, break off TCP connections after this many queries, default is 1024, -1 disables.
108 - `run` **EXPR**, run this many servers the default is `NumCPU()*1`, this can be a bare number,
109 like 5, or an expression like `NumCPU()*N`, where **N** is a whole number. `NumCPU()` may be spelled in lowercase.
110 These are all TCP servers, so `run 5` will start 5 servers, not 10 as would the case with `dns`.
111
112 This requires a `tls` setup too.
113
114 ## `doh`
115
116 With `doh` you set HTTP server options, defined are.
117
118 - `addr` **ADDRESS**: listen on this address, default is `[::]:443`.
119 - `limits` set further limits:
120 - `run` **EXPR**, run this many servers the default is `NumCPU()*1`, this can be a bare number,
121 like 5, or an expression like `NumCPU()*N`, where **N** is a whole number. `NumCPU()*` may be spelled in lowercase.
122 - `inflight` **EXPR**, like `run`, how many inflight connection are we allowing, default is 1024, -1 disables.
123
124 To allow the certificate challenge, all DOH HTTP servers will also handle the TLS-ALPN-1 challenge,
125 disregarding the port the run on. If the DOH servers are not running on port 443, one extra server will be
126 started on that port, _just_ for the certificate challenge. N.B. This is only done if the port isn't "0",
127 because that is usually used in testing scenarios. This requires the atomdns process to be able to bind to that
128 port.
129
130 This requires a `tls` setup too.
131
132 ## `dou`
133
134 With `dou` you configure an Unix domain socket to listen on, defined are.
135
136 - `addr` **SOCKET**: listen on this Unix domain socket. Note there are OS limits on the length of the socket's file name.
137 If this is a relative name the path from `root` will be prepended.
138
139 Querying over a Unix domain socket needs to be done using the TCP packet format, for example:
140 `kdig +tcp www.example.org @/tmp/atomdns.sock`, if **SOCKET** is set to `/tmp/atomdns.sock`.
141
142 ## `tls`
143
144 With `tls` you configure the TLS certificate setup. **ISSUER** can be `manual`, or `lets-encrypt`. The later
145 will set up the certificates automatically. If you use relative path in this configuration be sure that `root`
146 is set _above_ this config, so that its value is set.
147
148 Depending on **ISSUER**, you have the following further configuration:
149
150 If **ISSUER** is `manual`:
151
152 - `cert`, that lists in that order **CERT** the `cert.pem` (as an example name) file, **KEY** the private key,
153 `key.pem`
154 - `rootca`, the root `ca.pem` file. This is optional, but can aid in testing.
155
156 If **ISSUER** is `lets-encrypt`:
157
158 - `source`, a list of **IP**s or **IFACE** names for which the IP address should be retrieved, and for which
159 the TLS certificates should be requested.
160 - `contact`, where **EMAIL** is the contact email use when retrieving certificates. This can be set to (one
161 of) your SOA's Mbox (RNAME - responsible person) mail address.
162 - `directory` has the **DIRECTORY** where the certificates are stored. The global's `root` is prepended if this a
163 relative path name.
164 - `ca` lets you select the production or staging ACME CA endpoint, by specifying the URL here. The default for
165 the time being is Let's Encrypt staging endpoint: <https://acme-staging-v02.api.letsencrypt.org/directory>.
166 The production endpoint for Let's Encrypt is <https://acme-v02.api.letsencrypt.org/directory>.
167 If after the URL the literal text `test` is used, atomdns will not start a separate web server on port 443,
168 this is to aid in local testing.
169 - `rootca`, can also be used here. This is optional, but can aid in testing.
170
171 Both `source` and `contact` are mandatory.
172
173 To complete the challenge a web server needs to be running on port 443, if DOH is enabled (see `doh`), and is
174 not already running on 443 another server will be started on that port just for the challenge.
175
176 # Examples
177
178 A minimal example without any blocks, starts a DNS server on port 53, as said in the description. It is
179 authoritative for `example.org.` and has two handlers, _log_ and _whoami_.
180
181 ```txt
182 example.org
183 log
184 whoami
185 ```
186
187 This runs both a DNS and DOH server, the DOH server listens on port 8053.
188
189 ```txt
190 {
191 root /var/lib/atomdns
192 metrics localhost:9153
193 tls lets-encrypt {
194 contact [email protected]
195 source eth0
196 path certs
197 }
198 dns {
199 limits {
200 tcp -1
201 run NumCPU()*3
202 }
203 }
204 doh {
205 addr [::]:8053
206 }
207 }
208
209 example.org {
210 log
211 whoami
212 }
213 ```
214
215 Or run an health endpoint on http://localhost:8091, with a lame-duck delay of 200 ms.
216
217 ```txt
218 {
219 health localhost:8091 200ms
220 }
221 ```
222
223 Using the profiling tools.
224
225 ```txt
226 {
227 pprof atomdns.prof
228 }
229 ```
230
231 Then run atomdns, and use the profiling data: `go tool pprof -http localhost:8080 atomdns atomdns.prof` and
232 spot any bottlenecks.
233
234 # Metrics
235
236 If monitoring is enabled (via `metrics`) and `health` is enabled the following metrics are exported:
237
238 - `atomdns_health_request_duration_seconds{}` - `health` performs a self health check
239 once per second on the `/health` endpoint. This metric is the duration to process that request.
240 As this is a local operation it should be fast. A (large) increase in this
241 duration indicates the atomdns process is having trouble keeping up with its query load.
242 - `atomdns_health_request_failures_total{}` - The number of times the self health check failed, this also
243 points to imminent failure.