fix: Add tls-server-name support for Teleport and similar proxies#502
fix: Add tls-server-name support for Teleport and similar proxies#502
Conversation
This fix adds support for the `tls-server-name` field from kubeconfig, which is required when connecting to Kubernetes clusters through proxies like Teleport that use SNI-based routing. When Teleport is used, the server URL hostname differs from the TLS certificate's expected hostname. The `tls-server-name` field tells the client which hostname to use for SNI during TLS negotiation. Without this fix, SSL certificate verification fails because the client uses the server URL hostname instead of the required SNI name. Fixes #495
WalkthroughAdded support for reading and propagating the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Thanks for looking into this. I've tested it in my setup and it is not working. I'm still getting SSL errors. I have run it through my local coding agent to get some explanation for you. See below Summary of the Fix IssueThe current fix in commit 252fb24 is incomplete. Here's why: What the fix does
What's missingThe kubernetes-client v26.1.0 bundled with KRR doesn't use tls_server_name anywhere. The fix stores the value but For tls_server_name to work, it needs to be passed to urllib3 as server_hostname when creating the SSL connection. What would make it workOption A: Upgrade kubernetes dependency to v28+ which has native tls-server-name support (see lines 570-583 in Option B: Patch RESTClientObject in addition to KubeConfigLoader . The REST client would need to:
Verification # v26.1.0 has no tls_server_name support:
grep -n "tls_server_name" .venv/lib/python3.12/site-packages/kubernetes/config/kube_config.py
# Returns: nothing
# v28+ has it:
# Lines 570-571: if 'tls-server-name' in self._cluster:
# self.tls_server_name = self._cluster['tls-server-name']RecommendationUpgrading kubernetes-client to v28+ is the cleanest solution - it has native support and the config_patch.py changes |
Summary
Fixes #495 - SSL certificate verification fails when using Teleport Kubernetes proxy
Problem
When using KRR with Kubernetes clusters accessed through Teleport or similar proxies, SSL certificate verification fails with:
This happens because Teleport kubeconfigs use
tls-server-nameto specify the SNI hostname for TLS negotiation, which differs from the server URL:The CA certificate is valid for the
tls-server-name(SNI) hostname, not the server URL hostname.Solution
Extended the existing
config_patch.py(which already handlesproxy-url) to also supporttls-server-name:tls-server-namefrom the cluster configuration in kubeconfigtls_server_nameThis follows the same pattern already established for
proxy-urlsupport.Changes
robusta_krr/core/integrations/kubernetes/config_patch.py:tls-server-namefrom kubeconfig cluster configConfigurationclass to accepttls_server_nameparameter_set_configto iterate over bothproxyandtls_server_namekeysTesting
Users with Teleport access can test by:
tsh kube login)kubectl get podsworkskrr simple -p <prometheus-url>cc @prein (issue reporter who offered to help test)