crowdsecurity/crowdsec · error

invalid DSN %s for S3 source

Error message

invalid DSN %s for S3 source

What it means

After splitting the s3:// DSN path on '/', the code expects one part (bucket only) or more (bucket plus prefix/key); this branch is unreachable in practice (empty path is caught earlier) and guards against an unclassifiable path shape.

Source

Thrown at pkg/acquisition/modules/s3/config.go:271

	s.Config.Mode = configuration.CAT_MODE
	s.Config.UniqueId = uuid

	pathParts := strings.Split(args[0], "/")
	s.logger.Debugf("pathParts: %v", pathParts)

	// FIXME: handle s3://bucket/
	if len(pathParts) == 1 {
		s.Config.BucketName = pathParts[0]
		s.Config.Prefix = ""
	} else if len(pathParts) > 1 {
		s.Config.BucketName = pathParts[0]
		if args[0][len(args[0])-1] == '/' {
			s.Config.Prefix = strings.Join(pathParts[1:], "/")
		} else {
			s.Config.Key = strings.Join(pathParts[1:], "/")
		}
	} else {
		return fmt.Errorf("invalid DSN %s for S3 source", dsn)
	}

	client, err := s.newS3Client(ctx)
	if err != nil {
		return err
	}

	s.s3Client = client

	return nil
}

View on GitHub (pinned to 909b515798)

Solutions

  1. Specify a bucket in the DSN, e.g. s3://my-bucket/prefix
  2. Use s3://bucket to poll the whole bucket

Example fix

// before
s3://
// after
s3://my-logs-bucket/cloudtrail/AWSLogs/
Defensive patterns

Strategy: validation

Validate before calling

u, err := url.Parse(dsn)
if err != nil || u.Host == "" || strings.Trim(u.Path, "/") == "" {
    return fmt.Errorf("DSN must be s3://<bucket>/<prefix-or-key>, got %q", dsn)
}

Prevention

When it happens

Trigger: Calling ConfigureByDSN with a DSN lacking a bucket or path, e.g. `s3://` with no further parts, or a malformed scheme/path so the parsing branch never matches.

Common situations: Misconfigured acquis.yaml entries; users omitting the bucket; extra characters or wrong scheme; trailing-slash expectations not met.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


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