@@ -19,6 +19,7 @@ package authn
1919import (
2020 "bytes"
2121 "crypto/tls"
22+ "crypto/x509"
2223 "fmt"
2324 "io/ioutil"
2425 "strings"
@@ -31,6 +32,7 @@ type LDAPAuthConfig struct {
3132 Addr string `yaml:"addr,omitempty"`
3233 TLS string `yaml:"tls,omitempty"`
3334 InsecureTLSSkipVerify bool `yaml:"insecure_tls_skip_verify,omitempty"`
35+ CACertificate string `yaml:"ca_certificate,omitempty"`
3436 Base string `yaml:"base,omitempty"`
3537 Filter string `yaml:"filter,omitempty"`
3638 BindDN string `yaml:"bind_dn,omitempty"`
@@ -140,7 +142,20 @@ func (la *LDAPAuth) ldapConnection() (*ldap.Conn, error) {
140142 tlsConfig := & tls.Config {InsecureSkipVerify : true }
141143 if ! la .config .InsecureTLSSkipVerify {
142144 addr := strings .Split (la .config .Addr , ":" )
143- tlsConfig = & tls.Config {InsecureSkipVerify : false , ServerName : addr [0 ]}
145+ if la .config .CACertificate != "" {
146+ pool := x509 .NewCertPool ()
147+ pem , err := ioutil .ReadFile (la .config .CACertificate )
148+ if err != nil {
149+ return nil , fmt .Errorf ("Error loading CA File: %s" , err )
150+ }
151+ ok := pool .AppendCertsFromPEM (pem )
152+ if ! ok {
153+ return nil , fmt .Errorf ("Error loading CA File: Couldn't parse PEM in: %s" , la .config .CACertificate )
154+ }
155+ tlsConfig = & tls.Config {InsecureSkipVerify : false , ServerName : addr [0 ], RootCAs : pool }
156+ } else {
157+ tlsConfig = & tls.Config {InsecureSkipVerify : false , ServerName : addr [0 ]}
158+ }
144159 }
145160
146161 if la .config .TLS == "" || la .config .TLS == "none" || la .config .TLS == "starttls" {
0 commit comments