Help us shape the future of Go! Take the 2026 Go Developer Survey

config

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 19 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).

View Source
const MinFederationTokenLen = 16

MinFederationTokenLen is the shortest accepted federation token.

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 ClientDownloadsConfig added in v0.13.0

type ClientDownloadsConfig struct {
	// Enabled looks up RustDesk releases on GitHub (cached for 6 h) and serves
	// the Windows installer under a file name that carries this server's
	// settings. false: the page offers only the settings (config string, QR
	// code) and no outbound request is made. Default: true.
	Enabled bool `yaml:"enabled"`
	// Version pins a RustDesk release ("1.4.2"); empty: the latest one.
	Version string `yaml:"version"`
}

ClientDownloadsConfig configures the "Install client" page: the official RustDesk clients, set up for this server.

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"`
	// DBType is the database engine: "sqlite" (default) or "postgres".
	DBType string `yaml:"db_type"`
	// DBPath is the SQLite database file. Default: <DataDir>/panel.db.
	DBPath string `yaml:"db_path"`
	// DatabaseURL is the PostgreSQL connection string, e.g.
	// postgres://user:pass@host:5432/dbname?sslmode=require. It usually
	// carries a password, so it is a Secret (redacted when printed).
	DatabaseURL Secret `yaml:"database_url"`
	// DatabaseURLFile is read when DatabaseURL is empty (Docker/Kubernetes
	// secrets).
	DatabaseURLFile string `yaml:"database_url_file"`
	// 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"`
	Federation FederationConfig `yaml:"federation"`
	// WebClient configures the browser remote desktop client (/connect).
	WebClient WebClientConfig `yaml:"webclient"`
	// ClientDownloads configures the "Install client" page.
	ClientDownloads ClientDownloadsConfig `yaml:"client_downloads"`
	// ShareLinks configures public server share links (/s/<token>).
	ShareLinks ShareLinksConfig `yaml:"share_links"`
}

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 FederationConfig added in v0.11.0

type FederationConfig struct {
	// Enabled serves /api/v1/federation/{health,relays} to peer panels and
	// runs the peer sync loop.
	Enabled bool `yaml:"enabled"`
	// Token is the bearer token peer panels must present to this panel's
	// federation endpoints (at least MinFederationTokenLen characters;
	// required when Enabled). Peers store it as their "auth token" for this
	// panel.
	Token Secret `yaml:"token"`
}

FederationConfig controls panel federation (Server -> Federation). Off by default: when off, /api/v1/federation/* is not served and no peer is synced.

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"`
	// WebProxy controls whether RD Panel proxies browser WebSocket connections
	// (/ws/id and /ws/relay) to local hbbs/hbbr WebSocket listeners. Default: true.
	WebProxy bool `yaml:"web_proxy"`
	// WSIDServer is an explicit override for hbbs WebSocket address (default: IDServer port + 2).
	WSIDServer string `yaml:"ws_id_server"`
	// WSRelayServer is an explicit override for hbbr WebSocket address (default: RelayServer port + 2).
	WSRelayServer string `yaml:"ws_relay_server"`
	// Authz serves POST /internal/hbbs/authorize, where hbbs (AUTHZ_URL)
	// asks the panel whether a connection may start and which control
	// permissions it gets (connection rules and control roles). Loopback
	// callers presenting the secret in AuthzSecretFile only. Default: true.
	Authz bool `yaml:"authz"`
	// AuthzSecretFile holds the bearer secret hbbs presents to the
	// authorization endpoint; generated (32 random bytes, hex, mode 0600)
	// when missing. Default: <DataDir>/hbbs-authz.key.
	AuthzSecretFile string `yaml:"authz_secret_file"`
}

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).

func (HBBSConfig) WSIDAddr added in v0.10.4

func (h HBBSConfig) WSIDAddr() string

WSIDAddr returns the hbbs WebSocket address (WSIDServer if set, else IDServer port + 2).

func (HBBSConfig) WSRelayAddr added in v0.10.4

func (h HBBSConfig) WSRelayAddr() string

WSRelayAddr returns the hbbr WebSocket address (WSRelayServer if set, else RelayServer port + 2).

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 ShareLinksConfig added in v0.14.0

type ShareLinksConfig struct {
	// Enabled serves /s/* and lets admins (and user groups an admin allows)
	// create links.
	Enabled bool `yaml:"enabled"`
}

ShareLinksConfig controls public server share links: pages at <public_url>/s/<token> where anyone with the link gets the client set up for this server and its connection settings. Off by default: /s/* answers 404 and the panel hides the feature.

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 WebClientConfig added in v0.11.0

type WebClientConfig struct {
	// Enabled offers the web client to signed-in users. Default: true.
	Enabled bool `yaml:"enabled"`
	// AdminOnly limits the web client to panel admins.
	AdminOnly bool `yaml:"admin_only"`
	// IDURL / RelayURL are the WebSocket URLs of hbbs (21118) and hbbr
	// (21119) as seen by browsers. Empty: same origin as the panel,
	// /ws/id and /ws/relay.
	IDURL    string `yaml:"id_url"`
	RelayURL string `yaml:"relay_url"`
	// Servers are other RustDesk-compatible servers offered in the web
	// client next to this one (their WebSocket origins are allowed by CSP).
	Servers []WebClientServer `yaml:"servers"`
	// CustomServers lets users enter any server (CSP then allows every wss:
	// origin for WebSocket connections).
	CustomServers bool `yaml:"custom_servers"`
}

WebClientConfig configures the browser remote desktop client.

type WebClientServer added in v0.12.0

type WebClientServer struct {
	Name string `yaml:"name" json:"name"`
	// IDURL is hbbs' WebSocket URL as browsers reach it (wss://host/ws/id).
	IDURL string `yaml:"id_url" json:"id_url"`
	// RelayURL is hbbr's WebSocket URL; empty: IDURL with /ws/relay.
	RelayURL string `yaml:"relay_url" json:"relay_url"`
	// Key is the server's public key (id_ed25519.pub, base64).
	Key string `yaml:"key" json:"key"`
}

WebClientServer is an additional server offered in the web client.

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