Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skipper: add TLS client authentication config #3281

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ type Config struct {
Certificates []tls.Certificate `yaml:"-"`

// TLS version
TLSMinVersion string `yaml:"tls-min-version"`
TLSMinVersion string `yaml:"tls-min-version"`
TLSClientAuth tls.ClientAuthType `yaml:"tls-client-auth"`

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

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

// Exclude insecure cipher suites
flag.BoolVar(&cfg.ExcludeInsecureCipherSuites, "exclude-insecure-cipher-suites", false, "excludes insecure cipher suites")
Expand Down Expand Up @@ -727,6 +731,7 @@ func (c *Config) ToOptions() skipper.Options {
DebugListener: c.DebugListener,
CertPathTLS: c.CertPathTLS,
KeyPathTLS: c.KeyPathTLS,
TLSClientAuth: c.TLSClientAuth,
CipherSuites: c.filterCipherSuites(),
MaxLoopbacks: c.MaxLoopbacks,
DefaultHTTPStatus: c.DefaultHTTPStatus,
Expand Down Expand Up @@ -1047,6 +1052,21 @@ func (c *Config) getMinTLSVersion() uint16 {
return tlsVersionTable[defaultMinTLSVersion]
}

func (c *Config) setTLSClientAuth(s string) error {
var ok bool
c.TLSClientAuth, ok = map[string]tls.ClientAuthType{
"NoClientCert": tls.NoClientCert,
"RequestClientCert": tls.RequestClientCert,
"RequireAnyClientCert": tls.RequireAnyClientCert,
"VerifyClientCertIfGiven": tls.VerifyClientCertIfGiven,
"RequireAndVerifyClientCert": tls.RequireAndVerifyClientCert,
}[s]
if !ok {
return fmt.Errorf("unsupported TLS client authentication type")
}
return nil
}

func (c *Config) filterCipherSuites() []uint16 {
if !c.ExcludeInsecureCipherSuites {
return nil
Expand Down
5 changes: 5 additions & 0 deletions skipper.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,10 @@ type Options struct {
// multiple keys, the order must match the one given in CertPathTLS
KeyPathTLS string

// TLSClientAuth sets the policy the server will follow for
// TLS Client Authentication, see [tls.ClientAuthType]
TLSClientAuth tls.ClientAuthType

// TLS Settings for Proxy Server
ProxyTLS *tls.Config

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

config := &tls.Config{
MinVersion: o.TLSMinVersion,
ClientAuth: o.TLSClientAuth,
}

if o.CipherSuites != nil {
Expand Down
Loading