I’m revisiting the proof of concept I whipped up the other day (inspired
by this) regarding storing DNS zone data in a CouchDB database,
because I was perverting the concept of a document database, using my
old-school relational model: I had one document per DNS resource record. What
I should have done in the first place, was to think “zone” – store a full
zone into a single document and use CouchDB views to extract the data the
way I need it. So here goes: A DNS zone is one JSON document in
CouchDB. Here is the proverbial example.org example: I’d like to
point out the following things:
The SOA object contains an optional serial value. If this isn’t defined the document’s _rev is used (the integer before the MD5 of the _rev). This means we can have auto-incrementing zone serial numbers, whenever the CouchDB document changes.
The default TTL for all records in the zone is in default_ttl, but each record can override this with its own ttl value.
rr is an array of resource records, each of which have a name (the first label), a lowercase type (such as a, mx, etc.) and data. The latter is specific to the record type. A resource record’s name may be an empty string, in which case the record belongs to the zone.
In essence, once I retrieve the document for a zone, I have all I need, and
the DNS server could “produce” the rest. Instead of doing that, I’ve created a
CouchDB view which emits the zone’s individual record types and their data.
The key into the view is an array consisting of the domain name and the
requested type: (the GET command you see below is resty’s)
To support DNS queries of type ANY, the view’s map function also
emits those. (If there is a better way of doing this, I’d be pleased to here
of it.) So, this is my view:
Using this, the resulting name server becomes
So, let’s look at some example queries. First, a CNAME lookup:
Now a TXT query. Note the TTL from the record’s own entry:
And finally, the piece de resistance: the SOA with it’s automatic
PTR lookups work as well, even though I’m cheating a bit: all
addresses I find in the A resource records are converted into PTR RRs.
This remains a proof of concept, but I believe it fits CouchDB’s
model better. Continue…