Skip to content

Commit 1577f3b

Browse files
authored
Reject --mutual-tls and --client-ca when TLS is not enabled (#330)
Previously --mutual-tls and --client-ca were silently ignored when --cert/--key were not provided, which could lead an operator to believe client certificate authentication was enforcing access while the server was actually listening on plain HTTP. Both chunk-server and index-server now refuse to start in that state.
1 parent 3c83e00 commit 1577f3b

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

cmd/desync/options.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ func (o cmdServerOptions) validate() error {
8787
if (o.key == "") != (o.cert == "") {
8888
return errors.New("--key and --cert options need to be provided together")
8989
}
90+
if o.key == "" {
91+
if o.mutualTLS {
92+
return errors.New("--mutual-tls requires --cert and --key (TLS must be enabled)")
93+
}
94+
if o.clientCA != "" {
95+
return errors.New("--client-ca requires --cert and --key (TLS must be enabled)")
96+
}
97+
}
9098
return nil
9199
}
92100

cmd/desync/options_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,33 @@ func TestErrorRetryOptions(t *testing.T) {
9999
}
100100
}
101101

102+
func TestServerOptionsValidate(t *testing.T) {
103+
for _, test := range []struct {
104+
name string
105+
opt cmdServerOptions
106+
wantErr string
107+
}{
108+
{"no TLS, no mTLS", cmdServerOptions{}, ""},
109+
{"TLS only", cmdServerOptions{cert: "c", key: "k"}, ""},
110+
{"TLS with mutualTLS", cmdServerOptions{cert: "c", key: "k", mutualTLS: true}, ""},
111+
{"TLS with clientCA", cmdServerOptions{cert: "c", key: "k", clientCA: "ca"}, ""},
112+
{"key without cert", cmdServerOptions{key: "k"}, "--key and --cert"},
113+
{"cert without key", cmdServerOptions{cert: "c"}, "--key and --cert"},
114+
{"mutualTLS without TLS", cmdServerOptions{mutualTLS: true}, "--mutual-tls requires"},
115+
{"clientCA without TLS", cmdServerOptions{clientCA: "ca"}, "--client-ca requires"},
116+
} {
117+
t.Run(test.name, func(t *testing.T) {
118+
err := test.opt.validate()
119+
if test.wantErr == "" {
120+
require.NoError(t, err)
121+
return
122+
}
123+
require.Error(t, err)
124+
require.Contains(t, err.Error(), test.wantErr)
125+
})
126+
}
127+
}
128+
102129
func TestStringOptions(t *testing.T) {
103130
for _, test := range []struct {
104131
name string

0 commit comments

Comments
 (0)