Fix Docker instructions and add option to bind both UDP and TCP DNS listeners (#130)

This commit is contained in:
Joona Hoikkala 2018-12-13 12:19:10 +02:00 committed by GitHub
parent 20411b650f
commit f64de0353d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 12 deletions

View File

@ -19,3 +19,4 @@ RUN apk --no-cache add ca-certificates && update-ca-certificates
VOLUME ["/etc/acme-dns", "/var/lib/acme-dns"] VOLUME ["/etc/acme-dns", "/var/lib/acme-dns"]
ENTRYPOINT ["./acme-dns"] ENTRYPOINT ["./acme-dns"]
EXPOSE 53 80 443 EXPOSE 53 80 443
EXPOSE 53/udp

View File

@ -149,6 +149,7 @@ See the INSTALL section for information on how to do this.
``` ```
docker run --rm --name acmedns \ docker run --rm --name acmedns \
-p 53:53 \ -p 53:53 \
-p 53:53/udp \
-p 80:80 \ -p 80:80 \
-v /path/to/your/config:/etc/acme-dns:ro \ -v /path/to/your/config:/etc/acme-dns:ro \
-v /path/to/your/data:/var/lib/acme-dns \ -v /path/to/your/data:/var/lib/acme-dns \
@ -216,8 +217,8 @@ $ dig @auth.example.org d420c923-bbd7-4056-ab64-c3ca54c9b3cf.auth.example.org
# In this case acme-dns will error out and you will need to define the listening interface # In this case acme-dns will error out and you will need to define the listening interface
# for example: listen = "127.0.0.1:53" # for example: listen = "127.0.0.1:53"
listen = ":53" listen = ":53"
# protocol, "udp", "udp4", "udp6" or "tcp", "tcp4", "tcp6" # protocol, "both", "both4", "both6", "udp", "udp4", "udp6" or "tcp", "tcp4", "tcp6"
protocol = "udp" protocol = "both"
# domain name to serve the requests off of # domain name to serve the requests off of
domain = "auth.example.org" domain = "auth.example.org"
# zone name server # zone name server
@ -300,6 +301,10 @@ logformat = "text"
## Changelog ## Changelog
- master
- Changed
- A new protocol selection for DNS server "both", that binds both - UDP and TCP ports.
- v0.6 - v0.6
- New - New
- Command line flag `-c` to specify location of config file. - Command line flag `-c` to specify location of config file.

View File

@ -2,9 +2,9 @@
# DNS interface. Note that systemd-resolved may reserve port 53 on 127.0.0.53 # DNS interface. Note that systemd-resolved may reserve port 53 on 127.0.0.53
# In this case acme-dns will error out and you will need to define the listening interface # In this case acme-dns will error out and you will need to define the listening interface
# for example: listen = "127.0.0.1:53" # for example: listen = "127.0.0.1:53"
listen = ":53" listen = "127.0.0.1:53"
# protocol, "udp", "udp4", "udp6" or "tcp", "tcp4", "tcp6" # protocol, "both", "both4", "both6", "udp", "udp4", "udp6" or "tcp", "tcp4", "tcp6"
protocol = "udp" protocol = "both"
# domain name to serve the requests off of # domain name to serve the requests off of
domain = "auth.example.org" domain = "auth.example.org"
# zone name server # zone name server
@ -26,7 +26,8 @@ debug = false
engine = "sqlite3" engine = "sqlite3"
# Connection string, filename for sqlite3 and postgres://$username:$password@$host/$db_name for postgres # Connection string, filename for sqlite3 and postgres://$username:$password@$host/$db_name for postgres
# Please note that the default Docker image uses path /var/lib/acme-dns/acme-dns.db for sqlite3 # Please note that the default Docker image uses path /var/lib/acme-dns/acme-dns.db for sqlite3
connection = "/var/lib/acme-dns/acme-dns.db" #connection = "/var/lib/acme-dns/acme-dns.db"
connection = "acme-dns.db"
# connection = "postgres://user:password@localhost/acmedns_db" # connection = "postgres://user:password@localhost/acmedns_db"
[api] [api]

View File

@ -8,6 +8,7 @@ services:
ports: ports:
- "443:443" - "443:443"
- "53:53" - "53:53"
- "53:53/udp"
- "80:80" - "80:80"
volumes: volumes:
- ./config:/etc/acme-dns:ro - ./config:/etc/acme-dns:ro

28
main.go
View File

@ -8,6 +8,7 @@ import (
stdlog "log" stdlog "log"
"net/http" "net/http"
"os" "os"
"strings"
"syscall" "syscall"
"github.com/julienschmidt/httprouter" "github.com/julienschmidt/httprouter"
@ -60,8 +61,25 @@ func main() {
errChan := make(chan error, 1) errChan := make(chan error, 1)
// DNS server // DNS server
dnsServer := setupDNSServer() if strings.HasPrefix(Config.General.Proto, "both") {
go startDNS(dnsServer, errChan) // Handle the case where DNS server should be started for both udp and tcp
udpProto := "udp"
tcpProto := "tcp"
if strings.HasSuffix(Config.General.Proto, "4") {
udpProto += "4"
tcpProto += "4"
} else if strings.HasSuffix(Config.General.Proto, "6") {
udpProto += "6"
tcpProto += "6"
}
dnsServerUDP := setupDNSServer(udpProto)
dnsServerTCP := setupDNSServer(tcpProto)
go startDNS(dnsServerUDP, errChan)
go startDNS(dnsServerTCP, errChan)
} else {
dnsServer := setupDNSServer(Config.General.Proto)
go startDNS(dnsServer, errChan)
}
// HTTP API // HTTP API
go startHTTPAPI(errChan) go startHTTPAPI(errChan)
@ -79,15 +97,15 @@ func main() {
func startDNS(server *dns.Server, errChan chan error) { func startDNS(server *dns.Server, errChan chan error) {
// DNS server part // DNS server part
dns.HandleFunc(".", handleRequest) dns.HandleFunc(".", handleRequest)
log.WithFields(log.Fields{"addr": Config.General.Listen}).Info("Listening DNS") log.WithFields(log.Fields{"addr": Config.General.Listen, "proto": server.Net}).Info("Listening DNS")
err := server.ListenAndServe() err := server.ListenAndServe()
if err != nil { if err != nil {
errChan <- err errChan <- err
} }
} }
func setupDNSServer() *dns.Server { func setupDNSServer(proto string) *dns.Server {
return &dns.Server{Addr: Config.General.Listen, Net: Config.General.Proto} return &dns.Server{Addr: Config.General.Listen, Net: proto}
} }
func startHTTPAPI(errChan chan error) { func startHTTPAPI(errChan chan error) {

View File

@ -43,7 +43,7 @@ func TestMain(m *testing.M) {
_ = newDb.Init("sqlite3", ":memory:") _ = newDb.Init("sqlite3", ":memory:")
} }
DB = newDb DB = newDb
server := setupDNSServer() server := setupDNSServer("udp")
// Make sure that we're not creating a race condition in tests // Make sure that we're not creating a race condition in tests
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(1) wg.Add(1)