Stub raus, vollständig implementiert:
* Migration 0014: dns_settings (single-row) + dns_zones.forward_to.
Default-Settings sind sinnvoll für die typische LAN-Resolver-Rolle
(1.1.1.1 + 9.9.9.9 upstream, localnet allow, DNSSEC + qname-min on).
* internal/services/dns: CRUD-Repo für zones, records, settings.
* internal/handlers/dns.go: REST /api/v1/dns/zones, /records, /settings
mit Auto-Reload nach jeder Mutation.
* internal/unbound/unbound.cfg.tpl + unbound.go: Renderer schreibt
/etc/unbound/unbound.conf.d/edgeguard.conf direkt (kein Symlink-
Dance, weil AppArmor unbound nur /etc/unbound erlaubt). Local-zones
authoritativ aus dns_records; forward-zones per stub-zone; default-
forwarders catchen alles sonst.
* main.go: dnsRepo + unbound-Reloader injiziert.
* render.go: unbound.New() bekommt Pool.
* postinst:
- Conf-Datei /etc/unbound/unbound.conf.d/edgeguard.conf wird als
edgeguard:edgeguard 0644 angelegt damit Renderer schreiben kann.
- /etc/edgeguard + Service-Subdirs auf 0755 (Squid + Unbound laufen
NICHT als edgeguard, brauchen Read-Traversal).
- Sudoers: systemctl reload unbound.service whitelisted.
* Template: chroot:"" (Conf liegt außerhalb /var/lib/unbound default-
chroot), DNSSEC-Trust-Anchor NICHT setzen (Distro hat schon
root-auto-trust-anchor-file.conf — sonst doppelter Anchor → start
failure).
* Frontend /dns: PageHeader + zwei Tabs (Zones + Resolver-Settings).
Zones-Tab mit Drawer für Records (CRUD pro Zone, A/AAAA/CNAME/TXT/
MX/SRV/NS/PTR/CAA). Sidebar-Eintrag unter Network.
* i18n DE/EN für dns.* Block.
Verified end-to-end: render → unbound restart → dig @127.0.0.1
example.com → 104.20.23.154 / 172.66.147.243.
Version 1.0.34 (mehrere Iterationen wegen AppArmor + chroot + perms).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
56 lines
2.9 KiB
Go
56 lines
2.9 KiB
Go
package models
|
|
|
|
import "time"
|
|
|
|
// DNSZone is one Unbound zone:
|
|
// - zone_type='local': authoritative, records aus dns_records
|
|
// - zone_type='forward': stub-zone, forward_to ist Komma-Liste
|
|
// von upstream-IPs (z.B. "10.0.0.53, 8.8.8.8")
|
|
type DNSZone struct {
|
|
ID int64 `gorm:"primaryKey" json:"id"`
|
|
Name string `gorm:"column:name;uniqueIndex" json:"name"`
|
|
ZoneType string `gorm:"column:zone_type" json:"zone_type"`
|
|
Description *string `gorm:"column:description" json:"description,omitempty"`
|
|
ManagedBy string `gorm:"column:managed_by" json:"managed_by"`
|
|
ForwardTo *string `gorm:"column:forward_to" json:"forward_to,omitempty"`
|
|
Active bool `gorm:"column:active" json:"active"`
|
|
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
|
|
}
|
|
|
|
func (DNSZone) TableName() string { return "dns_zones" }
|
|
|
|
// DNSRecord — A/AAAA/CNAME/TXT/MX/SRV/NS/PTR/CAA. Value ist die
|
|
// RDATA in Textform (für MX: "10 mail.example.com").
|
|
type DNSRecord struct {
|
|
ID int64 `gorm:"primaryKey" json:"id"`
|
|
ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
|
|
Name string `gorm:"column:name" json:"name"`
|
|
RecordType string `gorm:"column:record_type" json:"record_type"`
|
|
Value string `gorm:"column:value" json:"value"`
|
|
TTL int `gorm:"column:ttl" json:"ttl"`
|
|
Active bool `gorm:"column:active" json:"active"`
|
|
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
|
|
}
|
|
|
|
func (DNSRecord) TableName() string { return "dns_records" }
|
|
|
|
// DNSSettings ist eine Single-Row-Tabelle mit globalen Resolver-
|
|
// Optionen. Default kommt aus der Migration (alle Werte sinnvoll
|
|
// für die typische LAN-Resolver-Rolle).
|
|
type DNSSettings struct {
|
|
ID int64 `gorm:"primaryKey" json:"id"`
|
|
ListenAddresses string `gorm:"column:listen_addresses" json:"listen_addresses"`
|
|
ListenPort int `gorm:"column:listen_port" json:"listen_port"`
|
|
UpstreamForwards string `gorm:"column:upstream_forwards" json:"upstream_forwards"`
|
|
AccessACL string `gorm:"column:access_acl" json:"access_acl"`
|
|
DNSSEC bool `gorm:"column:dnssec" json:"dnssec"`
|
|
QNameMinimisation bool `gorm:"column:qname_minimisation" json:"qname_minimisation"`
|
|
CacheMinTTL int `gorm:"column:cache_min_ttl" json:"cache_min_ttl"`
|
|
CacheMaxTTL int `gorm:"column:cache_max_ttl" json:"cache_max_ttl"`
|
|
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
|
|
}
|
|
|
|
func (DNSSettings) TableName() string { return "dns_settings" }
|