Enable a flag to change username attribute in LDAP
This commit is contained in:
No files matched your search
@@ -76,13 +76,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_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_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_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_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_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_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_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_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_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+)
|
## multi valued tags (v0.16+)
|
||||||
|
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ func main() {
|
|||||||
flag.StringVar(&ldapConfig.BindUser, "ldap-bind-user", "", "the bind user to bind to LDAP with (required for LDAP)")
|
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.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.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.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)")
|
flag.StringVar(&ldapConfig.AdminFilter, "ldap-admin-filter", "(memberof=cn=admin)", "the filter to select LDAP objects with (optional)")
|
||||||
|
|||||||
+8
-7
@@ -50,9 +50,10 @@ func (password CachedLDAPpassword) IsValid() bool {
|
|||||||
|
|
||||||
// Cofig stores the user's LDAP server options.
|
// Cofig stores the user's LDAP server options.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
BindUser string
|
BindUser string
|
||||||
BindPass string
|
BindPass string
|
||||||
BaseDN string
|
BaseDN string
|
||||||
|
UsernameAttr string
|
||||||
|
|
||||||
Filter string
|
Filter string
|
||||||
AdminFilter 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
|
// After we have a connection, let's try binding
|
||||||
_, err = l.SimpleBind(&ldap.SimpleBindRequest{
|
_, 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,
|
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.
|
// doesLDAPAdminExist checks if an admin exists on the server.
|
||||||
func doesLDAPAdminExist(username string, config Config, l *ldap.Conn) bool {
|
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(
|
searchReq := ldap.NewSearchRequest(
|
||||||
config.BaseDN,
|
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.
|
// doesLDAPUserExist checks if a user exists on the server.
|
||||||
func doesLDAPUserExist(username string, config Config, l *ldap.Conn) bool {
|
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(
|
searchReq := ldap.NewSearchRequest(
|
||||||
config.BaseDN,
|
config.BaseDN,
|
||||||
@@ -212,7 +213,7 @@ func createLDAPconnection(config Config) (*ldap.Conn, error) {
|
|||||||
|
|
||||||
// After we have a connection, let's try binding
|
// After we have a connection, let's try binding
|
||||||
_, err = l.SimpleBind(&ldap.SimpleBindRequest{
|
_, 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,
|
Password: config.BindPass,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user