config

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package config loads and validates the Jōei YAML/env configuration.

Index

Constants

View Source
const (
	DefaultAccessTTLMinutes = 15
	DefaultRefreshTTLHours  = 168
)

Default console session lifetimes, applied when the keys are unset. Fifteen minutes keeps a leaked access token short-lived; a week of refresh keeps an operator signed in across a working week.

View Source
const DefaultUpstreamMaxConcurrent = 6

DefaultUpstreamMaxConcurrent is the per-host outbound concurrency cap applied when server.upstream_max_concurrent is unset.

View Source
const DefaultUpstreamRatePerSecond = 10

DefaultUpstreamRatePerSecond is the per-host outbound request-rate cap applied when server.upstream_rate_per_second is unset.

View Source
const MinJWTSecretLen = 32

MinJWTSecretLen mirrors auth.MinSecretLen. It is duplicated rather than imported because config imports nothing from internal/.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthConfig

type AuthConfig struct {
	Users []AuthUser `mapstructure:"users"`
	// JWTSecret signs console session tokens (HS256). Empty means "resolve it
	// elsewhere": JOEI_CONSOLE_JWT_SECRET, then the settings store, then a
	// generated-and-persisted key. See cmd/jo-ei.
	JWTSecret string `mapstructure:"jwt_secret"`
	// AccessTTLMinutes is the access-token lifetime; zero selects the default
	// (DefaultAccessTTLMinutes).
	AccessTTLMinutes int `mapstructure:"access_ttl_minutes"`
	// RefreshTTLHours is the refresh-token lifetime; zero selects the default
	// (DefaultRefreshTTLHours).
	RefreshTTLHours int `mapstructure:"refresh_ttl_hours"`
}

AuthConfig holds the console/API credentials and JWT session parameters. An empty Users list means authentication is unconfigured; the API then serves 503 (fail-closed) while the console shell still loads its login screen.

type AuthUser

type AuthUser struct {
	Username     string `mapstructure:"username"`
	PasswordHash string `mapstructure:"password_hash"`
}

AuthUser is one console credential: a username and a bcrypt password hash.

type CVEConfig

type CVEConfig struct {
	Enabled         bool   `mapstructure:"enabled"`
	BaseURL         string `mapstructure:"base_url"`          // default "https://api.osv.dev"
	BlockOn         string `mapstructure:"block_on"`          // "CRITICAL"|"HIGH"|"MEDIUM"|"LOW"
	CacheTTLMinutes int    `mapstructure:"cache_ttl_minutes"` // default 1440
}

CVEConfig configures the CVE scanner (osv.dev).

type CacheConfig

type CacheConfig struct {
	Backend      string             `mapstructure:"backend"` // local | s3
	Local        LocalCache         `mapstructure:"local"`
	S3           S3Cache            `mapstructure:"s3"`
	Revalidation RevalidationConfig `mapstructure:"revalidation"`
}

type Config

type Config struct {
	Server      ServerConfig      `mapstructure:"server"`
	TLS         TLSConfig         `mapstructure:"tls"`
	Registries  RegistriesConfig  `mapstructure:"registries"`
	SupplyChain SupplyChainConfig `mapstructure:"supply_chain"`
	CVE         CVEConfig         `mapstructure:"cve"`
	ImageScan   ImageScanConfig   `mapstructure:"image_scan"`
	Malware     MalwareConfig     `mapstructure:"malware"`
	Cache       CacheConfig       `mapstructure:"cache"`
	Policy      PolicyConfig      `mapstructure:"policy"`
	Logging     LoggingConfig     `mapstructure:"logging"`
	Console     ConsoleConfig     `mapstructure:"console"`
	Health      HealthConfig      `mapstructure:"health"`
	Database    DatabaseConfig    `mapstructure:"database"`
}

func Load

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

Load reads a YAML config file and returns a Config. Environment variables prefixed with JOEI_ override file values: the variable name is the config key path with dots replaced by underscores, e.g. JOEI_LOGGING_LEVEL overrides logging.level and JOEI_CVE_BLOCK_ON overrides cve.block_on. Only keys present in the file can be overridden.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks cross-field invariants after loading.

type ConsoleConfig

type ConsoleConfig struct {
	Auth AuthConfig `mapstructure:"auth"`
}

ConsoleConfig holds admin-console settings.

type DatabaseConfig

type DatabaseConfig struct {
	Path               string `mapstructure:"path"`
	EventRetentionDays int    `mapstructure:"event_retention_days"`
	DailyRetentionDays int    `mapstructure:"daily_retention_days"`
}

DatabaseConfig configures the embedded SQLite persistence layer. Path is required; telemetry is always persisted to SQLite (no in-memory fallback). Retention values ≤ 0 use defaults (events 30 days, daily metrics 365 days).

type HealthConfig

type HealthConfig struct {
	ProbeIntervalSeconds int `mapstructure:"probe_interval_seconds"`
	SlowThresholdMS      int `mapstructure:"slow_threshold_ms"`
}

HealthConfig tunes the scanner health probes. Zero values use defaults (30s probe interval, 2000ms slow threshold), applied at wiring time.

type ImageScanConfig

type ImageScanConfig struct {
	Enabled        bool   `mapstructure:"enabled"`
	TrivyServer    string `mapstructure:"trivy_server"`    // e.g. "http://trivy:4954"
	TimeoutSeconds int    `mapstructure:"timeout_seconds"` // default 120
	Scanners       string `mapstructure:"scanners"`        // trivy --scanners value, default "vuln,secret"
	MaxLayerBytes  int64  `mapstructure:"max_layer_bytes"` // layer larger than this → fail-closed
}

