Documentation
¶
Overview ¶
Package render is the bdns renderer: a daemon beside an overlay host that follows the zones its operator names, verifies every state itself, and writes configuration for an ordinary DNS server (docs/render.md).
Index ¶
- Constants
- Variables
- func CatalogFile(name string, serial uint32, members map[string][32]byte) []byte
- func CatalogLabel(origin [32]byte) string
- func HostsFile(z *Zone) (file []byte, skipped int)
- func MasterFile(z *Zone) (file []byte, noNS bool)
- func Public(addr netip.Addr, allow []netip.Prefix) (ok, allowed bool)
- type Backend
- type BackendConfig
- type CheckAnswer
- type Config
- type Dnsmasq
- type EngineConfig
- type ForeignFile
- type Knot
- type MembersConfig
- type Metrics
- type OrgAsker
- type OrgConfig
- type Refusals
- type Renderer
- func (r *Renderer) Backends() []Backend
- func (r *Renderer) Handler() http.Handler
- func (r *Renderer) ListProblems() int
- func (r *Renderer) Once(ctx context.Context) (map[string]string, error)
- func (r *Renderer) Pass(ctx context.Context) (asked bool)
- func (r *Renderer) Reasons() map[string]string
- func (r *Renderer) Run(ctx context.Context) error
- func (r *Renderer) Start() error
- type SOAConfig
- type Skipped
- type Verdict
- type Zone
- type ZoneConfig
Constants ¶
const ( CheckPath = "/v1/check" AdvertisedPath = "/v1/advertised" )
CheckPath and AdvertisedPath are the checker's two questions.
const ( RefusedNotGranted = "not-granted" // the writer is not one of the grant's keys, nor granted by its organization RefusedOrgUnread = "org-unread" // the grant's organization could not be read: no member is admitted through it RefusedNoHost = "no-host" // no live host record of the member's host RefusedAddress = "address" // the address is in a refused range (B6) RefusedChallenge = "challenge" // the local checker's challenge failed RefusedUnjudged = "unjudged" // not challenged yet, or the checker could not judge RefusedNoBinding = "no-binding" // the name has no _bweb binding to one site RefusedNoSite = "no-site" // the checker does not know the bound site RefusedNoChecker = "no-checker" // no local checker is configured )
Why a member, or one of its addresses, is not answered: the values of the reason label of bdns_render_members_refused.
const ( ReasonRefused = "refused" // the refusal list names it; its files are withdrawn ReasonUnreachable = "unreachable" // no overlay host answered ReasonNoChain = "no-chain" // no host holds a state it believes of the origin ReasonVerify = "verify" // what a host answered does not verify from seq 0 ReasonNotOrigin = "not-origin" // the identifier is not an origin's ReasonKey = "key" // the origin's genesis key is not the pinned one ReasonNoRecordSet = "no-record-set" // no host holds a state it believes of the origin's record set ReasonNotAccepted = "not-accepted" // the record set's latest state does not list the origin's commitment ReasonCritical = "critical" // a state has a critical extension this version does not know ReasonLapsed = "lapsed" // every state read is unmined and past its lapse ReasonCheck = "check" // what the origin answers breaks a check (spec section 8) ReasonSerial = "serial" // the origin's serial plus the record set's seq passes 4,294,967,295 ReasonBackend = "backend" // a back end could not write it )
The reasons a zone is not rendered: the values of the reason label, and of a zone's outcome. A zone that is rendered has none.
const DefaultCatalogZone = "bdns.catalog.invalid"
DefaultCatalogZone is a catalog zone's name when none is set. The invalid top-level domain is never delegated (RFC 6761).
const HealthPath = "/health"
HealthPath answers 200: the renderer runs. It does not say a zone is rendered; the metrics do.
const MaxCheckAddrs = 16
MaxCheckAddrs is the most addresses one /v1/check names (the checker's max_addrs default). A longer question is asked in requests of at most this many, and their answers merged.
const MaxMemberTTL = 60
MaxMemberTTL is the longest lifetime of a member address set (B7).
Variables ¶
var ErrOrgStale = enforce.ErrStale
ErrOrgStale marks an allow kept through a failed read: the organization could not be read, and the writer was granted when it last was, within last_good_seconds and at the same organization token. As with the zone's own records, an outage keeps what was rendered for that long, and no longer. It is borg's enforce.ErrStale.
var ErrUnjudged = errors.New("the checker cannot judge now")
ErrUnjudged is a checker that cannot judge now: it answered 503, or did not answer. The renderer keeps its last verdicts, bounded.
var ErrUnknownSite = errors.New("the checker does not know the site")
ErrUnknownSite is a site the checker does not know (404).
var MemberRefusals = []string{RefusedNotGranted, RefusedOrgUnread, RefusedNoHost, RefusedAddress, RefusedChallenge, RefusedUnjudged, RefusedNoBinding, RefusedNoSite, RefusedNoChecker}
MemberRefusals are every value of the reason label.
var Reasons = []string{ReasonRefused, ReasonUnreachable, ReasonNoChain, ReasonVerify, ReasonNotOrigin, ReasonKey, ReasonNoRecordSet, ReasonNotAccepted, ReasonCritical, ReasonLapsed, ReasonCheck, ReasonSerial, ReasonBackend}
Reasons are every value of the reason label.
Functions ¶
func CatalogFile ¶
CatalogFile is a catalog zone (RFC 9432, version 2) of the member zones, by domain: its SOA and NS, which a catalog needs and nobody reads, the version, and one PTR for each member.
func CatalogLabel ¶
CatalogLabel is a member zone's unique label in a catalog zone: the 28 letters of the origin's topic, so a domain that moves to another origin is a new member, and its server starts it afresh (RFC 9432 section 5.4).
func HostsFile ¶
HostsFile is the zone's addresses as a hosts file: the marker, then one line for each A and AAAA record, the name in full. It also returns how many record sets it leaves out: every other type, a wildcard name, which a hosts file cannot hold, and an address record that is not an address.
func MasterFile ¶
MasterFile is the zone as an RFC 1035 master file: the marker, $ORIGIN, the SOA the renderer synthesizes, then every leaf's records in key order, each on a line with its TTL. The same zone gives the same bytes. A zone with no NS record at its apex is written all the same; the second result says so.
func Public ¶ added in v0.3.0
Public reports whether a member may name addr under the public-address rule (B6): not loopback, private, link-local, multicast, documentation, unspecified or reserved, in either family, unless allow lists a range that holds it. allowed reports that the address passed by allow alone.
Types ¶
type Backend ¶
type Backend interface {
Name() string
Reconcile(zones []ZoneConfig) error
Render(z *Zone) error
Remove(domain string) error
Flush(ctx context.Context) error
}
Backend writes zones as one DNS server's configuration. Render and Remove change files; Flush finishes a pass: it writes what spans zones and tells the server, only when a file changed. A back end is used from one goroutine.
Reconcile runs once at start: it withdraws the files of zones no longer configured, by the marker the back end wrote into each, and nothing else in its directory.
A back end never replaces a file it did not write: Render fails with an *ForeignFile when the zone's file is there without the marker.
type BackendConfig ¶
type BackendConfig struct {
// Kind is "knot" (RFC 1035 master files, and a catalog zone) or
// "dnsmasq" (hosts files).
Kind string `json:"kind"`
// Dir is where a knot back end writes <domain>.zone.
Dir string `json:"dir,omitempty"`
// Catalog has a knot back end keep a catalog zone (RFC 9432) of the
// zones it wrote; CatalogZone is its name (default
// bdns.catalog.invalid).
Catalog bool `json:"catalog,omitempty"`
CatalogZone string `json:"catalog_zone,omitempty"`
// Reload is the command a knot back end runs after a file changed
// (default ["knotc", "zone-reload"]); an empty list runs nothing.
Reload *[]string `json:"reload,omitempty"`
// ReloadTimeoutSeconds bounds one run of the reload command (default
// 60).
ReloadTimeoutSeconds int `json:"reload_timeout_seconds,omitempty"`
// HostsDir is where a dnsmasq back end writes <domain>.hosts.
HostsDir string `json:"hostsdir,omitempty"`
}
BackendConfig is one back end.
type CheckAnswer ¶ added in v0.3.0
CheckAnswer is the checker's answer to either question.
type Config ¶
type Config struct {
// Hosts are the overlay hosts whose lookup service is asked, in order:
// the first that answers a chain is read.
Hosts []string `json:"hosts"`
// Headers is the header source proofs are checked against (bcommon
// headers: woc:main, chaintracks:URL, bhs:URL, arcade:URL, or the URL
// of an overlay bridge). Network is main, test or regtest when the
// source does not imply it.
Headers string `json:"headers"`
Network string `json:"network,omitempty"`
// Chain is a chain view (bcommon nodeapi: woc:main, woc:test,
// asset:URL) asked for the proof of a state the host answers without
// one, each proof checked against Headers. Optional: without it a
// state is known mined only by the proof a host's answer carries.
Chain string `json:"chain,omitempty"`
// Engine names the overlay engine on the same host. With a URL the
// renderer asks it to carry each zone's topics. Optional.
Engine EngineConfig `json:"engine,omitzero"`
// Zones are the zones rendered, each by its operator's word: a domain,
// the origin's identifier and the origin's genesis key.
Zones []ZoneConfig `json:"zones"`
// Backends are the DNS servers written for; every zone goes to each.
Backends []BackendConfig `json:"backends"`
// RefuseFile is the refusal list (see Refusals). Optional.
RefuseFile string `json:"refuse_file,omitempty"`
// Listen is an address the metrics (/metrics) and the health path
// (/health) are served on. Optional.
Listen string `json:"listen,omitempty"`
// PollMS is how often each zone's chains are read again (default 2000).
PollMS int `json:"poll_ms,omitempty"`
// Workers is how many zones are read and judged at once (default 8).
Workers int `json:"workers,omitempty"`
// ZoneTimeoutSeconds bounds the read of one zone's chains in one pass
// (default 30): a host or a zone that is slow does not hold the others
// back longer.
ZoneTimeoutSeconds int `json:"zone_timeout_seconds,omitempty"`
// Members is how names with a member rule are answered (docs/render.md
// section 5). Optional: without a checker, such a name answers no member.
Members MembersConfig `json:"members,omitzero"`
}
Config is the renderer's configuration file.
func LoadConfig ¶
LoadConfig reads and checks a configuration file. A member the file names that this version does not know is an error.
type Dnsmasq ¶
type Dnsmasq struct {
// contains filtered or unexported fields
}
Dnsmasq is the back end for dnsmasq: one hosts file a zone, <hostsdir>/<domain>.hosts, holding the zone's A and AAAA records. On Linux dnsmasq reads a file of --hostsdir when it changes, so nothing is signaled.
func NewDnsmasq ¶
func NewDnsmasq(c BackendConfig, skipped func(domain string, n int)) *Dnsmasq
NewDnsmasq is a dnsmasq back end over c. skipped may be nil.
func (*Dnsmasq) Reconcile ¶
func (d *Dnsmasq) Reconcile(zones []ZoneConfig) error
Reconcile removes the hosts files of zones no longer configured.
type EngineConfig ¶
type EngineConfig struct {
// URL is the engine's base URL, such as http://127.0.0.1:8280.
URL string `json:"url,omitempty"`
// AskTTLSeconds is an ask's lifetime (default 600); it is asked again
// at half of it. An engine refuses one above its own bound.
AskTTLSeconds int `json:"ask_ttl_seconds,omitempty"`
}
EngineConfig names the overlay engine asked for topics.
type ForeignFile ¶
type ForeignFile struct{ Path string }
ForeignFile is a file in a back end's directory, at a path the back end writes, that does not carry the back end's marker for what it would write there. It is never replaced.
func (*ForeignFile) Error ¶
func (e *ForeignFile) Error() string
type Knot ¶
type Knot struct {
// contains filtered or unexported fields
}
Knot is the back end for Knot DNS, and for any server that loads RFC 1035 master files: one file a zone, <dir>/<domain>.zone, and with a catalog one more, <dir>/<catalog zone>.zone, that lists them.
func NewKnot ¶
func NewKnot(c BackendConfig, logf func(string, ...any)) *Knot
NewKnot is a knot back end over c.
func (*Knot) Flush ¶
Flush writes the catalog when its members changed and runs the reload command when any file changed. The files of withdrawn zones are deleted once the catalog no longer lists them: after the reload, so the server is not sent looking for a file that is gone, and all the same when the reload fails or is waiting to be tried again. A reload that fails is run again after 1 s, doubling to a minute, not at every pass.
func (*Knot) Reconcile ¶
func (k *Knot) Reconcile(zones []ZoneConfig) error
Reconcile takes the files of configured zones as the catalog's members, so a zone stays on the state it was last rendered at across a restart, and withdraws the files of zones no longer configured as a running renderer does: at the first Flush the catalog stops listing them, the server reloads, and then they are deleted.
func (*Knot) Remove ¶
Remove withdraws a zone: the catalog stops listing it, so the server drops it at the reload, and its file is removed. Without a catalog only the file goes: a server that has the zone loaded answers it until its operator takes it out of the server's configuration, and that is said.
type MembersConfig ¶ added in v0.3.0
type MembersConfig struct {
// TTLSeconds is the lifetime of a member address set and of the records
// that follow it (default 60, at most 60, spec B7). A server is
// challenged again once a lifetime, or half of one with FreshRecheck.
TTLSeconds int `json:"ttl_seconds,omitempty"`
// FreshRecheck (default true) asks the checker again, with fresh=1, for
// each address whose last verdict is half a lifetime old: the checker's
// own cache of a verdict then adds nothing to how long a removed server
// is answered. False asks once a lifetime and takes a cached verdict.
FreshRecheck *bool `json:"fresh_recheck,omitempty"`
// LastGoodSeconds bounds how long a name answers its last good set when
// every admitted member fails (default 600; 0 answers nothing then).
LastGoodSeconds *int `json:"last_good_seconds,omitempty"`
// AllowRanges are address ranges a member may name although the
// public-address rule refuses them (CIDR, either family). The zone's
// records hold no such list in this version, so the operator's
// configuration does.
AllowRanges []string `json:"allow_ranges,omitempty"`
// Checker is the local checker's base URL on loopback, such as
// http://127.0.0.1:9180 (docs/render.md section 5.4). Without it, a
// member name answers no member.
Checker string `json:"checker,omitempty"`
// CheckerTokenFile holds a bearer token the checker is asked with.
CheckerTokenFile string `json:"checker_token_file,omitempty"`
// CheckerTimeoutSeconds bounds one question to the checker (default 30).
CheckerTimeoutSeconds int `json:"checker_timeout_seconds,omitempty"`
// ChallengePort is the port a grant member's address is challenged on,
// over plain HTTP (default 80).
ChallengePort int `json:"challenge_port,omitempty"`
// Org is how a grant that names a borg organization is read
// (docs/render.md section 5.6). Optional: without it, such a grant
// admits its listed keys only.
Org OrgConfig `json:"org,omitzero"`
// contains filtered or unexported fields
}
MembersConfig is how the renderer answers a name with a member rule.
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics are the renderer's metrics, in Prometheus form. Every method is safe on a nil Metrics.
func NewMetrics ¶
NewMetrics are metrics for one renderer, with the Go runtime's and the process's own.
type OrgAsker ¶ added in v0.4.0
type OrgAsker interface {
Allows(ctx context.Context, hall string, org, subject []byte, permission string) (bool, error)
}
OrgAsker answers whether subject holds permission in the borg organization org of hall now. A read it cannot complete is an error: the renderer then admits no member through the organization, unless the answer is true and the error is an ErrOrgStale, an allow read before the outage and still within its bound. The renderer's own is a borg reader (newOrgReader); a test gives its own.
type OrgConfig ¶ added in v0.4.0
type OrgConfig struct {
// Hosts are overlay hosts that carry the organizations' halls, asked in
// order. Every answer is checked against the renderer's headers, and
// every grant held current by its chain view (config key chain, which
// must answer spends).
Hosts []string `json:"hosts,omitempty"`
// AllowSeconds is how long an allow is reused, and how often an
// organization's latest token is read again (default half of
// ttl_seconds, at most ttl_seconds): a grant revoked is answered at most
// this long, plus a record lifetime.
AllowSeconds int `json:"allow_seconds,omitempty"`
// DenySeconds is how long a deny is reused, and how often the latest
// token is read again while a writer is denied (default 10, at most
// allow_seconds): it bounds the reads a writer the organization does
// not grant costs, and how long a member just granted waits.
DenySeconds int `json:"deny_seconds,omitempty"`
// TimeoutSeconds bounds one request to a host (default 10).
TimeoutSeconds int `json:"timeout_seconds,omitempty"`
}
OrgConfig is where and how borg organizations are read.
type Refusals ¶
type Refusals struct {
// contains filtered or unexported fields
}
Refusals is what a renderer refuses to render: a zone by its origin's identifier, by its domain, or by an owner key. One entry a line, "origin:<hex>", "domain:<name>" or "key:<hex>"; blank lines and lines starting with # are skipped, and so is what follows " #" on a line. The file is read again when it changes.
A domain entry refuses that domain and every domain under it. A key entry refuses a zone whose origin or record set has that genesis key or that owner now.
A line that is not an entry is not dropped in silence: it is a problem of the list (Problems), and every other line applies.
func OpenRefusals ¶
OpenRefusals reads a refusal list; an empty path is a list that refuses nothing. A file that cannot be read is an error; a line that is not an entry is a problem of the list.
func (*Refusals) Problems ¶
Problems is how many lines of the list in force are not entries, or 1 when the file could not be read.
type Renderer ¶
type Renderer struct {
// Metrics is optional.
Metrics *Metrics
// Now is the clock a state's lapse is judged by.
Now func() time.Time
// Logf reports a change; nil logs nothing.
Logf func(format string, args ...any)
// Org reads borg organizations for a grant that names one; nil when
// none is configured (members.org). Set before Run to ask another.
Org OrgAsker
// contains filtered or unexported fields
}
Renderer follows the configured zones and writes them to the back ends.
Each pass reads every zone's origin chain and the record set chain it names from the lookup service, verifies both from seq 0 (chainread, as bdns show does), and judges the latest state it believes itself: a host's word that a state is mined, believed or renderable is never taken. A zone whose state does not pass is not written: its files stay as the last pass that did left them. A refused zone's files are removed.
func (*Renderer) Handler ¶
Handler serves /metrics (when the renderer has metrics) and the health path.
func (*Renderer) ListProblems ¶
ListProblems is how many lines of the refusal list in force are not entries (1 when the list cannot be read).
func (*Renderer) Once ¶
Once renders every zone once and returns the zones not rendered, each with its reason.
func (*Renderer) Pass ¶
Pass reads, judges and writes every zone once, then flushes the back ends. Zones are read and judged several at once (workers), each under its own deadline (zone_timeout_seconds), so a host or a zone that is slow holds no other back longer than that; the back ends are written from this goroutine alone, in the configuration's order. It reports whether an ask to the engine changed.
type SOAConfig ¶
type SOAConfig struct {
// MName defaults to the first apex NS record's target, or ns.<domain>
// when the zone has none; RName to hostmaster.<domain>. Both are full
// names, with or without the trailing dot.
MName string `json:"mname,omitempty"`
RName string `json:"rname,omitempty"`
// TTL is the SOA record's own (default 3600).
TTL uint32 `json:"ttl,omitempty"`
Refresh uint32 `json:"refresh,omitempty"` // default 3600
Retry uint32 `json:"retry,omitempty"` // default 600
Expire uint32 `json:"expire,omitempty"` // default 604800
Minimum uint32 `json:"minimum,omitempty"` // default 300
}
SOAConfig is the SOA record's fields other than the serial, which is the origin state's. A zero or empty field takes its default.
type Skipped ¶
type Skipped struct {
Leaf *zonerec.Leaf
// Why is "a name would pass 255 bytes under the domain" or "its data
// is not data of its type".
Why string
}
Skipped is a leaf left out of a zone, and why.
func Fit ¶
Fit splits leaves into those written under a domain and those left out: a leaf whose name, or a name in its data, would pass 255 bytes on the wire under the domain is not answered there (spec section 6), and neither is a leaf with a record that is not data of its type, which a DNS server would refuse the whole zone for.
type Verdict ¶ added in v0.3.0
type Verdict struct {
Address string `json:"address"`
Port int `json:"port"`
URL string `json:"url"`
Pass bool `json:"pass"`
Checked string `json:"checked"`
Samples int `json:"samples"`
Passed int `json:"passed"`
Reason string `json:"reason"`
// Unjudged is an address the checker cannot judge now: it keeps its
// last verdict, as for a 503, and is not a failure.
Unjudged bool `json:"unjudged,omitempty"`
// contains filtered or unexported fields
}
Verdict is one server's verdict, as the checker answers it.
type Zone ¶
type Zone struct {
// Domain is the zone's name in lower case, with no trailing dot.
Domain string
// Origin is the origin's identifier.
Origin [32]byte
// Serial is the SOA serial: the origin state's serial plus the record
// set state's seq.
Serial uint32
// SOA is the configured SOA fields; an empty or zero one is defaulted.
SOA SOAConfig
// Leaves are what the origin answers, in key order, each fitting
// under Domain (Fit).
Leaves []*zonerec.Leaf
}
Zone is one zone as a back end is given it: what its origin answers, verified and checked, under the domain its operator configured.
type ZoneConfig ¶
type ZoneConfig struct {
Domain string `json:"domain"`
// Origin is the origin's identifier, 64 lower-case hex digits.
Origin string `json:"origin"`
// Key is the origin's genesis key, 66 hex digits. It is pinned: an
// origin chain of another genesis key is never rendered.
Key string `json:"key"`
// RecordSet is the origin's record set, 64 lower-case hex digits.
// Optional: given, the first ask carries its topic, so a new zone
// renders in one pass. It must be the origin's base when read.
RecordSet string `json:"record_set,omitempty"`
// SOA overrides the SOA record the renderer writes. Optional.
SOA SOAConfig `json:"soa,omitzero"`
// contains filtered or unexported fields
}
ZoneConfig is one zone.