diff --git a/README.md b/README.md index 32bf024..80463d3 100644 --- a/README.md +++ b/README.md @@ -77,13 +77,14 @@ password can then be changed from the web interface | `GONIC_TRANSCODE_EJECT_INTERVAL` | `-transcode-eject-interval` | **optional** interval (in minutes) to eject transcode cache (0 = never) | | `GONIC_EXPVAR` | `-expvar` | **optional** enable the /debug/vars endpoint (exposes useful debugging attributes as well as database stats) | | `GONIC_LDAP_FQDN` | `-ldap-fqdn` | **optional** the name of the server to connect to (required for LDAP) | -| `GONIC_LDAP_PORT` | `-ldap-port` | **optional** what port the LDAP server is hosted on (*default* `389`) | -| `GONIC_LDAP_TLS` | `-ldap-tls` | **optional** whether gonic will connect to the LDAP server using TLS (*default* `false`) | +| `GONIC_LDAP_PORT` | `-ldap-port` | **optional** what port the LDAP server is hosted on (_default_ `389`) | +| `GONIC_LDAP_TLS` | `-ldap-tls` | **optional** whether gonic will connect to the LDAP server using TLS (_default_ `false`) | | `GONIC_LDAP_BASE_DN` | `-ldap-base-dn` | **optional** the base DN for LDAP objects (required for LDAP, escaping the commas might be necessary if using environmental variable) | +| `GONIC_LDAP_USERNAME_ATTR` | `-ldap-username-attr` | **optional** attribute used by the LDAP server for usernames, gets prepended to BaseDN (_default_ `uid`) | | `GONIC_LDAP_BIND_USER` | `-ldap-bind-user` | **optional** the bind user to bind to LDAP with (required for LDAP) | | `GONIC_LDAP_BIND_PASS` | `-ldap-bind-pass` | **optional** the password of the LDAP bind user (required for LDAP) | | `GONIC_LDAP_FILTER` | `-ldap-filter` | **optional** the filter to select LDAP objects with (escaping the commas might be necessary if using environmental variable) | -| `GONIC_LDAP_ADMIN_FILTER` | `-ldap-admin-filter` | **optional** the filter to select LDAP admin objects with (escaping the commas might be necessary if using environmental variable) (*default* `(memberof=cn=admin)`) | +| `GONIC_LDAP_ADMIN_FILTER` | `-ldap-admin-filter` | **optional** the filter to select LDAP admin objects with (escaping the commas might be necessary if using environmental variable) (_default_ `(memberof=cn=admin)`) | ## multi valued tags (v0.16+) diff --git a/cmd/gonic/gonic.go b/cmd/gonic/gonic.go index 202197e..ffd195d 100644 --- a/cmd/gonic/gonic.go +++ b/cmd/gonic/gonic.go @@ -90,6 +90,7 @@ func main() { flag.StringVar(&ldapConfig.BindUser, "ldap-bind-user", "", "the bind user to bind to LDAP with (required for LDAP)") flag.StringVar(&ldapConfig.BindPass, "ldap-bind-pass", "", "the password of the LDAP bind user (required for LDAP)") flag.StringVar(&ldapConfig.BaseDN, "ldap-base-dn", "", "the base DN for LDAP objects (required for LDAP)") + flag.StringVar(&ldapConfig.UsernameAttr, "ldap-username-attr", "uid", "attribute used by the LDAP server for usernames, gets prepended to BaseDN (optional)") flag.StringVar(&ldapConfig.Filter, "ldap-filter", "", "the filter to select LDAP objects with (optional)") flag.StringVar(&ldapConfig.AdminFilter, "ldap-admin-filter", "(memberof=cn=admin)", "the filter to select LDAP objects with (optional)") diff --git a/ldap/ldap.go b/ldap/ldap.go index acb4f43..5de1c8b 100644 --- a/ldap/ldap.go +++ b/ldap/ldap.go @@ -50,9 +50,10 @@ func (password CachedLDAPpassword) IsValid() bool { // Cofig stores the user's LDAP server options. type Config struct { - BindUser string - BindPass string - BaseDN string + BindUser string + BindPass string + BaseDN string + UsernameAttr string Filter string AdminFilter string @@ -98,7 +99,7 @@ func CheckLDAPcreds(username string, password string, dbc *db.DB, config Config, // After we have a connection, let's try binding _, err = l.SimpleBind(&ldap.SimpleBindRequest{ - Username: fmt.Sprintf("uid=%s,%s", username, config.BaseDN), + Username: fmt.Sprintf("%s=%s,%s", config.UsernameAttr, username, config.BaseDN), Password: password, }) @@ -147,7 +148,7 @@ func createUserFromLDAP(username string, dbc *db.DB, config Config, l *ldap.Conn // doesLDAPAdminExist checks if an admin exists on the server. func doesLDAPAdminExist(username string, config Config, l *ldap.Conn) bool { - filter := fmt.Sprintf("(&(uid=%s)%s)", ldap.EscapeFilter(username), config.AdminFilter) + filter := fmt.Sprintf("(&(%s=%s)%s)", config.UsernameAttr, ldap.EscapeFilter(username), config.AdminFilter) searchReq := ldap.NewSearchRequest( config.BaseDN, @@ -172,7 +173,7 @@ func doesLDAPAdminExist(username string, config Config, l *ldap.Conn) bool { // doesLDAPUserExist checks if a user exists on the server. func doesLDAPUserExist(username string, config Config, l *ldap.Conn) bool { - filter := fmt.Sprintf("(&(uid=%s)%s)", ldap.EscapeFilter(username), config.Filter) + filter := fmt.Sprintf("(&(%s=%s)%s)", config.UsernameAttr, ldap.EscapeFilter(username), config.Filter) searchReq := ldap.NewSearchRequest( config.BaseDN, @@ -212,7 +213,7 @@ func createLDAPconnection(config Config) (*ldap.Conn, error) { // After we have a connection, let's try binding _, err = l.SimpleBind(&ldap.SimpleBindRequest{ - Username: fmt.Sprintf("uid=%s,%s", config.BindUser, config.BaseDN), + Username: fmt.Sprintf("%s=%s,%s", config.UsernameAttr, config.BindUser, config.BaseDN), Password: config.BindPass, }) if err != nil {