config

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config loads and validates the node configuration from environment variables.

Index

Constants

View Source
const (
	// RolesSourceAccessToken reads the roles claim from the access token (default).
	RolesSourceAccessToken = "access_token"
	// RolesSourceUserInfo reads the roles claim from the userinfo endpoint.
	RolesSourceUserInfo = "userinfo"
)

Supported role sources of the generic profile (ADR 0028).

View Source
const (
	DefaultAutoProvisionPlan = "default"
	DefaultAutoProvisionMax  = 100
)

Defaults of the automatic provisioning (ADR 0029). DefaultAutoProvisionMax equals provision.DefaultMax.

Variables

This section is empty.

Functions

func ParseOrigin

func ParseOrigin(raw string) (string, error)

ParseOrigin returns the canonical origin (lower-case scheme://host[:port]) of an absolute http(s) URL. URLs with a path, query or user info are rejected for CORS_ORIGINS; PUBLIC_URL may carry a path, which is dropped.

Types

type AuthMode

type AuthMode string

AuthMode selects how users authenticate.

const (
	AuthLocal   AuthMode = "local"
	AuthOIDC    AuthMode = "oidc"
	AuthZitadel AuthMode = "zitadel"
)

Supported authentication modes. AuthZitadel is the legacy value of AUTH_MODE=zitadel. Load maps it to AuthOIDC with the zitadel profile and never returns it; it stays for callers that still reference it.

type Config

type Config struct {
	NodeName    string
	Role        Role
	DataDir     string
	HTTPAddr    string
	ClusterAddr string
	// ClusterAdvertise is the stable host:port other nodes use to reach this
	// node; it becomes the Raft server address (ADR 0005, FA-CLU-10).
	ClusterAdvertise string
	// ClusterJoin lists host:port of existing voters to join (FA-CLU-03). A
	// node with existing Raft state ignores it; without state and without
	// ClusterJoin it bootstraps a new cluster (FA-CLU-02).
	ClusterJoin []string
	// JoinToken or JoinTokenFile holds the one-time join token (FA-PKI-02).
	// Never log it.
	JoinToken     string
	JoinTokenFile string
	// RaftTimeout is the Raft heartbeat and election timeout (ADR 0012 A6).
	RaftTimeout time.Duration
	PublicURL   string
	// CORSOrigins are the origins (scheme://host[:port]) of external frontends
	// allowed to call the API from a browser (FA-API-05). The origin of
	// PublicURL is always included.
	CORSOrigins []string
	// MasterKey (base64) or MasterKeyFile provide the KEK (ADR 0011). Never log them.
	MasterKey     string
	MasterKeyFile string
	// ICMPMode is auto, privileged, unprivileged or off (FA-CHK-31).
	ICMPMode string
	// SSRFProtection is auto, on or off (FA-SEC-SSRF); auto enables it in
	// multi-tenant (Zitadel) mode.
	SSRFProtection string
	AuthMode       AuthMode
	// AuthModeAlias is set when AUTH_MODE=zitadel was given. The mode is then
	// AuthOIDC with the zitadel profile; main logs a notice (ADR 0027).
	AuthModeAlias bool
	// OIDC is the OpenID Connect configuration (ADR 0027), zero unless AuthMode is AuthOIDC.
	OIDC OIDCConfig
	// RawCompaction compacts heartbeats older than 48 h (FA-UPT-04).
	RawCompaction bool
	// Retention of raw data, hourly and daily rollups (FA-UPT-05); 0 = forever.
	RetentionRaw    time.Duration
	RetentionHourly time.Duration
	RetentionDaily  time.Duration
	// AuditRetention is how long audit log entries are kept, in command time
	// (AUDIT_RETENTION, FA-DAT-01, ADR 0031). At least 24 hours.
	AuditRetention time.Duration
	// AuthCookieDomain is the Domain of the refresh cookie; empty = host-only cookie (ADR 0008).
	AuthCookieDomain string
	// AlertMaxAttempts is the number of delivery attempts per alert and channel (FA-ALR-03).
	AlertMaxAttempts int
	// AlertBundleWindow bundles the alerts of one Shoutrrr channel that fall due
	// within this window into one message; 0 disables bundling (ADR 0023).
	AlertBundleWindow time.Duration
	// SelfCheckTargets are the raw, trimmed SELF_CHECK_TARGETS entries (ADR 0022);
	// empty disables the connectivity self-check. Parse them with selfcheck.ParseTargets.
	SelfCheckTargets []string
	// SelfHealthFailRatio is the share of deviating heartbeats at which a node
	// counts as impaired, in (0, 1] (ADR 0022).
	SelfHealthFailRatio float64
	// DegradedAfter is how long a voter may know no leader before it enters the
	// degraded mode (DEGRADED_AFTER, ADR 0024). Zero disables the degraded
	// mode, so nothing is sent without quorum.
	DegradedAfter time.Duration
	// MetricsAddr is the listen address of the Prometheus endpoint, host:port
	// (FA-OBS-02, ADR 0025). Empty disables it.
	MetricsAddr string
	// MetricsToken or MetricsTokenFile protect /metrics with a bearer token.
	// Never log them. Read the token with ResolveMetricsToken.
	MetricsToken     string
	MetricsTokenFile string
	// ReplicationLagAlert is the replication lag from which a system alert is
	// raised (REPLICATION_LAG_ALERT, FA-REP-05, ADR 0025).
	ReplicationLagAlert time.Duration
	// ClockSkewAlert is the clock offset from which a system alert is raised
	// (CLOCK_SKEW_ALERT, FA-OBS-01, ADR 0020, ADR 0025).
	ClockSkewAlert time.Duration
	// DiskFreeAlert is the free share of the data directory below which a
	// system alert is raised (DISK_FREE_ALERT, FA-OBS-01, ADR 0025), in (0, 1).
	DiskFreeAlert float64
	// WALSizeAlert is the size in bytes of a WAL file above which a system
	// alert is raised (WAL_SIZE_ALERT, FA-OBS-01, ADR 0025).
	WALSizeAlert    int64
	LogLevel        slog.Level
	LogFormat       string
	ShutdownTimeout time.Duration
}

Config is the validated node configuration.

func Load

func Load(getenv func(string) string) (Config, error)

Load reads the configuration using getenv (usually os.Getenv) and validates it. All validation errors are reported at once.

func (Config) ResolveMetricsToken

func (c Config) ResolveMetricsToken() (string, error)

ResolveMetricsToken returns the bearer token of /metrics. A token file is read and trimmed; an empty result means the endpoint is not protected by a token. The returned value is a secret and must not be logged.

func (Config) SSRFProtectionEnabled

func (c Config) SSRFProtectionEnabled() bool

SSRFProtectionEnabled reports whether check and notification targets in private networks are blocked. Auto enables it for the Zitadel profile, which is the former zitadel mode; AuthZitadel is still honored for callers that build a Config by hand.

type OIDCConfig

type OIDCConfig struct {
	// Profile is generic or zitadel (OIDC_PROFILE).
	Profile OIDCProfile
	// Issuer is the exact iss claim and discovery base, kept as given (OIDC_ISSUER).
	Issuer string
	// Audience must be contained in the aud claim (OIDC_AUDIENCE). With the
	// zitadel profile it is the project ID.
	Audience string
	// ClientIDs are the accepted azp values; the first one is the SPA client (OIDC_CLIENT_IDS).
	ClientIDs []string
	// RequireAZP rejects tokens without azp when true (OIDC_REQUIRE_AZP).
	RequireAZP bool
	// Algorithms are the accepted signature algorithms, each RS256, ES256 or EdDSA (OIDC_ALGORITHMS).
	Algorithms []string
	// MaxTokenTTL is the largest allowed exp minus iat (OIDC_MAX_TOKEN_TTL).
	MaxTokenTTL time.Duration
	// Scopes are requested from the identity provider (OIDC_SCOPES). They
	// always contain openid when set explicitly.
	Scopes []string
	// InsecureHTTP allows an http issuer, for development only (OIDC_INSECURE_HTTP).
	InsecureHTTP bool
	// RolesClaim is a dot path to the roles claim, generic profile only (OIDC_ROLES_CLAIM).
	RolesClaim string
	// RoleMap maps identity provider values to roles, generic profile only (OIDC_ROLE_MAP).
	RoleMap map[string]string
	// RolesSource is access_token or userinfo, generic profile only (OIDC_ROLES_SOURCE).
	RolesSource string
	// DefaultRole is the role for a valid token without a role from the roles source,
	// empty or a tenant role, generic profile only (OIDC_DEFAULT_ROLE).
	DefaultRole string
	// Tenancy is single or multi, zitadel profile only (OIDC_TENANCY). The generic profile is always single.
	Tenancy Tenancy
	// AutoProvision creates the tenant of an unknown organization on its first
	// login (OIDC_AUTO_PROVISION). Only with the zitadel profile and multi tenancy (ADR 0029).
	AutoProvision bool
	// AutoProvisionPlan is the plan of automatically created tenants (OIDC_AUTO_PROVISION_PLAN).
	AutoProvisionPlan string
	// AutoProvisionMax is the highest number of automatically created tenants,
	// counted cluster-wide (OIDC_AUTO_PROVISION_MAX).
	AutoProvisionMax int
	// PlatformOrgID is the Zitadel organization of the platform, zitadel profile only (ZITADEL_PLATFORM_ORG_ID).
	PlatformOrgID string
}

OIDCConfig is the OpenID Connect configuration (ADR 0027). It is zero unless AuthMode is AuthOIDC. Secrets do not occur here; the client IDs are public.

type OIDCProfile

type OIDCProfile string

OIDCProfile selects where roles and tenants come from in an OIDC token (ADR 0027).

const (
	ProfileGeneric OIDCProfile = "generic"
	ProfileZitadel OIDCProfile = "zitadel"
)

Supported OIDC profiles.

type Role

type Role string

Role is the role a node runs in.

const (
	RoleVoter Role = "voter"
	RoleProbe Role = "probe"
)

Supported node roles: a voter participates in the Raft cluster, a probe only runs checks.

type Tenancy

type Tenancy string

Tenancy selects how the zitadel profile maps tokens to tenants (ADR 0027).

const (
	TenancySingle Tenancy = "single"
	TenancyMulti  Tenancy = "multi"
)

Supported tenancy modes of the zitadel profile.

Jump to

Keyboard shortcuts

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