Documentation
¶
Index ¶
- Constants
- Variables
- func HashPassword(password string) (string, error)
- func SPAHandler() http.Handler
- func StartZabbixAgent(ctx context.Context, addr string, m *metrics.Metrics, c *cache.Cache, ...) error
- func ValidatePassword(password string) error
- type AdminServer
- func (s *AdminServer) CertManager() *certmanager.Manager
- func (s *AdminServer) RecordQuery(client, qname, qtype, rcode string, cached bool, durationMs float64)
- func (s *AdminServer) SetCertManager(cm *certmanager.Manager)
- func (s *AdminServer) SetConfigPath(path string)
- func (s *AdminServer) SetDoHEnabled(enabled bool)
- func (s *AdminServer) SetDoHHandler(h server.Handler)
- func (s *AdminServer) SetRuntimeApplier(fn func(*config.Config))
- func (s *AdminServer) Start(ctx context.Context) error
- func (s *AdminServer) StartUpdateChecker(ctx context.Context)
- type Bucket
- type QueryEntry
- type QueryLog
- type SetupRequest
- type TimeSeriesAggregator
- func (ts *TimeSeriesAggregator) Record(cached bool, latencyMs float64, isError bool)
- func (ts *TimeSeriesAggregator) RecordFallback(query, recovery int64)
- func (ts *TimeSeriesAggregator) Snapshot(window time.Duration) []Bucket
- func (ts *TimeSeriesAggregator) SnapshotAggregated(window, interval time.Duration) []Bucket
- type TopEntry
- type TopTracker
- type UpdateInfo
Constants ¶
const MaxClientQueryNumEntries = 1_000_000
MaxClientQueryNumEntries caps the size of AdminServer.clientQueryNum. The map is populated lazily by RecordQuery on every distinct client IP the resolver sees, and the TTL cleanup (default 5 minutes) only evicts entries idle past 2x the cleanup interval — between ticks a UDP-source-spoofing attacker can populate millions of entries from a single host, and even a busy ISP-side deployment can see 100k+ distinct legitimate clients in a 10-minute window. The cap stops unbounded growth without changing the per-client counter contract: on insert past the cap, the OLDEST-lastAccess entry is evicted. A returning client that was evicted simply restarts at 1 — the counter is a UI convenience, not a security boundary, so resetting it is acceptable when memory pressure forces eviction.
const MaxPasswordLength = 72
MaxPasswordLength caps the password at bcrypt's hard input limit. bcrypt silently truncates input to 72 bytes — without an explicit cap, two passwords sharing the same first 72 bytes hash identically. An operator who chose a 128-char passphrase would not learn that only the first 72 bytes are protective (the "long passphrase as extra security" mental model is a real attack surface here). The cap is enforced by ValidatePassword so the setup wizard and the change-password endpoint both refuse over-cap inputs with a clear message rather than silently accepting them.
const MaxQueryLogCapacity = 1_000_000
MaxQueryLogCapacity caps the QueryLog ring buffer size. Each QueryEntry is ~80 bytes (a few strings, int64s, a float64, a bool), so a 1M-entry ring holds ~80 MiB of buffered query history — enough for a dashboard to display many minutes of activity even on a busy resolver, and small enough that the worst-case footprint stays bounded. Without this cap, a typo in YAML (`query_log_buffer: 1000000000` instead of `1000000`) or a malicious config-raw PUT that planted a 1 GB+ value would allocate that slice upfront in NewQueryLog and OOM the resolver at startup.
const MaxRequestBodyBytes = 1 << 20 // 1 MiB
MaxRequestBodyBytes caps the size of any JSON request body the admin API will read. Every POST/PUT/PATCH handler decodes the body into a struct; without a cap, an attacker (or a buggy automation script) could POST a 1GB JSON blob and exhaust resolver RAM before the decoder failed. 1 MiB is well above any legitimate API request (the largest is a few-hundred-byte NTA install or blocklist domain list) and well below the threshold at which a single body would cause memory pressure. The middleware uses http.MaxBytesReader so Decode() naturally errors with http.MaxBytesError once the cap is exceeded, which jsonResponse turns into a clean 400.
const MinPasswordLength = 8
MinPasswordLength is the minimum required password length.
Variables ¶
var ( Version = "dev" BuildTime = "unknown" GoVersion = "unknown" )
Version info variables — set at build time from main.go.
Functions ¶
func HashPassword ¶
HashPassword hashes a plaintext password using bcrypt. Returns an error if the password is shorter than MinPasswordLength.
func SPAHandler ¶
SPAHandler serves the embedded React SPA, falling back to index.html for client-side routing.
func StartZabbixAgent ¶
func StartZabbixAgent(ctx context.Context, addr string, m *metrics.Metrics, c *cache.Cache, logger *slog.Logger) error
StartZabbixAgent starts a TCP listener implementing the Zabbix agent protocol (ZBXD header).
func ValidatePassword ¶
ValidatePassword checks if a password meets minimum requirements.
Types ¶
type AdminServer ¶
type AdminServer struct {
// contains filtered or unexported fields
}
AdminServer provides the admin dashboard HTTP backend.
func NewAdminServer ¶
func NewAdminServer(cfg *config.Config, c *cache.Cache, m *metrics.Metrics, r *resolver.Resolver, logger *slog.Logger, bl *blocklist.Manager) (*AdminServer, error)
NewAdminServer creates a new AdminServer. The bl parameter is optional and may be nil when the blocklist feature is disabled.
func (*AdminServer) CertManager ¶ added in v0.5.5
func (s *AdminServer) CertManager() *certmanager.Manager
CertManager returns the auto-TLS certificate manager (may be nil).
func (*AdminServer) RecordQuery ¶
func (s *AdminServer) RecordQuery(client, qname, qtype, rcode string, cached bool, durationMs float64)
RecordQuery is called from the DNS handler hook to log a query.
func (*AdminServer) SetCertManager ¶ added in v0.5.5
func (s *AdminServer) SetCertManager(cm *certmanager.Manager)
SetCertManager sets the auto-TLS certificate manager.
func (*AdminServer) SetConfigPath ¶
func (s *AdminServer) SetConfigPath(path string)
func (*AdminServer) SetDoHEnabled ¶
func (s *AdminServer) SetDoHEnabled(enabled bool)
SetDoHEnabled enables or disables the DoH endpoint.
func (*AdminServer) SetDoHHandler ¶
func (s *AdminServer) SetDoHHandler(h server.Handler)
SetDoHHandler sets the DNS handler used for DoH requests.
func (*AdminServer) SetRuntimeApplier ¶ added in v0.6.8
func (s *AdminServer) SetRuntimeApplier(fn func(*config.Config))
SetRuntimeApplier registers a callback invoked after a successful /api/config/raw save. The runtime uses it to hot-apply settings that do not require a process restart (e.g. security.private_address_filter, blocklist toggles). Settings the runtime cannot reload at runtime (listen addresses, TLS material, web server bind) still need a restart.
func (*AdminServer) Start ¶
func (s *AdminServer) Start(ctx context.Context) error
Start starts the HTTP server and blocks until the context is cancelled.
func (*AdminServer) StartUpdateChecker ¶
func (s *AdminServer) StartUpdateChecker(ctx context.Context)
StartUpdateChecker runs a background goroutine that periodically checks for updates.
type Bucket ¶
type Bucket struct {
Timestamp string `json:"timestamp"`
Queries int64 `json:"queries"`
CacheHits int64 `json:"cache_hits"`
CacheMisses int64 `json:"cache_misses"`
Errors int64 `json:"errors"`
AvgLatencyMs float64 `json:"avg_latency_ms"`
CacheHitRatio float64 `json:"cache_hit_ratio"`
FallbackQueries int64 `json:"fallback_queries"`
FallbackRecoveries int64 `json:"fallback_recoveries"`
}
Bucket represents an aggregated time-series data point.
type QueryEntry ¶
type QueryEntry struct {
ID uint64 `json:"id"`
GlobalNum uint64 `json:"global_num"`
ClientNum uint64 `json:"client_num"`
Timestamp string `json:"ts"`
Client string `json:"client"`
QName string `json:"qname"`
QType string `json:"qtype"`
RCode string `json:"rcode"`
Cached bool `json:"cached"`
DurationMs float64 `json:"duration_ms"`
Blocked bool `json:"blocked"`
DNSSECStatus string `json:"dnssec_status,omitempty"`
}
QueryEntry represents a single DNS query log entry.
type QueryLog ¶
type QueryLog struct {
// contains filtered or unexported fields
}
QueryLog is a thread-safe ring buffer of DNS query entries with pub/sub support.
func NewQueryLog ¶
NewQueryLog creates a new QueryLog with the given ring buffer capacity. Values <= 0 fall back to the 1000-entry default; values above MaxQueryLogCapacity are clamped to MaxQueryLogCapacity rather than rejected so an over-eager config doesn't fail-stop the resolver — it just trims the buffer to the cap.
func (*QueryLog) Recent ¶
func (ql *QueryLog) Recent(n int) []QueryEntry
Recent returns the last n entries in chronological order.
func (*QueryLog) Record ¶
func (ql *QueryLog) Record(entry QueryEntry)
Record adds an entry to the ring buffer and fans out to all subscribers.
func (*QueryLog) Subscribe ¶
func (ql *QueryLog) Subscribe() (uint64, <-chan QueryEntry)
Subscribe returns a unique subscription ID and a channel that receives new entries.
func (*QueryLog) Unsubscribe ¶
Unsubscribe removes a subscriber and closes its channel.
type SetupRequest ¶
type SetupRequest struct {
ListenAddr string `json:"listen_addr"`
WebAddr string `json:"web_addr"`
Username string `json:"username"`
Password string `json:"password"`
MaxCacheSize int `json:"max_cache_size"`
MaxDepth int `json:"max_depth"`
RateLimitRate float64 `json:"rate_limit_rate"`
RateLimitBurst int `json:"rate_limit_burst"`
LogLevel string `json:"log_level"`
LogFormat string `json:"log_format"`
}
SetupRequest represents the JSON body for the setup completion endpoint.
type TimeSeriesAggregator ¶
type TimeSeriesAggregator struct {
// contains filtered or unexported fields
}
TimeSeriesAggregator collects rolling 1-hour bucketed counters at 1-second intervals.
func NewTimeSeriesAggregator ¶
func NewTimeSeriesAggregator() *TimeSeriesAggregator
NewTimeSeriesAggregator creates a new time-series aggregator.
func (*TimeSeriesAggregator) Record ¶
func (ts *TimeSeriesAggregator) Record(cached bool, latencyMs float64, isError bool)
Record records a single query into the current time bucket.
func (*TimeSeriesAggregator) RecordFallback ¶ added in v0.6.2
func (ts *TimeSeriesAggregator) RecordFallback(query, recovery int64)
RecordFallback records one fallback query attempt and optionally one recovery.
func (*TimeSeriesAggregator) Snapshot ¶
func (ts *TimeSeriesAggregator) Snapshot(window time.Duration) []Bucket
Snapshot returns all buckets within the given time window.
func (*TimeSeriesAggregator) SnapshotAggregated ¶ added in v0.5.2
func (ts *TimeSeriesAggregator) SnapshotAggregated(window, interval time.Duration) []Bucket
SnapshotAggregated returns buckets within the given window, aggregated into super-buckets of the given interval. For example, window=15m and interval=1m produces ~15 data points. Each super-bucket sums queries/hits/misses/errors and computes a weighted-average latency plus cache-hit ratio.
type TopTracker ¶
type TopTracker struct {
// contains filtered or unexported fields
}
TopTracker is a concurrent top-N tracker that counts occurrences of string keys.
func NewTopTracker ¶
func NewTopTracker(limit int) *TopTracker
NewTopTracker creates a new TopTracker with the given limit.
func (*TopTracker) Inc ¶
func (t *TopTracker) Inc(key string)
Inc increments the count for the given key. If the map exceeds limit*10, low-count entries are pruned.
func (*TopTracker) Top ¶
func (t *TopTracker) Top(n int) []TopEntry
Top returns the top N entries sorted descending by count.
type UpdateInfo ¶
type UpdateInfo struct {
CurrentVersion string `json:"current_version"`
LatestVersion string `json:"latest_version"`
UpdateAvailable bool `json:"update_available"`
ReadOnly bool `json:"read_only"`
ReadOnlyHint string `json:"read_only_hint,omitempty"`
ReleaseURL string `json:"release_url,omitempty"`
ReleaseNotes string `json:"release_notes,omitempty"`
AssetName string `json:"asset_name,omitempty"`
}
UpdateInfo holds information about available updates.
Source Files
¶
- api_blocklist.go
- api_cache.go
- api_config.go
- api_dashboard_layout.go
- api_dnssec.go
- api_doh.go
- api_queries.go
- api_security.go
- api_setup.go
- api_stats.go
- api_system.go
- api_system_profile.go
- api_tls.go
- api_top.go
- api_trace.go
- api_update.go
- api_zabbix.go
- auth.go
- embed.go
- login_limiter.go
- middleware.go
- querylog.go
- server.go
- system_profile_unix.go
- timeseries.go
- timeseries_ws.go
- toptracker.go
- update_unix.go