|
| 1 | ++++ |
| 2 | +title = "pocketbase" |
| 3 | +description = "*pocketbase* - PocketBase backend for CoreDNS" |
| 4 | +weight = 10 |
| 5 | +tags = [ "plugin" , "pocketbase" ] |
| 6 | +categories = [ "plugin", "external" ] |
| 7 | +date = "2025-04-11T03:31:26+00:00" |
| 8 | +repo = "https://github.com/tinkernels/coredns-pocketbase" |
| 9 | +home = "https://github.com/tinkernels/coredns-pocketbase/blob/master/README.md" |
| 10 | ++++ |
| 11 | + |
| 12 | +# pocketbase |
| 13 | + |
| 14 | +PocketBase backend for CoreDNS |
| 15 | + |
| 16 | +## Name |
| 17 | + |
| 18 | +pocketbase - PocketBase backend for CoreDNS |
| 19 | + |
| 20 | +## Description |
| 21 | + |
| 22 | +This plugin uses PocketBase as a backend to store DNS records. These will then can served by CoreDNS. The backend uses a |
| 23 | +simple single table data structure that can add and remove records from the DNS server. |
| 24 | + |
| 25 | +## Syntax |
| 26 | + |
| 27 | +``` |
| 28 | +pocketbase { |
| 29 | + [listen LISTEN] |
| 30 | + [data_dir DATA_DIR] |
| 31 | + [su_email SU_EMAIL] |
| 32 | + [su_password SU_PASSWORD] |
| 33 | + [default_ttl DEFAULT_TTL] |
| 34 | + [cache_capacity CACHE_CAPACITY] |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +- `listen` pocketbase listening http address, default to `[::]:8090`, |
| 39 | +- `data_dir` directory to store pocketbase data, default to `pb_data`, |
| 40 | +- `su_email` superuser login email, can be overwritten by environment variable `COREDNS_PB_SUPERUSER_EMAIL`, default to `[email protected]`, |
| 41 | +- `su_password` superuser password, can be overwritten by environment variable `COREDNS_PB_SUPERUSER_PWD`, default to `[email protected]`, |
| 42 | +- `default_ttl` default ttl to use, default to `30`, |
| 43 | +- `cache_capacity` zone data cache capacity, `0` to disable cache, default to `0`. |
| 44 | + |
| 45 | +## Features |
| 46 | + |
| 47 | +### Supported Record Types |
| 48 | + |
| 49 | +- A |
| 50 | +- AAAA |
| 51 | +- CNAME |
| 52 | +- SOA |
| 53 | +- TXT |
| 54 | +- NS |
| 55 | +- MX |
| 56 | +- CAA |
| 57 | +- SRV |
| 58 | + |
| 59 | +*P.S.wildcard records supported* |
| 60 | + |
| 61 | +### Cache |
| 62 | + |
| 63 | +Use `github.com/dgraph-io/ristretto` as in-memory cache handler, handle cache refreshing with PocketBase event subscription mechanism. |
| 64 | + |
| 65 | +## Concept |
| 66 | + |
| 67 | +### PocketBase |
| 68 | + |
| 69 | +[PocketBase](https://github.com/pocketbase/pocketbase) use sqlite3 as storage, and comes with a web console. |
| 70 | + |
| 71 | +This plugin with init a super user and dns model in PocketBase, the admin console with look like |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | +#### Model in PocketBase |
| 76 | + |
| 77 | +```go |
| 78 | +type Record struct { |
| 79 | + Zone string `db:"zone" json:"zone"` // The DNS zone this record belongs to |
| 80 | + Name string `db:"name" json:"name"` // The name of the record (without the zone) |
| 81 | + RecordType string `db:"record_type" json:"record_type"` // The type of DNS record (A, AAAA, TXT, etc.) |
| 82 | + Ttl uint32 `db:"ttl" json:"ttl"` // Time to live for the record in seconds |
| 83 | + Content string `db:"content" json:"content"` // The content of the record in JSON format |
| 84 | +} |
| 85 | +``` |
| 86 | + |
| 87 | +### DNS records |
| 88 | + |
| 89 | +DNS records content stored as JSON. |
| 90 | + |
| 91 | +```go |
| 92 | +// ARecord represents an A (IPv4) DNS record |
| 93 | +type ARecord struct { |
| 94 | + Ip net.IP `json:"ip"` // IPv4 address |
| 95 | +} |
| 96 | +``` |
| 97 | +```go |
| 98 | +// AAAARecord represents an AAAA (IPv6) DNS record |
| 99 | +type AAAARecord struct { |
| 100 | + Ip net.IP `json:"ip"` // IPv6 address |
| 101 | +} |
| 102 | +``` |
| 103 | +```go |
| 104 | +// TXTRecord represents a TXT DNS record |
| 105 | +type TXTRecord struct { |
| 106 | + Text string `json:"text"` // Text content of the record |
| 107 | +} |
| 108 | +``` |
| 109 | +```go |
| 110 | +// CNAMERecord represents a CNAME DNS record |
| 111 | +type CNAMERecord struct { |
| 112 | + Host string `json:"host"` // Target hostname |
| 113 | + Zone string `json:"zone"` // Zone of the record |
| 114 | +} |
| 115 | +``` |
| 116 | +```go |
| 117 | +// NSRecord represents an NS (Name Server) DNS record |
| 118 | +type NSRecord struct { |
| 119 | + Host string `json:"host"` // Name server hostname |
| 120 | +} |
| 121 | +``` |
| 122 | +```go |
| 123 | +// MXRecord represents an MX (Mail Exchange) DNS record |
| 124 | +type MXRecord struct { |
| 125 | + Host string `json:"host"` // Mail server hostname |
| 126 | + Preference uint16 `json:"preference"` // Priority of the mail server |
| 127 | +} |
| 128 | +``` |
| 129 | +```go |
| 130 | +// SRVRecord represents an SRV (Service) DNS record |
| 131 | +type SRVRecord struct { |
| 132 | + Priority uint16 `json:"priority"` // Priority of the service |
| 133 | + Weight uint16 `json:"weight"` // Weight for load balancing |
| 134 | + Port uint16 `json:"port"` // Port number of the service |
| 135 | + Target string `json:"target"` // Target hostname |
| 136 | +} |
| 137 | +``` |
| 138 | +```go |
| 139 | +// SOARecord represents an SOA (Start of Authority) DNS record |
| 140 | +type SOARecord struct { |
| 141 | + Ns string `json:"ns"` // Primary name server |
| 142 | + MBox string `json:"mbox"` // Email address of the administrator |
| 143 | + Refresh uint32 `json:"refresh"` // Refresh interval in seconds |
| 144 | + Retry uint32 `json:"retry"` // Retry interval in seconds |
| 145 | + Expire uint32 `json:"expire"` // Expiration time in seconds |
| 146 | + MinTtl uint32 `json:"minttl"` // Minimum TTL in seconds |
| 147 | +} |
| 148 | +``` |
| 149 | +```go |
| 150 | +// CAARecord represents a CAA (Certification Authority Authorization) DNS record |
| 151 | +type CAARecord struct { |
| 152 | + Flag uint8 `json:"flag"` // Critical flag |
| 153 | + Tag string `json:"tag"` // Property identifier |
| 154 | + Value string `json:"value"` // Property value |
| 155 | +} |
| 156 | +``` |
| 157 | + |
| 158 | +## Setup (as an external plugin) |
| 159 | + |
| 160 | +Add this as an external plugin in `plugin.cfg` file from CoreDNS repo |
| 161 | + |
| 162 | +``` |
| 163 | +pocketbase:github.com/tinkernels/coredns-pocketbase |
| 164 | +``` |
| 165 | + |
| 166 | +*P.S.place pocketbase above cache plugin is recommended.* |
| 167 | + |
| 168 | +Then run |
| 169 | + |
| 170 | +```shell script |
| 171 | +$ go generate |
| 172 | +$ go build |
| 173 | +``` |
| 174 | + |
| 175 | +Add any required modules to CoreDNS code as prompted. |
| 176 | + |
| 177 | +## Credits |
| 178 | + |
| 179 | +Inspired by |
| 180 | + |
| 181 | +- [https://github.com/wenerme/coredns-pdsql](https://github.com/wenerme/coredns-pdsql) |
| 182 | +- [https://github.com/arvancloud/redis](https://github.com/arvancloud/redis) |
| 183 | +- [https://github.com/cloud66-oss/coredns_mysql](https://github.com/cloud66-oss/coredns_mysql) |
0 commit comments