Skip to content

Add custom CA certificate support for OTLP endpoints - #4676

Merged
ChrisJBurns merged 2 commits into
mainfrom
add-ca-bundle-otlp
Apr 8, 2026
Merged

ChrisJBurns merged 2 commits into
mainfrom
add-ca-bundle-otlp

Conversation

@ChrisJBurns

@ChrisJBurns ChrisJBurns commented Apr 8, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

When the OTLP collector uses TLS with certificates signed by an internal/private CA, there was no way to inject a custom CA bundle into the proxyrunner pod. The only workaround (SSL_CERT_FILE) replaces the entire system CA pool, which is fragile and error-prone.

  • Add caBundleRef field to MCPTelemetryOTelConfig (reuses existing CABundleSource type from OIDC)
  • Mount the referenced ConfigMap into proxyrunner pods following the same pattern as OIDC CA bundles
  • Thread the CA file path through all telemetry config layers to the OTLP exporters
  • Use WithTLSClientConfig() on both trace and metric HTTP exporters, appending the custom CA to the system pool

Closes #4672

Type of change

  • New feature

Test plan

  • Unit tests (task test)
  • Linting (task lint-fix)

Changes

File Change
cmd/thv-operator/api/v1alpha1/mcptelemetryconfig_types.go Add CABundleRef field to MCPTelemetryOTelConfig, add validateCABundle()
cmd/thv-operator/pkg/validation/telemetry_validation.go New constants for volume prefix, mount path, default key
cmd/thv-operator/pkg/controllerutil/telemetry_volumes.go New AddTelemetryCABundleVolumes() and TelemetryCABundleFilePath()
cmd/thv-operator/controllers/mcpserver_controller.go Wire CA volume into deploymentForMCPServer()
cmd/thv-operator/controllers/mcpserver_runconfig.go Compute CA path and pass to runconfig builder
cmd/thv-operator/pkg/runconfig/telemetry.go Accept and set caBundleFilePath on config
pkg/telemetry/providers/otlp/tls.go New newTLSConfigFromCA() — loads CA, appends to system pool
pkg/telemetry/providers/otlp/tracing.go Add WithTLSClientConfig() when CA path is set
pkg/telemetry/providers/otlp/metrics.go Same TLS support for metrics exporter
pkg/telemetry/providers/otlp/config.go Add CACertPath field
pkg/telemetry/config.go Add CACertPath field, wire through NewProvider()
pkg/telemetry/providers/providers.go Add CACertPath to Config, add WithCACertPath() option
pkg/telemetry/providers/providers_strategy.go Pass CACertPath to otlp.Config in both strategies

Does this introduce a user-facing change?

Yes. Users can now configure a caBundleRef in their MCPTelemetryConfig to trust custom CAs for OTLP endpoints:

apiVersion: toolhive.stacklok.dev/v1alpha1
kind: MCPTelemetryConfig
metadata:
  name: my-telemetry
spec:
  openTelemetry:
    enabled: true
    endpoint: otel-collector.internal:4318
    caBundleRef:
      configMapRef:
        name: otel-ca-bundle
        key: ca.crt

Special notes for reviewers

  • This only implements support via MCPTelemetryConfig (the shared CRD path). The deprecated inline OpenTelemetryConfig on MCPServer is intentionally not touched as it will be removed.
  • The TLS config appends the custom CA to the system pool (unlike SSL_CERT_FILE which replaces it), so both custom and public CAs are trusted.
  • Follows the established OIDC CA bundle pattern (oidc_volumes.go, ValidateCABundleSource).

Large PR Justification

  • This contains the whole custom CA cert support for OTLP

Generated with Claude Code

@github-actions github-actions Bot added the size/L Large PR: 600-999 lines changed label Apr 8, 2026
@codecov

