grindvakt-core
The engine of Grindvakt, the dynamic DNS updater,
as a library. It keeps A, AAAA, TXT and CNAME records on DNSimple or
DigitalOcean pointed at where your machine is, including the libp2p _dnsaddr TXT
record a peer-to-peer node publishes and aliases such as www → home. Use it to add "keep my name pointed at me" to your own
program (a browser, a home server dashboard, a node) without running the Grindvakt service.
[]
= "1.1.0"
What it does
- Finds your public addresses, IPv4 and IPv6 separately.
ip::discoverasks several independent HTTPS echo services per family (each request forced onto that family) and accepts an address only when at least two, and a strict majority of those that answered, agree. When there is nothing worth publishing (CGNAT, private-only, no IPv6) it returnsError::NoGlobalAddress, so a peer-to-peer app knows to use relays. Addresses you already know (for example from libp2p AutoNAT) need no lookup;ip::require_globalchecks them. - Plans.
plan(&provider, zone, &records)reads the zone and returns aPlan: for each wanted recordNoop,Create,Update, orAmbiguouswhen it will not guess (two A records where one is wanted). The plan is the dry run; print it. - Applies.
apply(&provider, &plan)writes it, and refuses the whole plan if anything is ambiguous. Running it again changes nothing.
TXT records are matched by their key (the text up to =, such as dnsaddr=), so your
_dnsaddr records never touch an SPF or site-verification record at the same name.
A name has at most one CNAME, which is kept, retargeted or created:
use Record;
let alias = cname; // trailing dot optional
A CNAME must be alone at its name, so the plan is Ambiguous (and apply refuses it)
when a CNAME is wanted where other records exist (any type, MX included), when an
A/AAAA/TXT record is wanted where a CNAME exists, or when one plan asks for both. CNAMEs
cannot sit at the zone apex, and targets must be full host names. DigitalOcean gets the
trailing dot it requires; DNSimple gets the bare name. Nothing is ever deleted.
What the caller owns
- Secrets: tokens come in as
SecretString. Keep them in your own keyring, or use the optionalvault. - Paths: every file path is an argument. Nothing defaults to
~/.grindvaktunless you turn onstandalone. - Timing: there is no scheduler. Call
plan/applywhen your app wants to (on start, on a network change, every few minutes while open). - UI: errors are typed so you can explain them:
Error::Auth,Error::RateLimited(withretry_after),Error::Ambiguous,Error::NoGlobalAddress,Error::Network,Error::Provider,Error::InvalidRecord. Messages never contain tokens or request URLs.
No CLI, no prompts, no global state, no spawned processes.
Quick start
use ;
async
Your own provider
provider::DnsProvider has a name and three async methods (list, create, update), with
Send futures. Implement it to drive another DNS host or a fake for tests; plan and
apply work with any implementation:
use DnsProvider;
use ;
;
Vault (feature vault)
use Provider;
use ;
use ;
#
A random 256-bit data key encrypts the token JSON with XChaCha20-Poly1305. That key is wrapped
twice, under Argon2id(password) (64 MiB, 3 passes, 1 lane by default; bounds are enforced when
loading so a hostile file can't demand unbounded work) and under HKDF-SHA256(recovery-phrase
entropy). Every AEAD call binds grindvakt-vault-v1. All primitives come from
weirdnet-keys. The file is byte-compatible with
every Grindvakt 0.x release in both directions; the tests prove it against fixtures written by
Grindvakt v0.7.0.
Next to a standalone Grindvakt (feature standalone)
An app that manages home.example.com must not fight a standalone Grindvakt that manages the
same name. standalone::find_conflicts(&["home.example.com"]) reads the standalone app's
config from its default location and reports installs that would conflict. The same feature
holds the standalone app's own config.toml model (config::AppConfig), default paths, and
its single-record sync::sync_once (an A record) and sync::sync_cname_once (a CNAME).
CNAME content from a Weirdnet link (feature weirdnet)
A CNAME's content is a cname::CnameSource: a fixed target name, or a Weirdnet resource link
weirdnet-<app>://<name>/<path> whose name becomes the target. The link is parsed by
weirdnet-schemes (Link::parse); this crate only
decides what it accepts: a resource link on a first-party weirdnet-<app> scheme whose name is
a full DNS host name. Invitation links (join/, answer/), user ids and other names without a
dot, IP addresses, ports, credentials, the bare weirdnet:// scheme and other apps' schemes are
refused, and an error never repeats an invitation code. Nothing is looked up: the target comes
from the link text alone.
use ;
use Record;
let link = "weirdnet-morph://Home.Example.com/notes/a.md";
assert_eq!;
assert!;
let target = WeirdnetLink.target?;
let alias = cname;
# Ok::
The standalone config.toml takes it as record = "cname" and a [cname] table with exactly
one of target or weirdnet_link. record defaults to "a", so existing configs are
unchanged. Without the feature, a config with weirdnet_link is refused with a clear error.
= "example.net"
= "www"
= "cname"
[]
= "weirdnet-morph://home.example.com/site"
Each pass resolves the content again, so changing the link retargets the record. The CNAME rules above still apply (not at the apex, alone at its name, nothing is deleted).
Examples
All of these run offline; the provider examples start a local mock API.
| example | shows |
|---|---|
embed_in_app |
a browser-like host: token from its keyring, addresses from its network stack, a dry-run preview, apply, typed errors for the UI, falling back to relays on CGNAT |
dns_plan_dry_run |
A, AAAA, _dnsaddr TXT and a www CNAME planned against a DNSimple mock, leaving an SPF record alone and refusing a CNAME beside an MX record |
ip_discovery |
IPv4/IPv6 discovery, majority voting, NoGlobalAddress (-- --live asks the real sources) |
vault_roundtrip |
create a vault, unlock by password and by recovery words, reset the password, add a token |
config_load |
load, validate, edit and atomically save the standalone config.toml |
Features
| feature | default | adds |
|---|---|---|
dnsimple |
yes | provider::DnsimpleProvider (official dnsimple crate, rustls) |
digitalocean |
yes | provider::DigitalOceanProvider (reqwest, rustls) |
public-ip |
yes | ip::discover (reqwest, rustls) |
vault |
no | vault: encrypted token file with password and recovery phrase |
standalone |
no | config::AppConfig, paths, sync, standalone::find_conflicts, lock::SingleInstanceLock::acquire |
weirdnet |
no | cname::weirdnet_link_target, and Weirdnet links as CnameSource and [cname] weirdnet_link (weirdnet-schemes) |
default-features = false has no network code: records, the planner, the provider trait,
the address rules, private file writes and the lock. The network features need a Tokio
runtime.
Mobile
Every feature builds for Android and iOS (CI checks aarch64-linux-android and
aarch64-apple-ios). TLS is rustls only, no OpenSSL. On Android, initialize
rustls-platform-verifier from your app before the first HTTPS call, as that crate
documents. Phones usually sit behind carrier NAT, so expect NoGlobalAddress there and use
relays.
Security notes
- Secrets are
secrecy::SecretString(re-exported) and are wiped on drop; vault keys, recovery phrases and token sets print as<redacted>. - Wrong passwords, wrong recovery words and tampering all give the same
Error::WrongSecret. - Files are written to a temp file, fsynced, renamed, and the directory fsynced; symlinks and reparse points are refused.
- Private means
fs::Privacy::CurrentUserby default (Unix0700/0600; Windows a protected DACL for you and SYSTEM), so an ordinary app can keep files in its own profile directory.Privacy::Serviceapplies the Grindvakt service rules (SYSTEM, Administrators and LocalService only) and refuses directories an ordinary user owns.Privacy::ServiceAccount("Name")does the same for a service's own virtual account (NT SERVICE\Name, SID fromfs::service_sid) instead of LocalService, andfs::repair_private_treere-applies a policy to a whole existing tree (for example to move files a LocalService install wrote to the new account). - This crate has not had an independent security audit.
Platforms and MSRV
Linux, macOS, Windows, Android and iOS. Rust 1.99 or newer, edition 2024.
Versioning
grindvakt-core is versioned in lockstep with the Grindvakt app: crate X.Y.Z is exactly
the library inside Grindvakt vX.Y.Z. Every Grindvakt release publishes grindvakt-core X.Y.Z
to crates.io first (both repos release with the shared WeirdBrains script,
scripts/weirdnet_release.py), and the app's release refuses to tag vX.Y.Z until that version is
live on crates.io and the app depends on =X.Y.Z. Semver applies to this crate's public API;
because of the lockstep, a minor or patch version may contain no library changes. The vault
and config formats are stable; changing them would take a major version and a migration path.
License
BSD-3-Clause. See LICENSE.