crowdsecurity/crowdsec · error
unable to create folder '%s': %w
Error message
unable to create folder '%s': %w
What it means
installAppsecRuleCustomFrom creates the runtime appsec-rules directory (os.MkdirAll) before copying a custom rule, and wraps MkdirAll failures. It means the directory <RuntimePath>/appsec-rules/ could not be created — a filesystem-level permission or path problem, not a missing rule.
Source
Thrown at pkg/hubtest/appsecrule.go:61
}
}
return nil
}
func (t *HubTestItem) installAppsecRuleCustomFrom(appsecrule string, customPath string) (bool, error) {
// we check if its a custom appsec-rule
customAppsecRulePath := filepath.Join(customPath, appsecrule)
if _, err := os.Stat(customAppsecRulePath); os.IsNotExist(err) {
return false, nil
}
customAppsecRulePathSplit := strings.Split(customAppsecRulePath, "/")
customAppsecRuleName := customAppsecRulePathSplit[len(customAppsecRulePathSplit)-1]
itemTypeDirDest := fmt.Sprintf("%s/appsec-rules/", t.RuntimePath)
if err := os.MkdirAll(itemTypeDirDest, os.ModePerm); err != nil {
return false, fmt.Errorf("unable to create folder '%s': %w", itemTypeDirDest, err)
}
customAppsecRuleDest := fmt.Sprintf("%s/appsec-rules/%s", t.RuntimePath, customAppsecRuleName)
if err := Copy(customAppsecRulePath, customAppsecRuleDest); err != nil {
return false, fmt.Errorf("unable to copy appsec-rule from '%s' to '%s': %w", customAppsecRulePath, customAppsecRuleDest, err)
}
return true, nil
}
func (t *HubTestItem) installAppsecRuleCustom(appsecrule string) error {
for _, customPath := range t.CustomItemsLocation {
found, err := t.installAppsecRuleCustomFrom(appsecrule, customPath)
if err != nil {
return err
}
if found {View on GitHub (pinned to 909b515798)
Solutions
- Check ownership/permissions of RuntimePath and create the appsec-rules directory with adequate rights (sudo/chown)
- Ensure no regular file named 'appsec-rules' is shadowing the directory path
- Point RuntimePath at a writable location for the test run
Example fix
# before mkdir: cannot create directory '/etc/crowdsec/appsec-rules/': Permission denied # after sudo mkdir -p /etc/crowdsec/appsec-rules && sudo chown -R $USER /etc/crowdsec/appsec-rules
Defensive patterns
Strategy: validation
Validate before calling
dest := filepath.Join(t.RuntimePath, "appsec-rules")
if fi, err := os.Stat(dest); err == nil && !fi.IsDir() {
return fmt.Errorf("%s exists but is not a directory", dest)
}
if err := os.MkdirAll(dest, 0o755); err != nil {
return fmt.Errorf("cannot create %s: %w", dest, err)
} Prevention
- Run hub tests with write access to RuntimePath (same user as directory owner)
- Never place a regular file named 'appsec-rules' under RuntimePath
- On CI, ensure the workspace is not mounted read-only during test setup
When it happens
Trigger: installAppsecRuleCustom → installAppsecRuleCustomFrom when the custom rule file exists under one of CustomItemsLocation but os.MkdirAll("<RuntimePath>/appsec-rules/", os.ModePerm) returns an error (EACCES, ENOENT ancestor with restricted rights, read-only fs, path component is a file).
Common situations: RuntimePath points inside a root-owned tree while tests run unprivileged; a file named 'appsec-rules' already exists at that path; tests executed on a read-only CI workspace.
Understand the failure class
Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.
Related errors
- while creating directories for %s: %w
- while creating %s: %w
- while creating %s: %w
- while creating data dir: %w
- unable to create directory '%s': %w
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/5d627b37b651a5d9.
Report an issue: GitHub.