2021-04-19 22:30:27 +00:00
|
|
|
package ldap
|
|
|
|
|
|
|
|
import (
|
2021-07-13 16:24:18 +00:00
|
|
|
"crypto/tls"
|
2021-05-04 19:49:15 +00:00
|
|
|
"sync"
|
|
|
|
|
2021-05-04 22:03:19 +00:00
|
|
|
"github.com/go-openapi/strfmt"
|
2021-04-19 22:30:27 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
2021-06-29 14:21:00 +00:00
|
|
|
"goauthentik.io/api"
|
2021-07-17 17:36:15 +00:00
|
|
|
"goauthentik.io/internal/crypto"
|
2021-06-16 10:02:02 +00:00
|
|
|
"goauthentik.io/internal/outpost/ak"
|
2021-04-19 22:30:27 +00:00
|
|
|
|
2021-05-04 19:49:15 +00:00
|
|
|
"github.com/nmcclain/ldap"
|
2021-04-19 22:30:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const GroupObjectClass = "group"
|
|
|
|
const UserObjectClass = "user"
|
|
|
|
|
2021-04-26 09:53:06 +00:00
|
|
|
type ProviderInstance struct {
|
2021-04-19 22:30:27 +00:00
|
|
|
BaseDN string
|
|
|
|
|
2021-08-21 15:53:09 +00:00
|
|
|
UserDN string
|
|
|
|
|
|
|
|
VirtualGroupDN string
|
|
|
|
GroupDN string
|
2021-04-26 09:53:06 +00:00
|
|
|
|
2021-05-04 22:03:19 +00:00
|
|
|
appSlug string
|
|
|
|
flowSlug string
|
|
|
|
s *LDAPServer
|
|
|
|
log *log.Entry
|
2021-05-04 19:49:15 +00:00
|
|
|
|
2021-09-16 08:03:31 +00:00
|
|
|
tlsServerName *string
|
|
|
|
cert *tls.Certificate
|
|
|
|
outpostName string
|
2021-05-04 22:03:19 +00:00
|
|
|
searchAllowedGroups []*strfmt.UUID
|
|
|
|
boundUsersMutex sync.RWMutex
|
|
|
|
boundUsers map[string]UserFlags
|
2021-07-14 07:17:01 +00:00
|
|
|
|
|
|
|
uidStartNumber int32
|
|
|
|
gidStartNumber int32
|
2021-05-04 19:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type UserFlags struct {
|
2021-08-05 16:16:06 +00:00
|
|
|
UserInfo *api.User
|
|
|
|
UserPk int32
|
2021-05-04 19:49:15 +00:00
|
|
|
CanSearch bool
|
2021-04-26 09:53:06 +00:00
|
|
|
}
|
2021-04-19 22:30:27 +00:00
|
|
|
|
2021-04-26 09:53:06 +00:00
|
|
|
type LDAPServer struct {
|
2021-07-13 16:24:18 +00:00
|
|
|
s *ldap.Server
|
|
|
|
log *log.Entry
|
|
|
|
ac *ak.APIController
|
2021-07-21 21:53:43 +00:00
|
|
|
cs *ak.CryptoStore
|
2021-07-13 16:24:18 +00:00
|
|
|
defaultCert *tls.Certificate
|
|
|
|
providers []*ProviderInstance
|
2021-04-19 22:30:27 +00:00
|
|
|
}
|
2021-04-25 20:07:12 +00:00
|
|
|
|
2021-07-14 07:17:01 +00:00
|
|
|
type LDAPGroup struct {
|
2021-07-14 18:37:27 +00:00
|
|
|
dn string
|
|
|
|
cn string
|
|
|
|
uid string
|
|
|
|
gidNumber string
|
|
|
|
member []string
|
|
|
|
isSuperuser bool
|
2021-07-14 07:17:01 +00:00
|
|
|
isVirtualGroup bool
|
2021-07-14 18:37:27 +00:00
|
|
|
akAttributes interface{}
|
2021-04-19 22:30:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewServer(ac *ak.APIController) *LDAPServer {
|
|
|
|
s := ldap.NewServer()
|
|
|
|
s.EnforceLDAP = true
|
|
|
|
ls := &LDAPServer{
|
2021-04-26 09:53:06 +00:00
|
|
|
s: s,
|
2021-04-26 13:35:56 +00:00
|
|
|
log: log.WithField("logger", "authentik.outpost.ldap"),
|
2021-04-26 09:53:06 +00:00
|
|
|
ac: ac,
|
2021-07-21 21:53:43 +00:00
|
|
|
cs: ak.NewCryptoStore(ac.Client.CryptoApi),
|
2021-04-26 09:53:06 +00:00
|
|
|
providers: []*ProviderInstance{},
|
2021-04-19 22:30:27 +00:00
|
|
|
}
|
2021-07-17 17:36:15 +00:00
|
|
|
defaultCert, err := crypto.GenerateSelfSignedCert()
|
2021-07-13 16:24:18 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Warning(err)
|
|
|
|
}
|
|
|
|
ls.defaultCert = &defaultCert
|
2021-04-19 22:30:27 +00:00
|
|
|
s.BindFunc("", ls)
|
|
|
|
s.SearchFunc("", ls)
|
2021-08-29 19:13:46 +00:00
|
|
|
s.CloseFunc("", ls)
|
2021-04-19 22:30:27 +00:00
|
|
|
return ls
|
|
|
|
}
|
2021-09-16 08:14:51 +00:00
|
|
|
|
|
|
|
func (ls *LDAPServer) Type() string {
|
|
|
|
return "ldap"
|
|
|
|
}
|