ImageScanConfig configures container-image vulnerability scanning (Trivy). It is separate from CVEConfig (osv.dev): a different engine and model.

type LocalCache

type LocalCache struct {
	Path      string `mapstructure:"path"`
	MaxSizeGB int    `mapstructure:"max_size_gb"`
	// StaleAfterDays marks entries idle this long as stale (reclaimable via
	// console cleanup). ≤0 uses the default (30) applied at wiring.
	StaleAfterDays int `mapstructure:"stale_after_days"`
}

type LoggingConfig

type LoggingConfig struct {
	Level  string `mapstructure:"level"`
	Format string `mapstructure:"format"`
	Output string `mapstructure:"output"`
}

type MalwareConfig

type MalwareConfig struct {
	Scanners []ScannerConfig `mapstructure:"scanners"`
	// MaxConcurrentScans caps how many artifacts are scanned at once across all
	// engines. It applies backpressure so bursts don't overwhelm clamd/ICAP
	// worker pools and make scans time out. Zero uses a default (applied at
	// wiring time); a negative value is rejected.
	MaxConcurrentScans int `mapstructure:"max_concurrent_scans"`
}

MalwareConfig configures the malware-scanning engines run after download.

type PolicyConfig

type PolicyConfig struct {
	ActiveProfile string                   `mapstructure:"active_profile"`
	Profiles      map[string]PolicyProfile `mapstructure:"profiles"`
}

type PolicyProfile

type PolicyProfile struct {
	CVEBlock         bool     `mapstructure:"cve_block"`
	CVEMinSeverity   string   `mapstructure:"cve_min_severity"` // overrides CVEConfig.BlockOn when non-empty
	SupplyChainBlock bool     `mapstructure:"supply_chain_block"`
	MalwareBlock     bool     `mapstructure:"malware_block"`
	Allowlist        []string `mapstructure:"allowlist"` // "pypi/requests" or "pypi/requests@2.31.0"
	Denylist         []string `mapstructure:"denylist"`
}

type RegistriesConfig

type RegistriesConfig struct {
	PyPI     RegistryConfig `mapstructure:"pypi"`
	NPM      RegistryConfig `mapstructure:"npm"`
	Maven    RegistryConfig `mapstructure:"maven"`
	RubyGems RegistryConfig `mapstructure:"rubygems"`
	Go       RegistryConfig `mapstructure:"go"`
	Docker   RegistryConfig `mapstructure:"docker"`
}

type RegistryConfig

type RegistryConfig struct {
	Upstreams []string `mapstructure:"upstreams"`
	Enabled   bool     `mapstructure:"enabled"`
}

type RevalidationConfig

type RevalidationConfig struct {
	CVETTLMinutes     int `mapstructure:"cve_ttl_minutes"`
	MalwareTTLMinutes int `mapstructure:"malware_ttl_minutes"`
}

RevalidationConfig sets per-gate TTLs for lazy re-validation of cache hits. A cache hit whose CVE or malware check is older than its TTL re-runs that gate before serving; an entry that now fails is blocked and evicted. 0 disables that gate's re-check. Defaults (1440 = 24h) come from viper defaults, so an omitted key gets the default while an explicit 0 disables.

type S3Cache

type S3Cache struct {
	Endpoint string `mapstructure:"endpoint"`
	Bucket   string `mapstructure:"bucket"`
	Region   string `mapstructure:"region"`
}

type ScannerConfig

type ScannerConfig struct {
	Type           string `mapstructure:"type"`            // "clamav" | "icap"
	Address        string `mapstructure:"address"`         // unix:///path | tcp:host:port
	TimeoutSeconds int    `mapstructure:"timeout_seconds"` // default 30
	Service        string `mapstructure:"service"`         // ICAP service name (icap only)
}

ScannerConfig configures a single malware-scanning engine.

type ServerConfig

type ServerConfig struct {
	Listen string `mapstructure:"listen"`
	// UpstreamMaxConcurrent caps the number of concurrent in-flight requests to
	// each upstream registry host, across metadata fetches, transparent proxying
	// and artifact downloads. It keeps parallel dependency resolution (Gradle,
	// Maven, npm) under the registry's rate limit so it does not return HTTP 429.
	// Zero or negative selects the default (DefaultUpstreamMaxConcurrent).
	UpstreamMaxConcurrent int `mapstructure:"upstream_max_concurrent"`
	// UpstreamRatePerSecond caps the request *rate* to each upstream registry
	// host (token bucket). Registries throttle by rate, not concurrency, so this
	// is the primary 429 defense; the concurrency cap is complementary. The burst
	// allowance is twice this value. Zero or negative selects the default
	// (DefaultUpstreamRatePerSecond); set a large value to effectively disable.
	UpstreamRatePerSecond int `mapstructure:"upstream_rate_per_second"`
}

type SupplyChainConfig

type SupplyChainConfig struct {
	MinAgeHours   int    `mapstructure:"min_age_hours"`
	AllowlistPath string `mapstructure:"allowlist_path"`
	Mode          string `mapstructure:"mode"` // enforce | dry_run | off
}

type TLSConfig added in v0.4.0

type TLSConfig struct {
	CAFiles []string `mapstructure:"ca_files"`
}

TLSConfig configures trust for outbound connections to upstream registries. CAFiles lists PEM files whose certificates are added to the system root pool, which is what makes a mirror with a corporate or self-signed certificate reachable. An empty list means system roots only.

Jump to

Keyboard shortcuts

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