config

package
v0.3.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SaveAgentConfig

func SaveAgentConfig(path string, cfg *AgentConfig) error

SaveAgentConfig writes cfg to path atomically (tmp + fsync + rename) with mode 0600. The parent directory is created with mode 0755 if missing.

func SaveServerConfig

func SaveServerConfig(path string, cfg *ServerConfig) error

SaveServerConfig writes the config to path atomically (temp file + rename). Existing comments and unknown fields in the file are not preserved.

Types

type AgentConfig

type AgentConfig struct {
	ServerURL        string        `yaml:"server_url"`
	DataDir          string        `yaml:"data_dir"`
	SigningKeyPath   string        `yaml:"signing_key_path"`
	PollInterval     time.Duration `yaml:"poll_interval"`
	NebulaConfigPath string        `yaml:"nebula_config_path"`
	NebulaPIDFile    string        `yaml:"nebula_pid_file"`
}

func DefaultAgentConfig

func DefaultAgentConfig() *AgentConfig

DefaultAgentConfig returns a config populated with the defaults the agent applies when fields are missing.

SigningKeyPath defaults to /etc/nebula-agent/host.signing.key — agent's Ed25519 poll-signature key lives next to agent.yml, deliberately *not* in /etc/nebula where Nebula's own secrets live (ADR 0004 + #88).

func LoadAgentConfig

func LoadAgentConfig(path string) (*AgentConfig, error)

type AlertsConfig

type AlertsConfig struct {
	Enabled           bool   `yaml:"enabled,omitempty"`
	Interval          string `yaml:"interval,omitempty"`
	Threshold         string `yaml:"threshold,omitempty"`
	WebhookURL        string `yaml:"webhook_url,omitempty"`
	WebhookHMACSecret string `yaml:"webhook_hmac_secret,omitempty"`
}

AlertsConfig drives the periodic cert-expiry scanner and its sinks. Threshold and Interval are parsed as Go durations (e.g. "72h", "5m").

func (AlertsConfig) IntervalDuration

func (a AlertsConfig) IntervalDuration() time.Duration

IntervalDuration returns Interval as a time.Duration. Falls back to 5m when unset or unparseable, matching the documented default.

func (AlertsConfig) ThresholdDuration

func (a AlertsConfig) ThresholdDuration() time.Duration

ThresholdDuration returns Threshold as a time.Duration. Falls back to 72h (three days) when unset or unparseable, matching the documented default.

type CAAutoRotateConfig

type CAAutoRotateConfig struct {
	Enabled   bool          `yaml:"enabled,omitempty"`
	Interval  time.Duration `yaml:"interval,omitempty"`
	Threshold float64       `yaml:"threshold,omitempty"`
}

CAAutoRotateConfig configures the CA auto-rotation scanner: interval between scans, and threshold (as fraction of total lifetime) to trigger rotation. Defaults: Interval=6h, Threshold=0.20 (applied at runtime in the scanner).

type MetricsConfig

type MetricsConfig struct {
	// Prometheus is a pointer so an unset value (yaml omitted) is treated
	// as the default (true). A user setting `prometheus: false` cleanly
	// disables the exporter.
	Prometheus *bool `yaml:"prometheus,omitempty"`
}

MetricsConfig toggles the Prometheus exporter. Legacy Go expvar stays on /debug/vars regardless.

func (MetricsConfig) PrometheusEnabled

func (m MetricsConfig) PrometheusEnabled() bool

PrometheusEnabled returns whether the Prometheus exporter should be served. Defaults to true when unset.

type OIDCConfig

type OIDCConfig struct {
	Enabled       bool     `yaml:"enabled"`
	Issuer        string   `yaml:"issuer"`
	ClientID      string   `yaml:"client_id"`
	ClientSecret  string   `yaml:"client_secret"`
	RedirectURL   string   `yaml:"redirect_url"`
	Scopes        []string `yaml:"scopes,omitempty"`
	UsernameClaim string   `yaml:"username_claim,omitempty"` // default "preferred_username"
	NameClaim     string   `yaml:"name_claim,omitempty"`     // default "name"
	GroupsClaim   string   `yaml:"groups_claim,omitempty"`   // default "groups"
	AllowedGroups []string `yaml:"allowed_groups,omitempty"`
	AllowedEmails []string `yaml:"allowed_emails,omitempty"`
	DefaultRole   string   `yaml:"default_role,omitempty"`

	// RequireEmailVerified gates the post-callback email_verified claim
	// check. Pointer-bool to distinguish unset (default true: the IdP
	// must assert email_verified before the address counts toward
	// AllowedEmails) from an explicit `false` opt-out. The explicit
	// opt-out is the escape hatch for legacy IdPs that omit the claim
	// or send it in a shape HandleCallback can't decode (numeric,
	// nested object, etc). emailVerifiedRequired() resolves nil → true.
	RequireEmailVerified *bool `yaml:"require_email_verified,omitempty"`
}

OIDCConfig configures an OpenID Connect identity provider for operator login. If nil or Enabled=false, OIDC login is not offered.

func (*OIDCConfig) EmailVerifiedRequired

func (o *OIDCConfig) EmailVerifiedRequired() bool

EmailVerifiedRequired reports whether HandleCallback must enforce the email_verified claim. Defaults to true when RequireEmailVerified is unset.

func (*OIDCConfig) Validate

func (o *OIDCConfig) Validate() error

Validate refuses configurations that would silently auto-provision the first OIDC user as admin. Either constrain who can log in (allowed_groups or allowed_emails), or auto-provision as a lower-privileged role (default_role != "admin"). Setting default_role: admin with empty allowlists is permitted only as a deliberate two-field opt-in to "anyone-who-can-log-in-is-admin".

type PasswordConfig

type PasswordConfig struct {
	MinLength      *int  `yaml:"min_length,omitempty"`
	RequireClasses *int  `yaml:"require_classes,omitempty"`
	BlockCommon    *bool `yaml:"block_common,omitempty"`
	BlockUsername  *bool `yaml:"block_username,omitempty"`
}

PasswordConfig overrides the password policy defaults.

type RateLimitConfig

type RateLimitConfig struct {
	// Enabled is a pointer so an absent YAML block defaults to "true"
	// (issue #52 requires on-by-default) while still allowing a
	// `rate_limit: { enabled: false }` to disable it.
	Enabled          *bool                           `yaml:"enabled,omitempty"`
	TrustProxyHeader bool                            `yaml:"trust_proxy_header,omitempty"`
	Groups           map[string]RateLimitGroupConfig `yaml:"groups,omitempty"`
}

RateLimitConfig drives the rate-limit middleware. Enabled defaults to true; turn it off in trusted-network deployments by setting `rate_limit: { enabled: false }`. Set `trust_proxy_header: true` when running behind a reverse proxy that adds X-Forwarded-For.

func (RateLimitConfig) IsEnabled

func (c RateLimitConfig) IsEnabled() bool

IsEnabled returns whether the limiter should run. Default: true.

type RateLimitGroupConfig

type RateLimitGroupConfig struct {
	Rate  float64 `yaml:"rate"`
	Burst int     `yaml:"burst"`
}

RateLimitGroupConfig is the per-group rate/burst pair.

type ServerConfig

type ServerConfig struct {
	Listen     string      `yaml:"listen"`
	DataDir    string      `yaml:"data_dir"`
	DBPath     string      `yaml:"db_path"`
	UIPassword string      `yaml:"ui_password,omitempty"`
	LogLevel   string      `yaml:"log_level"`
	TLSCert    string      `yaml:"tls_cert,omitempty"`
	TLSKey     string      `yaml:"tls_key,omitempty"`
	OIDC       *OIDCConfig `yaml:"oidc,omitempty"`

	// MasterKey is a base64-encoded 32-byte AES-256 key used to wrap
	// per-CA DEKs in the cas table. May be supplied via the
	// NEBULA_MGMT_MASTER_KEY env var instead.
	MasterKey string `yaml:"master_key,omitempty"`

	// AllowSelfRegistration controls whether unauthenticated visitors can
	// create their own operator account through /ui/register. Defaults to
	// false so closed deployments stay closed by default; administrators
	// can still create operators manually via the existing
	// `nebula-mgmt user create` CLI or `POST /api/v1/operators` API.
	AllowSelfRegistration bool `yaml:"allow_self_registration,omitempty"`

	// Metrics configures the optional /metrics Prometheus exporter. Default
	// is "enabled" so out-of-the-box installs can be scraped immediately;
	// air-gapped deployments can set Prometheus=false to drop the route.
	Metrics MetricsConfig `yaml:"metrics,omitempty"`

	// Alerts configures the cert-expiry alerter (see issue #41). Disabled
	// by default — operators must opt in by setting Enabled=true.
	Alerts AlertsConfig `yaml:"alerts,omitempty"`

	// RateLimit configures the per-IP, per-route-group token-bucket
	// limiter that fronts the Web UI and API (see issue #52). Enabled
	// by default so login + enrolment endpoints are protected from
	// online brute-force out of the box.
	RateLimit RateLimitConfig `yaml:"rate_limit,omitempty"`

	// Password configures the password policy applied to every server-
	// side password-setting path (see issue #48). All knobs are
	// optional: unset values fall back to the production defaults
	// (10-char min, 3-of-4 classes, common-pw + username block on).
	Password PasswordConfig `yaml:"password,omitempty"`

	// EnforceTOTP toggles admin-enforced 2FA (issue #49). When set, the
	// value is written into the server_settings table on startup so it
	// stays in effect across restarts. A nil pointer (unset YAML) leaves
	// the DB value alone — the future Settings UI (#47) will edit the
	// same row at runtime.
	EnforceTOTP *bool `yaml:"enforce_2fa,omitempty"`

	// EnrollmentTokenTTL is the default lifetime applied to freshly minted
	// enrollment tokens (ADR 0004 / #75). Per-network overrides live in
	// the `network_config` table under the `enrollment_token_ttl` key.
	// Empty / unparseable value falls back to 24h.
	EnrollmentTokenTTL string `yaml:"enrollment_token_ttl,omitempty"`

	// CAAutoRotate configures the periodic CA auto-rotation scanner (issue #110).
	// Disabled by default — operators must opt in by setting Enabled=true.
	CAAutoRotate CAAutoRotateConfig `yaml:"ca_auto_rotate,omitempty"`

	// CookieSecure controls the `Secure` attribute on session and OIDC
	// state cookies (GHSA-rqfj-vv8r-xhqc). When unset, the effective
	// value is inferred from the TLS configuration: true if both
	// tls_cert and tls_key are populated, false otherwise. Operators
	// terminating TLS at a reverse proxy must set this to true
	// explicitly — `rate_limit.trust_proxy_header` is not a reliable
	// signal that the proxy speaks TLS to clients.
	CookieSecure *bool `yaml:"cookie_secure,omitempty"`
	// contains filtered or unexported fields
}

func LoadServerConfig

func LoadServerConfig(path string) (*ServerConfig, error)

func (ServerConfig) CookieSecureResolved

func (c ServerConfig) CookieSecureResolved() bool

CookieSecureResolved returns the effective Secure-cookie flag for this configuration. Explicit value wins; if unset, infer from the presence of TLS material on the server itself.

func (ServerConfig) EnrollmentTokenTTLDuration

func (c ServerConfig) EnrollmentTokenTTLDuration() time.Duration

EnrollmentTokenTTLDuration returns the configured default token TTL parsed as a Go duration. Falls back to 24h when unset or invalid so the server always has a sane default.

func (*ServerConfig) HasLegacyAPIKey

func (c *ServerConfig) HasLegacyAPIKey() bool

HasLegacyAPIKey reports whether the YAML config contained a top-level `api_key:` key. The field was removed per #127 in favor of one-time stdout output and recovery via `nebula-mgmt ops mint-admin-key`.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL