{"record":{"id":"e406137ea70e8d0d","repo":"crowdsecurity/crowdsec","slug":"no-credentials-or-url-found-in-api-client-configur","errorCode":null,"errorMessage":"no credentials or URL found in api client configuration '%s'","messagePattern":"no credentials or URL found in api client configuration '(.+?)'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/csconfig/api.go","lineNumber":164,"sourceCode":"\tfcontent, err := patcher.MergedPatchContent()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tconfigData := csstring.StrictExpand(string(fcontent), os.LookupEnv)\n\n\tdec := yaml.NewDecoder(strings.NewReader(configData))\n\tdec.KnownFields(true)\n\n\terr = dec.Decode(&l.Credentials)\n\tif err != nil {\n\t\tif !errors.Is(err, io.EOF) {\n\t\t\treturn fmt.Errorf(\"failed to parse api client credential configuration file '%s': %w\", l.CredentialsFilePath, err)\n\t\t}\n\t}\n\n\tif l.Credentials == nil || l.Credentials.URL == \"\" {\n\t\treturn fmt.Errorf(\"no credentials or URL found in api client configuration '%s'\", l.CredentialsFilePath)\n\t}\n\n\tif l.Credentials != nil && l.Credentials.URL != \"\" {\n\t\t// don't append a trailing slash if the URL is a unix socket\n\t\tif strings.HasPrefix(l.Credentials.URL, \"http\") && !strings.HasSuffix(l.Credentials.URL, \"/\") {\n\t\t\tl.Credentials.URL += \"/\"\n\t\t}\n\t}\n\n\t// is the configuration asking for client authentication via TLS?\n\tcredTLSClientAuth := l.Credentials.CertPath != \"\" || l.Credentials.KeyPath != \"\"\n\n\t// is the configuration asking for TLS encryption and server authentication?\n\tcredTLS := credTLSClientAuth || l.Credentials.CACertPath != \"\"\n\n\tcredSocket := strings.HasPrefix(l.Credentials.URL, \"/\")\n\n\tif credTLS && credSocket {","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/csconfig/api.go#L146-L182","documentation":"After successfully decoding the credentials YAML, the loader validates that the resulting Credentials object exists and that its URL field is non-empty. This error means the file parsed cleanly as YAML but contains no usable client configuration — typically an empty file, a file with only comments, or a document missing the required `url` key. It guards against silently proceeding with a zero-value client config.","triggerScenarios":"Load() completes dec.Decode without error but l.Credentials == nil (empty/whitespace-only file, EOF document) or l.Credentials.URL == \"\" (file has login/password but no url key).","commonSituations":"credentials file created with `touch` but never populated; file truncated by a failed `cscli lapi register`; user deleted the url line while keeping login/password; mounted empty ConfigMap/volume in Kubernetes.","solutions":["Add the `url:` key pointing to the Local API, e.g. `url: http://127.0.0.1:8080`.","If the file is empty, regenerate it: `cscli lapi register -u <LAPI url>` or restore from backup.","Verify you are editing the file actually referenced (the path in the error message), not another config copy.","Check file permissions/readability if a volume mount unexpectedly yielded an empty file."],"exampleFix":"# before (empty or missing url)\nlogin: crowdsec\npassword: secret\n# after\nurl: http://127.0.0.1:8080/\nlogin: crowdsec\npassword: secret","handlingStrategy":"validation","validationCode":"cfg, err := yaml.Marshal(map[string]string{})\n_ = cfg\ndata, _ := os.ReadFile(credPath)\nvar probe struct{ URL string `yaml:\"url\"` }\nif err := yaml.Unmarshal(data, &probe); err != nil || probe.URL == \"\" {\n    return fmt.Errorf(\"%s has no 'url' set\", credPath)\n}","typeGuard":"func hasURL(m map[string]any) bool {\n    v, ok := m[\"url\"]\n    s, isStr := v.(string)\n    return ok && isStr && strings.TrimSpace(s) != \"\"\n}","tryCatchPattern":"if err := creds.Load(); err != nil {\n    if strings.Contains(err.Error(), \"no credentials or URL found\") {\n        return fmt.Errorf(\"credentials file empty or missing url; run 'cscli lapi register': %w\", err)\n    }\n    return err\n}","preventionTips":["Always include the `url:` key in api client credential files.","Check file size after provisioning steps; an empty file means a failed write.","In Kubernetes, verify the ConfigMap/volume actually contains data before starting the agent."],"tags":["config","validation","crowdsec"],"backgroundTag":"missing-required-config-field","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}