@@ -17,13 +17,11 @@ package main
17
17
18
18
import (
19
19
"context"
20
- "crypto/tls"
21
20
"flag"
22
21
"fmt"
23
22
"net/http"
24
23
_ "net/http/pprof"
25
24
"os"
26
- "strings"
27
25
"time"
28
26
29
27
"github.com/spf13/pflag"
@@ -72,10 +70,8 @@ type TLSOptions struct {
72
70
}
73
71
74
72
var (
75
- scheme = runtime .NewScheme ()
76
- setupLog = ctrl .Log .WithName ("setup" )
77
- tlsOptions = TLSOptions {}
78
- tlsSupportedVersions = []string {TLSVersion12 , TLSVersion13 }
73
+ scheme = runtime .NewScheme ()
74
+ setupLog = ctrl .Log .WithName ("setup" )
79
75
80
76
// flags.
81
77
managerOptions = flags.ManagerOptions {}
@@ -175,24 +171,6 @@ func InitFlags(fs *pflag.FlagSet) {
175
171
fs .IntVar (& scopeCacheMaxSize , "scope-cache-max-size" , 10 , "The maximum credentials count the operator should keep in cache. Setting this value to 0 means no cache." )
176
172
177
173
fs .BoolVar (& showVersion , "version" , false , "Show current version and exit." )
178
-
179
- fs .StringVar (& tlsOptions .TLSMinVersion , "tls-min-version" , TLSVersion12 ,
180
- "The minimum TLS version in use by the webhook server.\n " +
181
- fmt .Sprintf ("Possible values are %s." , strings .Join (tlsSupportedVersions , ", " )),
182
- )
183
-
184
- fs .StringVar (& tlsOptions .TLSMaxVersion , "tls-max-version" , TLSVersion13 ,
185
- "The maximum TLS version in use by the webhook server.\n " +
186
- fmt .Sprintf ("Possible values are %s." , strings .Join (tlsSupportedVersions , ", " )),
187
- )
188
-
189
- tlsCipherPreferredValues := cliflag .PreferredTLSCipherNames ()
190
- tlsCipherInsecureValues := cliflag .InsecureTLSCipherNames ()
191
- fs .StringVar (& tlsOptions .TLSCipherSuites , "tls-cipher-suites" , "" ,
192
- "Comma-separated list of cipher suites for the webhook server. " +
193
- "If omitted, the default Go cipher suites will be used. \n " +
194
- "Preferred values: " + strings .Join (tlsCipherPreferredValues , ", " )+ ". \n " +
195
- "Insecure values: " + strings .Join (tlsCipherInsecureValues , ", " )+ "." )
196
174
}
197
175
198
176
// Add RBAC for the authorized diagnostics endpoint.
@@ -225,12 +203,6 @@ func main() {
225
203
}()
226
204
}
227
205
228
- tlsOptionOverrides , err := GetTLSOptionOverrideFuncs (tlsOptions )
229
- if err != nil {
230
- setupLog .Error (err , "unable to add TLS settings to the webhook server" )
231
- os .Exit (1 )
232
- }
233
-
234
206
cfg , err := config .GetConfigWithContext (os .Getenv ("KUBECONTEXT" ))
235
207
if err != nil {
236
208
setupLog .Error (err , "unable to get kubeconfig" )
@@ -248,7 +220,7 @@ func main() {
248
220
}
249
221
}
250
222
251
- _ , metricsOpts , err := flags .GetManagerOptions (managerOptions )
223
+ tlsOpts , metricsOpts , err := flags .GetManagerOptions (managerOptions )
252
224
if err != nil {
253
225
setupLog .Error (err , "unable to get manager options" )
254
226
os .Exit (1 )
@@ -285,7 +257,7 @@ func main() {
285
257
webhook.Options {
286
258
Port : webhookPort ,
287
259
CertDir : webhookCertDir ,
288
- TLSOpts : tlsOptionOverrides ,
260
+ TLSOpts : tlsOpts ,
289
261
},
290
262
),
291
263
HealthProbeBindAddress : healthAddr ,
@@ -394,63 +366,3 @@ func setupWebhooks(mgr ctrl.Manager) {
394
366
func concurrency (c int ) controller.Options {
395
367
return controller.Options {MaxConcurrentReconciles : c }
396
368
}
397
-
398
- // GetTLSOptionOverrideFuncs returns a list of TLS configuration overrides to be used
399
- // by the webhook server.
400
- func GetTLSOptionOverrideFuncs (options TLSOptions ) ([]func (* tls.Config ), error ) {
401
- var tlsOptions []func (config * tls.Config )
402
-
403
- // To make a static analyzer happy, this block ensures there is no code
404
- // path that sets a TLS version outside the acceptable values, even in
405
- // case of unexpected user input.
406
- var tlsMinVersion , tlsMaxVersion uint16
407
- for version , option := range map [* uint16 ]string {& tlsMinVersion : options .TLSMinVersion , & tlsMaxVersion : options .TLSMaxVersion } {
408
- switch option {
409
- case TLSVersion12 :
410
- * version = tls .VersionTLS12
411
- case TLSVersion13 :
412
- * version = tls .VersionTLS13
413
- default :
414
- return nil , fmt .Errorf ("unexpected TLS version %q (must be one of: %s)" , option , strings .Join (tlsSupportedVersions , ", " ))
415
- }
416
- }
417
-
418
- if tlsMaxVersion != 0 && tlsMinVersion > tlsMaxVersion {
419
- return nil , fmt .Errorf ("TLS version flag min version (%s) is greater than max version (%s)" ,
420
- options .TLSMinVersion , options .TLSMaxVersion )
421
- }
422
-
423
- tlsOptions = append (tlsOptions , func (cfg * tls.Config ) {
424
- cfg .MinVersion = tlsMinVersion
425
- cfg .MaxVersion = tlsMaxVersion
426
- })
427
-
428
- // Cipher suites should not be set if empty.
429
- if tlsMinVersion >= tls .VersionTLS13 &&
430
- options .TLSCipherSuites != "" {
431
- setupLog .Info ("warning: Cipher suites should not be set for TLS version 1.3. Ignoring ciphers" )
432
- options .TLSCipherSuites = ""
433
- }
434
-
435
- if options .TLSCipherSuites != "" {
436
- tlsCipherSuites := strings .Split (options .TLSCipherSuites , "," )
437
- suites , err := cliflag .TLSCipherSuites (tlsCipherSuites )
438
- if err != nil {
439
- return nil , err
440
- }
441
-
442
- insecureCipherValues := cliflag .InsecureTLSCipherNames ()
443
- for _ , cipher := range tlsCipherSuites {
444
- for _ , insecureCipherName := range insecureCipherValues {
445
- if insecureCipherName == cipher {
446
- setupLog .Info (fmt .Sprintf ("warning: use of insecure cipher '%s' detected." , cipher ))
447
- }
448
- }
449
- }
450
- tlsOptions = append (tlsOptions , func (cfg * tls.Config ) {
451
- cfg .CipherSuites = suites
452
- })
453
- }
454
-
455
- return tlsOptions , nil
456
- }
0 commit comments