crowdsecurity/crowdsec · error

bouncer %s already exists

Error message

bouncer %s already exists

What it means

CreateBouncer inserts a new bouncer row; when ent reports a constraint error (unique name or API key), the error is replaced with this friendly 'bouncer %s already exists' message instead of leaking the raw constraint error. It is a deliberate mapping, not a generic DB failure.

Source

Thrown at pkg/database/bouncers.go:93

		return nil, fmt.Errorf("listing bouncers: %w: %w", err, QueryFail)
	}

	return result, nil
}

func (c *Client) CreateBouncer(ctx context.Context, name string, ipAddr string, apiKey string, authType string, autoCreated bool) (*ent.Bouncer, error) {
	bouncer, err := c.Ent.Bouncer.
		Create().
		SetName(name).
		SetAPIKey(apiKey).
		SetRevoked(false).
		SetAuthType(authType).
		SetIPAddress(ipAddr).
		SetAutoCreated(autoCreated).
		Save(ctx)
	if err != nil {
		if ent.IsConstraintError(err) {
			return nil, fmt.Errorf("bouncer %s already exists", name)
		}

		return nil, fmt.Errorf("unable to create bouncer: %w", err)
	}

	return bouncer, nil
}

func (c *Client) DeleteBouncer(ctx context.Context, name string) error {
	nbDeleted, err := c.Ent.Bouncer.
		Delete().
		Where(bouncer.NameEQ(name)).
		Exec(ctx)
	if err != nil {
		return err
	}

	if nbDeleted == 0 {

View on GitHub (pinned to 909b515798)

Solutions

  1. Use a unique name: 'cscli bouncers add <new-name>'
  2. Delete the stale bouncer first: 'cscli bouncers delete <name>', then re-add
  3. If it was auto-created, check whether the bouncer should reuse its existing API key instead of re-registering

Example fix

// before
cscli bouncers add mybouncer
// after - check existence first
cscli bouncers list -o json | grep -q mybouncer || cscli bouncers add mybouncer
Defensive patterns

Strategy: validation

Validate before calling

existing, _ := c.ListBouncers(ctx)
for _, b := range existing {
    if b.Name == name {
        return fmt.Errorf("bouncer %q already exists; delete it or pick another name", name)
    }
}

Try / catch

b, err := c.CreateBouncer(ctx, name, ip, key, authType, false)
if err != nil {
    if strings.Contains(err.Error(), "already exists") {
        return fmt.Errorf("choose a different name or run: cscli bouncers delete %s", name)
    }
    return err
}

Prevention

When it happens

Trigger: Calling CreateBouncer (from 'cscli bouncers add', or TLS/plain bouncer auth with auto-registration) with a name or generated API key that already exists in the bouncers table.

Common situations: Re-running 'cscli bouncers add mybouncer' for an existing name; two bouncers auto-registering with the same configured name at startup.

Related errors


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