Skip to content

Commit 4dfed54

Browse files
authored
Merge pull request #77 from radekg/multiple-client-certs-fixes
Additional changes to the multiple client cert validation
2 parents d09f219 + a147ea7 commit 4dfed54

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

cmd/kafka-proxy/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func initFlags() {
107107
Server.Flags().StringSliceVar(&c.Proxy.TLS.ListenerCipherSuites, "proxy-listener-cipher-suites", []string{}, "List of supported cipher suites")
108108
Server.Flags().StringSliceVar(&c.Proxy.TLS.ListenerCurvePreferences, "proxy-listener-curve-preferences", []string{}, "List of curve preferences")
109109

110-
Server.Flags().StringSliceVar(&c.Proxy.TLS.ClientCert.Subjects, "proxy-listener-tls-required-client-subject", []string{""}, "Required client certificate subject common name; example; s:/CN=[value]/C=[state]/C=[DE,PL] or r:/CN=[^val.{2}$]/C=[state]/C=[DE,PL]; check manual for more details")
110+
Server.Flags().StringSliceVar(&c.Proxy.TLS.ClientCert.Subjects, "proxy-listener-tls-required-client-subject", []string{}, "Required client certificate subject common name; example; s:/CN=[value]/C=[state]/C=[DE,PL] or r:/CN=[^val.{2}$]/C=[state]/C=[DE,PL]; check manual for more details")
111111

112112
// local authentication plugin
113113
Server.Flags().BoolVar(&c.Auth.Local.Enable, "auth-local-enable", false, "Enable local SASL/PLAIN authentication performed by listener - SASL handshake will not be passed to kafka brokers")

proxy/clientcertvalidate/parser.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"regexp"
88
"sort"
9+
"strings"
910
"unicode"
1011
)
1112

@@ -23,7 +24,8 @@ type SubjectParser interface {
2324

2425
// NewSubjectParser creates a new default subject parser.
2526
func NewSubjectParser(input string) SubjectParser {
26-
runeInput := []rune(input)
27+
// remove single quotes from around the string:
28+
runeInput := []rune(strings.TrimPrefix(strings.TrimSuffix(input, "'"), "'"))
2729
return &defaultSubjectParser{
2830
input: runeInput,
2931
pos: 0,
@@ -119,20 +121,19 @@ func (p *defaultSubjectParser) Parse() (ParsedSubject, error) {
119121
fieldPos := p.pos
120122
field, err := p.readAlphaStringUntil('=')
121123
if err != nil {
122-
switch err {
123-
case io.EOF:
124+
if err == io.EOF {
124125
// there was no key:
125126
return output, &ParserUnexpectedInputError{
126127
Expected: []rune("field"),
127128
Found: []rune("none"),
128129
Position: fieldPos,
129130
}
130-
case os.ErrInvalid:
131+
}
132+
if err == os.ErrInvalid {
131133
// there was no key:
132134
return output, &ParserInvalidSubjectFieldError{ConsumedString: field}
133-
default:
134-
return output, &ParserUnexpectedError{Unexpected: err}
135135
}
136+
return output, &ParserUnexpectedError{Unexpected: err}
136137
}
137138

138139
if _, ok := validSubjectFields[field]; !ok {
@@ -144,16 +145,14 @@ func (p *defaultSubjectParser) Parse() (ParsedSubject, error) {
144145
// key has been consumed, value must be enclosed in [...]
145146
nextRune, lookupErr = p.lookupOne()
146147
if lookupErr != nil {
147-
switch lookupErr {
148-
case io.EOF:
148+
if lookupErr == io.EOF {
149149
return output, &ParserUnexpectedInputError{
150150
Expected: []rune{'['},
151151
Found: []rune("none"),
152152
Position: p.pos,
153153
}
154-
default:
155-
return output, &ParserUnexpectedError{Unexpected: err}
156154
}
155+
return output, &ParserUnexpectedError{Unexpected: err}
157156
}
158157
if nextRune != '[' {
159158
return output, &ParserUnexpectedInputError{
@@ -167,14 +166,13 @@ func (p *defaultSubjectParser) Parse() (ParsedSubject, error) {
167166
valuePos := p.pos
168167
values, err := p.readValues()
169168
if err != nil {
170-
switch err {
171-
case io.EOF:
169+
if err == io.EOF {
172170
return output, &ParserValueInsufficientInputError{ValuePos: valuePos}
173-
case errUnexpectedPattern:
171+
}
172+
if err == errUnexpectedPattern {
174173
return output, fmt.Errorf("value starting at %d contains patterns but subject is type string", valuePos)
175-
default:
176-
return output, &ParserUnexpectedError{Unexpected: err}
177174
}
175+
return output, &ParserUnexpectedError{Unexpected: err}
178176
}
179177

180178
regexpKVs := []*regexp.Regexp{}

0 commit comments

Comments
 (0)