config

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package config loads and validates rdpanel configuration.

Precedence (lowest to highest): built-in defaults, the optional YAML file named by RDPANEL_CONFIG, then environment variables. Paths derived from the data directory (database, key files) are filled in after merging when left empty.

Index

Constants

View Source
const (
	SMTPEncryptionNone     = "none"
	SMTPEncryptionSTARTTLS = "starttls"
	SMTPEncryptionTLS      = "tls"
)

SMTP encryption modes.

View Source
const (
	APIDocsAuth   = "auth"
	APIDocsPublic = "public"
	APIDocsOff    = "off"
)

API docs modes (Config.APIDocs).

Variables

View Source
var ErrWebAuthnUnconfigured = errors.New("no admin_url/public_url and no webauthn.origins: passkeys are disabled")

ErrWebAuthnUnconfigured means no panel URL is known, so passkeys are off.

Functions

func DefaultSMTPPort

func DefaultSMTPPort(encryption string) int

DefaultSMTPPort returns the conventional port of an encryption mode.

func EnvNames

func EnvNames() []string

EnvNames lists every environment variable Load consults (for docs and help).

func ParsePrefixes

func ParsePrefixes(items []string) ([]netip.Prefix, error)

ParsePrefixes parses IPs ("10.0.0.1", "::1") and CIDRs ("10.0.0.0/8").

Types

type AuthConfig

type AuthConfig struct {
	// JWTKey is the HS256 key for client JWTs, read verbatim (raw bytes, no
	// base64) from RUSTDESK_API_JWT_KEY. It must be byte-identical to the key
	// hbbs uses for MUST_LOGIN and to the legacy rustdesk-api key.
	JWTKey Secret `yaml:"jwt_key"`
	// JWTKeyFile is used when JWTKey is empty: a random key is generated there
	// on first start. Default: <DataDir>/jwt.key.
	JWTKeyFile string `yaml:"jwt_key_file"`
	// TokenLifetime is the sliding lifetime of client tokens (DB view).
	TokenLifetime time.Duration `yaml:"token_lifetime"`
	// JWTLifetime is the fixed lifetime embedded in the JWT "exp" claim (the hbbs
	// view; hbbs cannot see revocation). Zero means "same as TokenLifetime".
	JWTLifetime time.Duration `yaml:"jwt_lifetime"`
	// SessionIdle is the idle timeout of panel (web) sessions.
	SessionIdle time.Duration `yaml:"session_idle"`
	// SessionAbsolute is the absolute lifetime of panel (web) sessions.
	SessionAbsolute time.Duration `yaml:"session_absolute"`
}

AuthConfig holds token and session settings.

type Config

type Config struct {
	// Listen is the HTTP bind address, e.g. ":21114" or "127.0.0.1:31114".
	Listen string `yaml:"listen"`
	// PublicURL is the externally visible base URL (scheme://host[:port][/prefix])
	// that RustDesk clients use as "API server". Used for OIDC redirect URIs and HSTS.
	PublicURL string `yaml:"public_url"`
	// AdminURL is the base URL of the panel (SPA + /api/v1/*) when it is served
	// from a different host than PublicURL (e.g. an internal-only admin vhost).
	// Panel-facing redirects (OIDC login/linking) use it. Default: PublicURL.
	AdminURL string `yaml:"admin_url"`
	// DataDir holds panel.db, secret.key and (by default) jwt.key.
	DataDir string `yaml:"data_dir"`
	// DBPath is the SQLite database file. Default: <DataDir>/panel.db.
	DBPath string `yaml:"db_path"`
	// SecretKey is a base64-encoded 32-byte AEAD key for secrets at rest. When
	// empty, the key is loaded from (or generated into) SecretKeyFile.
	SecretKey Secret `yaml:"secret_key"`
	// SecretKeyFile is the AEAD key file. Default: <DataDir>/secret.key.
	SecretKeyFile string `yaml:"secret_key_file"`
	// UpdateCheck lets the About page look up the latest RD Panel
	// release on GitHub (server-side, cached for 6 h; never blocks anything).
	UpdateCheck bool `yaml:"update_check"`
	// APIDocs controls the interactive admin API docs at /api/v1/docs and the
	// spec at /api/v1/openapi.{yaml,json}: "auth" (signed-in users, default),
	// "public" (readable without login) or "off" (404).
	APIDocs string `yaml:"api_docs"`

	Auth     AuthConfig     `yaml:"auth"`
	WebAuthn WebAuthnConfig `yaml:"webauthn"`
	HTTP     HTTPConfig     `yaml:"http"`
	HBBS     HBBSConfig     `yaml:"hbbs"`
	Log      LogConfig      `yaml:"log"`
	Logs     LogsConfig     `yaml:"logs"`
	SMTP     SMTPConfig     `yaml:"smtp"`
	Webhook  WebhookConfig  `yaml:"webhook"`
}

