 54ef88a6fa
			
		
	
	54ef88a6fa
	
	
	
		
			
			* rework Root DSE Signed-off-by: Jens Langhammer <jens@goauthentik.io> * always parse filter objectClass Signed-off-by: Jens Langhammer <jens@goauthentik.io> * start adding LDAP Schema Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add more schema Signed-off-by: Jens Langhammer <jens@goauthentik.io> * update schema more Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix cn for schema Signed-off-by: Jens Langhammer <jens@goauthentik.io> * only include main DN in namingContexts Signed-off-by: Jens Langhammer <jens@goauthentik.io> * use schema from gh Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add description Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add response filtering Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix response filtering Signed-off-by: Jens Langhammer <jens@goauthentik.io> * don't return rootDSE entry when searching for singleLevel Signed-off-by: Jens Langhammer <jens@goauthentik.io> * remove currentTime Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix attribute filtering Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * set SINGLE-VALUE Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix numbers Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io>
		
			
				
	
	
		
			85 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			85 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package ldap
 | |
| 
 | |
| import (
 | |
| 	"net"
 | |
| 
 | |
| 	"beryju.io/ldap"
 | |
| 	"github.com/getsentry/sentry-go"
 | |
| 	"github.com/prometheus/client_golang/prometheus"
 | |
| 	log "github.com/sirupsen/logrus"
 | |
| 	"goauthentik.io/internal/outpost/ldap/constants"
 | |
| 	"goauthentik.io/internal/outpost/ldap/metrics"
 | |
| 	"goauthentik.io/internal/outpost/ldap/search"
 | |
| )
 | |
| 
 | |
| func (ls *LDAPServer) Search(bindDN string, searchReq ldap.SearchRequest, conn net.Conn) (ldap.ServerSearchResult, error) {
 | |
| 	req, span := search.NewRequest(bindDN, searchReq, conn)
 | |
| 	selectedApp := ""
 | |
| 	defer func() {
 | |
| 		span.Finish()
 | |
| 		metrics.Requests.With(prometheus.Labels{
 | |
| 			"outpost_name": ls.ac.Outpost.Name,
 | |
| 			"type":         "search",
 | |
| 			"app":          selectedApp,
 | |
| 		}).Observe(float64(span.EndTime.Sub(span.StartTime)))
 | |
| 		req.Log().WithField("took-ms", span.EndTime.Sub(span.StartTime).Milliseconds()).Info("Search request")
 | |
| 	}()
 | |
| 
 | |
| 	defer func() {
 | |
| 		err := recover()
 | |
| 		if err == nil {
 | |
| 			return
 | |
| 		}
 | |
| 		log.WithError(err.(error)).Error("recover in search request")
 | |
| 		sentry.CaptureException(err.(error))
 | |
| 	}()
 | |
| 
 | |
| 	selectedProvider := ls.providerForRequest(req)
 | |
| 	if selectedProvider == nil {
 | |
| 		return ls.fallbackRootDSE(req)
 | |
| 	}
 | |
| 	selectedApp = selectedProvider.GetAppSlug()
 | |
| 	result, err := ls.searchRoute(req, selectedProvider)
 | |
| 	if err != nil {
 | |
| 		return result, nil
 | |
| 	}
 | |
| 	return ls.filterResultAttributes(req, result), nil
 | |
| }
 | |
| 
 | |
| func (ls *LDAPServer) fallbackRootDSE(req *search.Request) (ldap.ServerSearchResult, error) {
 | |
| 	req.Log().Trace("returning fallback Root DSE")
 | |
| 	return ldap.ServerSearchResult{
 | |
| 		Entries: []*ldap.Entry{
 | |
| 			{
 | |
| 				DN: "",
 | |
| 				Attributes: []*ldap.EntryAttribute{
 | |
| 					{
 | |
| 						Name:   "objectClass",
 | |
| 						Values: []string{constants.OCTop},
 | |
| 					},
 | |
| 					{
 | |
| 						Name:   "entryDN",
 | |
| 						Values: []string{""},
 | |
| 					},
 | |
| 					{
 | |
| 						Name:   "subschemaSubentry",
 | |
| 						Values: []string{"cn=subschema"},
 | |
| 					},
 | |
| 					{
 | |
| 						Name:   "namingContexts",
 | |
| 						Values: []string{},
 | |
| 					},
 | |
| 					{
 | |
| 						Name: "description",
 | |
| 						Values: []string{
 | |
| 							"This LDAP server requires an authenticated session.",
 | |
| 						},
 | |
| 					},
 | |
| 				},
 | |
| 			},
 | |
| 		},
 | |
| 		Referrals: []string{}, Controls: []ldap.Control{}, ResultCode: ldap.LDAPResultSuccess,
 | |
| 	}, nil
 | |
| 
 | |
| }
 |