Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for min tls version to v1.2 #2119

Merged
merged 4 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions pkg/cmd/start/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package start

import (
"context"
"crypto/tls"
"flag"
"fmt"
"os"
Expand All @@ -26,6 +27,7 @@ import (

// import OIDC cluster authentication plugin, e.g. for IBM Cloud
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
k8sapiflag "k8s.io/component-base/cli/flag"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -57,6 +59,11 @@ var (
setupLog = ctrl.Log.WithName("setup")
)

type tlsConfig struct {
minVersion string
cipherSuites []string
}

func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(jaegertracingv1.AddToScheme(scheme))
Expand Down Expand Up @@ -316,14 +323,24 @@ func createManager(ctx context.Context, cfg *rest.Config) manager.Manager {

namespace := viper.GetString(v1.ConfigWatchNamespace)

var tlsOpt tlsConfig
tlsOpt.minVersion = viper.GetString("tls-min-version")
tlsOpt.cipherSuites = viper.GetStringSlice("tls-cipher-suites")

// see https://github.com/openshift/library-go/blob/4362aa519714a4b62b00ab8318197ba2bba51cb7/pkg/config/leaderelection/leaderelection.go#L104
leaseDuration := time.Second * 137
renewDeadline := time.Second * 107
retryPeriod := time.Second * 26

optionsTlSOptsFuncs := []func(*tls.Config){
func(config *tls.Config) { tlsConfigSetting(config, tlsOpt) },
}

options := ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: webhookPort,
TLSOpts: optionsTlSOptsFuncs,
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "31e04290.jaegertracing.io",
Expand Down Expand Up @@ -434,3 +451,17 @@ func getNamespace(ctx context.Context) string {

return podNamespace
}

func tlsConfigSetting(cfg *tls.Config, tlsOpt tlsConfig) {
version, err := k8sapiflag.TLSVersion(tlsOpt.minVersion)
if err != nil {
setupLog.Error(err, "TLS version invalid")
}
cfg.MinVersion = version

cipherSuiteIDs, err := k8sapiflag.TLSCipherSuites(tlsOpt.cipherSuites)
if err != nil {
setupLog.Error(err, "Failed to convert TLS cipher suite name to ID")
}
cfg.CipherSuites = cipherSuiteIDs
}
2 changes: 2 additions & 0 deletions pkg/cmd/start/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func AddFlags(cmd *cobra.Command) {
cmd.Flags().String("secure-listen-address", "", "")
cmd.Flags().String("health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
cmd.Flags().Int("webhook-bind-port", 9443, "The address webhooks expose.")
cmd.Flags().String("tls-min-version", "VersionTLS12", "Minimum TLS version supported. Value must match version names from https://golang.org/pkg/crypto/tls/#pkg-constants.")
cmd.Flags().StringSlice("tls-cipher-suites", nil, "Comma-separated list of cipher suites for the server. Values are from tls package constants (https://golang.org/pkg/crypto/tls/#pkg-constants). If omitted, the default Go cipher suites will be used")
cmd.Flags().Bool("leader-elect", false, "Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")

Expand Down