Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uffd2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
thies
uffd2
Commits
cec51a3d
Commit
cec51a3d
authored
4 years ago
by
Julian
Browse files
Options
Downloads
Patches
Plain Diff
Made all ldap parameters configurable
parent
72092da6
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
deps/ldapalchemy
+1
-1
1 addition, 1 deletion
deps/ldapalchemy
uffd/default_config.cfg
+34
-20
34 additions, 20 deletions
uffd/default_config.cfg
uffd/mail/models.py
+8
-8
8 additions, 8 deletions
uffd/mail/models.py
uffd/user/models.py
+34
-21
34 additions, 21 deletions
uffd/user/models.py
with
77 additions
and
50 deletions
ldapalchemy
@
2358086f
Compare
d2c13338
...
2358086f
Subproject commit
d2c133381a8e536ee433e5ab305fc24146c0feb9
Subproject commit
2358086f5b8184fe89bbb69334a5c80e9b20cfbf
This diff is collapsed.
Click to expand it.
uffd/default_config.cfg
+
34
−
20
View file @
cec51a3d
LDAP_BASE_USER
=
"ou=users,dc=example,dc=com"
LDAP_USER_SEARCH_BASE
=
"ou=users,dc=example,dc=com"
LDAP_BASE_GROUPS
=
"ou=groups,dc=example,dc=com"
LDAP_USER_SEARCH_FILTER
=
[("objectClass", "person")]
LDAP_BASE_MAIL
=
"ou=postfix,dc=example,dc=com"
LDAP_USER_OBJECTCLASSES
=
["top", "inetOrgPerson", "organizationalPerson", "person", "posixAccount"]
LDAP_USER_MIN_UID
=
10000
LDAP_USER_MAX_UID
=
18999
LDAP_USER_GID
=
20001
LDAP_USER_DN_ATTRIBUTE
=
"uid"
LDAP_USER_UID_ATTRIBUTE
=
"uidNumber"
LDAP_USER_UID_ALIASES
=
[]
LDAP_USER_LOGINNAME_ATTRIBUTE
=
"uid"
LDAP_USER_LOGINNAME_ALIASES
=
[]
LDAP_USER_DISPLAYNAME_ATTRIBUTE
=
"cn"
LDAP_USER_DISPLAYNAME_ALIASES
=
["givenName", "displayName"]
LDAP_USER_MAIL_ATTRIBUTE
=
"mail"
LDAP_USER_MAIL_ALIASES
=
[]
LDAP_USER_DEFAULT_ATTRIBUTES
=
{
"sn":
"
",
"homeDirectory":
"/home/{loginname}",
"gidNumber":
LDAP_USER_GID
}
LDAP_FILTER_USER
=
[("objectClass","person")]
LDAP_GROUP_SEARCH_BASE
=
"ou=groups,dc=example,dc=com"
LDAP_FILTER_GROUP
=
[("objectClass","groupOfUniqueNames")]
LDAP_GROUP_SEARCH_FILTER
=
[("objectClass","groupOfUniqueNames")]
LDAP_FILTER_MAIL
=
[("objectClass","postfixVirtual")]
LDAP_GROUP_GID_ATTRIBUTE
=
"gidNumber"
LDAP_GROUP_NAME_ATTRIBUTE
=
"cn"
LDAP_GROUP_DESCRIPTION_ATTRIBUTE
=
"description"
LDAP_GROUP_MEMBER_ATTRIBUTE
=
"uniqueMember"
LDAP_MAIL_SEARCH_BASE
=
"ou=postfix,dc=example,dc=com"
LDAP_MAIL_SEARCH_FILTER
=
[("objectClass","postfixVirtual")]
LDAP_MAIL_OBJECTCLASSES
=
["top", "postfixVirtual"]
LDAP_MAIL_DN_ATTRIBUTE
=
"uid"
LDAP_MAIL_UID_ATTRIBUTE
=
"uid"
LDAP_MAIL_RECEIVERS_ATTRIBUTE
=
"mailacceptinggeneralid"
LDAP_MAIL_DESTINATIONS_ATTRIBUTE
=
"maildrop"
LDAP_SERVICE_BIND_DN
=
""
LDAP_SERVICE_BIND_DN
=
""
LDAP_SERVICE_BIND_PASSWORD
=
""
LDAP_SERVICE_BIND_PASSWORD
=
""
LDAP_SERVICE_URL
=
"ldapi:///"
LDAP_SERVICE_URL
=
"ldapi:///"
LDAP_SERVICE_USE_STARTTLS
=
True
LDAP_SERVICE_USE_STARTTLS
=
True
LDAP_USER_OBJECTCLASSES
=
["top", "inetOrgPerson", "organizationalPerson", "person", "posixAccount"]
LDAP_USER_ATTRIBUTE_UID
=
"uidNumber"
LDAP_USER_ATTRIBUTE_DISPLAYNAME
=
"cn"
LDAP_USER_ATTRIBUTE_MAIL
=
"mail"
# The User class gets filled by which LDAP attribute and to type (single/list)
LDAP_USER_ATTRIBUTE_EXTRA
=
{
#"phone": {"type": "single", "name": "mobile"},
}
LDAP_USER_GID
=
20001
LDAP_USER_MIN_UID
=
10000
LDAP_USER_MAX_UID
=
18999
SESSION_LIFETIME_SECONDS
=
3600
SESSION_LIFETIME_SECONDS
=
3600
# CSRF protection
# CSRF protection
SESSION_COOKIE_SECURE
=
True
SESSION_COOKIE_SECURE
=
True
SESSION_COOKIE_HTTPONLY
=
True
SESSION_COOKIE_HTTPONLY
=
True
SESSION_COOKIE_SAMESITE
=
'Strict'
SESSION_COOKIE_SAMESITE
=
'Strict'
ACL_ADMIN_GROUP
=
"uffd_admin"
ACL_ADMIN_GROUP
=
"uffd_admin"
ACL_SELFSERVICE_GROUP
=
"uffd_access"
ACL_SELFSERVICE_GROUP
=
"uffd_access"
...
@@ -39,7 +54,6 @@ MAIL_USERNAME='yourId@example.com'
...
@@ -39,7 +54,6 @@ MAIL_USERNAME='yourId@example.com'
MAIL_PASSWORD
=
'*****'
MAIL_PASSWORD
=
'*****'
MAIL_USE_STARTTLS
=
True
MAIL_USE_STARTTLS
=
True
MAIL_FROM_ADDRESS
=
'foo@bar.com'
MAIL_FROM_ADDRESS
=
'foo@bar.com'
MAIL_LDAP_OBJECTCLASSES
=
["top", "postfixVirtual"]
#MFA_ICON_URL = 'https://example.com/logo.png'
#MFA_ICON_URL = 'https://example.com/logo.png'
#MFA_RP_ID = 'example.com' # If unset, hostname from current request is used
#MFA_RP_ID = 'example.com' # If unset, hostname from current request is used
...
...
This diff is collapsed.
Click to expand it.
uffd/mail/models.py
+
8
−
8
View file @
cec51a3d
...
@@ -2,12 +2,12 @@ from uffd.ldap import ldap
...
@@ -2,12 +2,12 @@ from uffd.ldap import ldap
from
uffd.lazyconfig
import
lazyconfig_str
,
lazyconfig_list
from
uffd.lazyconfig
import
lazyconfig_str
,
lazyconfig_list
class
Mail
(
ldap
.
Model
):
class
Mail
(
ldap
.
Model
):
ldap_search_base
=
lazyconfig_str
(
'
LDAP_
BASE_MAIL
'
)
ldap_search_base
=
lazyconfig_str
(
'
LDAP_
MAIL_SEARCH_BASE
'
)
ldap_filter_params
=
lazyconfig_list
(
'
LDAP_FILTER
_MAIL
'
)
ldap_filter_params
=
lazyconfig_list
(
'
LDAP_
MAIL_SEARCH_
FILTER
'
)
ldap_object_classes
=
lazyconfig_list
(
'
MAIL_LDAP
_OBJECTCLASSES
'
)
ldap_object_classes
=
lazyconfig_list
(
'
LDAP_MAIL
_OBJECTCLASSES
'
)
ldap_dn_attribute
=
'
uid
'
ldap_dn_attribute
=
lazyconfig_str
(
'
LDAP_MAIL_DN_ATTRIBUTE
'
)
ldap_dn_base
=
lazyconfig_str
(
'
LDAP_
BASE_MAIL
'
)
ldap_dn_base
=
lazyconfig_str
(
'
LDAP_
MAIL_SEARCH_BASE
'
)
uid
=
ldap
.
Attribute
(
'
uid
'
)
uid
=
ldap
.
Attribute
(
lazyconfig_str
(
'
LDAP_MAIL_UID_ATTRIBUTE
'
)
)
receivers
=
ldap
.
Attribute
(
'
mailacceptinggeneralid
'
,
multi
=
True
)
receivers
=
ldap
.
Attribute
(
lazyconfig_str
(
'
LDAP_MAIL_RECEIVERS_ATTRIBUTE
'
)
,
multi
=
True
)
destinations
=
ldap
.
Attribute
(
'
maildrop
'
,
multi
=
True
)
destinations
=
ldap
.
Attribute
(
lazyconfig_str
(
'
LDAP_MAIL_DESTINATIONS_ATTRIBUTE
'
)
,
multi
=
True
)
This diff is collapsed.
Click to expand it.
uffd/user/models.py
+
34
−
21
View file @
cec51a3d
...
@@ -17,29 +17,40 @@ def get_next_uid():
...
@@ -17,29 +17,40 @@ def get_next_uid():
raise
Exception
(
'
No free uid found
'
)
raise
Exception
(
'
No free uid found
'
)
return
next_uid
return
next_uid
class
User
(
ldap
.
Model
):
class
DictView
:
ldap_search_base
=
lazyconfig_str
(
'
LDAP_BASE_USER
'
)
def
__init__
(
self
,
obj
):
ldap_filter_params
=
lazyconfig_list
(
'
LDAP_FILTER_USER
'
)
self
.
obj
=
obj
def
__getitem__
(
self
,
key
):
return
getattr
(
self
.
obj
,
key
)
class
BaseUser
(
ldap
.
Model
):
ldap_search_base
=
lazyconfig_str
(
'
LDAP_USER_SEARCH_BASE
'
)
ldap_filter_params
=
lazyconfig_list
(
'
LDAP_USER_SEARCH_FILTER
'
)
ldap_object_classes
=
lazyconfig_list
(
'
LDAP_USER_OBJECTCLASSES
'
)
ldap_object_classes
=
lazyconfig_list
(
'
LDAP_USER_OBJECTCLASSES
'
)
ldap_dn_base
=
lazyconfig_str
(
'
LDAP_
BASE_USER
'
)
ldap_dn_base
=
lazyconfig_str
(
'
LDAP_
USER_SEARCH_BASE
'
)
ldap_dn_attribute
=
'
uid
'
ldap_dn_attribute
=
lazyconfig_str
(
'
LDAP_USER_DN_ATTRIBUTE
'
)
uid
=
ldap
.
Attribute
(
lazyconfig_str
(
'
LDAP_USER_ATTRIBUTE
_UID
'
),
default
=
get_next_uid
)
uid
=
ldap
.
Attribute
(
lazyconfig_str
(
'
LDAP_USER_
UID_
ATTRIBUTE
'
),
default
=
get_next_uid
,
aliases
=
lazyconfig_list
(
'
LDAP_USER_UID_ALIASES
'
)
)
loginname
=
ldap
.
Attribute
(
'
uid
'
)
loginname
=
ldap
.
Attribute
(
lazyconfig_str
(
'
LDAP_USER_LOGINNAME_ATTRIBUTE
'
),
aliases
=
lazyconfig_list
(
'
LDAP_USER_LOGINNAME_ALIASES
'
)
)
displayname
=
ldap
.
Attribute
(
lazyconfig_str
(
'
LDAP_USER_
ATTRIBUTE_
DISPLAYNAME
'
),
aliases
=
[
'
givenName
'
,
'
displayName
'
]
)
displayname
=
ldap
.
Attribute
(
lazyconfig_str
(
'
LDAP_USER_DISPLAYNAME
_ATTRIBUTE
'
),
aliases
=
lazyconfig_list
(
'
LDAP_USER_DISPLAYNAME_ALIASES
'
)
)
mail
=
ldap
.
Attribute
(
lazyconfig_str
(
'
LDAP_USER_ATTRIBUTE
_MAIL
'
))
mail
=
ldap
.
Attribute
(
lazyconfig_str
(
'
LDAP_USER_
MAIL_
ATTRIBUTE
'
),
aliases
=
lazyconfig_list
(
'
LDAP_USER_MAIL_ALIASES
'
))
pwhash
=
ldap
.
Attribute
(
'
userPassword
'
,
default
=
lambda
:
hashed
(
HASHED_SALTED_SHA512
,
secrets
.
token_hex
(
128
)))
pwhash
=
ldap
.
Attribute
(
'
userPassword
'
,
default
=
lambda
:
hashed
(
HASHED_SALTED_SHA512
,
secrets
.
token_hex
(
128
)))
groups
=
[]
# Shuts up pylint, overwritten by back-reference
groups
=
[]
# Shuts up pylint, overwritten by back-reference
roles
=
[]
# Shuts up pylint, overwritten by back-reference
roles
=
[]
# Shuts up pylint, overwritten by back-reference
def
dummy_attribute_defaults
(
self
):
def
dummy_attribute_defaults
(
self
):
if
self
.
ldap_object
.
getattr
(
'
sn
'
)
==
[]:
for
name
,
patterns
in
current_app
.
config
[
'
LDAP_USER_DEFAULT_ATTRIBUTES
'
].
items
():
self
.
ldap_object
.
setattr
(
'
sn
'
,
[
'
'
])
if
not
isinstance
(
patterns
,
list
):
if
self
.
ldap_object
.
getattr
(
'
homeDirectory
'
)
==
[]:
patterns
=
[
patterns
]
self
.
ldap_object
.
setattr
(
'
homeDirectory
'
,
[
'
/home/%s
'
%
self
.
loginname
])
values
=
[]
if
self
.
ldap_object
.
getattr
(
'
gidNumber
'
)
==
[]:
for
pattern
in
patterns
:
self
.
ldap_object
.
setattr
(
'
gidNumber
'
,
[
current_app
.
config
[
'
LDAP_USER_GID
'
]])
if
isinstance
(
pattern
,
str
):
values
.
append
(
pattern
.
format_map
(
DictView
(
self
)))
else
:
values
.
append
(
pattern
)
self
.
ldap_object
.
setattr
(
name
,
values
)
ldap_add_hooks
=
ldap
.
Model
.
ldap_add_hooks
+
(
dummy_attribute_defaults
,)
ldap_add_hooks
=
ldap
.
Model
.
ldap_add_hooks
+
(
dummy_attribute_defaults
,)
...
@@ -101,13 +112,15 @@ class User(ldap.Model):
...
@@ -101,13 +112,15 @@ class User(ldap.Model):
self
.
mail
=
value
self
.
mail
=
value
return
True
return
True
User
=
BaseUser
class
Group
(
ldap
.
Model
):
class
Group
(
ldap
.
Model
):
ldap_search_base
=
lazyconfig_str
(
'
LDAP_
BASE_GROUPS
'
)
ldap_search_base
=
lazyconfig_str
(
'
LDAP_
GROUP_SEARCH_BASE
'
)
ldap_filter_params
=
lazyconfig_list
(
'
LDAP_FILTER
_GROUP
'
)
ldap_filter_params
=
lazyconfig_list
(
'
LDAP_
GROUP_SEARCH_
FILTER
'
)
gid
=
ldap
.
Attribute
(
'
gidNumber
'
)
gid
=
ldap
.
Attribute
(
lazyconfig_str
(
'
LDAP_GROUP_GID_ATTRIBUTE
'
)
)
name
=
ldap
.
Attribute
(
'
cn
'
)
name
=
ldap
.
Attribute
(
lazyconfig_str
(
'
LDAP_GROUP_NAME_ATTRIBUTE
'
)
)
description
=
ldap
.
Attribute
(
'
description
'
,
default
=
''
)
description
=
ldap
.
Attribute
(
lazyconfig_str
(
'
LDAP_GROUP_DESCRIPTION_ATTRIBUTE
'
)
,
default
=
''
)
members
=
ldap
.
Relationship
(
'
uniqueMember
'
,
User
,
backref
=
'
groups
'
)
members
=
ldap
.
Relationship
(
lazyconfig_str
(
'
LDAP_GROUP_MEMBER_ATTRIBUTE
'
)
,
User
,
backref
=
'
groups
'
)
roles
=
[]
# Shuts up pylint, overwritten by back-reference
roles
=
[]
# Shuts up pylint, overwritten by back-reference
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment