-
Notifications
You must be signed in to change notification settings - Fork 132
Allow sidecar server to reload TLS certificates #607
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,18 +4,21 @@ import ( | |||||||||||||||||||||||||||||||||||||||
| "context" | ||||||||||||||||||||||||||||||||||||||||
| "crypto/tls" | ||||||||||||||||||||||||||||||||||||||||
| "errors" | ||||||||||||||||||||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||||||||||||||||||||
| "net" | ||||||||||||||||||||||||||||||||||||||||
| "net/http" | ||||||||||||||||||||||||||||||||||||||||
| "net/http/httputil" | ||||||||||||||||||||||||||||||||||||||||
| "net/url" | ||||||||||||||||||||||||||||||||||||||||
| "syscall" | ||||||||||||||||||||||||||||||||||||||||
| "time" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| "sigs.k8s.io/gateway-api-inference-extension/pkg/common" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| // startHTTP starts the HTTP reverse proxy. | ||||||||||||||||||||||||||||||||||||||||
| func (s *Server) startHTTP(ctx context.Context, cert *tls.Certificate) error { | ||||||||||||||||||||||||||||||||||||||||
| func (s *Server) startHTTP(ctx context.Context) error { | ||||||||||||||||||||||||||||||||||||||||
| // Start SSRF protection validator | ||||||||||||||||||||||||||||||||||||||||
| if err := s.allowlistValidator.Start(ctx); err != nil { | ||||||||||||||||||||||||||||||||||||||||
| s.logger.Error(err, "Failed to start allowlist validator") | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -48,11 +51,36 @@ func (s *Server) startHTTP(ctx context.Context, cert *tls.Certificate) error { | |||||||||||||||||||||||||||||||||||||||
| MaxHeaderBytes: 1 << 20, // 1 MB for headers is sufficient | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| // Create TLS certificates | ||||||||||||||||||||||||||||||||||||||||
| var cert *tls.Certificate | ||||||||||||||||||||||||||||||||||||||||
| if s.config.SecureServing { | ||||||||||||||||||||||||||||||||||||||||
| var tempCert tls.Certificate | ||||||||||||||||||||||||||||||||||||||||
| if s.config.CertPath != "" { | ||||||||||||||||||||||||||||||||||||||||
| tempCert, err = tls.LoadX509KeyPair(s.config.CertPath+"/tls.crt", s.config.CertPath+"/tls.key") | ||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||
| tempCert, err = CreateSelfSignedTLSCertificate() | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||
| return fmt.Errorf("failed to create TLS certificate: %w", err) | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+58
to
+64
|
||||||||||||||||||||||||||||||||||||||||
| tempCert, err = tls.LoadX509KeyPair(s.config.CertPath+"/tls.crt", s.config.CertPath+"/tls.key") | |
| } else { | |
| tempCert, err = CreateSelfSignedTLSCertificate() | |
| } | |
| if err != nil { | |
| return fmt.Errorf("failed to create TLS certificate: %w", err) | |
| } | |
| certFile := s.config.CertPath + "/tls.crt" | |
| keyFile := s.config.CertPath + "/tls.key" | |
| tempCert, err = tls.LoadX509KeyPair(certFile, keyFile) | |
| if err != nil { | |
| return fmt.Errorf("failed to load TLS key pair from cert %q and key %q: %w", certFile, keyFile, err) | |
| } | |
| } else { | |
| tempCert, err = CreateSelfSignedTLSCertificate() | |
| if err != nil { | |
| return fmt.Errorf("failed to generate self-signed TLS certificate: %w", err) | |
| } | |
| } |
Copilot
AI
Feb 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TLS certificate reloading via common.NewCertReloader is newly introduced but doesn’t appear to be covered by tests. Adding an integration/unit test that starts the server with CertPath pointing to a temp dir, rotates tls.crt/tls.key, and verifies a new TLS handshake presents the updated cert would help prevent regressions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Data-parallel clone servers call startHTTP(), which now derives TLS settings (and connector selection) from s.config, but Clone() does not copy the config field. As a result, cloned servers will run with zero-value config (e.g., SecureServing false / CertPath empty), so TLS cert reloading (and potentially connector behavior) won’t apply to the data-parallel proxy ports. Consider copying config (and any other required fields) in Clone(), or explicitly setting clone.config = s.config before calling clone.startHTTP().