Skip to content

Commit b66afe9

Browse files
authored
Merge pull request #504 from xuezhaojun/fix-ciphersuites-option
Fix: ciphersuites length equals to 1(expecting 0) when using the default value.
2 parents 7e475a9 + 011c9fa commit b66afe9

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

cmd/server/app/options/options.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ type ProxyRunOptions struct {
101101
// also checks if given comma separated list contains cipher from tls.InsecureCipherSuites().
102102
// NOTE that cipher suites are not configurable for TLS1.3,
103103
// see: https://pkg.go.dev/crypto/tls#Config, so in that case, this option won't have any effect.
104-
CipherSuites string
104+
CipherSuites []string
105105
}
106106

107107
func (o *ProxyRunOptions) Flags() *pflag.FlagSet {
@@ -136,7 +136,7 @@ func (o *ProxyRunOptions) Flags() *pflag.FlagSet {
136136
flags.IntVar(&o.KubeconfigBurst, "kubeconfig-burst", o.KubeconfigBurst, "Maximum client burst (proxy server uses this client to authenticate agent tokens).")
137137
flags.StringVar(&o.AuthenticationAudience, "authentication-audience", o.AuthenticationAudience, "Expected agent's token authentication audience (used with agent-namespace, agent-service-account, kubeconfig).")
138138
flags.StringVar(&o.ProxyStrategies, "proxy-strategies", o.ProxyStrategies, "The list of proxy strategies used by the server to pick a backend/tunnel, available strategies are: default, destHost.")
139-
flags.StringVar(&o.CipherSuites, "cipher-suites", o.CipherSuites, "The comma separated list of allowed cipher suites. Has no effect on TLS1.3. Empty means allow default list.")
139+
flags.StringSliceVar(&o.CipherSuites, "cipher-suites", o.CipherSuites, "The comma separated list of allowed cipher suites. Has no effect on TLS1.3. Empty means allow default list.")
140140

141141
flags.Bool("warn-on-channel-limit", true, "This behavior is now thread safe and always on. This flag will be removed in a future release.")
142142
flags.MarkDeprecated("warn-on-channel-limit", "This behavior is now thread safe and always on. This flag will be removed in a future release.")
@@ -306,10 +306,9 @@ func (o *ProxyRunOptions) Validate() error {
306306
}
307307

308308
// validate the cipher suites
309-
if o.CipherSuites != "" {
309+
if len(o.CipherSuites) != 0 {
310310
acceptedCiphers := util.GetAcceptedCiphers()
311-
css := strings.Split(o.CipherSuites, ",")
312-
for _, cipher := range css {
311+
for _, cipher := range o.CipherSuites {
313312
_, ok := acceptedCiphers[cipher]
314313
if !ok {
315314
return fmt.Errorf("cipher suite %s not supported, doesn't exist or considered as insecure", cipher)
@@ -352,7 +351,7 @@ func NewProxyRunOptions() *ProxyRunOptions {
352351
KubeconfigBurst: 0,
353352
AuthenticationAudience: "",
354353
ProxyStrategies: "default",
355-
CipherSuites: "",
354+
CipherSuites: make([]string, 0),
356355
}
357356
return &o
358357
}

cmd/server/app/options/options_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ package options
1818

1919
import (
2020
"fmt"
21-
"github.com/stretchr/testify/assert"
2221
"reflect"
2322
"testing"
2423
"time"
24+
25+
"github.com/stretchr/testify/assert"
2526
)
2627

2728
/*
@@ -59,7 +60,7 @@ func TestDefaultServerOptions(t *testing.T) {
5960
assertDefaultValue(t, "KubeconfigBurst", defaultServerOptions.KubeconfigBurst, 0)
6061
assertDefaultValue(t, "AuthenticationAudience", defaultServerOptions.AuthenticationAudience, "")
6162
assertDefaultValue(t, "ProxyStrategies", defaultServerOptions.ProxyStrategies, "default")
62-
assertDefaultValue(t, "CipherSuites", defaultServerOptions.CipherSuites, "")
63+
assertDefaultValue(t, "CipherSuites", defaultServerOptions.CipherSuites, make([]string, 0))
6364
}
6465

6566
func assertDefaultValue(t *testing.T, fieldName string, actual, expected interface{}) {
@@ -139,10 +140,17 @@ func TestValidate(t *testing.T) {
139140
value: 49152,
140141
expected: fmt.Errorf("please do not try to use ephemeral port 49152 for the health port"),
141142
},
143+
"CommaSparatedCipherSuites": {
144+
field: "CipherSuites",
145+
value: "TLS_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
146+
expected: nil,
147+
},
142148
} {
143149
t.Run(desc, func(t *testing.T) {
144150
testServerOptions := NewProxyRunOptions()
145-
if tc.field != "" {
151+
if tc.field == "CipherSuites" {
152+
testServerOptions.Flags().Set("cipher-suites", tc.value.(string))
153+
} else if tc.field != "" {
146154
rv := reflect.ValueOf(testServerOptions)
147155
rv = rv.Elem()
148156
fv := rv.FieldByName(tc.field)

cmd/server/app/server.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
"runtime"
3131
runpprof "runtime/pprof"
3232
"strconv"
33-
"strings"
3433
"sync"
3534
"syscall"
3635
"time"
@@ -260,13 +259,13 @@ func (p *Proxy) runUDSFrontendServer(ctx context.Context, o *options.ProxyRunOpt
260259
return stop, nil
261260
}
262261

263-
func (p *Proxy) getTLSConfig(caFile, certFile, keyFile, cipherSuites string) (*tls.Config, error) {
262+
func (p *Proxy) getTLSConfig(caFile, certFile, keyFile string, cipherSuites []string) (*tls.Config, error) {
264263
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
265264
if err != nil {
266265
return nil, fmt.Errorf("failed to load X509 key pair %s and %s: %v", certFile, keyFile, err)
267266
}
268267

269-
cipherSuiteIDs := tlsCipherSuites(strings.Split(cipherSuites, ","))
268+
cipherSuiteIDs := tlsCipherSuites(cipherSuites)
270269

271270
if caFile == "" {
272271
return &tls.Config{Certificates: []tls.Certificate{cert}, MinVersion: tls.VersionTLS12, CipherSuites: cipherSuiteIDs}, nil

0 commit comments

Comments
 (0)