config

package
v0.18.12 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package config provides YAML configuration loading for Wadjet.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ABACCondition

type ABACCondition struct {
	Attribute string `yaml:"attribute"` // e.g. "subject.role", "resource.name", "env.source_ip"
	Operator  string `yaml:"operator"`  // eq, neq, in, not_in, gt, lt, gte, lte, contains, regex, exists, not_exists
	Value     string `yaml:"value"`     // single value or comma-separated for "in"/"not_in"
}

ABACCondition defines a condition that must match for the rule to apply.

type ABACObligation

type ABACObligation struct {
	Type   string `yaml:"type"`   // row_filter, mask_column, deny_column, query_limit
	Target string `yaml:"target"` // column name or table name
	Value  string `yaml:"value"`  // filter expression, mask function, limit value
}

ABACObligation defines a side-effect obligation on an allow rule.

type ABACPolicy

type ABACPolicy struct {
	Name        string     `yaml:"name"`
	Description string     `yaml:"description"`
	Priority    int        `yaml:"priority"` // lower = evaluated first
	Enabled     *bool      `yaml:"enabled"`  // nil = true
	Rules       []ABACRule `yaml:"rules"`
}

ABACPolicy defines an attribute-based access control policy in config.

type ABACRule

type ABACRule struct {
	Effect      string           `yaml:"effect"` // "allow" or "deny"
	Conditions  []ABACCondition  `yaml:"conditions"`
	Obligations []ABACObligation `yaml:"obligations"` // only for "allow" rules
}

ABACRule defines a single rule within an ABAC policy.

type Auth

type Auth struct {
	Enabled      bool         `yaml:"enabled"`
	APIKeys      []AuthAPIKey `yaml:"api_keys"`
	JWT          AuthJWT      `yaml:"jwt"`
	MTLS         AuthMTLS     `yaml:"mtls"`
	Roles        []AuthRole   `yaml:"roles"`
	Policies     []AuthPolicy `yaml:"policies"`      // cell-level access policies (legacy)
	ABACPolicies []ABACPolicy `yaml:"abac_policies"` // ABAC access control policies
}

Auth configures authentication and authorization.

type AuthAPIKey

type AuthAPIKey struct {
	Key  string `yaml:"key"`
	Name string `yaml:"name"`
	Role string `yaml:"role"`
}

AuthAPIKey defines an API key credential.

type AuthJWT

type AuthJWT struct {
	Enabled       bool   `yaml:"enabled"`
	Secret        string `yaml:"secret"`
	PublicKeyFile string `yaml:"public_key_file"`
	RoleClaim     string `yaml:"role_claim"`
	Issuer        string `yaml:"issuer"`
}

AuthJWT configures JWT authentication.

type AuthMTLS

type AuthMTLS struct {
	Enabled     bool              `yaml:"enabled"`
	CAFile      string            `yaml:"ca_file"`
	CertFile    string            `yaml:"cert_file"` // server TLS cert
	KeyFile     string            `yaml:"key_file"`  // server TLS key
	RoleMap     map[string]string `yaml:"role_map"`  // CN/SAN -> role
	DefaultRole string            `yaml:"default_role"`
}

AuthMTLS configures mutual TLS authentication.

type AuthPolicy

type AuthPolicy struct {
	Table     string            `yaml:"table"`
	Role      string            `yaml:"role"`
	Columns   map[string]string `yaml:"columns"`    // column -> "allow", "mask", "deny"
	RowFilter string            `yaml:"row_filter"` // SQL WHERE predicate
}

AuthPolicy defines a cell-level access policy for a table+role.

type AuthRole

type AuthRole struct {
	Name        string       `yaml:"name"`
	Tables      []string     `yaml:"tables"`       // table names or "*" for all
	Allow       []string     `yaml:"allow"`        // "read", "write", "admin"
	QueryLimits *QueryLimits `yaml:"query_limits"` // per-role overrides (nil = use global)
}

AuthRole defines a role with table access and permissions.

type ChangeEvent

type ChangeEvent struct {
	Old *Config
	New *Config
}

ChangeEvent describes what changed in a configuration update.

type Config

type Config struct {
	Mode        string      `yaml:"mode"` // standalone, coordinator, worker
	Storage     Storage     `yaml:"storage"`
	NATS        NATS        `yaml:"nats"`
	HTTP        HTTP        `yaml:"http"`
	GRPC        GRPC        `yaml:"grpc"`
	Worker      Worker      `yaml:"worker"`
	Parquet     Parquet     `yaml:"parquet"`
	Auth        Auth        `yaml:"auth"`
	GeoIP       GeoIP       `yaml:"geoip"`
	QueryLimits QueryLimits `yaml:"query_limits"` // global query cost limits
	Telemetry   Telemetry   `yaml:"telemetry"`    // OpenTelemetry tracing export
}

Config is the top-level configuration for Wadjet.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a configuration with sensible defaults.

func Load

func Load(path string) (*Config, error)

Load reads a YAML config file and merges with defaults.

func LoadOrDefault

func LoadOrDefault(path string) *Config

LoadOrDefault loads a config file if it exists, otherwise returns defaults. Environment variables with WADJET_ prefix always override file/default values.

type GRPC

type GRPC struct {
	Addr string `yaml:"addr"`
}

GRPC configures the gRPC API server.

type GeoIP

