Skip to content

Commit 262c326

Browse files
authoredOct 21, 2024··
skipper: add TLS client authentication config (#3281)
Add an option and a flag to configure TLS Client Authentication policy of the Server. Fixes #3280 Signed-off-by: Alexander Yastrebov <yastrebov.alex@gmail.com>
1 parent 03c4af4 commit 262c326

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed
 

‎config/config.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ type Config struct {
217217
Certificates []tls.Certificate `yaml:"-"`
218218

219219
// TLS version
220-
TLSMinVersion string `yaml:"tls-min-version"`
220+
TLSMinVersion string `yaml:"tls-min-version"`
221+
TLSClientAuth tls.ClientAuthType `yaml:"tls-client-auth"`
221222

222223
// Exclude insecure cipher suites
223224
ExcludeInsecureCipherSuites bool `yaml:"exclude-insecure-cipher-suites"`
@@ -523,6 +524,9 @@ func NewConfig() *Config {
523524

524525
// TLS version
525526
flag.StringVar(&cfg.TLSMinVersion, "tls-min-version", defaultMinTLSVersion, "minimal TLS Version to be used in server, proxy and client connections")
527+
flag.Func("tls-client-auth", "TLS client authentication policy for server, one of: "+
528+
"NoClientCert, RequestClientCert, RequireAnyClientCert, VerifyClientCertIfGiven or RequireAndVerifyClientCert. "+
529+
"See https://pkg.go.dev/crypto/tls#ClientAuthType for details.", cfg.setTLSClientAuth)
526530

527531
// Exclude insecure cipher suites
528532
flag.BoolVar(&cfg.ExcludeInsecureCipherSuites, "exclude-insecure-cipher-suites", false, "excludes insecure cipher suites")
@@ -727,6 +731,7 @@ func (c *Config) ToOptions() skipper.Options {
727731
DebugListener: c.DebugListener,
728732
CertPathTLS: c.CertPathTLS,
729733
KeyPathTLS: c.KeyPathTLS,
734+
TLSClientAuth: c.TLSClientAuth,
730735
CipherSuites: c.filterCipherSuites(),
731736
MaxLoopbacks: c.MaxLoopbacks,
732737
DefaultHTTPStatus: c.DefaultHTTPStatus,
@@ -1047,6 +1052,21 @@ func (c *Config) getMinTLSVersion() uint16 {
10471052
return tlsVersionTable[defaultMinTLSVersion]
10481053
}
10491054

1055+
func (c *Config) setTLSClientAuth(s string) error {
1056+
var ok bool
1057+
c.TLSClientAuth, ok = map[string]tls.ClientAuthType{
1058+
"NoClientCert": tls.NoClientCert,
1059+
"RequestClientCert": tls.RequestClientCert,
1060+
"RequireAnyClientCert": tls.RequireAnyClientCert,
1061+
"VerifyClientCertIfGiven": tls.VerifyClientCertIfGiven,
1062+
"RequireAndVerifyClientCert": tls.RequireAndVerifyClientCert,
1063+
}[s]
1064+
if !ok {
1065+
return fmt.Errorf("unsupported TLS client authentication type")
1066+
}
1067+
return nil
1068+
}
1069+
10501070
func (c *Config) filterCipherSuites() []uint16 {
10511071
if !c.ExcludeInsecureCipherSuites {
10521072
return nil

‎skipper.go

+5
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,10 @@ type Options struct {
617617
// multiple keys, the order must match the one given in CertPathTLS
618618
KeyPathTLS string
619619

620+
// TLSClientAuth sets the policy the server will follow for
621+
// TLS Client Authentication, see [tls.ClientAuthType]
622+
TLSClientAuth tls.ClientAuthType
623+
620624
// TLS Settings for Proxy Server
621625
ProxyTLS *tls.Config
622626

@@ -1198,6 +1202,7 @@ func (o *Options) tlsConfig(cr *certregistry.CertRegistry) (*tls.Config, error)
11981202

11991203
config := &tls.Config{
12001204
MinVersion: o.TLSMinVersion,
1205+
ClientAuth: o.TLSClientAuth,
12011206
}
12021207

12031208
if o.CipherSuites != nil {

0 commit comments

Comments
 (0)
Please sign in to comment.