DNS agent
valgrid-agent keeps a DNS server in your network serving the zones of one
Valgrid namespace. It checks the namespace's
DNS configuration regularly, writes
each zone as a standard zone file into a directory your DNS server loads, and
can run a command to make the server reload. Your DNS server keeps answering
from those files while Valgrid is unreachable.
Run one agent next to each DNS server. Several agents can serve the same namespace.
Settings
Each setting can be given as a flag or as an environment variable. A flag wins over its environment variable.
| Flag | Environment variable | Required | Description |
|---|---|---|---|
-api-url |
VALGRID_API_URL |
Yes, except with -init |
Valgrid API base URL, such as https://api.valgrid.io. |
-namespace-id |
VALGRID_NAMESPACE_ID |
Yes, except with -init |
ID of the namespace to serve. |
-token-file |
VALGRID_AGENT_TOKEN_FILE |
One of the two, except with -init |
File holding the agent's token. When both are set, the file is used. |
VALGRID_AGENT_TOKEN |
The agent's token itself. | ||
-zone-dir |
VALGRID_ZONE_DIR |
Yes | Existing directory the zone files are written to. |
-poll-interval |
VALGRID_POLL_INTERVAL |
No, default 30s |
Time between checks, such as 30s or 2m. At least 5s. |
-reload-command |
VALGRID_RELOAD_COMMAND |
No | Command run after zone files change. Arguments are split on spaces, and no shell is used. Replaces the bind profile's own reload. |
-reload-timeout |
VALGRID_RELOAD_TIMEOUT |
No, default 30s |
Time a reload may take. |
-http-timeout |
VALGRID_HTTP_TIMEOUT |
No, default 30s |
Time one request to Valgrid may take. |
-server |
VALGRID_SERVER |
Only with -init |
DNS server profile: coredns or bind. Without it, the agent only writes zone files. See DNS server profiles. |
-corefile |
VALGRID_COREFILE |
No, default <zone-dir>/Corefile |
coredns profile: path of the starter Corefile. Setting it without -server selects the coredns profile. |
-rndc-address |
VALGRID_RNDC_ADDRESS |
No, default 127.0.0.1:953 |
bind profile: host:port of BIND's control channel. |
-rndc-key-file |
VALGRID_RNDC_KEY_FILE |
No, default <zone-dir>/rndc.key |
bind profile: rndc key file. The file must exist unless -reload-command is set. |
-init |
No | Write the profile's starter files and exit, without contacting Valgrid. Needs only -zone-dir and -server, and cannot be combined with -once. |
|
-once |
No | Check once and exit. The exit status is 0 when the zone files are up to date. |
|
-version |
No | Print the version and exit. |
Example configuration
A typical agent next to CoreDNS needs only the required settings and the profile. As environment variables, for example in an env file:
VALGRID_API_URL=https://api.valgrid.io
VALGRID_NAMESPACE_ID=0193f1c2-7a4b-7c3d-9e8f-1a2b3c4d5e6f
VALGRID_AGENT_TOKEN_FILE=/etc/valgrid/agent-token
VALGRID_ZONE_DIR=/var/lib/valgrid
VALGRID_SERVER=coredns
# Optional: check every minute instead of every 30 seconds.
VALGRID_POLL_INTERVAL=1m
The same configuration as flags:
valgrid-agent \
-api-url https://api.valgrid.io \
-namespace-id 0193f1c2-7a4b-7c3d-9e8f-1a2b3c4d5e6f \
-token-file /etc/valgrid/agent-token \
-zone-dir /var/lib/valgrid \
-server coredns \
-poll-interval 1m
Use your own namespace ID, and put your agent's token in
/etc/valgrid/agent-token. The file holds only the token, and must be readable
by the user the agent runs as.
Give the agent its own agent credential, from
vg register agent, or an API token that only
has the config:read permission. Prefer a token file, such as a mounted
secret, over the environment variable.
Files the agent writes
In the zone directory the agent writes:
db.<zone>: one zone file per zone, such asdb.corp.internal. Files that have not changed are left alone, and the files of deleted zones are removed.named.zones.conf: zone declarations for BIND, toincludeinnamed.conf.- The starter files of the server profile, if one is set.
.valgrid-agent-state.json: the configuration version the agent last applied, so that a restarted agent does not download the configuration again.
Do not edit these files; the agent overwrites them. Do not put other db.*
files in the zone directory. Other files, such as a Corefile, are left alone.
When a zone has no NS records at its apex, the agent adds one that points to
the zone's SOA primary name server. If that name is inside the zone, give it an
A or AAAA record, or BIND refuses to load the zone; the agent logs a warning
when it is missing.
Failures
When Valgrid cannot be reached, or the token is rejected, the agent logs the error, keeps the zone files it last wrote, and tries again with a growing delay of up to five minutes. A configuration that the agent cannot turn into zone files is not written at all. When the reload fails, the agent applies the configuration again on the next check, at the normal poll interval.
Logs are JSON lines on standard error.
DNS server profiles
A profile sets up the agent for one DNS server. It writes the server's starter files, each only when it does not exist yet, so your edits are kept. It also decides how the server learns about changes.
| Profile | Starter files | After zone files change |
|---|---|---|
coredns |
Corefile |
Nothing: CoreDNS picks up changed files by itself. |
bind |
named.conf, rndc.key and an empty named.zones.conf |
The agent sends rndc reload to BIND's control channel, signed with the key. |
With the bind profile the agent talks to BIND directly, so it needs no BIND
tools and can run in a separate container. The starter named.conf serves the
zones authoritatively (no recursion), and accepts control commands on port 953
from any address that holds the key. Keep that port on a private network.
Without a profile, the agent only writes zone files and named.zones.conf, and
runs -reload-command if you set one.
Example: BIND
Write the starter files once, then start BIND with them and run the agent:
valgrid-agent -init -server bind -zone-dir /var/lib/valgrid
named -c /var/lib/valgrid/named.conf
VALGRID_API_URL=https://api.valgrid.io \
VALGRID_NAMESPACE_ID=<namespace_id> \
VALGRID_AGENT_TOKEN_FILE=/etc/valgrid/agent-token \
VALGRID_ZONE_DIR=/var/lib/valgrid \
VALGRID_SERVER=bind \
valgrid-agent
To use your own named.conf instead, include the agent's zone list and give
the agent your rndc key and control channel address:
include "/var/lib/valgrid/named.zones.conf";
VALGRID_SERVER=bind \
VALGRID_RNDC_KEY_FILE=/etc/bind/rndc.key \
VALGRID_RNDC_ADDRESS=127.0.0.1:953 \
valgrid-agent
Containers
The agent has its own container image, ghcr.io/valgrid-dns/valgrid-agent.
Run it next to an unmodified DNS server container, not inside it: the two
share the zone directory as a volume, so the DNS server keeps answering while
the agent restarts or is upgraded, and only the agent holds the token. With
CoreDNS no reload command is needed; with BIND the agent reloads it over its
control channel. The deployment guide has ready-made Docker
Compose and Kubernetes examples.
The starter Corefile serves every zone in the zone directory and offers
health (:8080/health) and readiness (:8181/ready) endpoints. Edit it as
you need; the agent writes it only when no file exists. The DNS server must
see the zone directory at the same path as the agent, /var/lib/valgrid in
the image.
Example: CoreDNS
CoreDNS's auto plugin loads every db.<zone> file in a directory and
reloads changed files by itself, so no reload command is needed:
. {
auto {
directory /var/lib/valgrid
reload 30s
}
}
VALGRID_API_URL=https://api.valgrid.io \
VALGRID_NAMESPACE_ID=<namespace_id> \
VALGRID_AGENT_TOKEN_FILE=/etc/valgrid/agent-token \
VALGRID_ZONE_DIR=/var/lib/valgrid \
valgrid-agent