Closed Nudelsalad closed 10 months ago
I think this is a casting issue @Nudelsalad - try changing the setting to this INVENTREE_LDAP_GLOBAL_OPTIONS= {"OPT_X_TLS_CACERTFILE":"/home/inventree/data/cert.pem","OPT_X_TLS_NEWCTX":0}
From the code base over at python-ldap it seem like OPT_X_TLS_NEWCTX
is assumed to be an int not str.
Hi @matmair appreciate your help and thanks for pointing out the obious,
Setting global options to:
INVENTREE_LDAP_GLOBAL_OPTIONS= {"OPT_X_TLS_CACERTFILE":"/home/inventree/data/cert.pem","OPT_X_TLS_NEWCTX":0}
leads to
Loading config file : /home/inventree/data/config.yaml
Python version 3.10.13 - /usr/local/bin/python
Traceback (most recent call last):
File "/root/.local/bin/gunicorn", line 8, in <module>
sys.exit(run())
File "/root/.local/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 67, in run
WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
File "/root/.local/lib/python3.10/site-packages/gunicorn/app/base.py", line 236, in run
super().run()
File "/root/.local/lib/python3.10/site-packages/gunicorn/app/base.py", line 72, in run
Arbiter(self).run()
File "/root/.local/lib/python3.10/site-packages/gunicorn/arbiter.py", line 58, in __init__
self.setup(app)
File "/root/.local/lib/python3.10/site-packages/gunicorn/arbiter.py", line 118, in setup
self.app.wsgi()
File "/root/.local/lib/python3.10/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/root/.local/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
return self.load_wsgiapp()
File "/root/.local/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
return util.import_app(self.app_uri)
File "/root/.local/lib/python3.10/site-packages/gunicorn/util.py", line 371, in import_app
mod = importlib.import_module(module)
File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/home/inventree/InvenTree/InvenTree/wsgi.py", line 15, in <module>
application = get_wsgi_application() # pragma: no cover
File "/root/.local/lib/python3.10/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
django.setup(set_prefix=False)
File "/root/.local/lib/python3.10/site-packages/django/__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/root/.local/lib/python3.10/site-packages/django/conf/__init__.py", line 82, in __getattr__
self._setup(name)
File "/root/.local/lib/python3.10/site-packages/django/conf/__init__.py", line 69, in _setup
self._wrapped = Settings(settings_module)
File "/root/.local/lib/python3.10/site-packages/django/conf/__init__.py", line 170, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/home/inventree/InvenTree/InvenTree/settings.py", line 334, in <module>
if v.startswith("OPT_"):
AttributeError: 'int' object has no attribute 'startswith'
I already tried playing arround with some values, however setting the global options to:
INVENTREE_LDAP_GLOBAL_OPTIONS= {"OPT_X_TLS_REQUIRE_CERT":"OPT_X_TLS_NEVER"}
gives me pip error of the installed plugins into inventree with pip. Disabling these plugins temporarely leads to:
Caught LDAPError while authenticating nudelsalad: OPERATIONS_ERROR({'result': 1, 'desc': 'Operations error', 'ctrls': [], 'info': 'SSL connection already established.'})
The SSL connection already established info lead me to this post in Stackoverflow. Event though this config seems redundant 34 people upvoted it and trying to set the proposed values leads me to multiple Attribute Errors. Removing succesively the values leads to SSL connection already established
Even though turning SSL off is not the admired solution it also does not kinda work. Thanks in advance
@Nudelsalad are you trying to use TLS and SSL at the same time? That would not work
Hi @matmair thanks for your time, I guess I need to dig deeper into the network materia. However for those having a similar issue there are two options that worked out for me: First option: Mounting certificate of private CA into container and specifying it in the config:
INVENTREE_LDAP_ENABLED=True
INVENTREE_LDAP_SERVER_URI=ldaps://ldapsrv.example.com
INVENTREE_LDAP_BIND_DN="uid=ldap-read-access,cn=sysaccounts,cn=etc,dc=example,dc=com"
INVENTREE_LDAP_BIND_PASSWORD=[redacted by nudelsalat]
INVENTREE_LDAP_SEARCH_BASE_DN="dc=example,dc=com"
INVENTREE_LDAP_GLOBAL_OPTIONS= {"OPT_X_TLS_CACERTFILE":"/home/inventree/data/cert.pem"}
Second option:
INVENTREE_LDAP_ENABLED=True
INVENTREE_LDAP_SERVER_URI=ldap://ldapsrv.example.com
INVENTREE_LDAP_BIND_DN="uid=ldap-read-access,cn=sysaccounts,cn=etc,dc=example,dc=com"
(INVENTREE_LDAP_START_TLS=True)
INVENTREE_LDAP_BIND_PASSWORD=[redacted by nudelsalat]
INVENTREE_LDAP_SEARCH_BASE_DN="dc=example,dc=com"
INVENTREE_LDAP_GLOBAL_OPTIONS= {"OPT_X_TLS_REQUIRE_CERT":"OPT_X_TLS_NEVER"}
I would like to know now which one is "safer" so I can close this issue but thanks in advance @matmair!
@Nudelsalad mounting the ca public cert and using it for LDAPS is certainly the safer option as the traffic is encrypted and harder to sniff.
Deployment Method
Describe the problem*
Hi, after spending hours of trying to setup the LDAP for Inventree I thought I'll give it a shot here.
This is my config:
With this config I receive the following error:
Caught LDAPError while authenticating nudelsalad: OPERATIONS_ERROR({'result': 1, 'desc': 'Operations error', 'ctrls': [], 'info': 'SSL connection already established.'})
I tried adding "OPT_X_TLS_NEWCTX":"0" to the Global_Options to apply TLS settings to internal TLS context. According to Link Value 0 creates a new client-side context
Modifying INVENTREE_LDAP_GLOBAL_OPTIONS to
INVENTREE_LDAP_GLOBAL_OPTIONS= {"OPT_X_TLS_CACERTFILE":"/home/inventree/data/cert.pem","OPT_X_TLS_NEWCTX":"0"}
gives me an internal server error, it seems to somehow authenticate... -> see attached log
The TypeError: 'str' object cannot be interpreted as an integer somhow makes me wondering
Running latest version of inventree in docker setup (my other services running in container can authenticate) Any help appreciated
Steps to Reproduce
As described above
Relevant log output