crowdsecurity/crowdsec · error

please provide a data directory with the 'data_dir' directiv

Error message

please provide a data directory with the 'data_dir' directive in the 'config_paths' section

What it means

After defaulting ConfigDir from the config file location, loadConfigurationPaths requires an explicit data_dir. The data directory holds the database and hub artifacts, so it has no safe default and must be declared in the 'config_paths' section. Missing it aborts configuration loading.

Source

Thrown at pkg/csconfig/config_paths.go:29

	SimulationFilePath string `yaml:"simulation_path,omitempty"`
	HubIndexFile       string `yaml:"index_path,omitempty"` // path of the .index.json
	HubDir             string `yaml:"hub_dir,omitempty"`
	PluginDir          string `yaml:"plugin_dir,omitempty"`
	NotificationDir    string `yaml:"notification_dir,omitempty"`
	PatternDir         string `yaml:"pattern_dir,omitempty"`
}

func (c *Config) loadConfigurationPaths() error {
	if c.ConfigPaths == nil {
		return errors.New("no configuration paths provided")
	}

	if c.ConfigPaths.ConfigDir == "" {
		c.ConfigPaths.ConfigDir = filepath.Dir(c.FilePath)
	}

	if c.ConfigPaths.DataDir == "" {
		return errors.New("please provide a data directory with the 'data_dir' directive in the 'config_paths' section")
	}

	if c.ConfigPaths.HubDir == "" {
		c.ConfigPaths.HubDir = filepath.Join(c.ConfigPaths.ConfigDir, "hub")
	}

	if c.ConfigPaths.HubIndexFile == "" {
		c.ConfigPaths.HubIndexFile = filepath.Join(c.ConfigPaths.HubDir, ".index.json")
	}

	if c.ConfigPaths.NotificationDir == "" {
		c.ConfigPaths.NotificationDir = filepath.Join(c.ConfigPaths.ConfigDir, "notifications")
	}

	if c.ConfigPaths.PatternDir == "" {
		c.ConfigPaths.PatternDir = filepath.Join(c.ConfigPaths.ConfigDir, "patterns")
	}

View on GitHub (pinned to 909b515798)

Solutions

  1. Add 'data_dir: /var/lib/crowdsec/data' (or your path) under config_paths in the config file
  2. Ensure the data_dir exists and the crowdsec user can write to it
  3. When generating configs programmatically, always set ConfigPaths.DataDir alongside ConfigDir

Example fix

// before
config_paths:
  config_dir: /etc/crowdsec

// after
config_paths:
  config_dir: /etc/crowdsec
  data_dir: /var/lib/crowdsec/data
Defensive patterns

Strategy: validation

Validate before calling

if cfg.ConfigPaths != nil && cfg.ConfigPaths.DataDir == "" {
    return fmt.Errorf("config_paths.data_dir is required")
}

Try / catch

if err := cfg.LoadDBConfig(false); err != nil {
    if strings.Contains(err.Error(), "data directory") {
        log.Fatalf("set data_dir in config_paths of %s", cfg.FilePath)
    }
    return err
}

Prevention

When it happens

Trigger: A config.yaml whose config_paths section sets config_dir but omits data_dir, passed to NewConfig via -c.

Common situations: Partially copied config files; users deleting the data_dir line thinking it is derived from config_dir; packaging a config tree for containers and forgetting data_dir.

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


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/30c7fc756bd752f8. Report an issue: GitHub.