crowdsecurity/crowdsec · critical

while loading profiles for LAPI: %w

Error message

while loading profiles for LAPI: %w

What it means

LoadAPIServer wraps any error returned by LocalApiServerCfg.LoadProfiles() with this prefix. Profiles define automated decisions (tainted scenario defaults, etc.) loaded from profile.yaml files at LAPI startup; a parse, missing-file, or validation failure there aborts LAPI configuration loading.

Source

Thrown at pkg/csconfig/api.go:426

	if err := c.API.Server.LoadAutoRegister(); err != nil {
		return err
	}

	if c.API.Server.AutoRegister != nil && c.API.Server.AutoRegister.Enable != nil && *c.API.Server.AutoRegister.Enable && !inCli {
		log.Infof("auto LAPI registration enabled for ranges %+v", c.API.Server.AutoRegister.AllowedRanges)
	}

	if c.API.Server.UseForwardedForHeaders && c.API.Server.TrustedProxies == nil {
		c.API.Server.TrustedProxies = &[]string{"0.0.0.0/0"}
	}

	if c.API.Server.TrustedProxies != nil {
		c.API.Server.UseForwardedForHeaders = true
	}

	if err := c.API.Server.LoadProfiles(); err != nil {
		return fmt.Errorf("while loading profiles for LAPI: %w", err)
	}

	if c.API.Server.ConsoleConfigPath == "" {
		c.API.Server.ConsoleConfigPath = DefaultConsoleConfigFilePath
	}

	if err := c.API.Server.LoadConsoleConfig(); err != nil {
		return fmt.Errorf("while loading console options: %w", err)
	}

	if c.API.CTI != nil {
		if err := c.API.CTI.Load(); err != nil {
			return fmt.Errorf("loading CTI configuration: %w", err)
		}
	}

	return nil
}

View on GitHub (pinned to 909b515798)

Solutions

  1. Inspect the wrapped inner error to find the offending profile file and line
  2. Restore the stock profile.yaml from the package or the GitHub repo (config/profile.yaml)
  3. Fix YAML syntax / invalid keys in profile.yaml
  4. Ensure api.server.profiles / profile paths in config.yaml point to existing files

Example fix

// before (config.yaml, broken)
api:
  server:
    profiles_path: /etc/crowdsec/profile.yaml.bak
// after
api:
  server:
    profiles_path: /etc/crowdsec/profile.yaml
Defensive patterns

Strategy: try-catch

Validate before calling

if _, err := os.Stat(profilesPath); os.IsNotExist(err) { log.Warn("profile file missing: "+profilesPath) }

Try / catch

if err := cfg.LoadAPIServer(); err != nil {
	if strings.Contains(err.Error(), "while loading profiles for LAPI") {
		log.Fatalf("profile config invalid: %v — restore stock profile.yaml", err)
	}
	return err
}

Prevention

When it happens

Trigger: csconfig.LoadAPIServer is called during crowdsec startup (or `cscli` config load) and api.server.profiles points at a profile file that is missing, malformed YAML, or fails profile validation in LoadProfiles.

Common situations: Upgrading crowdsec with an old /etc/crowdsec/profile.yaml that no longer validates; hand-edited profile.yaml with wrong keys/types; config value profile_dir pointing to an empty or wrong directory; packaged profiles deleted by accident.

Understand the failure class

Background: "Config file not found": what it means and how to fix it in docker-sync, Maven, Vagrant, Turborepo and other tools — this error's family across 60 libraries.

Related errors


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