Coder Social home page Coder Social logo

coredns-pdsql's Introduction

title description weight tags categories date repo home
pdsql
*pdsql* use powerdns generic sql as backend.
10
plugin
pdsql
plugin
external
2017-12-09T10:26:00+08:00

pdsql

pdsql use PowerDNS generic sql as backend.

Use jinzhu/gorm to handle database, support many database as gorm dose.

Syntax

pdsql <dialect> <arg> {
    # enable debug mode
    debug [db]
    # create table for test
    auto-migrate
}

Install Driver

pdsql need db driver for dialect, to install a driver you need to add import in plugin.cfg, like

pdsql_mysql:github.com/jinzhu/gorm/dialects/mysql
pdsql_sqlite:github.com/jinzhu/gorm/dialects/sqlite

pdsql_mysql and pdsql_sqlite are meaningless, choose to prevent duplicated.

Examples

Start a server on the 1053 port, use test.db as backend.

test.:1053 {
    pdsql sqlite3 ./test.db {
        debug db
        auto-migrate
    }
}

Prepare data for test.

# Insert records for wener.test
sqlite3 ./test.db 'insert into records(name,type,content,ttl,disabled)values("wener.test","A","192.168.1.1",3600,0)'
sqlite3 ./test.db 'insert into records(name,type,content,ttl,disabled)values("wener.test","TXT","TXT Here",3600,0)'

When queried for "wener.test. A", CoreDNS will respond with:

;; QUESTION SECTION:
;wener.test.			IN	A

;; ANSWER SECTION:
wener.test.		3600	IN	A	192.168.1.1

When queried for "wener.test. ANY", CoreDNS will respond with:

;; QUESTION SECTION:
;wener.test.			IN	ANY

;; ANSWER SECTION:
wener.test.		3600	IN	A	192.168.1.1
wener.test.		3600	IN	TXT	"TXT Here"

Wildcard

# domain id 1
sqlite3 ./test.db 'insert into domains(name,type)values("example.test","NATIVE")'
sqlite3 ./test.db 'insert into records(domain_id,name,type,content,ttl,disabled)values(1,"*.example.test","A","192.168.1.1",3600,0)'

When queried for "first.example.test. A", CoreDNS will respond with:

;; QUESTION SECTION:
;first.example.test.		IN	A

;; ANSWER SECTION:
first.example.test.	3600	IN	A	192.168.1.1

TODO

  • support wildcard record

coredns-pdsql's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

coredns-pdsql's Issues

Unable to authenticate to PostgreSQL using PGPASSFILE environment variable

Hi,

First off, this might be an upstream bug, unsure.

I am unable to authenticate to my postgresql database using environment variable PGPASSFILE to point to a file containing the password for my database. Storing the same password in the environment variable PGPASSWORD surprisingly works.

These two environment variables are defined in the postgres docs for env vars

PGPASSWORD behaves the same as the password connection parameter. Use of this environment variable is not recommended for security reasons, as some operating systems allow non-root users to see process environment variables via ps; instead consider using a password file (see Section 34.16).

PGPASSFILE behaves the same as the passfile connection parameter.

password file documentation: https://www.postgresql.org/docs/16/libpq-pgpass.html

There is a foot note that the file it self needs to have access mode 0600 which docker can do with mode parameter in secrets-block


Example environment (using Docker compose!)

docker-compose.yml

version: '3.8'

secrets:
  coredns_user_postgres_password:
    file: ./coredns.pgpass

services:
  coredns:
    build:
      context: .
      dockerfile: ./Coredns.dockerfile
      args:
        VERSION: 1.11.1
        TARGETPLATFORM: linux/amd64
    volumes:
      - ./coredns-config:/etc/coredns
    ports:
      - 53:53/udp
    init: true
    restart: always
    command: -conf /etc/coredns-config/Corefile
    depends_on:
      - postgresql
    environment:
      - PGPASSFILE=/run/secrets/coredns_user_postgres_password
    secrets:
      - source: coredns_user_postgres_password
        mode: 0600

  postgresql:
    image: bitnami/postgresql:16.2.0
    init: true
    volumes:
      - db:/bitnami/postgresql
    environment:
      - POSTGRESQL_USERNAME=postgres
      - POSTGRESQL_PASSWORD=postgres
    ports:
      - 5432:5432

volumes:
  db
    driver: local

coredns.pgpass

*:*:*:postgres:postgres

Logs:

# docker compose logs -tf coredns
coredns-1  | 2024-02-16T11:03:26.017368987Z pq: password authentication failed for user "coredns"
coredns-1  | 2024-02-16T11:03:26.437155600Z pq: password authentication failed for user "coredns"
coredns-1  | 2024-02-16T11:03:26.880961062Z pq: password authentication failed for user "coredns"
coredns-1  | 2024-02-16T11:03:27.518046141Z pq: password authentication failed for user "coredns"
coredns-1  | 2024-02-16T11:03:28.545084505Z pq: password authentication failed for user "coredns"
coredns-1  | 2024-02-16T11:03:30.389228798Z pq: password authentication failed for user "coredns"
coredns-1  | 2024-02-16T11:03:33.838719388Z pq: password authentication failed for user "coredns"
coredns-1  | 2024-02-16T11:03:40.477094519Z pq: password authentication failed for user "coredns"


Add MX records

I forked and made a change to pdsql.go to handle MX records. If you want I can do a pull request here with the same change. This was my first attempt at go programming.

Bad column type in MySQL

using varchar(64000) is not valid for MySQL and if auto-migrate is enabled, it would raise an error asking for the column type to be either TEXT or BLOB. Changing that to text in the model fixes the issue.

I'm not sure how to do this via a PR since go modules require the module name and path to be changed to the fork's and therefore the PR is not going to just include the model file but a bunch of other files and go.mod that refer to this repo.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.