Skip to content

Commit 44604b1

Browse files
committed
manager: remove TLS options
They are in CAPI now, we import them.
1 parent 010ddad commit 44604b1

File tree

3 files changed

+5
-239
lines changed

3 files changed

+5
-239
lines changed

config/manager/manager.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ spec:
2323
- "--leader-elect"
2424
- "--v=2"
2525
- "--diagnostics-address=127.0.0.1:8080"
26-
- "--insecure-diagnostics"
26+
- "--insecure-diagnostics=true"
2727
image: controller:latest
2828
imagePullPolicy: Always
2929
name: manager

main.go

Lines changed: 4 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ package main
1717

1818
import (
1919
"context"
20-
"crypto/tls"
2120
"flag"
2221
"fmt"
2322
"net/http"
2423
_ "net/http/pprof"
2524
"os"
26-
"strings"
2725
"time"
2826

2927
"github.com/spf13/pflag"
@@ -72,10 +70,8 @@ type TLSOptions struct {
7270
}
7371

7472
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")
7975

8076
// flags.
8177
managerOptions = flags.ManagerOptions{}
@@ -175,24 +171,6 @@ func InitFlags(fs *pflag.FlagSet) {
175171
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.")
176172

177173
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, ", ")+".")
196174
}
197175

198176
// Add RBAC for the authorized diagnostics endpoint.
@@ -225,12 +203,6 @@ func main() {
225203
}()
226204
}
227205

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-
234206
cfg, err := config.GetConfigWithContext(os.Getenv("KUBECONTEXT"))
235207
if err != nil {
236208
setupLog.Error(err, "unable to get kubeconfig")
@@ -248,7 +220,7 @@ func main() {
248220
}
249221
}
250222

251-
_, metricsOpts, err := flags.GetManagerOptions(managerOptions)
223+
tlsOpts, metricsOpts, err := flags.GetManagerOptions(managerOptions)
252224
if err != nil {
253225
setupLog.Error(err, "unable to get manager options")
254226
os.Exit(1)
@@ -285,7 +257,7 @@ func main() {
285257
webhook.Options{
286258
Port: webhookPort,
287259
CertDir: webhookCertDir,
288-
TLSOpts: tlsOptionOverrides,
260+
TLSOpts: tlsOpts,
289261
},
290262
),
291263
HealthProbeBindAddress: healthAddr,
@@ -394,63 +366,3 @@ func setupWebhooks(mgr ctrl.Manager) {
394366
func concurrency(c int) controller.Options {
395367
return controller.Options{MaxConcurrentReconciles: c}
396368
}
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-
}

main_test.go

Lines changed: 0 additions & 146 deletions
This file was deleted.

0 commit comments

Comments
 (0)