Add "insecure" flag to graph LDAP backend
To allow skipping TLS Certificate verification in development environments.
This commit is contained in:
@@ -37,6 +37,7 @@ type Spaces struct {
|
|||||||
|
|
||||||
type LDAP struct {
|
type LDAP struct {
|
||||||
URI string `ocisConfig:"uri" env:"GRAPH_LDAP_URI"`
|
URI string `ocisConfig:"uri" env:"GRAPH_LDAP_URI"`
|
||||||
|
Insecure bool `ocisConfig:"insecure" env:"OCIS_INSECURE;GRAPH_LDAP_INSECURE"`
|
||||||
BindDN string `ocisConfig:"bind_dn" env:"GRAPH_LDAP_BIND_DN"`
|
BindDN string `ocisConfig:"bind_dn" env:"GRAPH_LDAP_BIND_DN"`
|
||||||
BindPassword string `ocisConfig:"bind_password" env:"GRAPH_LDAP_BIND_PASSWORD"`
|
BindPassword string `ocisConfig:"bind_password" env:"GRAPH_LDAP_BIND_PASSWORD"`
|
||||||
UseServerUUID bool `ocisConfig:"use_server_uuid" env:"GRAPH_LDAP_SERVER_UUID"`
|
UseServerUUID bool `ocisConfig:"use_server_uuid" env:"GRAPH_LDAP_SERVER_UUID"`
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ func DefaultConfig() *Config {
|
|||||||
Backend: "cs3",
|
Backend: "cs3",
|
||||||
LDAP: LDAP{
|
LDAP: LDAP{
|
||||||
URI: "ldap://localhost:9125",
|
URI: "ldap://localhost:9125",
|
||||||
|
Insecure: false,
|
||||||
BindDN: "",
|
BindDN: "",
|
||||||
BindPassword: "",
|
BindPassword: "",
|
||||||
UseServerUUID: false,
|
UseServerUUID: false,
|
||||||
|
|||||||
@@ -31,14 +31,21 @@ type ConnWithReconnect struct {
|
|||||||
logger *log.Logger
|
logger *log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLDAPWithReconnect(logger *log.Logger, ldapURI, bindDN, bindPassword string) ConnWithReconnect {
|
type Config struct {
|
||||||
|
URI string
|
||||||
|
BindDN string
|
||||||
|
BindPassword string
|
||||||
|
TLSConfig *tls.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewLDAPWithReconnect(logger *log.Logger, config Config) ConnWithReconnect {
|
||||||
conn := ConnWithReconnect{
|
conn := ConnWithReconnect{
|
||||||
conn: make(chan ldapConnection),
|
conn: make(chan ldapConnection),
|
||||||
reset: make(chan *ldap.Conn),
|
reset: make(chan *ldap.Conn),
|
||||||
retries: 1,
|
retries: 1,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}
|
}
|
||||||
go conn.ldapAutoConnect(ldapURI, bindDN, bindPassword)
|
go conn.ldapAutoConnect(config)
|
||||||
return conn
|
return conn
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,8 +179,8 @@ func (c ConnWithReconnect) GetConnection() (*ldap.Conn, error) {
|
|||||||
return c.reconnect(conn.Conn)
|
return c.reconnect(conn.Conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c ConnWithReconnect) ldapAutoConnect(ldapURI, bindDN, bindPassword string) {
|
func (c ConnWithReconnect) ldapAutoConnect(config Config) {
|
||||||
l, err := c.ldapConnect(ldapURI, bindDN, bindPassword)
|
l, err := c.ldapConnect(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.logger.Error().Err(err).Msg("autoconnect could not get ldap Connection")
|
c.logger.Error().Err(err).Msg("autoconnect could not get ldap Connection")
|
||||||
}
|
}
|
||||||
@@ -190,7 +197,7 @@ func (c ConnWithReconnect) ldapAutoConnect(ldapURI, bindDN, bindPassword string)
|
|||||||
}
|
}
|
||||||
if l == resConn || l == nil {
|
if l == resConn || l == nil {
|
||||||
c.logger.Debug().Msg("reconnecting to LDAP")
|
c.logger.Debug().Msg("reconnecting to LDAP")
|
||||||
l, err = c.ldapConnect(ldapURI, bindDN, bindPassword)
|
l, err = c.ldapConnect(config)
|
||||||
} else {
|
} else {
|
||||||
c.logger.Debug().Msg("already reconnected")
|
c.logger.Debug().Msg("already reconnected")
|
||||||
}
|
}
|
||||||
@@ -199,16 +206,24 @@ func (c ConnWithReconnect) ldapAutoConnect(ldapURI, bindDN, bindPassword string)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c ConnWithReconnect) ldapConnect(ldapURI, bindDN, bindPassword string) (*ldap.Conn, error) {
|
func (c ConnWithReconnect) ldapConnect(config Config) (*ldap.Conn, error) {
|
||||||
c.logger.Debug().Msgf("Connecting to %s", ldapURI)
|
c.logger.Debug().Msgf("Connecting to %s", config.URI)
|
||||||
l, err := ldap.DialURL(ldapURI)
|
|
||||||
|
var err error
|
||||||
|
var l *ldap.Conn
|
||||||
|
if config.TLSConfig != nil {
|
||||||
|
l, err = ldap.DialURL(config.URI, ldap.DialWithTLSConfig(config.TLSConfig))
|
||||||
|
} else {
|
||||||
|
l, err = ldap.DialURL(config.URI)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.logger.Error().Err(err).Msg("could not get ldap Connection")
|
c.logger.Error().Err(err).Msg("could not get ldap Connection")
|
||||||
} else {
|
} else {
|
||||||
c.logger.Debug().Msg("LDAP Connected")
|
c.logger.Debug().Msg("LDAP Connected")
|
||||||
if bindDN != "" {
|
if config.BindDN != "" {
|
||||||
c.logger.Debug().Msgf("Binding as %s", bindDN)
|
c.logger.Debug().Msgf("Binding as %s", config.BindDN)
|
||||||
err = l.Bind(bindDN, bindPassword)
|
err = l.Bind(config.BindDN, config.BindPassword)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.logger.Error().Err(err).Msg("Bind failed")
|
c.logger.Error().Err(err).Msg("Bind failed")
|
||||||
l.Close()
|
l.Close()
|
||||||
|
|||||||
@@ -59,10 +59,21 @@ func NewService(opts ...Option) Service {
|
|||||||
}
|
}
|
||||||
case "ldap":
|
case "ldap":
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
var tlsConf *tls.Config
|
||||||
|
if options.Config.Identity.LDAP.Insecure {
|
||||||
|
tlsConf = &tls.Config{
|
||||||
|
InsecureSkipVerify: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
conn := ldap.NewLDAPWithReconnect(&options.Logger,
|
conn := ldap.NewLDAPWithReconnect(&options.Logger,
|
||||||
options.Config.Identity.LDAP.URI,
|
ldap.Config{
|
||||||
options.Config.Identity.LDAP.BindDN,
|
URI: options.Config.Identity.LDAP.URI,
|
||||||
options.Config.Identity.LDAP.BindPassword,
|
BindDN: options.Config.Identity.LDAP.BindDN,
|
||||||
|
BindPassword: options.Config.Identity.LDAP.BindPassword,
|
||||||
|
TLSConfig: tlsConf,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
if backend, err = identity.NewLDAPBackend(conn, options.Config.Identity.LDAP, &options.Logger); err != nil {
|
if backend, err = identity.NewLDAPBackend(conn, options.Config.Identity.LDAP, &options.Logger); err != nil {
|
||||||
options.Logger.Error().Msgf("Error initializing LDAP Backend: '%s'", err)
|
options.Logger.Error().Msgf("Error initializing LDAP Backend: '%s'", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user