Config is the effective rdpanel configuration.

func Defaults

func Defaults() *Config

Defaults returns the built-in configuration before files and env are applied.

func Load

func Load(lookup LookupFunc) (*Config, error)

Load builds the configuration from defaults, the YAML file named by RDPANEL_CONFIG (if any) and the environment, then validates it.

func (*Config) AdminHTTPS

func (c *Config) AdminHTTPS() bool

AdminHTTPS reports whether the panel (admin) URL uses https: panel cookies (session, CSRF, OIDC binding) get the Secure attribute.

func (*Config) HTTPS

func (c *Config) HTTPS() bool

HTTPS reports whether the public or the admin URL uses https (enables HSTS).

func (*Config) Redacted

func (c *Config) Redacted() ([]byte, error)

Redacted renders the effective configuration as YAML with secrets redacted.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks the configuration and pre-parses derived values.

func (*Config) WebAuthnRP

func (c *Config) WebAuthnRP() (rpID string, origins []string, err error)

WebAuthnRP returns the effective passkey relying party id and allowed origins (see WebAuthnConfig). Browsers reject IP addresses as RP ids, so a panel reached only by IP cannot use passkeys.

type HBBSConfig

type HBBSConfig struct {
	// IDServer is the hbbs rendezvous TCP address (default 127.0.0.1:21116).
	// The hbbs admin channel listens on its port minus one.
	IDServer string `yaml:"id_server"`
	// RelayServer is the hbbr TCP address (default 127.0.0.1:21117); the hbbr
	// admin channel shares this port (loopback only).
	RelayServer string `yaml:"relay_server"`
	// RelayPublicHost is the public host[:port] of the co-located hbbr as
	// clients reach it; the "local" relay on the Relays tab is seeded from it.
	// Default: the first entry of RELAY (the hbbs -r value in the s6 image).
	RelayPublicHost string `yaml:"relay_public_host"`
	// PublicKeyFile is the hbbs public key served to clients. Default: <DataDir>/id_ed25519.pub.
	PublicKeyFile string `yaml:"public_key_file"`
	// Enabled turns on the hbbs/hbbr workers (presence poller, reconciler).
	Enabled bool `yaml:"enabled"`
	// PollInterval is the presence poll period (OnlineRequest to IDServer).
	PollInterval time.Duration `yaml:"poll_interval"`
	// ReconcileInterval is the admin-channel probe / drift-check period.
	ReconcileInterval time.Duration `yaml:"reconcile_interval"`
	// ListDir is hbbr's working directory; when set, the reconciler keeps
	// blacklist.txt / blocklist.txt there in sync with the desired lists
	// (/data in the s6 image). Empty disables writing the files.
	ListDir string `yaml:"list_dir"`
}

HBBSConfig describes how to reach the co-located hbbs/hbbr processes.

func (HBBSConfig) AdminAddr

func (h HBBSConfig) AdminAddr() string

AdminAddr returns the hbbs loopback admin address (rendezvous port - 1).

func (HBBSConfig) RelayAdminAddr

func (h HBBSConfig) RelayAdminAddr() string

RelayAdminAddr returns the hbbr loopback admin address (same as the relay port).

type HTTPConfig

type HTTPConfig struct {
	// TrustedProxies lists IPs/CIDRs whose forwarding headers are honoured.
	TrustedProxies []string `yaml:"trusted_proxies"`
	// RealIPHeader is the header carrying the client IP when the peer is a
	// trusted proxy: X-Forwarded-For, X-Real-IP or CF-Connecting-IP.
	RealIPHeader string `yaml:"real_ip_header"`
	// MetricsAllow lists IPs/CIDRs (as resolved client IPs) allowed to scrape /metrics.
	MetricsAllow []string `yaml:"metrics_allow"`
	// MetricsPerDevice exports rdpanel_presence_device_online{id=...}, one
	// series per device. Off by default: cardinality grows with the fleet.
	MetricsPerDevice bool `yaml:"metrics_per_device"`
	// contains filtered or unexported fields
}

HTTPConfig holds HTTP-layer settings.

func (*HTTPConfig) MetricsAllowPrefixes

