From 8959cabd674154e234e66435de03add2cda60fbb Mon Sep 17 00:00:00 2001 From: Bryan Joshua Pedini Date: Sat, 21 Nov 2026 19:48:30 +0100 Subject: [PATCH] coredns-powerdns-api-wrapper deployment --- .gitignore | 1 + README.md | 29 +++++++++++++++++++++++++++++ docker-compose.yml | 37 +++++++++++++++++++++++++++++++++++++ env.example | 25 +++++++++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 .gitignore create mode 100644 docker-compose.yml create mode 100644 env.example diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/README.md b/README.md index 05b19f9..b851366 100644 --- a/README.md +++ b/README.md @@ -1 +1,30 @@ # coredns-powerdns-api-wrapper Deployment +PowerDNS Authoritative API subset used by acme.sh `dns_pdns`, backed by the records table of the CoreDNS `mysql` plugin: [source/coredns-powerdns-api-wrapper](https://git.bjphoster.com/source/coredns-powerdns-api-wrapper). + +Every `/api/v1` call requires `X-API-Key`. `/healthz` is an unauthenticated check that pings MySQL; `/version` reports the running version. The binary starts as root and drops to `PUID`/`PGID` itself, so the compose sets no `user:`. It keeps no local state and needs no volume. + +## Requirements +- MySQL or MariaDB holding the plugin's `records` table. The application never creates or alters it. `CPAW_TABLE_PREFIX` must match the plugin's `table_prefix`. +- A dedicated database user limited to the statements the service runs (`SELECT`, plus `DELETE` and `INSERT` inside one transaction per PATCH): +```sql +CREATE USER 'corednsapi'@'%' IDENTIFIED BY ''; +GRANT SELECT, INSERT, DELETE ON `coredns`.`coredns_records` TO 'corednsapi'@'%'; +``` + +## Usage +```sh +cp env.example .env +# edit .env +docker compose up -d +``` + +`MYSQL_DSN` is built from the `CPAW_DB_*` variables. Wrap `CPAW_DB_PASSWORD` in single quotes in `.env` if it contains `$`, otherwise Compose interpolates it. + +acme.sh connects with `PDNS_Url=https://pdnsapi.example.com`, `PDNS_ServerId` set to `CPAW_PDNS_SERVER_ID` and `PDNS_Token` set to `CPAW_PDNS_API_KEY`. + +## Update +Set `CPAW_VERSION` in `.env`, then: +```sh +docker compose pull +docker compose up -d +``` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0b94aaa --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,37 @@ +--- +services: + coredns-powerdns-api-wrapper: + image: git.bjphoster.com/source/coredns-powerdns-api-wrapper:${CPAW_VERSION} + restart: unless-stopped + stop_grace_period: 30s + environment: + - LISTEN_ADDR=:${TRAEFIK_SERVICE_PORT} + - MYSQL_DSN=${CPAW_DB_USER}:${CPAW_DB_PASSWORD}@tcp(${CPAW_DB_HOST}:${CPAW_DB_PORT})/${CPAW_DB_NAME}?parseTime=true + - TABLE_PREFIX=${CPAW_TABLE_PREFIX} + - PDNS_API_KEY=${CPAW_PDNS_API_KEY} + - PDNS_SERVER_ID=${CPAW_PDNS_SERVER_ID} + - DEFAULT_TTL=${CPAW_DEFAULT_TTL} + - LOG_LEVEL=${CPAW_LOG_LEVEL} + - PUID=${CPAW_PUID} + - PGID=${CPAW_PGID} + labels: + ### Section Træfik + - traefik.enable=${TRAEFIK_ENABLED} + - traefik.docker.network=${TRAEFIK_NETWORK} + # HTTPS + - traefik.http.routers.https-${TRAEFIK_ROUTER}.entrypoints=https + # configure the exposed service + - traefik.http.routers.https-${TRAEFIK_ROUTER}.middlewares=${TRAEFIK_MIDDLEWARES} + - traefik.http.routers.https-${TRAEFIK_ROUTER}.rule=${TRAEFIK_MATCHRULE} + # enable TLS and its certificate provider + - traefik.http.routers.https-${TRAEFIK_ROUTER}.tls=${TRAEFIK_TLSENABLED} + - traefik.http.routers.https-${TRAEFIK_ROUTER}.tls.certresolver=${TRAEFIK_CERTRESOLVER} + # specify a service so a custom port can be used + - traefik.http.services.${TRAEFIK_SERVICE}.loadbalancer.server.port=${TRAEFIK_SERVICE_PORT} + networks: + - traefik + +networks: + traefik: + external: true + name: ${TRAEFIK_NETWORK} diff --git a/env.example b/env.example new file mode 100644 index 0000000..301eb35 --- /dev/null +++ b/env.example @@ -0,0 +1,25 @@ +# Træfik +TRAEFIK_ENABLED=true +TRAEFIK_NETWORK=traefik +TRAEFIK_ROUTER=pdnsapi_example_com +TRAEFIK_SERVICE=pdnsapi_example_com +TRAEFIK_SERVICE_PORT=3000 +TRAEFIK_MATCHRULE=Host(`pdnsapi.example.com`) +TRAEFIK_TLSENABLED=true +TRAEFIK_CERTRESOLVER=letsencrypt +TRAEFIK_MIDDLEWARES=hsts + +# coredns-powerdns-api-wrapper +CPAW_VERSION=1.0.0 +CPAW_DB_HOST=mysql.example.com +CPAW_DB_PORT=3306 +CPAW_DB_USER=corednsapi +CPAW_DB_PASSWORD=changeme +CPAW_DB_NAME=coredns +CPAW_TABLE_PREFIX=coredns_ +CPAW_PDNS_API_KEY=changeme +CPAW_PDNS_SERVER_ID=localhost +CPAW_DEFAULT_TTL=120 +CPAW_LOG_LEVEL=info +CPAW_PUID=1000 +CPAW_PGID=1000