type GeoIP struct {
	CityDB string `yaml:"city_db"` // path to GeoLite2-City.mmdb
	ASNDB  string `yaml:"asn_db"`  // path to GeoLite2-ASN.mmdb
}

GeoIP configures MaxMind GeoIP database paths.

type HTTP

type HTTP struct {
	Addr string `yaml:"addr"`
}

HTTP configures the HTTP API server.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager provides atomic access to configuration with change notification. Reads are lock-free via atomic.Pointer. Writes are serialized and notify subscribers.

func NewManager

func NewManager(initial *Config, logger *slog.Logger) *Manager

NewManager creates a ConfigManager with the given initial config.

func (*Manager) Apply

func (m *Manager) Apply(newCfg *Config) error

Apply atomically replaces the configuration and notifies subscribers. Fields that should not be hot-reloaded (Mode, HTTP.Addr, NATS.Port) are preserved from the current config.

func (*Manager) Current

func (m *Manager) Current() *Config

Current returns the current configuration. Lock-free.

func (*Manager) Reload

func (m *Manager) Reload(path string) error

Reload reads the config file and applies changes.

func (*Manager) Subscribe

func (m *Manager) Subscribe(fn Subscriber)

Subscribe registers a callback for configuration changes. Subscribers are called synchronously in order during Apply.

type NATS

type NATS struct {
	Port        int      `yaml:"port"`
	URL         string   `yaml:"url"`          // for worker mode: coordinator's NATS URL
	StoreDir    string   `yaml:"store_dir"`    // JetStream storage directory
	ClusterID   string   `yaml:"cluster_id"`   // unique cluster identifier (e.g., "central", "afb-east")
	LeafRemotes []string `yaml:"leaf_remotes"` // remote NATS URLs for leaf node connections
	TLSCert     string   `yaml:"tls_cert"`     // TLS certificate file (server or client)
	TLSKey      string   `yaml:"tls_key"`      // TLS private key file
	TLSCA       string   `yaml:"tls_ca"`       // CA certificate for verifying peers (enables mTLS)
}

NATS configures the embedded NATS server or client connection.

type Parquet

type Parquet struct {
	Compression    string `yaml:"compression"`      // snappy, zstd, gzip, lz4, none
	RowGroupSize   int    `yaml:"row_group_size"`   // rows per row group
	PageBufferSize int    `yaml:"page_buffer_size"` // page size in bytes
}

Parquet configures Parquet file writing.

type QueryLimits

type QueryLimits struct {
	MaxScanBytes            int64 `yaml:"max_scan_bytes"`             // max estimated bytes across all scans
	MaxScanRows             int64 `yaml:"max_scan_rows"`              // max estimated rows across all scans
	MaxScanFiles            int   `yaml:"max_scan_files"`             // max files across all scans
	RequireFilterAboveBytes int64 `yaml:"require_filter_above_bytes"` // require WHERE on tables exceeding this size
	RequireLimitAboveRows   int64 `yaml:"require_limit_above_rows"`   // require LIMIT on scans exceeding this row count
}

QueryLimits configures cost-based query guards. Zero values mean unlimited. Per-role limits in Auth.Roles override these global defaults.

type Storage

type Storage struct {
	Type      string `yaml:"type"`     // "s3" (default) or "file"
	DataDir   string `yaml:"data_dir"` // local directory for type=file
	Endpoint  string `yaml:"endpoint"`
	AccessKey string `yaml:"access_key"`
	SecretKey string `yaml:"secret_key"`
	Bucket    string `yaml:"bucket"`
	UseSSL    bool   `yaml:"use_ssl"`
	Region    string `yaml:"region"`
}

Storage configures the object store connection.

type Subscriber

type Subscriber func(event ChangeEvent)

Subscriber is called when configuration changes.

type Telemetry

type Telemetry struct {
	Endpoint   string  `yaml:"endpoint"`    // OTLP gRPC endpoint (e.g., "localhost:4317")
	Insecure   bool    `yaml:"insecure"`    // use plaintext gRPC (no TLS)
	SampleRate float64 `yaml:"sample_rate"` // 0.0-1.0 (default: 1.0 = always)
}

Telemetry configures OpenTelemetry tracing export.

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher polls a config file for changes and triggers reload. Uses file modtime + size instead of fsnotify to avoid external dependencies.

func NewWatcher

func NewWatcher(cfg WatcherConfig, manager *Manager, logger *slog.Logger) *Watcher

NewWatcher creates a file watcher for configuration hot-reload.

func (*Watcher) Watch

func (w *Watcher) Watch(ctx context.Context)

Watch starts polling in a goroutine and stops when ctx is cancelled.

type WatcherConfig

type WatcherConfig struct {
	Path     string        // config file path
	Interval time.Duration // poll interval (default 2s)
	Debounce time.Duration // debounce window after change detected (default 500ms)
}

WatcherConfig configures the file watcher.

type Worker

type Worker struct {
	MaxConcurrent    int    `yaml:"max_concurrent"`
	CacheBytes       int64  `yaml:"cache_bytes"`
	MemoryBudget     int64  `yaml:"memory_budget"`      // per-task memory budget in bytes (0 = unlimited, no spill)
	SpillDir         string `yaml:"spill_dir"`          // directory for spill files (default: os temp dir)
	ResultStoreBytes int64  `yaml:"result_store_bytes"` // in-memory result store capacity (0 = disabled)
}

Worker configures the worker.

Jump to

Keyboard shortcuts

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