Skip to content

Commit

Permalink
Merge branch 'rel/v0.2.0+0.1.1' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
nix committed Nov 25, 2024
2 parents bdc8485 + b80716a commit 55888f7
Show file tree
Hide file tree
Showing 34 changed files with 2,184 additions and 958 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/pdns-etcd3

# IDEs
/.idea/
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pdns-etcd3
Copyright 2016-2022 nix <https://keybase.io/nixn>
Copyright 2016-2024 nix <https://keybase.io/nixn>

This product includes software developed by
nix <https://keybase.io/nixn>
216 changes: 149 additions & 67 deletions README.md

Large diffs are not rendered by default.

367 changes: 265 additions & 102 deletions doc/ETCD-structure.md

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions docker/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# available profiles:
# - standalone (backend in unix mode)
# - pdns-34 (defunct)
# - pdns-44
# - pdns-45
# - pdns-49
# - pdns-50
# - pdns-all
# - etcdkeeper
COMPOSE_PROFILES=standalone,etcdkeeper,pdns-49
PDNS_BACKEND_MODE=unix
PDNS49_PUBLIC_PORT=5300
#ETCD_PUBLIC_CLIENT_PORT=23790
ETCDKEEPER_PORT=8080
1 change: 1 addition & 0 deletions docker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.env
2 changes: 2 additions & 0 deletions docker/Dockerfile-backend
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM debian:12-slim
ENTRYPOINT ["/pdns-etcd3", "-unix=/common/pdns-etcd3.sock", "-endpoints=etcd:2379"]
15 changes: 15 additions & 0 deletions docker/Dockerfile-etcdkeeper
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM debian:12-slim
ADD etcdkeeper.sh /opt/
ADD https://github.com/evildecay/etcdkeeper/releases/download/v0.7.8/etcdkeeper-v0.7.8-linux_x86_64.tar.gz /opt/
WORKDIR /opt
RUN <<EOF
set -ex
tar -xf etcdkeeper*.tar.gz
chmod +x etcdkeeper etcdkeeper.sh
export DEBIAN_FRONTENT=noninteractive
apt-get update
apt-get install -y simpleproxy
EOF
ENV ETCD_ENDPOINT=""
ENTRYPOINT ./etcdkeeper.sh "$ETCD_ENDPOINT"
EXPOSE 8080/tcp
129 changes: 129 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#version: '3.8'
name: pdns-etcd3
services:
backend:
build:
context: .
dockerfile: Dockerfile-backend
command: -prefix=/DNS/ -log-debug=main+etcd+data
volumes:
- ../pdns-etcd3:/pdns-etcd3:ro
- common:/common
profiles:
- standalone
pdns34:
image: powerdns/pdns-auth-34 # TODO build
volumes:
- ../pdns-etcd3:/pdns-etcd3:ro
- common:/common
- ./pdns.conf:/etc/powerdns/pdns.conf:ro
- ./pdns-1-listen-legacy.conf:/etc/powerdns/pdns.d/pdns-1-listen-legacy.conf:ro
- ./pdns-5-${PDNS_BACKEND_MODE:?}-v3.conf:/etc/powerdns/pdns.d/pdns-5-backend.conf:ro
ports:
- "${PDNS34_PUBLIC_TCP_PORT:-${PDNS34_PUBLIC_PORT:-}}:53"
- "${PDNS34_PUBLIC_UDP_PORT:-${PDNS34_PUBLIC_PORT:-}}:53/udp"
depends_on:
- backend
profiles:
- pdns-34
#- pdns-all # TODO re-enable (when working)
pdns44:
image: powerdns/pdns-auth-44
volumes:
- ../pdns-etcd3:/pdns-etcd3:ro
- common:/common
- ./pdns.conf:/etc/powerdns/pdns.conf:ro
- ./pdns-1-listen.conf:/etc/powerdns/pdns.d/pdns-1-listen.conf:ro
- ./pdns-5-${PDNS_BACKEND_MODE:?}.conf:/etc/powerdns/pdns.d/pdns-5-backend.conf:ro
ports:
- "${PDNS44_PUBLIC_TCP_PORT:-${PDNS44_PUBLIC_PORT:-}}:53"
- "${PDNS44_PUBLIC_UDP_PORT:-${PDNS44_PUBLIC_PORT:-}}:53/udp"
depends_on:
- backend
profiles:
- pdns-44
- pdns-all
pdns45:
image: powerdns/pdns-auth-45
volumes:
- ../pdns-etcd3:/pdns-etcd3:ro
- common:/common
- ./pdns.conf:/etc/powerdns/pdns.conf:ro
- ./pdns-1-listen.conf:/etc/powerdns/pdns.d/pdns-1-listen.conf:ro
- ./pdns-3-zone-cache.conf:/etc/powerdns/pdns.d/pdns-3-zone-cache.conf:ro
- ./pdns-5-${PDNS_BACKEND_MODE:?}.conf:/etc/powerdns/pdns.d/pdns-5-backend.conf:ro
ports:
- "${PDNS45_PUBLIC_TCP_PORT:-${PDNS45_PUBLIC_PORT:-}}:53"
- "${PDNS45_PUBLIC_UDP_PORT:-${PDNS45_PUBLIC_PORT:-}}:53/udp"
depends_on:
- backend
profiles:
- pdns-45
- pdns-all
pdns49:
image: powerdns/pdns-auth-49
volumes:
- ../pdns-etcd3:/pdns-etcd3:ro
- common:/common
- ./pdns.conf:/etc/powerdns/pdns.conf:ro
- ./pdns-1-listen.conf:/etc/powerdns/pdns.d/pdns-1-listen.conf:ro
- ./pdns-3-zone-cache.conf:/etc/powerdns/pdns.d/pdns-3-zone-cache.conf:ro
- ./pdns-5-${PDNS_BACKEND_MODE:?}.conf:/etc/powerdns/pdns.d/pdns-5-backend.conf:ro
ports:
- "${PDNS49_PUBLIC_TCP_PORT:-${PDNS49_PUBLIC_PORT:-}}:53"
- "${PDNS49_PUBLIC_UDP_PORT:-${PDNS49_PUBLIC_PORT:-}}:53/udp"
depends_on:
- backend
profiles:
- pdns-49
- pdns-all
pdns50:
image: powerdns/pdns-auth-master
volumes:
- ../pdns-etcd3:/pdns-etcd3:ro
- common:/common
- ./pdns.conf:/etc/powerdns/pdns.conf:ro
- ./pdns-1-listen.conf:/etc/powerdns/pdns.d/pdns-1-listen.conf:ro
- ./pdns-3-zone-cache.conf:/etc/powerdns/pdns.d/pdns-3-zone-cache.conf:ro
- ./pdns-5-${PDNS_BACKEND_MODE:?}.conf:/etc/powerdns/pdns.d/pdns-5-backend.conf:ro
ports:
- "${PDNS50_PUBLIC_TCP_PORT:-${PDNS50_PUBLIC_PORT:-}}:53"
- "${PDNS50_PUBLIC_UDP_PORT:-${PDNS50_PUBLIC_PORT:-}}:53/udp"
depends_on:
- backend
profiles:
- pdns-50
- pdns-all
etcd:
image: quay.io/coreos/etcd:${ETCD_IMAGE_VERSION:-v3.5.14}
volumes:
- etcd-data:/data
command: |
etcd
--data-dir=/data
--name=etcd
--initial-advertise-peer-urls=http://etcd:2380
--listen-peer-urls=http://0.0.0.0:2380
--advertise-client-urls=http://etcd:2379
--listen-client-urls=http://0.0.0.0:2379
--initial-cluster=etcd=http://etcd:2380
--auto-compaction-retention=1h
ports:
- "${ETCD_PUBLIC_CLIENT_PORT:-}:2379"
restart: unless-stopped
etcdkeeper:
build:
context: .
dockerfile: Dockerfile-etcdkeeper
environment:
ETCD_ENDPOINT: etcd:2379
ports:
- "${ETCDKEEPER_PORT:-}:8080"
depends_on:
- etcd
profiles:
- etcdkeeper

