Skip to content

Commit 8e3269b

Browse files
authored
Merge pull request #13 from flavienbwk/develop
Added secure LDAP support
2 parents 06b7cd3 + d7e7a1c commit 8e3269b

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

api/app/service/auth_service.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
from model.User import User
2020
from model.Token import Token
2121

22+
LDAP_SCHEME = os.environ.get("LDAP_SCHEME")
2223
LDAP_HOST = os.environ.get("LDAP_HOST")
2324
LDAP_PORT = os.environ.get("LDAP_PORT")
24-
LDAP_ENDPOINT = "ldap://{}:{}".format(LDAP_HOST, LDAP_PORT)
25+
LDAP_ENDPOINT = "{}://{}:{}".format(LDAP_SCHEME, LDAP_HOST, LDAP_PORT)
2526
LDAP_USERS_DN = os.environ.get("LDAP_USERS_DN")
2627
LDAP_ADMIN_DN = os.environ.get("LDAP_ADMIN_DN")
2728
LDAP_ADMIN_PASSWORD = os.environ.get("LDAP_ADMIN_PASSWORD")
@@ -94,6 +95,7 @@ def checkLDAPCredentials(username: str, password: str):
9495
return_value = False
9596
search_filter = "(&(uid={})(objectClass=inetOrgPerson))".format(username)
9697
try:
98+
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
9799
connection = ldap.initialize(LDAP_ENDPOINT)
98100
connection.protocol_version = ldap.VERSION3
99101
connection.simple_bind_s(LDAP_ADMIN_DN, LDAP_ADMIN_PASSWORD)

api/app/service/user_service.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
from model.User import User
1616
from model.Token import Token
1717

18+
LDAP_SCHEME = os.environ.get("LDAP_SCHEME")
1819
LDAP_HOST = os.environ.get("LDAP_HOST")
1920
LDAP_PORT = os.environ.get("LDAP_PORT")
20-
LDAP_ENDPOINT = "ldap://{}:{}".format(LDAP_HOST, LDAP_PORT)
21+
LDAP_ENDPOINT = "{}://{}:{}".format(LDAP_SCHEME, LDAP_HOST, LDAP_PORT)
2122
LDAP_USERS_DN = os.environ.get("LDAP_USERS_DN")
2223
LDAP_ADMIN_DN = os.environ.get("LDAP_ADMIN_DN")
2324
LDAP_ADMIN_PASSWORD = os.environ.get("LDAP_ADMIN_PASSWORD")
@@ -60,6 +61,7 @@ def updateLDAPUser(user: User):
6061
response = ApiResponse()
6162
search_filter = "(&(uid={})(objectClass=inetOrgPerson))".format(user.username)
6263
try:
64+
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
6365
connection = ldap.initialize(LDAP_ENDPOINT)
6466
connection.protocol_version = ldap.VERSION3
6567
connection.simple_bind_s(LDAP_ADMIN_DN, LDAP_ADMIN_PASSWORD)

docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ services:
6666
LOG_LEVEL: "DEBUG" # DEBUG, INFO, WARNING or ERROR
6767

6868
LDAP_HOST: "ldap"
69-
LDAP_PORT: 389 # Secure LDAP (LDAPS) are not supported yet
69+
LDAP_SCHEME: "ldap" # "ldaps" if using secure LDAP, "ldap" else
70+
LDAP_PORT: 389
7071
LDAP_USERS_DN: "dc=mycompany,dc=com"
7172
LDAP_ADMIN_DN: "cn=admin,dc=mycompany,dc=com"
7273
LDAP_ADMIN_PASSWORD: "adminpwd"

0 commit comments

Comments
 (0)