crowdsecurity/crowdsec · error

basic_auth is selected, but basic_auth is not provided

Error message

basic_auth is selected, but basic_auth is not provided

What it means

When `auth_type: basic_auth` is set on an HTTP datasource, Validate() requires the `basic_auth` block (username/password pair) to be present. If c.BasicAuth is nil while c.AuthType == "basic_auth", it returns this composite error built from the baseErr prefix plus " basic_auth is not provided".

Source

Thrown at pkg/acquisition/modules/http/config.go:107

	s.Config = cfg

	return nil
}

func (c *Configuration) Validate() error {
	if c.ListenAddr == "" && c.ListenSocket == "" {
		return errors.New("listen_addr or listen_socket is required")
	}

	if c.Path[0] != '/' {
		return errors.New("path must start with /")
	}

	switch c.AuthType {
	case "basic_auth":
		baseErr := "basic_auth is selected, but"
		if c.BasicAuth == nil {
			return errors.New(baseErr + " basic_auth is not provided")
		}

		if c.BasicAuth.Username == "" {
			return errors.New(baseErr + " username is not provided")
		}

		if c.BasicAuth.Password == "" {
			return errors.New(baseErr + " password is not provided")
		}
	case "headers":
		if c.Headers == nil {
			return errors.New("headers is selected, but headers is not provided")
		}
	case "mtls":
		if c.TLS == nil || c.TLS.CaCert == "" {
			return errors.New("mtls is selected, but ca_cert is not provided")
		}
	default:

View on GitHub (pinned to 909b515798)

Solutions

  1. Add a `basic_auth` block with `username` and `password` under the datasource config.
  2. Check YAML indentation so `basic_auth:` is a sibling of `auth_type` inside the same datasource entry.
  3. If basic auth is not actually needed, remove or change `auth_type`.

Example fix

// before
source: http
auth_type: basic_auth

// after
source: http
auth_type: basic_auth
basic_auth:
  username: user
  password: secret
Defensive patterns

Strategy: validation

Validate before calling

if cfg.AuthType == "basic_auth" && cfg.BasicAuth == nil {
    return errors.New("auth_type basic_auth requires a basic_auth block")
}

Prevention

When it happens

Trigger: Set `auth_type: basic_auth` in the http datasource config without a corresponding `basic_auth:` section, or with the section misspelled/nested incorrectly so it fails to unmarshal into c.BasicAuth, leaving it nil.

Common situations: Users enable basic_auth but forget to add credentials; YAML indentation places the basic_auth block outside the datasource; copying a config that uses header-based auth and changing only auth_type.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


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