Skip to content

Commit a3dee46

Browse files
committed
feat: add flag to configure TLS cipher suites
This commit introduces a new command-line flag `-tls-cipher-suites` to the webhook server. This allows users to specify a comma-separated list of allowed TLS cipher suites, enhancing security configurability. Assisted-by: gemini-3-pro-preview
1 parent c926cd0 commit a3dee46

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

cmd/webhook/main.go

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"flag"
66
"fmt"
77
"net/http"
8+
"strings"
89

910
"github.com/open-policy-agent/cert-controller/pkg/rotator"
1011
"k8s.io/apimachinery/pkg/runtime"
@@ -42,6 +43,7 @@ const (
4243
var (
4344
audience string
4445
webhookCertDir string
46+
tlsCipherSuites string
4547
tlsMinVersion string
4648
healthAddr string
4749
metricsAddr string
@@ -73,6 +75,7 @@ func mainErr() error {
7375
flag.StringVar(&audience, "audience", "", "Audience for service account token")
7476
flag.StringVar(&webhookCertDir, "webhook-cert-dir", "/certs", "Webhook certificates dir to use. Defaults to /certs")
7577
flag.BoolVar(&disableCertRotation, "disable-cert-rotation", false, "disable automatic generation and rotation of webhook TLS certificates/keys")
78+
flag.StringVar(&tlsCipherSuites, "tls-cipher-suites", "", "Comma-separated list of TLS cipher suites")
7679
flag.StringVar(&tlsMinVersion, "tls-min-version", "1.3", "Minimum TLS version")
7780
flag.StringVar(&healthAddr, "health-addr", ":9440", "The address the health endpoint binds to")
7881
flag.StringVar(&metricsAddr, "metrics-addr", ":8095", "The address the metrics endpoint binds to")
@@ -114,10 +117,20 @@ func mainErr() error {
114117
if err != nil {
115118
return fmt.Errorf("entrypoint: unable to parse TLS version: %w", err)
116119
}
120+
tlsOpts := []func(c *tls.Config){func(c *tls.Config) { c.MinVersion = tlsVersion }}
121+
122+
cipherSuites, err := parseTLSCipherSuites(tlsCipherSuites)
123+
if err != nil {
124+
return fmt.Errorf("entrypoint: unable to parse TLS cipher suites: %w", err)
125+
}
126+
127+
if len(cipherSuites) > 0 {
128+
tlsOpts = append(tlsOpts, func(c *tls.Config) { c.CipherSuites = cipherSuites })
129+
}
117130

118131
serverOpts := webhook.Options{
119132
CertDir: webhookCertDir,
120-
TLSOpts: []func(c *tls.Config){func(c *tls.Config) { c.MinVersion = tlsVersion }},
133+
TLSOpts: tlsOpts,
121134
}
122135
mgr, err := ctrl.NewManager(config, ctrl.Options{
123136
Scheme: scheme,
@@ -219,3 +232,33 @@ func parseTLSVersion(tlsVersion string) (uint16, error) {
219232
return 0, fmt.Errorf("invalid TLS version. Must be one of: 1.0, 1.1, 1.2, 1.3")
220233
}
221234
}
235+
236+
func parseTLSCipherSuites(cipherSuites string) ([]uint16, error) {
237+
if cipherSuites == "" {
238+
return nil, nil
239+
}
240+
241+
// Build a map of all available cipher suites
242+
availableSuites := make(map[string]uint16)
243+
for _, s := range tls.CipherSuites() {
244+
availableSuites[s.Name] = s.ID
245+
}
246+
// Also include insecure suites just in case, though discouraged
247+
for _, s := range tls.InsecureCipherSuites() {
248+
availableSuites[s.Name] = s.ID
249+
}
250+
251+
var ids []uint16
252+
for _, name := range strings.Split(cipherSuites, ",") {
253+
name = strings.TrimSpace(name)
254+
if name == "" {
255+
continue
256+
}
257+
id, ok := availableSuites[name]
258+
if !ok {
259+
return nil, fmt.Errorf("unsupported cipher suite: %s", name)
260+
}
261+
ids = append(ids, id)
262+
}
263+
return ids, nil
264+
}

0 commit comments

Comments
 (0)