Skip to content

Conversation

@harshit-jindal02
Copy link

Summary

This PR fixes a bug in the ClickHouse exporter where the TLS configuration was ignored
if neither cert_file nor key_file were set — even when a valid ca_file was provided.
As a result, server-side TLS verification setups (CA-only) failed unexpectedly.


Root Cause

In the previous logic inside buildClickHouseOptions(), TLS initialization was conditioned
on both cert_file and key_file being provided.
However, for many ClickHouse deployments, only a ca_file is necessary to validate
the server certificate without using client-side authentication.

This caused the exporter to skip TLS setup entirely when only ca_file was specified.


Fix Implemented

  • Updated buildClickHouseOptions() to initialize TLS even when only a ca_file is set.

  • Ensured server-side TLS verification is correctly configured.

  • Added a new regression test to prevent future regressions:

    TestBuildClickHouseOptions_WithCAFileOnly

This test verifies:

  • TLS initialization occurs when only a ca_file is present.
  • The function handles invalid CA files gracefully without panic.
  • Exporter logic remains stable under all TLS configurations.

Test Plan

Run locally:

cd exporter/clickhouseexporter
go test -v ./...

Expected output:

=== RUN   TestBuildClickHouseOptions_WithCAFileOnly
--- PASS: TestBuildClickHouseOptions_WithCAFileOnly (0.00s)
PASS
ok  	github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter	0.8s

Behavior Before

  • TLS configuration was ignored when cert_file and key_file were not provided.
  • Exporter silently defaulted to a non-TLS connection even if a ca_file existed.

Behavior After

  • TLS setup is respected when only a ca_file is configured.
  • Server certificate validation now works as expected.
  • Added unit test ensures this behavior remains protected against regressions.

Affected Files

  • exporter/clickhouseexporter/config.go
  • exporter/clickhouseexporter/config_test.go

Related Issue

Fixes: #43911


Additional Notes

This improvement ensures the ClickHouse exporter correctly handles standard TLS verification
scenarios where a root CA file is provided but no client certificates are required.

It brings the exporter in line with expected ClickHouse server security behavior and adds
a regression test to safeguard future changes.

@harshit-jindal02 harshit-jindal02 requested a review from a team as a code owner November 6, 2025 23:28
@github-actions github-actions bot added the first-time contributor PRs made by new contributors label Nov 6, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2025

Welcome, contributor! Thank you for your contribution to opentelemetry-collector-contrib.

Important reminders:

A maintainer will review your pull request soon. Thank you for helping make OpenTelemetry better!

Copy link
Member

@SpencerTorres SpencerTorres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as this doesn't break default configs, should be good. Also add changelog. Thanks!

@harshit-jindal02
Copy link
Author

As long as this doesn't break default configs, should be good. Also add changelog. Thanks!

Added changelog entry as requested.

@pjanotti
Copy link
Contributor

pjanotti commented Nov 7, 2025

Thanks for the PR @harshit-jindal02 - don't edit the changelog directly, add the change using chloggen, follow the instructions at https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/a1bbdc152908d8822a0989a5bde4e44a798bd11d/CONTRIBUTING.md#changelog

@pjanotti
Copy link
Contributor

pjanotti commented Nov 7, 2025

The tests are going to fail due to the changelog, but I'm approving the workflows to run so we get a run of the new test.

@harshit-jindal02
Copy link
Author

Thanks for the PR @harshit-jindal02 - don't edit the changelog directly, add the change using chloggen, follow the instructions at https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/a1bbdc152908d8822a0989a5bde4e44a798bd11d/CONTRIBUTING.md#changelog

Thanks @pjanotti, I’ve updated and validated the changelog entry as suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[exporter/clickhouse] TLS configuration is ignored if neither cert_file nor key_file are set

5 participants