Skip to content

Commit 0b92784

Browse files
authoredMay 28, 2024··
Adding support to provide tls version and tls cipher suites. (#778)
* Set default minimum TLS version for webhook server to 1.2 * Adding options to set TLS version and cipher suites
1 parent 08df3bb commit 0b92784

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed
 

‎config/helm/appmesh-controller/templates/deployment.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ spec:
124124
# this must be same as livenessProbe port which can be configured
125125
- --health-probe-port={{ .Values.livenessProbe.httpGet.port }}
126126
- --wait-until-proxy-ready={{ .Values.sidecar.waitUntilProxyReady }}
127+
# TLS configuration
128+
- --tls-min-version={{ .Values.tlsMinVersion }}
129+
- --tls-cipher-suite={{ .Values.tlsCipherSuite }}
127130
{{- if .Values.env }}
128131
env:
129132
{{- range $key, $value := .Values.env }}

‎config/helm/appmesh-controller/values.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ podDisruptionBudget: {}
147147
# Environment variables to set in appmesh-controller pod
148148
env: {}
149149

150+
# TLS setting for appmesh-controller
151+
tlsMinVersion: VersionTLS12
152+
tlsCipherSuite:
153+
150154
#Example
151155
#env:
152156
# http_proxy: http://proxyserver:3128

‎main.go

+36-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package main
1818

1919
import (
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"
@@ -73,6 +75,11 @@ var (
7375
setupLog = ctrl.Log.WithName("setup")
7476
)
7577

78+
type tlsConfig struct {
79+
minVersion string
80+
cipherSuites []string
81+
}
82+
7683
func 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(

‎pkg/inject/config.go

+12
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ const (
5959
flagXRayImage = "xray-image"
6060

6161
flagClusterName = "cluster-name"
62+
63+
flagTlsMinVersion = "tls-min-version"
64+
flagTlsCipherSuite = "tls-cipher-suite"
6265
)
6366

6467
type Config struct {
@@ -123,6 +126,10 @@ type Config struct {
123126
XRayImage string
124127

125128
ClusterName string
129+
130+
// TLS settings
131+
TlsMinVersion string
132+
TlsCipherSuite []string
126133
}
127134

128135
// MultipleTracer checks if more than one tracer is configured.
@@ -224,6 +231,11 @@ func (cfg *Config) BindFlags(fs *pflag.FlagSet) {
224231
"Secret access key for envoy container (for integration testing)")
225232
fs.StringVar(&cfg.EnvoyAwsSessionToken, flagEnvoyAwsSessionToken, "",
226233
"Session token for envoy container (for integration testing)")
234+
fs.StringVar(&cfg.TlsMinVersion, flagTlsMinVersion, "VersionTLS12",
235+
"Minimum TLS version supported. Value must match version names from https://golang.org/pkg/crypto/tls/#pkg-constants.")
236+
fs.StringSliceVar(&cfg.TlsCipherSuite, flagTlsCipherSuite, nil,
237+
"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")
238+
227239
}
228240

229241
func (cfg *Config) BindEnv() error {

0 commit comments

Comments
 (0)
Please sign in to comment.