config

package
v1.138.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DirEnvVar  = "CONFIG_DIR"
	PathEnvVar = "CONFIG_PATH"

	// EnvVar selects the environment for both loaders: configs/environments/$ENV.toml
	// and configs/<service>/$ENV.yaml.
	EnvVar     = "ENV"
	DefaultEnv = "development-l2"

	ConfigFileName = "config.yaml"
)
View Source
const (
	ServiceAuth       = "auth"
	ServiceDataAccess = "data-access"
	// ServiceIAM names the assembly `iam serve all` runs, as opposed to a
	// service it hosts; its profile lives under configs/iam/.
	ServiceIAM = "iam"
)
View Source
const VaultPlaceholder = platformConfig.VaultPlaceholder

VaultPlaceholder and RejectPlaceholder are the platform config's; services outside pkg/ cannot import the internal package, so they reach them here.

Variables

This section is empty.

Functions

func ApplyCORSDefaults added in v1.133.0

func ApplyCORSDefaults(c *configpb.Cors)

ApplyCORSDefaults fills the methods, headers, max age and credentials flag a cors block left out. allowed_origins has no default: the schema requires it.

func LoadDBMigrationConfig added in v1.35.0

func LoadDBMigrationConfig() (platformConfig.DatabaseConfig, error)

LoadDBMigrationConfig loads the platform database config for migrations (driver + a DataSource resolved from the migration credentials), independent of any service. It is used by cmd/migrate, which connects as the migration role; running services load their DB config via Load[T] instead.

func RejectPlaceholder added in v1.88.1

func RejectPlaceholder(field, value string) error

func SecretsPath added in v1.59.0

func SecretsPath(configPath, ref string) string

func SetIfAbsent added in v1.64.0

func SetIfAbsent[T any](field **T, value T)

SetIfAbsent fills an optional field the file left out.

func UsesYAMLConfig added in v1.59.0

func UsesYAMLConfig() bool

func ValidateServiceTokens added in v1.105.0

func ValidateServiceTokens(sa serviceauth.Config) error

ValidateServiceTokens is what every reader of a service token pair requires of it: the current token set, and neither slot still the Vault placeholder.

Types

type AssemblyConfig added in v1.133.0

type AssemblyConfig struct {
	Name        string
	Domains     []string
	Listen      ListenConfig
	ServiceAuth serviceauth.Config
}

AssemblyConfig is a profile's assembly block as boot reads it: the process's name, the domains it hosts, one address per transport its listeners serve with the probe as MetricsAddress, and the one token every caller presents.

type AuthSecrets added in v1.61.0

type AuthSecrets struct {
	SharedSecrets

	OAuthHMACSecret secret.Secret
	OAuthSigningKey secret.Secret
	OAuthProviders  map[string]OAuthClientCredentials
}

type CORSConfig

type CORSConfig struct {
	AllowedOrigins []string `mapstructure:"allowed_origins"`

	AllowedMethods []string `mapstructure:"allowed_methods"`

	AllowedHeaders []string `mapstructure:"allowed_headers"`

	MaxAge int `mapstructure:"max_age" default:"300"`

	AllowCredentials bool `mapstructure:"allow_credentials" default:"false"`
}

func CORSFromProto added in v1.133.0

func CORSFromProto(c *configpb.Cors) CORSConfig

CORSFromProto maps a cors block onto the runtime shape; nil maps to the zero value, for a file that has none.

func PublicCORS added in v1.135.0

func PublicCORS(methods, headers []string, maxAge int) CORSConfig

PublicCORS is the policy for a route any origin may call without credentials, the way gitlab.com's rack-cors opens its discovery documents and its token and revoke routes: a wildcard origin, the methods the route takes, its headers on top of the simple ones, and the configured max age. Credentials stay off because a browser rejects a wildcard origin on a response that allows them.

func (*CORSConfig) Validate

func (c *CORSConfig) Validate() error

type DataAccessSecrets added in v1.61.0

type DataAccessSecrets struct {
	SharedSecrets
}

type DatabaseSecrets added in v1.61.0

type DatabaseSecrets struct {
	Username          string
	Password          secret.Secret
	MigrationUsername string
	MigrationPassword secret.Secret
}

type GRPCConfig added in v1.10.0

type GRPCConfig struct {
	// EnableReflection registers the gRPC server reflection service, which lets
	// clients (grpcurl, grpcui) enumerate services, methods, and message
	// schemas at runtime. Reflection is exposed as a stream RPC and is NOT
	// covered by the unary service-token interceptors, so it is unauthenticated
	// wherever it is on. Keep it off in production (the zero value): it leaks the
	// full API surface of the auth services to anyone who can reach the port.
	// Enabled in development/CI/staging config for debugging.
	EnableReflection bool `mapstructure:"enable_reflection" default:"false"`
}

GRPCConfig holds platform-wide gRPC server settings shared by all services.

type GRPCService

type GRPCService interface {
	GRPCAddr() string
}

type HTTPDefaults

