crowdsecurity/crowdsec · error
no database configuration provided
Error message
no database configuration provided
What it means
LoadDBConfig requires a decoded DbConfig (the 'db_config' section). When DbConfig is nil there is no database to connect to and shared config propagation (to cscli and API server) cannot proceed, so the error is raised before any defaults are applied.
Source
Thrown at pkg/csconfig/database.go:74
CertDuration *time.Duration
Api *string `yaml:"api_key,omitempty"`
ApiDuration *time.Duration
LoginPassword *string `yaml:"login_password,omitempty"`
LoginPasswordDuration *time.Duration
}
type FlushDBCfg struct {
MaxItems *int `yaml:"max_items,omitempty"`
// We could unmarshal as time.Duration, but alert filters right now are a map of strings
MaxAge cstime.DurationWithDays `yaml:"max_age,omitempty"`
BouncersGC *AuthGCCfg `yaml:"bouncers_autodelete,omitempty"`
AgentsGC *AuthGCCfg `yaml:"agents_autodelete,omitempty"`
MetricsMaxAge cstime.DurationWithDays `yaml:"metrics_max_age,omitempty"`
}
func (c *Config) LoadDBConfig(inCli bool) error {
if c.DbConfig == nil {
return errors.New("no database configuration provided")
}
if c.Cscli != nil {
c.Cscli.DbConfig = c.DbConfig
}
if c.API != nil && c.API.Server != nil {
c.API.Server.DbConfig = c.DbConfig
}
if c.DbConfig.MaxOpenConns == 0 {
c.DbConfig.MaxOpenConns = DEFAULT_MAX_OPEN_CONNS
}
if !inCli && c.DbConfig.Type == "sqlite" {
if c.DbConfig.UseWal == nil {
dbDir := filepath.Dir(c.DbConfig.DbPath)
isNetwork, fsType, err := fsutil.IsNetworkFS(dbDir)View on GitHub (pinned to 909b515798)
Solutions
- Add a db_config section to the config file, e.g. db_config: {log_level: info, type: sqlite3, db_path: /var/lib/crowdsec/data/crowdsec.db}
- Ensure NewConfig parsed the file into cfg.DbConfig before LoadDBConfig is invoked
- For cscli-only usage, still provide db_config so the CLI can reach the same database
Example fix
// before
api:
server:
enabled: true
// after
db_config:
type: sqlite3
db_path: /var/lib/crowdsec/data/crowdsec.db
api:
server:
enabled: true Defensive patterns
Strategy: validation
Validate before calling
if cfg.DbConfig == nil {
return fmt.Errorf("config file must contain a 'db_config' section")
} Try / catch
if err := cfg.LoadDBConfig(false); err != nil {
if strings.Contains(err.Error(), "no database configuration") {
log.Fatal("add a db_config section to the config file")
}
return err
} Prevention
- Keep db_config in every environment's config, even cscli-only hosts
- Load config via csconfig.NewConfig so DbConfig is decoded before LoadDBConfig
- Lint config files in CI with a smoke NewConfig+LoadDBConfig call
When it happens
Trigger: Calling Config.LoadDBConfig when the YAML had no 'db_config:' section; calling it before the config file has been parsed; API server startup (LoadAPIServer) on a config stripped of db_config.
Common situations: Minimal LAPI config missing db_config; tests building Config structs manually; users commenting out db_config while debugging and forgetting to restore it.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- max_items can't be zero or negative
- path must start with /
- on_challenge hooks are only valid in-band, not under outofba
- empty cti key
- no listen_uri or listen_socket specified
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/ff3dee6f38c0b662.
Report an issue: GitHub.