|
5 | 5 | "flag" |
6 | 6 | "fmt" |
7 | 7 | "net/http" |
| 8 | + "strings" |
8 | 9 |
|
9 | 10 | "github.com/open-policy-agent/cert-controller/pkg/rotator" |
10 | 11 | "k8s.io/apimachinery/pkg/runtime" |
@@ -42,6 +43,7 @@ const ( |
42 | 43 | var ( |
43 | 44 | audience string |
44 | 45 | webhookCertDir string |
| 46 | + tlsCipherSuites string |
45 | 47 | tlsMinVersion string |
46 | 48 | healthAddr string |
47 | 49 | metricsAddr string |
@@ -73,6 +75,7 @@ func mainErr() error { |
73 | 75 | flag.StringVar(&audience, "audience", "", "Audience for service account token") |
74 | 76 | flag.StringVar(&webhookCertDir, "webhook-cert-dir", "/certs", "Webhook certificates dir to use. Defaults to /certs") |
75 | 77 | 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") |
76 | 79 | flag.StringVar(&tlsMinVersion, "tls-min-version", "1.3", "Minimum TLS version") |
77 | 80 | flag.StringVar(&healthAddr, "health-addr", ":9440", "The address the health endpoint binds to") |
78 | 81 | flag.StringVar(&metricsAddr, "metrics-addr", ":8095", "The address the metrics endpoint binds to") |
@@ -114,10 +117,20 @@ func mainErr() error { |
114 | 117 | if err != nil { |
115 | 118 | return fmt.Errorf("entrypoint: unable to parse TLS version: %w", err) |
116 | 119 | } |
| 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 | + } |
117 | 130 |
|
118 | 131 | serverOpts := webhook.Options{ |
119 | 132 | CertDir: webhookCertDir, |
120 | | - TLSOpts: []func(c *tls.Config){func(c *tls.Config) { c.MinVersion = tlsVersion }}, |
| 133 | + TLSOpts: tlsOpts, |
121 | 134 | } |
122 | 135 | mgr, err := ctrl.NewManager(config, ctrl.Options{ |
123 | 136 | Scheme: scheme, |
@@ -219,3 +232,33 @@ func parseTLSVersion(tlsVersion string) (uint16, error) { |
219 | 232 | return 0, fmt.Errorf("invalid TLS version. Must be one of: 1.0, 1.1, 1.2, 1.3") |
220 | 233 | } |
221 | 234 | } |
| 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