outposts/ldap: use forked version of ldap library
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
		| @ -1,17 +1,18 @@ | ||||
| package ldap | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"net" | ||||
|  | ||||
| 	"github.com/nmcclain/ldap" | ||||
| 	"github.com/goauthentik/ldap" | ||||
| ) | ||||
|  | ||||
| func (ls *LDAPServer) Bind(bindDN string, bindPW string, conn net.Conn) (ldap.LDAPResultCode, error) { | ||||
| func (ls *LDAPServer) Bind(bindDN string, bindPW string, conn net.Conn, ctx context.Context) (ldap.LDAPResultCode, error) { | ||||
| 	ls.log.WithField("boundDN", bindDN).Info("bind") | ||||
| 	for _, instance := range ls.providers { | ||||
| 		username, err := instance.getUsername(bindDN) | ||||
| 		if err == nil { | ||||
| 			return instance.Bind(username, bindPW, conn) | ||||
| 			return instance.Bind(username, bindPW, conn, ctx) | ||||
| 		} | ||||
| 	} | ||||
| 	ls.log.WithField("boundDN", bindDN).WithField("request", "bind").Warning("No provider found for request") | ||||
|  | ||||
| @ -11,11 +11,13 @@ import ( | ||||
|  | ||||
| 	goldap "github.com/go-ldap/ldap/v3" | ||||
| 	httptransport "github.com/go-openapi/runtime/client" | ||||
| 	"github.com/nmcclain/ldap" | ||||
| 	"github.com/goauthentik/ldap" | ||||
| 	"goauthentik.io/outpost/pkg/client/core" | ||||
| 	"goauthentik.io/outpost/pkg/client/flows" | ||||
| ) | ||||
|  | ||||
| const ContextUserKey = "ak_user" | ||||
|  | ||||
| type UIDResponse struct { | ||||
| 	UIDFIeld string `json:"uid_field"` | ||||
| } | ||||
| @ -42,7 +44,7 @@ func (pi *ProviderInstance) getUsername(dn string) (string, error) { | ||||
| 	return "", errors.New("failed to find dn") | ||||
| } | ||||
|  | ||||
| func (pi *ProviderInstance) Bind(username string, bindPW string, conn net.Conn) (ldap.LDAPResultCode, error) { | ||||
| func (pi *ProviderInstance) Bind(username string, bindPW string, conn net.Conn, ctx context.Context) (ldap.LDAPResultCode, error) { | ||||
| 	jar, err := cookiejar.New(nil) | ||||
| 	if err != nil { | ||||
| 		pi.log.WithError(err).Warning("Failed to create cookiejar") | ||||
| @ -73,6 +75,16 @@ func (pi *ProviderInstance) Bind(username string, bindPW string, conn net.Conn) | ||||
| 		return ldap.LDAPResultOperationsError, nil | ||||
| 	} | ||||
| 	pi.log.WithField("boundDN", username).Info("User has access") | ||||
| 	// Get user info to store in context | ||||
| 	userInfo, err := pi.s.ac.Client.Core.CoreUsersMe(&core.CoreUsersMeParams{ | ||||
| 		Context:    ctx, | ||||
| 		HTTPClient: client, | ||||
| 	}, httptransport.PassThroughAuth) | ||||
| 	if err != nil { | ||||
| 		pi.log.WithField("boundDN", username).WithError(err).Warning("failed to get user info") | ||||
| 		return ldap.LDAPResultOperationsError, nil | ||||
| 	} | ||||
| 	ctx = context.WithValue(ctx, ContextUserKey, userInfo.Payload.User) | ||||
| 	return ldap.LDAPResultSuccess, nil | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -6,7 +6,7 @@ import ( | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
|  | ||||
| 	"github.com/nmcclain/ldap" | ||||
| 	"github.com/goauthentik/ldap" | ||||
| 	"goauthentik.io/outpost/pkg/client/core" | ||||
| ) | ||||
|  | ||||
|  | ||||
| @ -4,7 +4,7 @@ import ( | ||||
| 	log "github.com/sirupsen/logrus" | ||||
| 	"goauthentik.io/outpost/pkg/ak" | ||||
|  | ||||
| 	"github.com/nmcclain/ldap" | ||||
| 	"github.com/goauthentik/ldap" | ||||
| ) | ||||
|  | ||||
| const GroupObjectClass = "group" | ||||
|  | ||||
| @ -5,7 +5,7 @@ import ( | ||||
| 	"net" | ||||
|  | ||||
| 	goldap "github.com/go-ldap/ldap/v3" | ||||
| 	"github.com/nmcclain/ldap" | ||||
| 	"github.com/goauthentik/ldap" | ||||
| ) | ||||
|  | ||||
| func (ls *LDAPServer) Search(boundDN string, searchReq ldap.SearchRequest, conn net.Conn) (ldap.ServerSearchResult, error) { | ||||
|  | ||||
| @ -3,7 +3,7 @@ package ldap | ||||
| import ( | ||||
| 	"fmt" | ||||
|  | ||||
| 	"github.com/nmcclain/ldap" | ||||
| 	"github.com/goauthentik/ldap" | ||||
| 	"goauthentik.io/outpost/pkg/models" | ||||
| ) | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Jens Langhammer
					Jens Langhammer