redis

package module
v0.0.0-...-bb93485 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

README

redis enables reading zone data from redis database.

build

this plugin should be located right next to etcd in plugins.cfg

git clone https://github.com/coredns/coredns
cd coredns
echo 'redis:github.com/threefoldtech/coredns-redis' >> plugin.cfg
make
chmod +x coredns

development

  • clone repo git@github.com:threefoldtech/coredns-redis.git under ~/go/src/coredns-redis
  • in coredns repo in plugins dir add redis:coredns-redis
  • in coredns repo make

syntax

redis

redis loads authoritative zones from redis server

Address will default to local redis server (localhost:6379)

redis {
    address ADDR
    password PWD
    prefix PREFIX
    suffix SUFFIX
    connect_timeout TIMEOUT
    read_timeout TIMEOUT
    ttl TTL
}
  • address is redis server address to connect in the form of host:port or ip:port.
  • password is redis server auth key
  • connect_timeout time in ms to wait for redis server to connect
  • read_timeout time in ms to wait for redis server to respond
  • ttl default ttl for dns records, 300 if not provided
  • prefix add PREFIX to all redis keys
  • suffix add SUFFIX to all redis keys

examples

. {
    redis example.com {
        address localhost:6379
        password foobared
        connect_timeout 100
        read_timeout 100
        ttl 360
        prefix _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>

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AAAA_Record

type AAAA_Record struct {
	Ttl uint32 `json:"ttl,omitempty"`
	Ip  net.IP `json:"ip"`
}

type A_Record

type A_Record struct {
	Ttl uint32 `json:"ttl,omitempty"`
	Ip  net.IP `json:"ip"`
}

type CAA_Record

type CAA_Record struct {
	Flag  uint8  `json:"flag"`
	Tag   string `json:"tag"`
	Value string `json:"value"`
}

type CNAME_Record

type CNAME_Record struct {
	Ttl  uint32 `json:"ttl,omitempty"`
	Host string `json:"host"`
}

type MX_Record

type MX_Record struct {
	Ttl        uint32 `json:"ttl,omitempty"`
	Host       string `json:"host"`
	Preference uint16 `json:"preference"`
}

type NS_Record

type NS_Record struct {
	Ttl  uint32 `json:"ttl,omitempty"`
	Host string `json:"host"`
}

type Record

type Record struct {
	A     []A_Record     `json:"a,omitempty"`
	AAAA  []AAAA_Record  `json:"aaaa,omitempty"`
	TXT   []TXT_Record   `json:"txt,omitempty"`
	CNAME []CNAME_Record `json:"cname,omitempty"`
	NS    []NS_Record    `json:"ns,omitempty"`
	MX    []MX_Record    `json:"mx,omitempty"`
	SRV   []SRV_Record   `json:"srv,omitempty"`
	CAA   []CAA_Record   `json:"caa,omitempty"`
	SOA   SOA_Record     `json:"soa,omitempty"`
}

type Redis

type Redis struct {
	Next plugin.Handler
	Pool *redisCon.Pool

	Ttl            uint32
	LastZoneUpdate time.Time
	// contains filtered or unexported fields
}

func (*Redis) A

func (redis *Redis) A(name string, z *Zone, record *Record) (answers, extras []dns.RR)

func (Redis) AAAA

func (redis Redis) AAAA(name string, z *Zone, record *Record) (answers, extras []dns.RR)

func (*Redis) AXFR

func (redis *Redis) AXFR(z *Zone) (records []dns.RR)

func (*Redis) CAA

func (redis *Redis) CAA(name string, z *Zone, record *Record) (answers, extras []dns.RR)

func (*Redis) CNAME

func (redis *Redis) CNAME(name string, z *Zone, record *Record) (answers, extras []dns.RR)

func (*Redis) Connect

func (redis *Redis) Connect()

func (*Redis) MX

func (redis *Redis) MX(name string, z *Zone, record *Record) (answers, extras []dns.RR)

func (*Redis) NS

func (redis *Redis) NS(name string, z *Zone, record *Record) (answers, extras []dns.RR)

func (*Redis) Name

func (redis *Redis) Name() string

Name implements the Handler interface.

func (*Redis) SOA

func (redis *Redis) SOA(name string, z *Zone, record *Record) (answers, extras []dns.RR)

func (*Redis) SRV

func (redis *Redis) SRV(name string, z *Zone, record *Record) (answers, extras []dns.RR)

func (*Redis) ServeDNS

func (redis *Redis) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

ServeDNS implements the plugin.Handler interface.

func (*Redis) TXT

func (redis *Redis) TXT(name string, z *Zone, record *Record) (answers, extras []dns.RR)

type SOA_Record

type SOA_Record struct {
	Ttl     uint32 `json:"ttl,omitempty"`
	Ns      string `json:"ns"`
	MBox    string `json:"MBox"`
	Refresh uint32 `json:"refresh"`
	Retry   uint32 `json:"retry"`
	Expire  uint32 `json:"expire"`
	MinTtl  uint32 `json:"minttl"`
}

type SRV_Record

type SRV_Record struct {
	Ttl      uint32 `json:"ttl,omitempty"`
	Priority uint16 `json:"priority"`
	Weight   uint16 `json:"weight"`
	Port     uint16 `json:"port"`
	Target   string `json:"target"`
}

type TXT_Record

type TXT_Record struct {
	Ttl  uint32 `json:"ttl,omitempty"`
	Text string `json:"text"`
}

type Zone

type Zone struct {
	Name      string
	Locations map[string]struct{}
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL