@@ -18,7 +18,7 @@ package main
18
18
19
19
import (
20
20
"context"
21
- "github.com/aws/aws-sdk-go/service/eks "
21
+ "crypto/tls "
22
22
"os"
23
23
"strconv"
24
24
"time"
@@ -30,6 +30,7 @@ import (
30
30
"github.com/aws/aws-app-mesh-controller-for-k8s/pkg/virtualrouter"
31
31
"github.com/aws/aws-app-mesh-controller-for-k8s/pkg/virtualservice"
32
32
sdkgoaws "github.com/aws/aws-sdk-go/aws"
33
+ "github.com/aws/aws-sdk-go/service/eks"
33
34
"github.com/spf13/pflag"
34
35
35
36
"github.com/aws/aws-app-mesh-controller-for-k8s/pkg/conversions"
@@ -42,6 +43,7 @@ import (
42
43
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
43
44
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
44
45
"k8s.io/client-go/tools/leaderelection/resourcelock"
46
+ k8sapiflag "k8s.io/component-base/cli/flag"
45
47
ctrl "sigs.k8s.io/controller-runtime"
46
48
"sigs.k8s.io/controller-runtime/pkg/healthz"
47
49
"sigs.k8s.io/controller-runtime/pkg/log/zap"
73
75
setupLog = ctrl .Log .WithName ("setup" )
74
76
)
75
77
78
+ type tlsConfig struct {
79
+ minVersion string
80
+ cipherSuites []string
81
+ }
82
+
76
83
func init () {
77
84
_ = clientgoscheme .AddToScheme (scheme )
78
85
@@ -147,6 +154,33 @@ func main() {
147
154
148
155
k8sVersion := k8s .ServerVersion (clientSet .Discovery ())
149
156
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
+
150
184
mgr , err := ctrl .NewManager (kubeConfig , ctrl.Options {
151
185
Scheme : scheme ,
152
186
SyncPeriod : & syncPeriod ,
@@ -156,6 +190,7 @@ func main() {
156
190
LeaderElectionID : "appmesh-controller-leader-election" ,
157
191
LeaderElectionResourceLock : resourcelock .ConfigMapsLeasesResourceLock ,
158
192
HealthProbeBindAddress : healthProbeBindAddress ,
193
+ TLSOpts : optionsTlSOptsFuncs ,
159
194
})
160
195
161
196
customController := k8s .NewCustomController (
0 commit comments