func (h *HTTPConfig) MetricsAllowPrefixes() []netip.Prefix

MetricsAllowPrefixes returns the parsed /metrics allow-list (valid after Validate).

func (*HTTPConfig) TrustedProxyPrefixes

func (h *HTTPConfig) TrustedProxyPrefixes() []netip.Prefix

TrustedProxyPrefixes returns the parsed trusted proxy networks (valid after Validate).

type LogConfig

type LogConfig struct {
	// Level is one of debug, info, warn, error.
	Level string `yaml:"level"`
	// Format is json (default) or text.
	Format string `yaml:"format"`
}

LogConfig controls slog output.

type LogsConfig added in v0.3.0

type LogsConfig struct {
	// Buffer is the number of recent lines kept per source (hbbs, hbbr,
	// panel); 0 disables the buffer and the Logs page.
	Buffer int `yaml:"buffer"`
	// Dir holds one s6-log directory per source (<dir>/<source>/current),
	// written by the s6 image's log pipelines (/run/rdpanel/logs there). When
	// empty, only the panel's own lines are captured.
	Dir string `yaml:"dir"`
}

LogsConfig controls the in-memory log buffer behind Server -> Logs.

type LookupFunc

type LookupFunc func(key string) (string, bool)

LookupFunc matches os.LookupEnv; injected for tests.

type SMTPConfig

type SMTPConfig struct {
	Host string `yaml:"host"`
	// Port defaults to 587 (starttls), 465 (tls) or 25 (none).
	Port     int    `yaml:"port"`
	Username string `yaml:"username"`
	Password Secret `yaml:"password"`
	// PasswordFile is read when Password is empty (Docker/Kubernetes secrets).
	PasswordFile string `yaml:"password_file"`
	// From is the sender address, e.g. "RD Panel <panel@example.com>".
	From string `yaml:"from"`
	// Encryption is none, starttls (default) or tls (implicit TLS, "SMTPS").
	Encryption         string `yaml:"encryption"`
	InsecureSkipVerify bool   `yaml:"insecure_skip_verify"`
}

SMTPConfig is the outgoing mail server (e-mail verification, e-mail codes, password reset). E-mail features are off when Host is empty here and in the panel settings; a non-empty Host makes the whole block authoritative (the panel's Settings -> Email form becomes read-only).

func (SMTPConfig) Enabled

func (s SMTPConfig) Enabled() bool

Enabled reports whether the configuration defines a mail server.

type Secret

type Secret string

Secret is a string configuration value that must never be printed or logged. Every textual representation (fmt, JSON, YAML, slog) is redacted; use Reveal to obtain the raw value.

func (Secret) GoString

func (s Secret) GoString() string

GoString implements fmt.GoStringer so %#v is redacted too.

func (Secret) IsSet

func (s Secret) IsSet() bool

IsSet reports whether the secret is non-empty.

func (Secret) LogValue

func (s Secret) LogValue() slog.Value

LogValue implements slog.LogValuer with a redacted value.

func (Secret) MarshalText

func (s Secret) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler (used by JSON) with a redacted value.

func (Secret) MarshalYAML

func (s Secret) MarshalYAML() (any, error)

MarshalYAML implements yaml.Marshaler with a redacted value.

func (Secret) Reveal

func (s Secret) Reveal() string

Reveal returns the raw secret value.

func (Secret) String

func (s Secret) String() string

String implements fmt.Stringer with a redacted value.

type WebAuthnConfig

type WebAuthnConfig struct {
	// RPID is the WebAuthn relying party id: a host name equal to, or a
	// registrable parent domain of, every origin's host (e.g. "example.com" to
	// share passkeys between panel.example.com and admin.example.com).
	RPID string `yaml:"rp_id"`
	// Origins are the exact origins (scheme://host[:port]) the panel SPA is
	// served from. Default: the AdminURL origin, plus the PublicURL origin
	// when its host is within the RP ID.
	Origins []string `yaml:"origins"`
}

WebAuthnConfig overrides the relying party of panel passkeys. Both default from AdminURL (which itself defaults to PublicURL): the RP ID is its host name and the allowed origin is its origin.

type WebhookConfig added in v0.5.4

type WebhookConfig struct {
	URL    string `yaml:"url"`
	Secret Secret `yaml:"secret"`
}

WebhookConfig specifies an optional webhook endpoint for critical alerts.

func (WebhookConfig) Enabled added in v0.5.4

func (w WebhookConfig) Enabled() bool

Enabled reports whether webhooks are configured.

Jump to

Keyboard shortcuts

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