Repository navigation
Description
What happened
The OTEL surfacer panics at startup if its exporter is configured with a tls_config block that sets any field.
Both exporter branches pass nil to tlsconfig.UpdateTLSConfig instead of the tls.Config they just allocated:
https://github.com/cloudprober/cloudprober/blob/main/internal/surfacers/otel/otel.go#L90-L96 (HTTP, line 92)
https://github.com/cloudprober/cloudprober/blob/main/internal/surfacers/otel/otel.go#L127-L133 (gRPC, line 129)
if expConf.GetTlsConfig() != nil {
tlsConfig := &tls.Config{}
err := tlsconfig.UpdateTLSConfig(nil, expConf.GetTlsConfig()) // should be tlsConfig
...
opts = append(opts, otlpmetricgrpc.WithTLSCredentials(credentials.NewTLS(tlsConfig)))
}UpdateTLSConfig writes to its first argument as soon as any config field is set (common/tlsconfig/tlsconfig.go:67), so this is a nil dereference.
There are two failure modes:
- Panic — if
tls_configsetsdisable_cert_validation,ca_cert_file,tls_cert_file,server_name, ormin_tls_version. - Silently ignored TLS config — if
tls_config {}is present but empty, nothing is dereferenced, and the exporter is built from an emptytls.Config. The configured settings never take effect.
Config to reproduce
surfacer {
type: OTEL
otel_surfacer {
otlp_grpc_exporter {
endpoint: "localhost:4317"
tls_config { disable_cert_validation: true }
}
}
}
Stack trace
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0xa0]
github.com/cloudprober/cloudprober/common/tlsconfig.UpdateTLSConfig(...)
common/tlsconfig/tlsconfig.go:67
github.com/cloudprober/cloudprober/internal/surfacers/otel.getExporter(...)
internal/surfacers/otel/otel.go:129
(Reproduced against main at b40d714 by calling getExporter directly with the config above; the HTTP branch at line 92 fails the same way.)
Fix
Pass tlsConfig in both places. Worth a small test covering each exporter branch with a non-empty tls_config, since an empty one doesn't fail.
Noticed while reviewing #1358 — internal/tracing/tracing.go in that PR does the equivalent thing correctly, so the tracing path is not affected.
Activity
[surfacers.otel] Pass the allocated tls.Config to UpdateTLSConfig (cl…