type HTTPDefaults struct {
	ReadTimeout  time.Duration `mapstructure:"read_timeout" default:"30s"`
	WriteTimeout time.Duration `mapstructure:"write_timeout" default:"30s"`
	IdleTimeout  time.Duration `mapstructure:"idle_timeout" default:"60s"`
}

type HTTPService

type HTTPService interface {
	HTTPAddr() string
}

type ListenConfig added in v1.66.0

type ListenConfig struct {
	// GRPCAddress serves every gRPC service, grpc.health.v1 and reflection.
	GRPCAddress string
	// HTTPAddress serves every HTTP route.
	HTTPAddress string
	// MetricsAddress serves labkit's /-/metrics, /-/liveness and /-/readiness.
	MetricsAddress string
}

ListenConfig is the set of addresses one process listens on: at most one gRPC, one HTTP and one metrics listener, whatever it hosts. bind.Assembly produces it from a profile's listeners, and pkg/boot reduces every standalone service's own `*_address` keys to it.

type Loaded added in v1.61.0

type Loaded[T ServiceRoot, S ServiceSecrets] struct {
	Config  T
	Secrets S
}

Loaded is a config file and its secrets, from the secrets file and the files the config references, parsed and validated, with the platform defaults applied. Each service package applies its own defaults when it maps the file.

func LoadAssemblyMigration added in v1.137.0

func LoadAssemblyMigration(name string, domains []string) (*Loaded[*configpb.AssemblyConfig, *MigrationSecrets], error)

LoadAssemblyMigration reads the profile of the assembly named name as the migrate command does. The file is checked as LoadAssembly checks it, so a profile serve all refuses is refused here too, but only the database block of the secrets is read: a migration runs from a secrets file that holds the database credentials alone, with no service token and no OAuth material.

func LoadAssemblyMigrationFile added in v1.137.0

func LoadAssemblyMigrationFile(path string) (*Loaded[*configpb.AssemblyConfig, *MigrationSecrets], error)

LoadAssemblyMigrationFile is LoadAssemblyMigration for a path the caller chose.

func LoadAuth added in v1.61.0

func LoadAuth() (*Loaded[*configpb.AuthConfig, *AuthSecrets], error)

func LoadAuthFile added in v1.61.0

func LoadAuthFile(path string) (*Loaded[*configpb.AuthConfig, *AuthSecrets], error)

func LoadDataAccess added in v1.61.0

func LoadDataAccess() (*Loaded[*configpb.DataAccessConfig, *DataAccessSecrets], error)

func LoadDataAccessFile added in v1.61.0

func LoadDataAccessFile(path string) (*Loaded[*configpb.DataAccessConfig, *DataAccessSecrets], error)

func LoadMigration added in v1.88.0

func LoadMigration() (*Loaded[*configpb.MigrationConfig, *MigrationSecrets], error)

LoadMigration reads the file CONFIG_DIR or CONFIG_PATH names as the migrate command's root, which either service's file satisfies. There is no local file to fall back to: the command has no service name.

func LoadMigrationFile added in v1.88.0

func LoadMigrationFile(path string) (*Loaded[*configpb.MigrationConfig, *MigrationSecrets], error)

func (*Loaded[T, S]) Platform added in v1.96.0

func (l *Loaded[T, S]) Platform() (PlatformConfig, error)

Platform maps the file's platform block onto the runtime config. CORS comes from platform.cors, which only an assembly profile carries; auth/config.FromLoaded sets it from AuthConfig's root cors instead.

type MetricsService added in v1.54.0

type MetricsService interface {
	MetricsAddr() string
}

MetricsService is required of every service pkg/boot.Boot runs: Boot refuses to start a service whose config lacks it. An empty MetricsAddr() skips the metrics server.

type MigrationSecrets added in v1.88.0

type MigrationSecrets struct {
	Database DatabaseSecrets
}

MigrationSecrets is the database block of either service's secrets file, which is all the migrate command reads.

func (*MigrationSecrets) DatabaseSecrets added in v1.88.0

func (s *MigrationSecrets) DatabaseSecrets() DatabaseSecrets

type OAuthClientCredentials added in v1.61.0

type OAuthClientCredentials struct {
	ClientID     string
	ClientSecret secret.Secret
}

type PlatformConfig added in v1.66.0

type PlatformConfig struct {
	Database platformConfig.DatabaseConfig `mapstructure:"database"`
	CORS     CORSConfig                    `mapstructure:"cors"`
	HTTP     HTTPDefaults                  `mapstructure:"http"`
	GRPC     GRPCConfig                    `mapstructure:"grpc"`
}

PlatformConfig is the `[platform]` table: settings every service in a process shares, as opposed to the per-service `[services.<name>]` tables.

func LoadPlatform added in v1.98.0

func LoadPlatform(service string) (PlatformConfig, error)

LoadPlatform maps the platform block of the file ResolveConfigPath(service) picks and validates its database config. The service section is not validated.

func (*PlatformConfig) GetDatabaseConfig added in v1.98.0

