Skip to content

About

Tool that applies phpIPAM changelog to DNS via dynamic updates.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Repository files navigation

phpipam2dns

First goal of this project is to learn go. Side effect is a tool that applies phpIPAM changelog to DNS via dynamic updates.

usage

  • -once: run only once and exits, by default it loops forever with a one second sleep in-between
  • -skip-state: start to handle the changelogs from the first entry, and reconcile every address again

Reconciliation

phpIPAM writes no changelog row for changes made through its API (no logged-in user), so the changelog alone misses them. Every 15 seconds (and on the first loop), phpipam2dns also reads every address that has a hostname from ipaddresses and diffs it against the previous read:

  • new or changed address: A and PTR ensured (the stale A/PTR of a renamed or readdressed one is deleted first)
  • removed address, or hostname cleared: A and PTR deleted
  • rows sharing a deleted hostname or IP are ensured again, since a delete clears every A of the name and every PTR of the IP
  • a failed DNS update is retried on the next pass
  • an empty read while the previous one was not is refused, so an emptied table cannot wipe the zones

The last read is kept in state.json (addresses), so deletions made while phpipam2dns is stopped are still applied. Without it (first run, -skip-state), every address is ensured once. A hostname has a single A and an IP a single PTR: two addresses sharing either one overwrite each other.

Configuration

Environment variables

  • LOG_LEVEL (optional): one of panic, fatal, error, warn, warning, info, debug or trace. Default: info (see logrus ParseLevel)

Config file

Main config file is named config.yml and is expected to be in the current working directory. It contains dsn, zones and key definitions for forward and reverse updates as follow:

  • dsn: using username:password@tcp(ip-or-hostname)/database format. For more information refer to mysql go driver data source name
  • forward zones and reverse zones: configuration for straight and reverse zones. Each of those entries are dictionaries where keys are zone name and values are server definitions, like so:

Example of config.yml

dsn: username:password@tcp(127.0.0.3)/phpipam
forward zones:
  example.com: &server-127-0-0-2-keyname
    server: 127.0.0.2
    algo: hmac-sha256
    keyname: keyname
    secret: wL8Yu+QOrf1+oijvVYgafKIyRYMvXTs6gEMd7yw5wZo=
  example.org: *server-127-0-0-2-keyname
reverse zones:
  0.16.172.in-addr.arpa: *server-127-0-0-2-keyname
  0.168.192.in-addr.arpa: *server-127-0-0-2-keyname
  1.168.192.in-addr.arpa: *server-127-0-0-2-keyname

Bind configuration example

First, generate a key using ddns-confgen -k keyname or tsig-keygen keyname and include the key "xxx" {[...]}; in your bind configuration.

Then configure the zones you want to update with the allow-update stanza. example:

zone "example.com" in {
  type master;
  file "/etc/bind/masters/example.com";
  allow-update { key "keyname"; };
};

Make sure bind has write permission on the folder to write journal files and write permission on zone files for bind to rewrite it on rndc sync calls.

Reload bind and once configured accordingly, run phpipam2dns

Tests

  • Unit: go test ./...
  • End to end: phpIPAM (web + API), MariaDB and BIND in e2e/compose.yml, BIND published on 127.0.0.2:53. The suite builds the binary, makes changes through the phpIPAM API (static app code: reconcile path; user login: changelog path) and reads the result back from BIND.
    docker compose -f e2e/compose.yml up -d --wait
    go test -tags e2e -count=1 ./e2e/
    docker compose -f e2e/compose.yml down -v
    
    With GOCOVERDIR set, the binary is built with -cover and writes its coverage there (go tool covdata textfmt turns it into a profile).
  • CI: unit, E2E and combined coverage in the job summary; the HTML report is the coverage artifact.

About

Tool that applies phpIPAM changelog to DNS via dynamic updates.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages