LDAP Integration. ModuleNotFoundError: No module named 'user_settings.ldap_connection_settings'

Hello,
Sorry for this question… but i’m have tried to find a solution by myself and tbh i’m lost.
I’ve copied and edited the file ldap_connection_settings.py in my docker volume.
in my case /var/lib/docker/volumes/mayan_app/_data/user_settings/
And when i start up the docker-compose i have the error:
ModuleNotFoundError: No module named ‘user_settings.ldap_connection_settings’
Any idea how i can fix it ?
Thank you by advence for your time.
Best Regards.

Env:
MAYAN_SETTINGS_MODULE=user_settings.ldap_connection_settings

Error dump:
app_1 | During handling of the above exception, another exception occurred:
app_1 |
app_1 | Traceback (most recent call last):
app_1 | File “/opt/mayan-edms/bin/mayan-edms.py”, line 22, in
app_1 | main()
app_1 | File “/opt/mayan-edms/bin/mayan-edms.py”, line 18, in main
app_1 | execute_from_command_line(sys.argv)
app_1 | File “/opt/mayan-edms/lib/python3.9/site-packages/django/core/management/init.py”, line 419, in execute_from_command_line
app_1 | utility.execute()
app_1 | File “/opt/mayan-edms/lib/python3.9/site-packages/django/core/management/init.py”, line 413, in execute
app_1 | self.fetch_command(subcommand).run_from_argv(self.argv)
app_1 | File “/opt/mayan-edms/lib/python3.9/site-packages/django/core/management/init.py”, line 244, in fetch_command
app_1 | settings.INSTALLED_APPS
app_1 | File “/opt/mayan-edms/lib/python3.9/site-packages/django/conf/init.py”, line 82, in getattr
app_1 | self._setup(name)
app_1 | File “/opt/mayan-edms/lib/python3.9/site-packages/django/conf/init.py”, line 69, in _setup
app_1 | self._wrapped = Settings(settings_module)
app_1 | File “/opt/mayan-edms/lib/python3.9/site-packages/django/conf/init.py”, line 170, in init
app_1 | mod = importlib.import_module(self.SETTINGS_MODULE)
app_1 | File “/usr/lib/python3.9/importlib/init.py”, line 127, in import_module
app_1 | return _bootstrap._gcd_import(name[level:], package, level)
app_1 | File “”, line 1030, in _gcd_import
app_1 | File “”, line 1007, in _find_and_load
app_1 | File “”, line 984, in _find_and_load_unlocked
app_1 | ModuleNotFoundError: No module named ‘user_settings.ldap_connection_settings’

Hi there, saw there was no movement on this, and while I do not use ldap I may in the future so I thought I would reply.

First off did you get your settings file from the repo? Also are you using the docker compose method of install?

Cheers

Ken

Hello DocCyblade
thank you for your answer.
Yes for both of your questions.
I use exactly the installation process who i’ve found here.
https://docs.mayan-edms.com/parts/installation.html#docker-compose
THank you for your time.
Best

