Documentation
¶
Overview ¶
Package dnssync keeps a Technitium zone in step with hlab's inventory.
The inventory already knows every machine's name, address and hardware address. Keeping the DNS server's idea of the fleet in step with it by hand is exactly the sort of task that is done once, correctly, and then quietly rots as machines are added and addresses change.
Index ¶
- Constants
- func BuildReadScript(zone string) (string, error)
- func BuildSyncScript(zone string, changes []Change, reservations []Reservation) (string, error)
- func ParseRecords(out string) (map[string]string, error)
- func ParseReservations(out string) map[string]string
- func ParseScopeRange(out string) (start, end string)
- func ValidateZone(zone string) error
- type Action
- type Change
- type Plan
- type Record
- type Reservation
Constants ¶
const ( MarkerRecord = "hlab:record" MarkerDone = "hlab:dns-done" MarkerNoAuth = "hlab:no-admin-password" )
Markers the scripts print.
const ( MarkerJSON = "hlab:json" MarkerScope = "hlab:scope" )
Markers separating the two raw API responses the read script returns.
const PasswordPath = "/opt/hlab/stacks/technitium/config/admin-password"
PasswordPath is where the Technitium stack keeps its admin password.
Variables ¶
This section is empty.
Functions ¶
func BuildReadScript ¶
BuildReadScript renders the script that dumps a zone's A records.
The raw response comes back and is parsed here rather than picked apart with sed on the machine. Technitium nests the address inside an rData object, so any line-oriented extraction separates a record's name from its value and silently finds nothing — which reads as an empty zone and would have hlab recreate every record it already has.
func BuildSyncScript ¶
func BuildSyncScript(zone string, changes []Change, reservations []Reservation) (string, error)
BuildSyncScript renders the script that applies the plan.
Only creates and updates are emitted. Nothing is ever deleted: the zone is shared with every device DHCP registers, and a name hlab does not recognise is far more likely to be somebody's phone than a mistake.
func ParseRecords ¶
ParseRecords reads the A records out of the read script's output.
func ParseReservations ¶
ParseReservations reads the reserved leases the scope already holds, keyed by hardware address.
Without this the plan asserts every reservation on every run and therefore always claims there is work to do, which trains an operator to ignore it.
func ParseScopeRange ¶
ParseScopeRange reports the addresses the DHCP scope hands out.
A reservation outside that range means nothing: the server will never offer the address, so pinning it is at best noise and at worst an error the operator has to interpret. Statically configured machines deliberately live outside the pool, which is exactly the case this excludes.
func ValidateZone ¶
ValidateZone rejects a zone name that is not a zone name.
It is interpolated into a URL inside a root shell script, so it is checked rather than trusted.
Types ¶
type Action ¶
type Action string
Action is what should happen to one record.
const ( // Create is a name the zone does not have. Create Action = "create" // Update is a name whose address disagrees with the inventory. Update Action = "update" // Unchanged needs nothing. Unchanged Action = "unchanged" // Extra is a name in the zone that hlab does not know about. It is // reported and never removed. Extra Action = "extra" )
type Change ¶
type Change struct {
Action Action `json:"action" yaml:"action"`
Name string `json:"name" yaml:"name"`
Address string `json:"address,omitempty" yaml:"address,omitempty"`
// Was is the address the zone currently holds, when they disagree.
Was string `json:"was,omitempty" yaml:"was,omitempty"`
}
Change is one difference between the inventory and the zone.
type Plan ¶
type Plan struct {
Zone string `json:"zone" yaml:"zone"`
Changes []Change `json:"changes,omitempty" yaml:"changes,omitempty"`
Reservations []Reservation `json:"reservations,omitempty" yaml:"reservations,omitempty"`
Skipped []string `json:"skipped,omitempty" yaml:"skipped,omitempty"`
}
Plan is the whole difference.
func (Plan) Actionable ¶
Actionable reports whether anything would change.
type Record ¶
type Record struct {
Name string `json:"name" yaml:"name"`
Address string `json:"address" yaml:"address"`
}
Record is one name the zone should hold.
func DesiredRecords ¶
DesiredRecords derives the names a zone should hold from the inventory.
Only managed machines are included. An unmanaged record is something a scan saw once; publishing it as authoritative DNS would give a name to a machine nobody has verified, and hlab has no way to notice when it goes away.
type Reservation ¶
type Reservation struct {
Name string `json:"name" yaml:"name"`
MAC string `json:"mac" yaml:"mac"`
Address string `json:"address" yaml:"address"`
}
Reservation pins a machine's address in DHCP.
func DesiredReservations ¶
func DesiredReservations(hosts []inventory.Host) []Reservation
DesiredReservations pins each machine's address to the interface that holds it, so DHCP cannot hand that address to something else.
The MAC is taken from the interface actually carrying the machine's address rather than the first one found: a machine with both wired and wireless interfaces would otherwise have its address reserved against the wrong one, which is worse than no reservation because it looks done.
func MissingReservations ¶
func MissingReservations(want []Reservation, have map[string]string, start, end string) []Reservation
MissingReservations drops the ones the scope already holds correctly, and the ones it could never hold at all.
An address outside the scope's range is not reservable: the server will never offer it, so pinning it is noise. Statically configured machines are deliberately outside the pool, which is exactly what this excludes — and they never ask DHCP for an address anyway.