func (p *PlatformConfig) GetDatabaseConfig() platformConfig.DatabaseConfig

func (*PlatformConfig) Validate added in v1.137.0

func (p *PlatformConfig) Validate(servesHTTP bool) error

Validate checks the platform block for the servers a process opens: the database always, CORS only when an HTTP server applies it. A standalone service runs it from RuntimeConfig.Validate and an assembly from bind.Assembly, so both paths check the platform alike.

type Profile added in v1.133.0

Profile is a loaded assembly profile: the AssemblyConfig file and its secrets, which have the auth secrets shape because the auth domain is the only one with secrets of its own.

func LoadAssembly added in v1.133.0

func LoadAssembly(name string, domains []string) (*Profile, error)

LoadAssembly reads the profile of the assembly named name from the file CONFIG_DIR or CONFIG_PATH names, else the committed profile under configs/<name>/. A profile written for another assembly is refused: one named for another, or one that does not list exactly the domains the binary hosts.

func LoadAssemblyFile added in v1.133.0

func LoadAssemblyFile(path string) (*Profile, error)

LoadAssemblyFile is LoadAssembly for a path the caller chose. The secrets loaded follow the domains: OAuth material is required when the profile hosts auth and refused when it does not.

type RuntimeConfig

type RuntimeConfig[T ServiceConfig] struct {
	Platform PlatformConfig
	Service  T
}

func Load

func Load[T ServiceConfig](serviceName string) (*RuntimeConfig[T], error)

Load reads serviceName's `[services.<name>]` table and the `[platform]` tables from the TOML files, validated for a standalone binary. `iam serve all` reads its assembly profile instead (LoadAssembly).

func (*RuntimeConfig[T]) GRPCReflectionEnabled added in v1.10.0

func (r *RuntimeConfig[T]) GRPCReflectionEnabled() bool

GRPCReflectionEnabled reports whether gRPC server reflection should be registered. It defaults to false (production-safe) and is opted into by the development/CI/staging environment config. See GRPCConfig.EnableReflection.

func (*RuntimeConfig[T]) GetDatabaseConfig

func (r *RuntimeConfig[T]) GetDatabaseConfig() platformConfig.DatabaseConfig

func (*RuntimeConfig[T]) Validate

func (r *RuntimeConfig[T]) Validate() error

Validate checks the config of a standalone service, its own service token included when it is a TokenService.

type SecretsRoot added in v1.102.0

type SecretsRoot[R any] interface {
	ServiceRoot
	GetSecrets() R
}

SecretsRoot is a config root whose secrets block holds references of type R: AuthSecretRefs, DataAccessSecretRefs or MigrationSecretRefs.

type ServiceConfig

type ServiceConfig interface {
	Validate() error
}

ServiceConfig interface all service configs must implement

type ServiceRoot added in v1.61.0

type ServiceRoot interface {
	proto.Message
	GetPlatform() *configpb.Platform
	GetSecretsFile() string
}

ServiceRoot is a config root message: AuthConfig or DataAccessConfig for a service, MigrationConfig for the migrate command.

type ServiceSecrets added in v1.61.0

type ServiceSecrets interface {
	*AuthSecrets | *DataAccessSecrets | *MigrationSecrets
	DatabaseSecrets() DatabaseSecrets
}

ServiceSecrets is a secrets file held as secret.Secret values, which print and marshal as [REDACTED]: AuthSecrets or DataAccessSecrets for a service, MigrationSecrets for the migrate command. The generated message prints every field, so it never leaves this package.

type SharedSecrets added in v1.61.0

type SharedSecrets struct {
	Database         DatabaseSecrets
	ServiceToken     secret.Secret
	NextServiceToken secret.Secret
}

func (*SharedSecrets) DatabaseSecrets added in v1.88.0

func (s *SharedSecrets) DatabaseSecrets() DatabaseSecrets

DatabaseSecrets is what pkg/config/bind reads from any secrets file.

type Source added in v1.59.0

type Source int
const (
	SourceNone Source = iota
	SourceDir
	SourcePath
	SourceLocal
)

func ResolveConfigPath added in v1.59.0

func ResolveConfigPath(service string) (string, Source, error)

Only the local file is checked for existence, so a wrong CONFIG_DIR or CONFIG_PATH fails at load time naming that path.

type TokenService added in v1.105.0

type TokenService interface {
	ServiceTokens() serviceauth.Config
}

TokenService is a service whose callers present a service token. Load requires one for a standalone binary and rejects the Vault placeholder. Under `iam serve all` the domain configs carry none: every hosted service sits behind the assembly's one token (see boot.BootAll).

Directories

Path Synopsis
Package bind maps a config loaded from YAML onto RuntimeConfig.
Package bind maps a config loaded from YAML onto RuntimeConfig.
Package configtest holds the iam assembly profile the loader and binder tests start from, and the edits that turn it into its variants.
Package configtest holds the iam assembly profile the loader and binder tests start from, and the edits that turn it into its variants.

Jump to

Keyboard shortcuts

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