This error points to the issue that python is trying to load the file (because you set the MAYAN_SETTINGS_MODULE=user_settings.ldap_connection_settings in your env file. That would mean your file could not be read.

  1. Check your user permissions within the running container.
  2. Ensure the custom config file is where it should be.

Also what version of Mayan are trying to implement ldap on?

EDIT: Link was wrong, fixed that

Hello,
yes totally, that’s what i supposed.

  1. -rw-r–r-- 1 root root 5539 Mar 1 09:02 ldap_connection_settings.py (and that’s my right on it.)
  2. In my installation the file is located here : /var/lib/docker/volumes/mayan_app/_data/user_settings/ldap_connection_settings.py

My mayan version is :

thank you very much for your time.
Best.
G.

So I checked my setup, my permissions show 1000 as the user/group. This may be your issue.

drwxr-xr-x 3 1000 1000 4096 Feb 24 22:46 user_settings

For giggles try and change your files owner/group to 1000 and restart the containers
sudo chown 1000:1000 /var/lib/docker/volumes/mayan_app/_data/user_settings/ldap_connection_settings.py

Hello Thank you very much for your answer, sadly it’s does’nt work.
I will continue to investigate.
Thank you again for your time and sorry for the delay of answer.
Best regards.
G.

What is your output of the following commands:
ls -l /var/lib/docker/volumes/mayan_app/_data/
ls -l /var/lib/docker/volumes/mayan_app/_data/user_settings/

Are you getting the same error, can’t import the ldap settings file?
Might be worth posting your ldap settings file too (just make sure you remove any passwords and organization specific info you don’t want on the interwebs

Just wondering if the user_settings permissions is right and is it setup to be a python module.

I need help with the same thing in LDAP, I have it working perfectly on version 3 here is the code that currently working

Do I need to generate a new Secret Key for the new deployment?
I copied the database and everything over to the newer version.

Here is where the ldap_settings.py is located /opt/mayan-edms/media/mayan_settings

LDAP FILE
from future import absolute_import

from mayan.settings.production import *

import ldap
from django_auth_ldap.config import (
LDAPSearch, LDAPSearchUnion, NestedActiveDirectoryGroupType
)

from django.contrib.auth import get_user_model

SECRET_KEY = ‘’

makes sure this works in Active Directory

ldap.set_option(ldap.OPT_REFERRALS, 0)

Turn of debug output, turn this off when everything is working as expected

ldap.set_option(ldap.OPT_DEBUG_LEVEL, 4095)

This is the default, but I like to be explicit.

AUTH_LDAP_ALWAYS_UPDATE_USER = True

LDAP_USER_AUTO_CREATION = “False”

LDAP_URL = “ldap://”
LDAP_BASE_DN = “DC=usit,DC=com”
LDAP_ADMIN_DN = “CN=,OU=,DC=usit,DC=com”
LDAP_PASSWORD = “”

AUTH_LDAP_SERVER_URI = LDAP_URL
AUTH_LDAP_BIND_DN = LDAP_ADMIN_DN
AUTH_LDAP_BIND_PASSWORD = LDAP_PASSWORD

AUTH_LDAP_USER_SEARCH = LDAPSearchUnion(
LDAPSearch(
‘OU=,DC=USIT,DC=com’,
ldap.SCOPE_SUBTREE,‘(samaccountname=%(user)s)’
),
LDAPSearch(
‘OU= ,DC=USIT,DC=com’,
ldap.SCOPE_SUBTREE,‘(samaccountname=%(user)s)’
),
LDAPSearch(
‘OU=,DC=USIT,DC=com’,
ldap.SCOPE_SUBTREE,‘(samaccountname=%(user)s)’
),
LDAPSearch(
‘OU=,DC=USIT,DC=com’,
ldap.SCOPE_SUBTREE,‘(samaccountname=%(user)s)’
),
LDAPSearch(
‘OU=& ,DC=USIT,DC=com’,
ldap.SCOPE_SUBTREE,‘(samaccountname=%(user)s)’
),
LDAPSearch(
‘OU=,DC=USIT,DC=com’,
ldap.SCOPE_SUBTREE,‘(samaccountname=%(user)s)’
),

)

AUTH_LDAP_USER_ATTR_MAP = {
‘first_name’: ‘givenName’,
‘last_name’: ‘sn’,
‘email’: ‘mail’
}
AUTHENTICATION_BACKENDS = (
‘django_auth_ldap.backend.LDAPBackend’,
‘django.contrib.auth.backends.ModelBackend’,
‘mayan.media.mayan_settings.ldaplogin.EmailOrUsernameModelBackend’,
)

class EmailOrUsernameModelBackend(object):
“”"
This is a ModelBacked that allows authentication with either a username or $
“”"
def authenticate(self, username=None, password=None):
if ‘@’ in username:
kwargs = {‘email’: username}
else:
kwargs = {‘username’: username}
try:
user = get_user_model().objects.get(**kwargs)
if user.check_password(password):
return user
except get_user_model().DoesNotExist:
return None

def get_user(self, username):
    try:
        return get_user_model().objects.get(pk=username)
    except get_user_model().DoesNotExist:
        return None

Mayan CONF file settings
environment=
PYTHONPATH=“/opt/mayan-edms/media/user_settings”,
MAYAN_ALLOWED_HOSTS=‘[“*”]’,
MAYAN_MEDIA_ROOT=“/opt/mayan-edms/media”,
MAYAN_PYTHON_BIN_DIR=/opt/mayan-edms/bin/,
MAYAN_GUNICORN_BIN=/opt/mayan-edms/bin/gunicorn,
MAYAN_GUNICORN_LIMIT_REQUEST_LINE=4094,
MAYAN_GUNICORN_MAX_REQUESTS=500,
MAYAN_GUNICORN_REQUESTS_JITTER=50,
MAYAN_GUNICORN_TEMPORARY_DIRECTORY=“”,
MAYAN_GUNICORN_TIMEOUT=120,
MAYAN_GUNICORN_WORKER_CLASS=sync,
MAYAN_GUNICORN_WORKERS=3,
MAYAN_SETTINGS_MODULE=mayan.settings.production,
MAYAN_WORKER_A_CONCURRENCY=“”,
MAYAN_WORKER_A_MAX_MEMORY_PER_CHILD=“–max-memory-per-child=300000”,
MAYAN_WORKER_A_MAX_TASKS_PER_CHILD=“–max-tasks-per-child=100”,
MAYAN_WORKER_B_CONCURRENCY=“”,
MAYAN_WORKER_B_MAX_MEMORY_PER_CHILD=“–max-memory-per-child=300000”,
MAYAN_WORKER_B_MAX_TASKS_PER_CHILD=“–max-tasks-per-child=100”,
MAYAN_WORKER_C_CONCURRENCY=“”,
MAYAN_WORKER_C_MAX_MEMORY_PER_CHILD=“–max-memory-per-child=300000”,
MAYAN_WORKER_C_MAX_TASKS_PER_CHILD=“–max-tasks-per-child=100”,
MAYAN_WORKER_D_CONCURRENCY=“–concurrency=1”,
MAYAN_WORKER_D_MAX_MEMORY_PER_CHILD=“–max-memory-per-child=300000”,
MAYAN_WORKER_D_MAX_TASKS_PER_CHILD=“–max-tasks-per-child=10”,
_LAST_LINE=“”

Thank you