{"record":{"id":"7927699f7dfd341f","repo":"crowdsecurity/crowdsec","slug":"crowdsec-enable-not-a-string","errorCode":null,"errorMessage":"crowdsec.enable not a string","messagePattern":"crowdsec\\.enable not a string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/acquisition/modules/docker/source.go","lineNumber":92,"sourceCode":"\n\treturn parseLabels(containerDetails.Container.Config.Labels)\n}\n\nfunc (d *Source) processCrowdsecLabels(parsedLabels map[string]any, entityID string, entityType string) (map[string]string, error) {\n\tif len(parsedLabels) == 0 {\n\t\td.logger.Tracef(\"%s has no 'crowdsec' labels set, ignoring %s: %s\", entityType, entityType, entityID)\n\t\treturn nil, errors.New(\"no crowdsec labels\")\n\t}\n\n\tif _, ok := parsedLabels[\"enable\"]; !ok {\n\t\td.logger.Errorf(\"%s has 'crowdsec' labels set but no 'crowdsec.enable' key found\", entityType)\n\t\treturn nil, errors.New(\"no crowdsec.enable key\")\n\t}\n\n\tenable, ok := parsedLabels[\"enable\"].(string)\n\tif !ok {\n\t\td.logger.Errorf(\"%s has 'crowdsec.enable' label set but it's not a string\", entityType)\n\t\treturn nil, errors.New(\"crowdsec.enable not a string\")\n\t}\n\n\tif strings.ToLower(enable) != \"true\" {\n\t\td.logger.Debugf(\"%s has 'crowdsec.enable' label not set to true ignoring %s: %s\", entityType, entityType, entityID)\n\t\treturn nil, errors.New(\"crowdsec.enable not true\")\n\t}\n\n\tif _, ok = parsedLabels[\"labels\"]; !ok {\n\t\td.logger.Errorf(\"%s has 'crowdsec.enable' label set to true but no 'labels' keys found\", entityType)\n\t\treturn nil, errors.New(\"no labels key\")\n\t}\n\n\tlabelsTypeCast, ok := parsedLabels[\"labels\"].(map[string]any)\n\tif !ok {\n\t\td.logger.Errorf(\"%s has 'crowdsec.enable' label set to true but 'labels' is not a map\", entityType)\n\t\treturn nil, errors.New(\"labels not a map\")\n\t}\n","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/acquisition/modules/docker/source.go#L74-L110","documentation":"Docker labels are always strings, but processCrowdsecLabels received a parsed 'enable' entry whose dynamic value is not a string, so the type assertion parsedLabels[\"enable\"].(string) failed and the entity is rejected. This guard exists because labels may be re-parsed/normalized before validation.","triggerScenarios":"processCrowdsecLabels (via EvalContainer/EvalService) sees parsedLabels[\"enable\"] present but holding a non-string value (e.g. bool or number after custom parsing), failing the .(string) assertion.","commonSituations":"Users writing enable=true in a config layer that parses YAML/JSON types instead of raw docker labels; custom wrappers feeding non-string label maps; boolean-like values coerced upstream.","solutions":["Set the label as a plain string: crowdsec.enable=true (docker labels are strings; avoid structured config wrappers that coerce types)","If using a custom label source, ensure values are serialized as strings before reaching the docker source","Check for tooling or templates that emit YAML booleans and force quoting: crowdsec.enable: \"true\"","Pin/verify crowdsec version; older parsers handled label types differently"],"exampleFix":"# before (values coerced to bool)\nlabels:\n  crowdsec.enable: true\n# after (string, as docker labels require)\nlabels:\n  crowdsec.enable: \"true\"","handlingStrategy":"type-guard","validationCode":"v, ok := labels[\"crowdsec.enable\"]\nif !ok || reflect.TypeOf(v) != reflect.TypeOf(\"\") {\n\treturn fmt.Errorf(\"crowdsec.enable must be a string, got %T\", v)\n}","typeGuard":"func enableIsString(v any) bool {\n\t_, ok := v.(string)\n\treturn ok\n}","tryCatchPattern":"if _, err := source.EvalContainer(ctx, ctr); err != nil {\n\tif strings.Contains(err.Error(), \"crowdsec.enable not a string\") {\n\t\tlog.Errorf(\"container %s: quote the enable label value\", ctr.ID)\n\t}\n}","preventionTips":["Quote label values in YAML templates so they stay strings","Avoid middleware that coerces label values to bool/number","Test with plain docker labels where values are always strings"],"tags":["docker","labels","type-mismatch"],"backgroundTag":"config-type-mismatch","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}