crowdsecurity/crowdsec · error

basic_auth is selected, but username is not provided

Error message

basic_auth is selected, but username is not provided

What it means

With `auth_type: basic_auth` and a present `basic_auth` block, Validate() additionally requires a non-empty username. An empty c.BasicAuth.Username triggers this error: baseErr + " username is not provided".

Source

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

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:
		return errors.New("invalid auth_type: must be one of basic_auth, headers, mtls")
	}

	if c.TLS != nil {

View on GitHub (pinned to 909b515798)

Solutions

  1. Set `basic_auth.username` to the actual user name.
  2. If the username comes from an env var, verify it is set and non-empty at load time.
  3. Remove `auth_type: basic_auth` if basic auth is not required.

Example fix

// before
basic_auth:
  password: secret

// after
basic_auth:
  username: user
  password: secret
Defensive patterns

Strategy: validation

Validate before calling

if cfg.AuthType == "basic_auth" && (cfg.BasicAuth == nil || cfg.BasicAuth.Username == "") {
    return errors.New("basic_auth requires a non-empty username")
}

Prevention

When it happens

Trigger: The `basic_auth` block exists but omits the `username` key, sets it to an empty string, or an env-var/template interpolation resolves to empty.

Common situations: Users fill in only the password; credentials pulled from a secrets file/env var where the username var is unset; partial copy-paste of a config snippet.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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