codecov Bot commented Apr 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.90476% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.83%. Comparing base (8b8412b) to head (56316e8).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
pkg/telemetry/providers/otlp/metrics.go 0.00% 4 Missing and 1 partial ⚠️
pkg/telemetry/providers/otlp/tracing.go 0.00% 4 Missing and 1 partial ⚠️
...d/thv-operator/controllers/mcpserver_controller.go 60.00% 3 Missing and 1 partial ⚠️
pkg/telemetry/providers/otlp/tls.go 78.57% 2 Missing and 1 partial ⚠️
...md/thv-operator/controllers/mcpserver_runconfig.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4676      +/-   ##
==========================================
- Coverage   68.84%   68.83%   -0.01%     
==========================================
  Files         509      507       -2     
  Lines       52668    52696      +28     
==========================================
+ Hits        36259    36275      +16     
- Misses      13606    13619      +13     
+ Partials     2803     2802       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions Bot added size/XL Extra large PR: 1000+ lines changed and removed size/L Large PR: 600-999 lines changed labels Apr 8, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Large PR Detected

This PR exceeds 1000 lines of changes and requires justification before it can be reviewed.

How to unblock this PR:

Add a section to your PR description with the following format:

## Large PR Justification

[Explain why this PR must be large, such as:]
- Generated code that cannot be split
- Large refactoring that must be atomic
- Multiple related changes that would break if separated
- Migration or data transformation

Alternative:

Consider splitting this PR into smaller, focused changes (< 1000 lines each) for easier review and reduced risk.

See our Contributing Guidelines for more details.


This review will be automatically dismissed once you add the justification section.

@github-actions github-actions Bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Apr 8, 2026
JAORMX
JAORMX previously approved these changes Apr 8, 2026

@ChrisJBurns ChrisJBurns left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Multi-Agent Consensus Review

Agents consulted: kubernetes-expert, security-advisor, code-reviewer, site-reliability-engineer

Consensus Summary

# Finding Consensus Severity Action
1 Redundant API call + return nil on telemetry config fetch error 8/10 MEDIUM Fix
2 Constant duplication between types.go and validation pkg 8/10 LOW Fix
3 No runtime guard for Insecure + CACertPath at library level 7/10 LOW Discuss

Overall

This is a well-structured PR that cleanly follows the established OIDC CA bundle pattern across the CRD types, controller, volume helpers, and telemetry config threading. The TLS implementation is sound — appending to the system pool rather than replacing it, enforcing TLS 1.2 minimum, and handling missing system cert pools gracefully. Test coverage is thorough with 850+ lines of new tests.

The main concern is the error handling in deploymentForMCPServer (Finding 1). The new telemetry CA bundle block calls getTelemetryConfigForMCPServer() again (already called at line 1085) and returns nil on error — unlike the existing telemetry env var block (line 1085-1092) which logs a warning and proceeds, and the OIDC CA block (line 1202) which uses if err == nil. This introduces a behavioral regression where a transient API error that previously degraded gracefully now blocks deployment creation entirely. The constant duplication (Finding 2) is a minor DRY concern with a clear fix path.


Generated with Claude Code

@github-actions github-actions Bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Apr 8, 2026
…onfig

When the OTLP collector uses TLS with certificates signed by an internal
CA, there was no way to inject a custom CA bundle into the proxyrunner
pod. Users had to resort to SSL_CERT_FILE which replaces the entire
system CA pool.

Add a caBundleRef field to MCPTelemetryOTelConfig that references a
ConfigMap containing the CA bundle. The operator mounts it into the pod
and threads the file path through the telemetry config layers so the
OTLP HTTP exporters use WithTLSClientConfig() with the custom CA
appended to the system pool.

Closes #4672

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@github-actions github-actions Bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Apr 8, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@ChrisJBurns
ChrisJBurns requested a review from amirejaz as a code owner April 8, 2026 19:41
@github-actions github-actions Bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Apr 8, 2026
@github-actions
github-actions Bot dismissed their stale review April 8, 2026 19:45

Large PR justification has been provided. Thank you!

@github-actions

github-actions Bot commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

✅ Large PR justification has been provided. The size review has been dismissed and this PR can now proceed with normal review.

@ChrisJBurns
ChrisJBurns merged commit d8ddb89 into main Apr 8, 2026
41 checks passed
@ChrisJBurns
ChrisJBurns deleted the add-ca-bundle-otlp branch April 8, 2026 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XL Extra large PR: 1000+ lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support custom CA certificates for OTLP endpoints in proxyrunner

2 participants