volumes:
etcd-data:
common:
4 changes: 4 additions & 0 deletions docker/etcdkeeper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -e
simpleproxy -L 2379 -R "$1" -d
./etcdkeeper
2 changes: 2 additions & 0 deletions docker/pdns-1-listen-legacy.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
local-address=0.0.0.0
local-ipv6=::
1 change: 1 addition & 0 deletions docker/pdns-1-listen.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
local-address=0.0.0.0, ::
2 changes: 2 additions & 0 deletions docker/pdns-3-zone-cache.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# 4.5+: avoid currently unimplemented getAllDomains call
zone-cache-refresh-interval=0
3 changes: 3 additions & 0 deletions docker/pdns-5-pipe-v3.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pipe:
distributor-threads=1
remote-connection-string=pipe:command=/pdns-etcd3,endpoints=etcd:2379,log-trace=main+pdns,log-debug=etcd+data,prefix=DNS/,pdns-version=3
3 changes: 3 additions & 0 deletions docker/pdns-5-pipe.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pipe:
distributor-threads=1
remote-connection-string=pipe:command=/pdns-etcd3,endpoints=etcd:2379,log-trace=main+pdns,log-debug=etcd+data,prefix=DNS/
3 changes: 3 additions & 0 deletions docker/pdns-5-unix-v3.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#unix:
distributor-threads=3
remote-connection-string=unix:path=/common/pdns-etcd3.sock,log-trace=main+pdns,something=useless,pdns-version=3
3 changes: 3 additions & 0 deletions docker/pdns-5-unix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#unix:
distributor-threads=3
remote-connection-string=unix:path=/common/pdns-etcd3.sock,log-trace=main+pdns,something=useless
3 changes: 3 additions & 0 deletions docker/pdns.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
security-poll-suffix=
launch=remote
include-dir=/etc/powerdns/pdns.d
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ require (
github.com/ghodss/yaml v1.0.0
github.com/golang/protobuf v1.0.0
github.com/grpc-ecosystem/grpc-gateway v1.1.0
github.com/sirupsen/logrus v1.8.1
golang.org/x/net v0.0.0-20161018194804-d4c55e66d8c3
google.golang.org/grpc v1.0.1-GA
gopkg.in/yaml.v2 v2.0.0
)

require golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 // indirect
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spacejam/loghisto v0.0.0-20170903153131-ca67f4ecfdd3 h1:ZdlGogSwSZXVtaMY6eTl23ouBWm0Vu0cCz4SuQR0JWQ=
Expand Down Expand Up @@ -580,6 +582,7 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
9 changes: 6 additions & 3 deletions pdns-etcd3.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2016-2022 nix <https://keybase.io/nixn>
/* Copyright 2016-2024 nix <https://keybase.io/nixn>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -16,8 +16,11 @@ package main

import P "github.com/nixn/pdns-etcd3/src"

var gitVersion = "GIT_VERSION_UNSET"
var (
programVersion = P.VersionType{IsDevelopment: true, Major: 2, Minor: 0} // update this in a release branch
gitVersion = "GIT_VERSION_UNSET"
)

func main() {
P.Main(gitVersion)
P.Main(programVersion, gitVersion)
}
44 changes: 44 additions & 0 deletions src/comm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* Copyright 2016-2024 nix <https://keybase.io/nixn>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

package src

import (
"encoding/json"
"io"
)

type commType[T any] struct {
in *json.Decoder
out *json.Encoder
}

func newComm[T any](in io.Reader, out io.Writer) *commType[T] {
comm := commType[T]{
json.NewDecoder(in),
json.NewEncoder(out),
}
comm.out.SetEscapeHTML(false)
return &comm
}

func (comm *commType[T]) read() (*T, error) {
var data T
err := comm.in.Decode(&data)
return &data, err
}

func (comm *commType[T]) write(data any) error {
return comm.out.Encode(data)
}
42 changes: 35 additions & 7 deletions src/const.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2016-2022 nix <https://keybase.io/nixn>
/* Copyright 2016-2024 nix <https://keybase.io/nixn>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -15,29 +15,57 @@ limitations under the License. */
package src

import (
"os"
"regexp"
"time"
)

const (
defaultPdnsVersion = 4
defaultPrefix = ""
)

const (
defaultPdnsVersion = 4
defaultEndpointIPv4 = "127.0.0.1:2379"
defaultEndpointIPv6 = "[::1]:2379"
defaultDialTimeout = 2 * time.Second
minimumDialTimeout = 10 * time.Millisecond
)

const (
pdnsVersionParam = "pdns-version"
prefixParam = "prefix"
logParamPrefix = "log-"
configFileParam = "config-file"
endpointsParam = "endpoints"
dialTimeoutParam = "timeout"
)

const (
defaultsKey = "-defaults-"
optionsKey = "-options-"
keySeparator = "/"
labelPrefix = "+"
idSeparator = "#"
versionSeparator = "@"
)

type ipMetaT map[int]struct {
totalOctets int
partOctets int
separator string
}

var (
qtypeRegex = regexp.MustCompile("^[A-Z]+$")
pid = os.Getpid()
qtypeRegex = regexp.MustCompile("^[A-Z][A-Z0-9]*$")
ipMeta = ipMetaT{
4: {4, 1, `.`},
6: {16, 2, `:`},
}
ipHexRE = regexp.MustCompile("^(0[xX])?([0-9a-fA-F]+)$")
ip4OctetRE = regexp.MustCompile("^[0-9]{1,3}$")
priorityRE = regexp.MustCompile("{priority:(.*?)}")
)

const (
autoPtrOption = "auto-ptr"
ipPrefixOption = "ip-prefix"
zoneAppendDomainOption = "zone-append-domain"
)
Loading

0 comments on commit 55888f7

Please sign in to comment.