Skip to content

Commit ab8ae55

Browse files
authored
feat: use knative.dev/pkg/tls for activator TLS configuration (#16424)
Replace the hardcoded tls.VersionTLS13 in the activator's HTTPS server with the shared knative.dev/pkg/tls package, allowing TLS settings to be configured via ACTIVATOR_TLS_MIN_VERSION, ACTIVATOR_TLS_MAX_VERSION, ACTIVATOR_TLS_CIPHER_SUITES, and ACTIVATOR_TLS_CURVE_PREFERENCES environment variables. The default remains TLS 1.3 when no env var is set. Signed-off-by: Mikhail Fedosin <mfedosin@redhat.com>
1 parent cff5211 commit ab8ae55

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

cmd/activator/main.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package main
1818

1919
import (
2020
"context"
21-
"crypto/tls"
2221
"errors"
2322
"fmt"
2423
"log"
@@ -50,6 +49,7 @@ import (
5049
k8sruntime "knative.dev/pkg/observability/runtime/k8s"
5150
"knative.dev/pkg/signals"
5251
"knative.dev/pkg/system"
52+
knativetls "knative.dev/pkg/tls"
5353
"knative.dev/pkg/version"
5454
"knative.dev/pkg/websocket"
5555
"knative.dev/serving/pkg/activator"
@@ -292,7 +292,7 @@ func main() {
292292
"profile": pprof.Server,
293293
}
294294

295-
errCh := make(chan error, len(servers))
295+
errCh := make(chan error, len(servers)+1)
296296
for name, server := range servers {
297297
go func(name string, s *http.Server) {
298298
// Don't forward ErrServerClosed as that indicates we're already shutting down.
@@ -306,17 +306,21 @@ func main() {
306306
// At this moment activator with TLS does not disable HTTP.
307307
// See also https://github.com/knative/serving/issues/12808.
308308
if tlsEnabled {
309-
name, server := "https", pkgnet.NewServer(":"+strconv.Itoa(networking.BackendHTTPSPort), ah)
310-
go func(name string, s *http.Server) {
311-
s.TLSConfig = &tls.Config{
312-
MinVersion: tls.VersionTLS13,
313-
GetCertificate: certCache.GetCertificate,
314-
}
309+
tlsCfg, err := knativetls.DefaultConfigFromEnv("ACTIVATOR_")
310+
if err != nil {
311+
logger.Fatalw("Failed to read TLS configuration from environment", zap.Error(err))
312+
}
313+
314+
server := pkgnet.NewServer(":"+strconv.Itoa(networking.BackendHTTPSPort), ah)
315+
servers["https"] = server
316+
go func(s *http.Server) {
317+
s.TLSConfig = tlsCfg
318+
s.TLSConfig.GetCertificate = certCache.GetCertificate
315319
// Don't forward ErrServerClosed as that indicates we're already shutting down.
316320
if err := s.ListenAndServeTLS("", ""); err != nil && !errors.Is(err, http.ErrServerClosed) {
317-
errCh <- fmt.Errorf("%s server failed: %w", name, err)
321+
errCh <- fmt.Errorf("https server failed: %w", err)
318322
}
319-
}(name, server)
323+
}(server)
320324
}
321325

322326
// Wait for the signal to drain.

0 commit comments

Comments
 (0)