@@ -18,7 +18,7 @@ package main
1818
1919import (
2020 "context"
21- "github.com/aws/aws-sdk-go/service/eks "
21+ "crypto/tls "
2222 "os"
2323 "strconv"
2424 "time"
@@ -30,6 +30,7 @@ import (
3030 "github.com/aws/aws-app-mesh-controller-for-k8s/pkg/virtualrouter"
3131 "github.com/aws/aws-app-mesh-controller-for-k8s/pkg/virtualservice"
3232 sdkgoaws "github.com/aws/aws-sdk-go/aws"
33+ "github.com/aws/aws-sdk-go/service/eks"
3334 "github.com/spf13/pflag"
3435
3536 "github.com/aws/aws-app-mesh-controller-for-k8s/pkg/conversions"
@@ -42,6 +43,7 @@ import (
4243 clientgoscheme "k8s.io/client-go/kubernetes/scheme"
4344 _ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
4445 "k8s.io/client-go/tools/leaderelection/resourcelock"
46+ k8sapiflag "k8s.io/component-base/cli/flag"
4547 ctrl "sigs.k8s.io/controller-runtime"
4648 "sigs.k8s.io/controller-runtime/pkg/healthz"
4749 "sigs.k8s.io/controller-runtime/pkg/log/zap"
7375 setupLog = ctrl .Log .WithName ("setup" )
7476)
7577
78+ type tlsConfig struct {
79+ minVersion string
80+ cipherSuites []string
81+ }
82+
7683func init () {
7784 _ = clientgoscheme .AddToScheme (scheme )
7885
@@ -147,6 +154,33 @@ func main() {
147154
148155 k8sVersion := k8s .ServerVersion (clientSet .Discovery ())
149156
157+ optionsTlSOptsFuncs := []func (* tls.Config ){}
158+
159+ setupLog .Info ("TlsVersion" , "TLSVersion" , injectConfig .TlsMinVersion )
160+ setupLog .Info ("TlsCipherSuite" , "TlsCipherSuite" , injectConfig .TlsCipherSuite )
161+
162+ // This function get the option from command argument (tlsConfig), check the validity through k8sapiflag
163+ // and set the config for webhook server.
164+ // refer to https://pkg.go.dev/k8s.io/component-base/cli/flag
165+ tlsOption := func (cfg * tls.Config ) {
166+ tlsVersion , err := k8sapiflag .TLSVersion (injectConfig .TlsMinVersion )
167+ if err != nil {
168+ setupLog .Error (err , "TLS version invalid" )
169+ os .Exit (1 )
170+ }
171+ cfg .MinVersion = tlsVersion
172+
173+ // TLSCipherSuites helper function returns a list of cipher suite IDs from the cipher suite names passed.
174+ cipherSuiteIDs , err := k8sapiflag .TLSCipherSuites (injectConfig .TlsCipherSuite )
175+ if err != nil {
176+ setupLog .Error (err , "Failed to convert TLS cipher suite name to ID" )
177+ os .Exit (1 )
178+ }
179+ cfg .CipherSuites = cipherSuiteIDs
180+ }
181+
182+ optionsTlSOptsFuncs = append (optionsTlSOptsFuncs , tlsOption )
183+
150184 mgr , err := ctrl .NewManager (kubeConfig , ctrl.Options {
151185 Scheme : scheme ,
152186 SyncPeriod : & syncPeriod ,
@@ -156,6 +190,7 @@ func main() {
156190 LeaderElectionID : "appmesh-controller-leader-election" ,
157191 LeaderElectionResourceLock : resourcelock .ConfigMapsLeasesResourceLock ,
158192 HealthProbeBindAddress : healthProbeBindAddress ,
193+ TLSOpts : optionsTlSOptsFuncs ,
159194 })
160195
161196 customController := k8s .NewCustomController (
0 commit comments