open-telemetry / opentelemetry-collector-contrib

Contrib repository for the OpenTelemetry Collector
https://opentelemetry.io
Apache License 2.0
3.02k stars 2.33k forks source link

panic in kafkaexporter config validation if SASL is not configured/used #24457

Closed icot closed 1 year ago

icot commented 1 year ago

Component(s)

exporter/kafka

What happened?

Description

The following snippet from commit c62e76d446 makes it a requirement to have a SASL related section, as the call for validateSASLConfig is always executed as the tail of the validate() method.

+       return validateSASLConfig(cfg.Authentication.SASL)
+}
+
+func validateSASLConfig(c *SASLConfig) error {
+       if c.Username == "" {
+               return fmt.Errorf("auth.sasl.username is required")
+       }

This produces a fatal nil object dereferencing when no SASL configuration is present.

Steps to Reproduce

Start the collector with a configuration file containing a kafka exporter without SASL configuration section.

Expected Result

The collector starts normally

Actual Result

Error derreferencil an nil object and fatal crash

Collector version

8a4348cb00

Environment information

Environment

OS: Debian 12.0 Compiler(if manually compiled): go version go1.20.5 linux/amd64

OpenTelemetry Collector configuration

receivers:
  otlp:
    protocols:
      grpc:
        include_metadata: true 
        tls:
          ca_file: /etc/pki/tls/certs/CERN-bundle.pem
          client_ca_file: /etc/pki/tls/certs/CERN-bundle.pem
          min_version: "1.2"
      http:
        include_metadata: true 

processors:
  memory_limiter:
    check_interval: 1s
    limit_percentage: 70
    spike_limit_percentage: 20
  batch:
  batch/2:
    send_batch_size: 1
  routing:
    from_attribute: Monit-Job
    default_exporters:
    - file/1
    table:
    - value: monit-agent-sec
      exporters: [file/2]

extensions:
  health_check:
  pprof:
  zpages:
  memory_ballast:
    size_mib: 512
exporters:
  logging:
  file/1:
    path: /tmp/file1
  file/2:
    path: /tmp/file2
  kafka/metrics:
    protocol_version: 2.8.2
    topic: otlp_metrics
    producer:
      compression: zstd
    brokers:
      - nile-kafka-qa3-a01.cern.ch:9093
    auth:
      tls:
        ca_file: /etc/pki/tls/certs/CERN-bundle.pem
        insecure: true
      kerberos:
        service_name: kafka
        realm: CERN.CH
        username: kafkauser
        password: XXXXXXXX
        use_keytab: false
        config_file: /etc/krb5.conf
service:
  telemetry:
    logs:
      level: debug
    metrics:
      level: detailed
  pipelines:
    logs:
      receivers: [otlp]
      processors: [batch]
      exporters: [logging, file/1]
    logs/routed:
      receivers: [otlp]
      processors: [routing]
      exporters: [logging, file/1, file/2]

Log output

pcitdb46:poc $ /tmp/monit-otel/monit-otel --config otel/otelcontribcol.config
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x18b3838]

goroutine 1 [running]:
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/kafkaexporter.validateSASLConfig(0xc0003a9b6c?)
    github.com/open-telemetry/opentelemetry-collector-contrib/exporter/kafkaexporter@v0.81.0/config.go:107 +0x18
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/kafkaexporter.(*Config).Validate(0xc000ba4700)
    github.com/open-telemetry/opentelemetry-collector-contrib/exporter/kafkaexporter@v0.81.0/config.go:103 +0x6b
go.opentelemetry.io/collector/component.callValidateIfPossible({0x49a4140?, 0xc000ba4700?, 0x0?})
    go.opentelemetry.io/collector/component@v0.81.0/config.go:104 +0x1ca
go.opentelemetry.io/collector/component.validate({0x49a4140?, 0xc000ba4700?, 0x1?})
    go.opentelemetry.io/collector/component@v0.81.0/config.go:59 +0x17d
go.opentelemetry.io/collector/component.validate({0x41bfee0?, 0xc000ba4700?, 0x418ed6?})
    go.opentelemetry.io/collector/component@v0.81.0/config.go:56 +0x1b5
go.opentelemetry.io/collector/component.ValidateConfig({0x41bfee0?, 0xc000ba4700?})
    go.opentelemetry.io/collector/component@v0.81.0/config.go:47 +0xa5
go.opentelemetry.io/collector/otelcol.(*Config).Validate(0xc000ba5c00)
    go.opentelemetry.io/collector@v0.81.0/otelcol/config.go:66 +0x28c
go.opentelemetry.io/collector/otelcol.(*Collector).setupConfigurationComponents(0xc000714180, {0x552d368, 0xc00007c0e0})
    go.opentelemetry.io/collector@v0.81.0/otelcol/collector.go:151 +0x10e
go.opentelemetry.io/collector/otelcol.(*Collector).Run(0xc000714180, {0x552d368, 0xc00007c0e0})
    go.opentelemetry.io/collector@v0.81.0/otelcol/collector.go:207 +0x65
go.opentelemetry.io/collector/otelcol.NewCommand.func1(0xc00057e300, {0x4c1cc92?, 0x2?, 0x2?})
    go.opentelemetry.io/collector@v0.81.0/otelcol/command.go:27 +0x96
github.com/spf13/cobra.(*Command).execute(0xc00057e300, {0xc0000741c0, 0x2, 0x2})
    github.com/spf13/cobra@v1.7.0/command.go:940 +0x862
github.com/spf13/cobra.(*Command).ExecuteC(0xc00057e300)
    github.com/spf13/cobra@v1.7.0/command.go:1068 +0x3bd
github.com/spf13/cobra.(*Command).Execute(0xc0005f0f60?)
    github.com/spf13/cobra@v1.7.0/command.go:992 +0x19
main.runInteractive({{0xc0005f0f60, 0xc0005fe120, 0xc0005f12c0, 0xc0005f0bd0, 0xc0005fe1e0}, {{0x4c24ff6, 0xa}, {0x4cfdcd3, 0x3b}, {0x4c22b2a, ...}}, ...})
    github.com/open-telemetry/opentelemetry-collector-contrib/cmd/otelcontribcol/main.go:31 +0x5d
main.run(...)
    github.com/open-telemetry/opentelemetry-collector-contrib/cmd/otelcontribcol/main_others.go:11
main.main()
    github.com/open-telemetry/opentelemetry-collector-contrib/cmd/otelcontribcol/main.go:24 +0x1d9

Additional context

No response

github-actions[bot] commented 1 year ago

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

callmediaomao commented 1 year ago

I had the same problem.

rcrowe commented 1 year ago

This was fixed by https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/24798 & will be in the next release

icot commented 1 year ago

Indeed, it can be closed