Skip to content

Commit 06b3d72

Browse files
committed
Fix missing TLS ServerName in HelmRepository
Add ServerName configuration to TLS config in HelmRepository client options to ensure proper SNI (Server Name Indication) support for virtual hosting environments. This addresses the regression introduced when migrating from internal/tls to runtime/secrets, where ServerName was not being set automatically. Without ServerName, TLS handshakes fail with certificate mismatch errors when connecting to Helm repositories using virtual hosting where multiple repositories are hosted on the same IP address. Signed-off-by: cappyzawa <[email protected]>
1 parent 26abfa9 commit 06b3d72

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

internal/helm/getter/client_opts.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"crypto/tls"
2222
"errors"
2323
"fmt"
24+
neturl "net/url"
2425
"os"
2526
"path"
2627

@@ -155,6 +156,20 @@ func configureAuthentication(ctx context.Context, c client.Client, obj *sourcev1
155156
}
156157
}
157158

159+
// Set ServerName for proper virtual hosting support.
160+
// This is crucial for Helm repositories that use virtual hosting where multiple
161+
// repositories are hosted on the same IP address. Without ServerName, the TLS
162+
// handshake would fail with a certificate mismatch error.
163+
// Note: runtime/secrets does not set ServerName, so this must be done at the
164+
// controller level to ensure proper TLS SNI (Server Name Indication) support.
165+
if opts.TlsConfig != nil {
166+
u, err := neturl.Parse(url)
167+
if err != nil {
168+
return false, nil, nil, fmt.Errorf("cannot parse repository URL: %w", err)
169+
}
170+
opts.TlsConfig.ServerName = u.Hostname()
171+
}
172+
158173
return deprecatedTLS, certSecret, authSecret, nil
159174
}
160175

0 commit comments

Comments
 (0)