Go to file
Simon Beck 086949801e Update readme 2021-10-05 20:10:45 +02:00
plugin Fix compile issues 2021-10-05 19:59:09 +02:00
record add PTR 2020-11-10 11:15:57 +01:00
vendor Go vendor 2020-09-23 09:20:14 +02:00
.gitignore Go vendor 2020-09-23 09:20:14 +02:00
README.md Update readme 2021-10-05 20:10:45 +02:00
go.mod Fix module name 2021-10-05 20:01:46 +02:00
go.sum Fix module name 2021-10-05 20:01:46 +02:00
redis.go 1 add readme and example (#2) 2021-01-14 12:19:57 +01:00
redis_test.go Add some logging 2020-10-01 09:43:46 +02:00

README.md

coredns-redis

coredns-redis uses redis as a backend for coredns this plugin should be located right next to etcd in plugins.cfg:

...
secondary:secondary
etcd:etcd
redis:github.com/rverst/coredns-redis/plugin
loop:loop
forward:forward
grpc:grpc
...

configuration

{
  redis {
    address HOST:PORT
    username USER
    password PASSWORD
    connect_timeout TIME_MS
    read_timeout TIME_MS
    ttl TIME_S
    prefix PREFIX
    suffix SUFFIX
  }
}
  • address is the address of the redis backend in form of host:port (defaults to localhost:6379)
  • username is the username for connectiong to the redis backend (optional)
  • password is the redis password (optional)
  • connect_timeout maximum time to establish a connection to the redis backend (in ms, optional)
  • read_timeout maximum time to wait for the redis backend to respond (in ms, optional)
  • ttl default ttl for dns records which have no ttl set (in seconds, default 3600)
  • prefix a prefix added to all redis keys
  • suffix a suffix added to all redis keys

example

corefile:

{
  .{
    redis {
      address localhost:6379
      username redis_user
      password super_secret
      connect_timeout 2000
      read_timeout 2000
      ttl 300
      prefix DNS_
      suffix _DNS
    }
  }
}

reverse zones

reverse zones is not supported yet

proxy

proxy is not supported yet

zone format in redis db

zones

each zone is stored in redis as a hash map with zone as key

redis-cli>KEYS *
1) "example.com."
2) "example.net."
redis-cli>

dns RRs

dns RRs are stored in redis as json strings inside a hash map using address as field key. @ is used for zone's own RR values.

A

{
    "a":{
        "ip" : "1.2.3.4",
        "ttl" : 360
    }
}

AAAA

{
    "aaaa":{
        "ip" : "::1",
        "ttl" : 360
    }
}

CNAME

{
    "cname":{
        "host" : "x.example.com.",
        "ttl" : 360
    }
}

TXT

{
    "txt":{
        "text" : "this is a text",
        "ttl" : 360
    }
}

NS

{
    "ns":{
        "host" : "ns1.example.com.",
        "ttl" : 360
    }
}

MX

{
    "mx":{
        "host" : "mx1.example.com",
        "priority" : 10,
        "ttl" : 360
    }
}

SRV

{
    "srv":{
        "host" : "sip.example.com.",
        "port" : 555,
        "priority" : 10,
        "weight" : 100,
        "ttl" : 360
    }
}

SOA

{
    "soa":{
        "ttl" : 100,
        "mbox" : "hostmaster.example.com.",
        "ns" : "ns1.example.com.",
        "refresh" : 44,
        "retry" : 55,
        "expire" : 66
    }
}

CAA

{
    "caa":{
        "flag" : 0,
        "tag" : "issue",
        "value" : "letsencrypt.org"
    }
}

example

$ORIGIN example.net.
 example.net.                 300 IN  SOA   <SOA RDATA>
 example.net.                 300     NS    ns1.example.net.
 example.net.                 300     NS    ns2.example.net.
 *.example.net.               300     TXT   "this is a wildcard"
 *.example.net.               300     MX    10 host1.example.net.
 sub.*.example.net.           300     TXT   "this is not a wildcard"
 host1.example.net.           300     A     5.5.5.5
 _ssh.tcp.host1.example.net.  300     SRV   <SRV RDATA>
 _ssh.tcp.host2.example.net.  300     SRV   <SRV RDATA>
 subdel.example.net.          300     NS    ns1.subdel.example.net.
 subdel.example.net.          300     NS    ns2.subdel.example.net.
 host2.example.net                    CAA   0 issue "letsencrypt.org"

above zone data should be stored at redis as follow:

redis-cli> hgetall example.net.
 1) "_ssh._tcp.host1"
 2) "{\"srv\":[{\"ttl\":300, \"target\":\"tcp.example.com.\",\"port\":123,\"priority\":10,\"weight\":100}]}"
 3) "*"
 4) "{\"txt\":[{\"ttl\":300, \"text\":\"this is a wildcard\"}],\"mx\":[{\"ttl\":300, \"host\":\"host1.example.net.\",\"preference\": 10}]}"
 5) "host1"
 6) "{\"a\":[{\"ttl\":300, \"ip\":\"5.5.5.5\"}]}"
 7) "sub.*"
 8) "{\"txt\":[{\"ttl\":300, \"text\":\"this is not a wildcard\"}]}"
 9) "_ssh._tcp.host2"
10) "{\"srv\":[{\"ttl\":300, \"target\":\"tcp.example.com.\",\"port\":123,\"priority\":10,\"weight\":100}]}"
11) "subdel"
12) "{\"ns\":[{\"ttl\":300, \"host\":\"ns1.subdel.example.net.\"},{\"ttl\":300, \"host\":\"ns2.subdel.example.net.\"}]}"
13) "@"
14) "{\"soa\":{\"ttl\":300, \"minttl\":100, \"mbox\":\"hostmaster.example.net.\",\"ns\":\"ns1.example.net.\",\"refresh\":44,\"retry\":55,\"expire\":66},\"ns\":[{\"ttl\":300, \"host\":\"ns1.example.net.\"},{\"ttl\":300, \"host\":\"ns2.example.net.\"}]}"
15) "host2"
16)"{\"caa\":[{\"flag\":0, \"tag\":\"issue\", \"value\":\"letsencrypt.org\"}]}"
redis-cli>

API

Package redis provides functions to manipulate (get, add, edit, delete) the data in the redis backend. The DNS zones are saved as hashmaps with the zone-name as key in the backend. While the data format is JSON at the moment, but I am considering switching to protobuf for performance reasons later.

credits

this plugin started as a fork of github.com/arvancloud/redis.