summaryrefslogtreecommitdiffstats
path: root/etc
diff options
context:
space:
mode:
authorPetr Špaček <petr.spacek@nic.cz>2020-03-20 15:59:58 +0100
committerPetr Špaček <petr.spacek@nic.cz>2020-03-25 14:23:36 +0100
commit83629f6b0b10751520e2e8f0852085777ba251c9 (patch)
tree0c47aafa0dd5c9085a88eb79d9617d37d1e9cadf /etc
parentpolicy.DEBUG: fix to respect user-provided callbacks (diff)
downloadknot-resolver-83629f6b0b10751520e2e8f0852085777ba251c9.tar.xz
knot-resolver-83629f6b0b10751520e2e8f0852085777ba251c9.zip
Dockerfile with one-shot mode
Intended usage: Quick resolution attempt with an empty cache. export QNAME=... export QTYPE=... sudo -E docker run -e QNAME -e QTYPE krestest:latest '-n' '-c' '/etc/knot-resolver/kresd.conf'
Diffstat (limited to 'etc')
-rw-r--r--etc/config/config.docker111
1 files changed, 79 insertions, 32 deletions
diff --git a/etc/config/config.docker b/etc/config/config.docker
index eaaffc9b..b7739e49 100644
--- a/etc/config/config.docker
+++ b/etc/config/config.docker
@@ -1,37 +1,84 @@
-- SPDX-License-Identifier: CC0-1.0
-- vim:syntax=lua:set ts=4 sw=4:
-- Refer to manual: https://knot-resolver.readthedocs.io/en/stable/
+print('Knot Resolver ' .. package_version())
--- Listen on all interfaces (localhost would not work in Docker)
-net.listen('0.0.0.0', 53, { kind = 'dns' })
-net.listen('0.0.0.0', 853, { kind = 'tls' })
-net.listen('0.0.0.0', 443, { kind = 'doh' })
-net.listen('0.0.0.0', 8453, { kind = 'webmgmt' })
-
--- Load Useful modules
-modules = {
- 'stats', -- Track internal statistics
- 'http',
-}
-
--- Smaller cache size
-cache.size = 10 * MB
-
-function print_help()
- print('\nUsage\n'
- .. '=====\n'
- .. 'Run this container using command:\n'
- .. '$ docker run -Pti cznic/knot-resolver\n'
- .. '\n'
- .. 'Docker will map ports 53, 443, 853, and 8453 to some other numbers, see\n'
- .. '$ docker ps\n'
- .. '(column PORTS)\n'
- .. '53 -> DNS protocol over UDP and TCP\n'
- .. '443 -> DNS-over-HTTPS protocol\n'
- .. '853 -> DNS-over-TLS protocol\n'
- .. '8453 -> web interface\n'
- .. '\n'
- .. 'For verbose logging enter following command to prompt below:\n'
- .. 'verbose(true)\n')
+function interactive_mode()
+ -- Listen on all interfaces (localhost would not work in Docker)
+ net.listen('0.0.0.0', 53, { kind = 'dns' })
+ net.listen('0.0.0.0', 853, { kind = 'tls' })
+ net.listen('0.0.0.0', 443, { kind = 'doh' })
+ net.listen('0.0.0.0', 8453, { kind = 'webmgmt' })
+
+ -- Load Useful modules
+ modules = {
+ 'stats', -- Track internal statistics
+ 'http',
+ }
+
+ -- Smaller cache size
+ cache.size = 10 * MB
+
+ function print_help()
+ print('\nUsage\n'
+ .. '=====\n'
+ .. 'Run this container using command:\n'
+ .. '$ docker run -Pti cznic/knot-resolver\n'
+ .. '\n'
+ .. 'Docker will map ports 53, 443, 853, and 8453 to some other numbers, see\n'
+ .. '$ docker ps\n'
+ .. '(column PORTS)\n'
+ .. '53 -> DNS protocol over UDP and TCP\n'
+ .. '443 -> DNS-over-HTTPS protocol\n'
+ .. '853 -> DNS-over-TLS protocol\n'
+ .. '8453 -> web interface\n'
+ .. '\n'
+ .. 'For verbose logging enter following command to prompt below:\n'
+ .. 'verbose(true)\n')
+ end
+ print_help()
+end
+
+function debug_mode(qname, qtype)
+ env.KRESD_NO_LISTEN = 1
+
+ -- limit noise in verbose logs
+ modules.unload('detect_time_skew')
+ modules.unload('priming')
+ modules.unload('ta_signal_query')
+ modules.unload('ta_update')
+
+
+ -- execute query right after start up and exit when the query is finished
+ event.after(0, function()
+ -- ultra verbose log
+ verbose(true)
+ policy.add(policy.all(policy.DEBUG_ALWAYS))
+ log('INFO: starting your DNS query for %s %s, verbose log follows', qname, kres.tostring.type[qtype])
+ resolve({
+ name = qname,
+ type = qtype,
+ finish = function(pkt)
+ -- delay exit after packet is finished
+ -- to prevent us from losing policy.DEBUG finish callback
+ event.after(1,
+ function()
+ os.exit()
+ end)
+ end
+ })
+ end)
+end
+
+local qname = os.getenv('QNAME')
+local qtype = os.getenv('QTYPE')
+if qname and qtype then
+ qtypenum = kres.type[qtype]
+ if not qtypenum then
+ log('ERROR: unsupported query type "%s", use TYPE12345 notation', qtype)
+ os.exit()
+ end
+ debug_mode(qname, qtypenum)
+else
+ interactive_mode()
end
-print_help()