Debian Codegraph @

cmd/atomdns/handlers/dbsqlite/README.md

raw
1 # Name
2
3 _dbsqilte_ - serve zone data from a SQLite database
4
5 # Description
6
7 The _dbsqlite_ handler reads zone data from a data and serves that to clients. If the database contains
8 signatures (i.e. is signed using DNSSEC), correct DNSSEC answers are returned. Only NSEC is supported. You can
9 create the database completely off-line, if it holds the correct data, _dbsqlite_ will happily serve from it.
10
11 The _sign_ handler does _not_ support databases, so you need something like ldns-signzone to sign and resign
12 your zones and put the generated records in the database.
13
14 When started the database file will be created and the schema will be written to it (if it does not already
15 exist). After this step, the handler will never write to the database, for the purpose of generating answers
16 the database is completely read-only. The database can be prepared beforehand.
17
18 An RR that fails to be converted into a proper `dns.RR` is silently discarded, unless `debug` is active, see
19 atomdns-global(7) for details. The class is `IN` and can't be overridden.
20
21 When atomdns starts up the _dbsqlite_ handler will log how many zones it found in the database, this is a live
22 query and may differ with the zones specified in the configuration.
23
24 The server will reply with minimal responses by default.
25
26 ## Database
27
28 The schema used for the database is:
29
30 ```sql
31 CREATE TABLE rrs (
32 name VARCHAR(255),
33 type VARCHAR(10),
34 data VARCHAR(65535),
35 ttl INTEGER,
36 UNIQUE (name, type, data)
37 );
38 ```
39
40 You can just add RRs to this table for _any_ zone and _dbsqlite_ will happily use them. Relative names will be
41 made not be made into fully qualified ones, and for some queries that will not be matched and silently _not_ included.
42
43 sqlite> insert into rrs values ( '_ssh._tcp.host1.example.', 'srv', '10 5 43 example', 3600);
44 sqlite> insert into rrs values ( 'subdel.example', 'ns', 'ns.example.com', 3600);
45
46 This one database can be safely used for all zones you have. Note that you still have to make sure the handler
47 gets queries for new zones.
48
49 ### Importing zone files
50
51 If you have a zone file you can use the `.import` feature of SQLite to import the file in one go using the
52 excellent "ldns" utils from NLnet Labs (https://www.nlnetlabs.nl/projects/ldns/about/).
53
54 ldns-read-zone db.example.org | sed 's/;.*$//' | sed 's/ $//' | \
55 awk '{print $1 "," $4 "," substr($0, index($0, $5)) "," $2}' > csv.example.org
56
57 And then:
58
59 sqlite3 /tmp/db <<EOF
60 heredoc> .mode csv
61 heredoc> BEGIN;
62 heredoc> .import csv.example.org rrs
63 heredoc> COMMIT;
64 heredoc> EOF
65
66 Where the `ldns-read-zone` pipeline removes trailing white space, and the helpful comments after DNSKEY
67 records, then `awk` re-arranges it into the proper format.
68
69 # Syntax
70
71 In it simplest form _dbsqlite_ you can use:
72
73 ```
74 dbsqlite DATABASE
75 ```
76
77 - **DATABASE** the file with the SQLite database to query. If the path is relative, the path from the global root config will be
78 prepended to it.
79
80 If **DATABASE** does not exists the file is created and the `rrs` table is initialized.
81
82 For extra control you can open the block and define multiple extra properties that deal with zone transfers. Only outgoing zone
83 transfers are supported.
84 It is similar to _dbfile_, and we refer to that documentation then to repeat it here.
85
86 ```
87 dbsqlite DATABASE {
88 transfer {
89 to [IP[:PORT]]... {
90 notify IP[:PORT] [IP[:PORT]]...
91 source IP [IP]...
92 key NAME ALGORITHM SECRET
93 }
94 }
95 }
96 ```
97
98 # Examples
99
100 Have both `example.org` and `example.net` read from the same database.
101
102 ```conffile
103 example.org example.net {
104 dbsqlite example.db
105 }
106 ```
107
108 If you want _everything_ to end up in _dbsqlite_, you might be tempted to:
109
110 ```conffile
111 . {
112 dbsqlite root.db
113 }
114 ```
115
116 But this fails, _unless_ you are actually authoritative for `.` (the root zone), this because the named zones are
117 used to find those in the database.