Documentation
¶
Overview ¶
Package config loads and validates the node configuration from environment variables.
Index ¶
Constants ¶
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).
const ( DefaultAutoProvisionPlan = "default" DefaultAutoProvisionMax = 100 )
Defaults of the automatic provisioning (ADR 0029). DefaultAutoProvisionMax equals provision.DefaultMax.
Variables ¶
This section is empty.
Functions ¶
func ParseOrigin ¶
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.
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
// ClusterSeeds lists host:port of voter API endpoints for probes to
// connect to (ADR 0034).
ClusterSeeds []string
// JoinToken or JoinTokenFile holds the one-time join token (FA-PKI-02).
// Never log it.
JoinToken string
JoinTokenFile string
// NodeRegion is the optional region label of the node (NODE_REGION, ADR 0034).
NodeRegion string
// NodeLabels are optional key=value labels of the node (NODE_LABELS, ADR 0034).
NodeLabels map[string]string
// ProbeBufferMaxAge is how long unacknowledged probe results are kept
// in the local buffer (PROBE_BUFFER_MAX_AGE, ADR 0034).
ProbeBufferMaxAge time.Duration
// ProbeBufferMaxBytes is the maximum size of the local probe result
// buffer in bytes (PROBE_BUFFER_MAX_BYTES, ADR 0034).
ProbeBufferMaxBytes int64
// ProbeAckRetain is how long acknowledged probe results are retained
// before pruning (PROBE_ACK_RETAIN, ADR 0034).
ProbeAckRetain time.Duration
// ProbeSessionTimeout is how long a probe stream session may be idle
// before timing out (PROBE_SESSION_TIMEOUT, ADR 0034).
ProbeSessionTimeout time.Duration
// ProbeAllowTargets is the local target policy of a probe
// (PROBE_ALLOW_TARGETS, ADR 0044); nil means unset, which a private probe
// refuses at startup.
ProbeAllowTargets *probepolicy.Targets
// ProbeAllowMethods are the HTTP methods a probe may use
// (PROBE_ALLOW_HTTP_METHODS, ADR 0044); nil means the default of the role.
ProbeAllowMethods *probepolicy.Methods
// ProbeAllowTypes are the monitor types a probe may run
// (PROBE_ALLOW_MONITOR_TYPES, ADR 0044); nil means all.
ProbeAllowTypes []string
// ProbeResultDetail is full or minimal (PROBE_RESULT_DETAIL, ADR 0044).
ProbeResultDetail 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
// ProbeOfflineAlert is how long a probe must be unhealthy before an
// offline alert is raised (PROBE_OFFLINE_ALERT, FA-PRB-06, ADR 0035).
ProbeOfflineAlert time.Duration
LogLevel slog.Level
LogFormat string
ShutdownTimeout time.Duration
}
Config is the validated node configuration.
func Load ¶
Load reads the configuration using getenv (usually os.Getenv) and validates it. All validation errors are reported at once.
func (Config) ResolveMetricsToken ¶
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 ¶
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.