Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v14] Fix issue Teleport Connect Kube terminal throws internal server error #32612

Merged
merged 1 commit into from Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/teleterm/gateway/kube.go
Expand Up @@ -98,6 +98,11 @@ func (k *kube) makeALPNLocalProxyForKube(cas map[string]tls.Certificate) error {
return trace.NewAggregate(err, listener.Close())
}

webProxyHost, err := utils.Host(k.cfg.WebProxyAddr)
if err != nil {
return trace.Wrap(err)
}

k.localProxy, err = alpnproxy.NewLocalProxy(alpnproxy.LocalProxyConfig{
InsecureSkipVerify: k.cfg.Insecure,
RemoteProxyAddr: k.cfg.WebProxyAddr,
Expand All @@ -107,7 +112,7 @@ func (k *kube) makeALPNLocalProxyForKube(cas map[string]tls.Certificate) error {
ALPNConnUpgradeRequired: k.cfg.TLSRoutingConnUpgradeRequired,
},
alpnproxy.WithHTTPMiddleware(middleware),
alpnproxy.WithSNI(client.GetKubeTLSServerName(k.cfg.WebProxyAddr)),
alpnproxy.WithSNI(client.GetKubeTLSServerName(webProxyHost)),
alpnproxy.WithClusterCAs(k.closeContext, k.cfg.RootClusterCACertPoolFunc),
)
if err != nil {
Expand Down
10 changes: 7 additions & 3 deletions lib/teleterm/gateway/kube_test.go
Expand Up @@ -223,16 +223,20 @@ func mustStartMockProxyWithKubeAPI(t *testing.T, identity tlsca.Identity) *mockP
return m
}

func mustGenCAForProxyKubeAddr(t *testing.T, key *keys.PrivateKey, host string) (tls.Certificate, *tlsca.CertAuthority) {
func mustGenCAForProxyKubeAddr(t *testing.T, key *keys.PrivateKey, hostAddr string) (tls.Certificate, *tlsca.CertAuthority) {
t.Helper()

addr, err := utils.ParseAddr(hostAddr)
require.NoError(t, err)

certPem, err := tlsca.GenerateSelfSignedCAWithConfig(tlsca.GenerateCAConfig{
Entity: pkix.Name{
CommonName: "localhost",
Organization: []string{"Teleport"},
},
Signer: key,
DNSNames: []string{client.GetKubeTLSServerName(host)}, // Use special kube SNI.
Signer: key,
// Use special kube SNI. Make sure only host (no port) is used.
DNSNames: []string{client.GetKubeTLSServerName(addr.Host())},
TTL: defaults.CATTL,
})
require.NoError(t, err)
Expand Down