crowdsecurity/crowdsec · warning

failed to get absolute path of %q: %w

Error message

failed to get absolute path of %q: %w

What it means

ensureAbsolutePath normalizes configured paths to absolute ones via filepath.Abs before crowdsec uses them. filepath.Abs essentially only fails when it cannot determine the current working directory (e.g. the cwd was deleted, or os.Getwd hits an OS error). The wrapper preserves the original path and the underlying error so the operator can tell which config path is problematic.

Source

Thrown at pkg/csconfig/paths.go:24

	log "github.com/sirupsen/logrus"
)

func ensureAbsolutePath(p *string) error {
	// TODO: this will become a straight IsAbs check + return error
	var err error

	if *p == "" {
		return nil
	}

	if !filepath.IsAbs(*p) {
		log.Warnf("Using a relative path for %q is deprecated and will be disallowed in a future release", *p)
	}

	*p, err = filepath.Abs(*p)
	if err != nil {
		return fmt.Errorf("failed to get absolute path of %q: %w", *p, err)
	}

	return nil
}

View on GitHub (pinned to 909b515798)

Solutions

  1. Restart crowdsec from a valid, existing working directory (e.g. cd / before launching).
  2. Fix the unit/container working directory: set WorkingDirectory=/etc/crowdsec in the systemd unit or workdir in the container spec.
  3. Replace relative config paths with absolute ones in the yaml (this also silences the deprecation warning) so cwd resolution no longer matters.
  4. Check `pwd` works in the launching shell; if the directory was removed, open a new shell.

Example fix

// before (config.yaml)
config_paths:
  config_dir: ./config
// after
config_paths:
  config_dir: /etc/crowdsec/config
Defensive patterns

Strategy: validation

Validate before calling

if !filepath.IsAbs(p) {
    abs, err := filepath.Abs(p)
    if err != nil {
        return fmt.Errorf("cannot resolve %q: %w (check working directory)", p, err)
    }
    p = abs
}
if _, err := os.Stat(p); err != nil {
    return fmt.Errorf("path %q missing: %w", p, err)
}

Try / catch

if err := csconfig.LoadCrowdsec(...); err != nil {
    if strings.Contains(err.Error(), "failed to get absolute path") {
        // cwd is invalid; restart from a valid directory or fix paths to absolute
    }
}

Prevention

When it happens

Trigger: A relative path is configured (apparent from the deprecation warning) and the process's current working directory cannot be resolved — classically when the binary is started from a directory that has been deleted, or cwd resolution fails at OS level.

Common situations: Running crowdsec from a tmpfs/removed directory, systemd units with a WorkingDirectory that no longer exists, or container setups where the workdir was unmounted before exec.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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