PMExtra / sentry-auth-ldap

A Sentry extension to add an LDAP server as an authention source.
Apache License 2.0
27 stars 7 forks source link

ModuleNotFoundError: No module named 'ldap' #16

Closed Zian502 closed 9 months ago

Zian502 commented 9 months ago

Traceback (most recent call last): File "/usr/local/bin/sentry", line 8, in sys.exit(main()) File "/usr/local/lib/python3.10/site-packages/sentry/runner/init.py", line 195, in main func(kwargs) File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1157, in call return self.main(args, kwargs) File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1078, in main rv = self.invoke(ctx) File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1688, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1434, in invoke return ctx.invoke(self.callback, ctx.params) File "/usr/local/lib/python3.10/site-packages/click/core.py", line 783, in invoke return __callback(args, kwargs) File "/usr/local/lib/python3.10/site-packages/click/decorators.py", line 33, in new_func return f(get_current_context(), *args, **kwargs) File "/usr/local/lib/python3.10/site-packages/sentry/runner/decorators.py", line 28, in inner configure() File "/usr/local/lib/python3.10/site-packages/sentry/runner/init.py", line 131, in configure _configure(ctx, py, yaml, skip_service_validation) File "/usr/local/lib/python3.10/site-packages/sentry/runner/settings.py", line 144, in configure hasattr(settings, "INSTALLED_APPS") File "/usr/local/lib/python3.10/site-packages/django/conf/init.py", line 82, in getattr self._setup(name) File "/usr/local/lib/python3.10/site-packages/django/conf/init.py", line 69, in _setup self._wrapped = Settings(settings_module) File "/usr/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 "", line 1050, in _gcd_import File "", line 1027, in _find_and_load File "", line 1006, in _find_and_load_unlocked File "", line 688, in _load_unlocked File "", line 883, in exec_module File "", line 241, in _call_with_frames_removed File "/usr/local/lib/python3.10/site-packages/sentry/runner/default_settings.py", line 8, in populate_module(sys.modules[name]) File "/usr/local/lib/python3.10/site-packages/sentry/runner/importer.py", line 16, in populate_module _load_settings(SENTRY_CONF_PY, settings=settings_mod) File "/usr/local/lib/python3.10/site-packages/sentry/runner/importer.py", line 27, in _load_settings exec(source_file.read(), conf.dict) File "", line 335, in ModuleNotFoundError: No module named 'ldap' Error in install/set-up-and-migrate-database.sh:12. '$dcr web upgrade' exited with status 1

Zian502 commented 9 months ago

getsentry/sentry:23.12.1

Zian502 commented 9 months ago

Collecting sentry-ldap

8 89.76 Downloading sentry_ldap-1.2.16-py3-none-any.whl (7.4 kB)

8 90.84 Collecting django-auth-ldap==4.1.0

8 91.00 Downloading django_auth_ldap-4.1.0-py3-none-any.whl (20 kB)

8 91.37 Requirement already satisfied: sentry>=23.6.0 in /usr/local/lib/python3.10/site-packages (from sentry-ldap) (23.12.1)

8 91.37 Requirement already satisfied: Django>=2.2 in /usr/local/lib/python3.10/site-packages (from django-auth-ldap==4.1.0->sentry-ldap) (3.2.23)

8 93.19 Collecting python-ldap>=3.1

8 93.41 Downloading python-ldap-3.4.4.tar.gz (377 kB)

8 109.4 ━━━ 30.7/377.9 kB 113.5 MB/s eta 0:00:01

8 109.4 ERROR: Exception:

8 109.4 Traceback (most recent call last):

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_vendor/urllib3/response.py", line 438, in _error_catcher

8 109.4 yield

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_vendor/urllib3/response.py", line 561, in read

8 109.4 data = self._fp_read(amt) if not fp_closed else b""

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_vendor/urllib3/response.py", line 527, in _fp_read

8 109.4 return self._fp.read(amt) if amt is not None else self._fp.read()

8 109.4 File "/usr/local/lib/python3.10/http/client.py", line 466, in read

8 109.4 s = self.fp.read(amt)

8 109.4 File "/usr/local/lib/python3.10/socket.py", line 705, in readinto

8 109.4 return self._sock.recv_into(b)

8 109.4 File "/usr/local/lib/python3.10/ssl.py", line 1307, in recv_into

8 109.4 return self.read(nbytes, buffer)

8 109.4 File "/usr/local/lib/python3.10/ssl.py", line 1163, in read

8 109.4 return self._sslobj.read(len, buffer)

8 109.4 TimeoutError: The read operation timed out

8 109.4

8 109.4 During handling of the above exception, another exception occurred:

8 109.4

8 109.4 Traceback (most recent call last):

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 160, in exc_logging_wrapper

8 109.4 status = run_func(*args)

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 247, in wrapper

8 109.4 return func(self, options, args)

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_internal/commands/install.py", line 419, in run

8 109.4 requirement_set = resolver.resolve(

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 92, in resolve

8 109.4 result = self._result = resolver.resolve(

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 481, in resolve

8 109.4 state = resolution.resolve(requirements, max_rounds=max_rounds)

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 373, in resolve

8 109.4 failure_causes = self._attempt_to_pin_criterion(name)

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 213, in _attempt_to_pin_criterion

8 109.4 criteria = self._get_updated_criteria(candidate)

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 204, in _get_updated_criteria

8 109.4 self._add_to_criteria(criteria, requirement, parent=candidate)

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 172, in _add_to_criteria

8 109.4 if not criterion.candidates:

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_vendor/resolvelib/structs.py", line 151, in bool

8 109.4 return bool(self._sequence)

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 155, in bool

8 109.4 return any(self)

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 143, in

8 109.4 return (c for c in iterator if id(c) not in self._incompatible_ids)

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 47, in _iter_built

8 109.4 candidate = func()

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 206, in _make_candidate_from_link

8 109.4 self._link_candidate_cache[link] = LinkCandidate(

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 297, in init

8 109.4 super().init(

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 162, in init

8 109.4 self.dist = self._prepare()

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 231, in _prepare

8 109.4 dist = self._prepare_distribution()

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 308, in _prepare_distribution

8 109.4 return preparer.prepare_linked_requirement(self._ireq, parallel_builds=True)

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_internal/operations/prepare.py", line 491, in prepare_linked_requirement

8 109.4 return self._prepare_linked_requirement(req, parallel_builds)

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_internal/operations/prepare.py", line 536, in _prepare_linked_requirement

8 109.4 local_file = unpack_url(

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_internal/operations/prepare.py", line 166, in unpack_url

8 109.4 file = get_http_url(

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_internal/operations/prepare.py", line 107, in get_http_url

8 109.4 from_path, content_type = download(link, temp_dir.path)

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_internal/network/download.py", line 147, in call

8 109.4 for chunk in chunks:

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_internal/cli/progress_bars.py", line 53, in _rich_progress_bar

8 109.4 for chunk in iterable:

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_internal/network/utils.py", line 63, in response_chunks

8 109.4 for chunk in response.raw.stream(

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_vendor/urllib3/response.py", line 622, in stream

8 109.4 data = self.read(amt=amt, decode_content=decode_content)

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_vendor/urllib3/response.py", line 560, in read

8 109.4 with self._error_catcher():

8 109.4 File "/usr/local/lib/python3.10/contextlib.py", line 153, in exit

8 109.4 self.gen.throw(typ, value, traceback)

8 109.4 File "/usr/local/lib/python3.10/site-packages/pip/_vendor/urllib3/response.py", line 443, in _error_catcher

8 109.4 raise ReadTimeoutError(self._pool, None, "Read timed out.")

8 109.4 pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.

PMExtra commented 9 months ago

image Please see README.

PMExtra commented 9 months ago

https://mirror.nju.edu.cn/mirrorz-help/pypi/?mirror=NJU

Zian502 commented 9 months ago

服务起来了,但是登陆后,报错了。

Zian502 commented 9 months ago

服务起来了,但是登陆后,报错了。

Oops! Something went wrong It looks like you've hit an issue in our server API. Don't worry though! We use Sentry to monitor Sentry and it's likely we're already looking into this!

If you're daring, you may want to try the following:

Give it a few seconds and reload the page. If all else fails, contact us with more details.

Zian502 commented 9 months ago

通过查看日志有个错误。

Zian502 commented 9 months ago

通过查看日志有个错误。

Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/django/core/handlers/exception.py", line 47, in inner response = get_response(request) File "/usr/local/lib/python3.10/site-packages/django/core/handlers/base.py", line 181, in _get_response response = wrapped_callback(request, *callback_args, callback_kwargs) File "/usr/local/lib/python3.10/site-packages/sentry/../sentry_sdk/integrations/django/views.py", line 84, in sentry_wrapped_callback return callback(request, *args, *kwargs) File "/usr/local/lib/python3.10/site-packages/django/views/generic/base.py", line 70, in view return self.dispatch(request, args, kwargs) File "/usr/local/lib/python3.10/site-packages/sentry/silo/base.py", line 156, in override return original_method(*args, kwargs) File "/usr/local/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view return view_func(*args, *kwargs) File "/usr/local/lib/python3.10/site-packages/sentry/web/frontend/base.py", line 390, in dispatch return self.handle(request, args, kwargs) File "/usr/local/lib/python3.10/site-packages/django/utils/decorators.py", line 43, in _wrapper return bound_method(*args, kwargs) File "/usr/local/lib/python3.10/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func response = view_func(request, *args, *kwargs) File "/usr/local/lib/python3.10/site-packages/sentry/web/frontend/auth_organization_login.py", line 87, in handle response = self.handle_basic_auth(request, organization=organization) File "/usr/local/lib/python3.10/site-packages/sentry/web/frontend/auth_login.py", line 669, in handle_basic_auth elif login_form.is_valid(): File "/usr/local/lib/python3.10/site-packages/django/forms/forms.py", line 175, in is_valid return self.is_bound and not self.errors File "/usr/local/lib/python3.10/site-packages/django/forms/forms.py", line 170, in errors self.full_clean() File "/usr/local/lib/python3.10/site-packages/django/forms/forms.py", line 373, in full_clean self._clean_form() File "/usr/local/lib/python3.10/site-packages/django/forms/forms.py", line 400, in _clean_form cleaned_data = self.clean() File "/usr/local/lib/python3.10/site-packages/sentry/web/forms/accounts.py", line 133, in clean self.user_cache = authenticate(username=username, password=password) File "/usr/local/lib/python3.10/site-packages/django/views/decorators/debug.py", line 42, in sensitive_variables_wrapper return func(func_args, func_kwargs) File "/usr/local/lib/python3.10/site-packages/django/contrib/auth/init.py", line 68, in authenticate for backend, backend_path in _get_backends(return_tuples=True): File "/usr/local/lib/python3.10/site-packages/django/contrib/auth/init.py", line 27, in _get_backends backend = load_backend(backend_path) File "/usr/local/lib/python3.10/site-packages/django/contrib/auth/init.py", line 21, in load_backend return import_string(path)() File "/usr/local/lib/python3.10/site-packages/django/utils/module_loading.py", line 17, in import_string module = import_module(module_path) File "/usr/local/lib/python3.10/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1050, in _gcd_import File "", line 1027, in _find_and_load File "", line 992, in _find_and_load_unlocked File "", line 241, in _call_with_frames_removed File "", line 1050, in _gcd_import File "", line 1027, in _find_and_load File "", line 1004, in _find_and_load_unlocked ModuleNotFoundError: No module named 'sentry_auth_ldap' 09:18:34 [ERROR] django.request: Internal Server Error: /auth/login/zcy/ (status_code=500 request=<WSGIRequest: POST '/auth/login/zcy/'>)

bryanjuho commented 9 months ago

Hey guys, same thing happened to me. Seems that building Dockerfile cache skips enhance-image.sh.

I added ARG CACHEBUST=1 to ./sentry/Dockerfile

example:

ARG SENTRY_IMAGE
ARG CACHEBUST=1

FROM ${SENTRY_IMAGE}

COPY . /usr/src/sentry

RUN if [ -s /usr/src/sentry/enhance-image.sh ]; then \
    /usr/src/sentry/enhance-image.sh; \
fi

RUN if [ -s /usr/src/sentry/requirements.txt ]; then \
    echo "sentry/requirements.txt is deprecated, use sentry/enhance-image.sh - see https://github.com/getsentry/self-hosted#enhance-sentry-image"; \
    pip install -r /usr/src/sentry/requirements.txt; \
fi
bryanjuho commented 9 months ago

Also take note of these changes in ./sentry/sentry.conf.py

https://github.com/getsentry/self-hosted/pull/2722/files

Zian502 commented 9 months ago

Hey guys, same thing happened to me. Seems that building Dockerfile cache skips enhance-image.sh.

I added ARG CACHEBUST=1 to ./sentry/Dockerfile

example:

ARG SENTRY_IMAGE
ARG CACHEBUST=1

FROM ${SENTRY_IMAGE}

COPY . /usr/src/sentry

RUN if [ -s /usr/src/sentry/enhance-image.sh ]; then \
    /usr/src/sentry/enhance-image.sh; \
fi

RUN if [ -s /usr/src/sentry/requirements.txt ]; then \
    echo "sentry/requirements.txt is deprecated, use sentry/enhance-image.sh - see https://github.com/getsentry/self-hosted#enhance-sentry-image"; \
    pip install -r /usr/src/sentry/requirements.txt; \
fi

It still doesn't work.

Zian502 commented 9 months ago

!/bin/bash

requirements=( 'sentry-ldap'

You can add other packages here, just like requirements.txt

)

Install the dependencies of ldap

apt-get update apt-get install -y --no-install-recommends build-essential libldap2-dev libsasl2-dev

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple ${requirements[@]}

Clean up to shrink the image size

apt-get purge -y --auto-remove build-essential rm -rf /var/lib/apt/lists/*

Support ldap over tls (ldaps://) protocol

mkdir -p /etc/ldap && echo "TLS_CACERT /etc/ssl/certs/ca-certificates.crt" > /etc/ldap/ldap.conf

Zian502 commented 9 months ago

import ldap from django_auth_ldap.config import LDAPSearch, GroupOfUniqueNamesType

AUTH_LDAP_SERVER_URI = 'xxx' AUTH_LDAP_BIND_DN = 'CN=dev,CN=Users,DC=ldap,DC=cai-inc,DC=com' AUTH_LDAP_BIND_PASSWORD = 'xxx' AUTH_LDAP_USER_QUERY_FIELD = 'username'

AUTH_LDAP_USER_SEARCH = LDAPSearch( 'OU=ALL,OU=政采云有限公司,DC=ldap,DC=cai-inc,DC=com', ldap.SCOPE_SUBTREE, '(mail=%(user)s)', )

AUTH_LDAP_USER_ATTR_MAP = {

'username': 'uid',

'name': 'displayName',
'email': 'mail'

}

AUTH_LDAP_MAIL_VERIFIED = True

AUTH_LDAP_GROUP_SEARCH = LDAPSearch( 'OU=政采云有限公司,DC=ldap,DC=cai-inc,DC=com', ldap.SCOPE_SUBTREE, '(objectClass=groupOfUniqueNames)' )

AUTH_LDAP_GROUP_TYPE = GroupOfUniqueNamesType() AUTH_LDAP_REQUIRE_GROUP = None AUTH_LDAP_DENY_GROUP = None AUTH_LDAP_FIND_GROUP_PERMS = False AUTH_LDAP_CACHE_GROUPS = True AUTH_LDAP_GROUP_CACHE_TIMEOUT = 3600 AUTH_LDAP_SENTRY_SUBSCRIBE_BY_DEFAULT = False # 关键,关闭默认角色

AUTH_LDAP_SENTRY_DEFAULT_ORGANIZATION = 'Zcy' AUTH_LDAP_DEFAULT_SENTRY_ORGANIZATION = 'Zcy' AUTH_LDAP_SENTRY_ORGANIZATION_ROLE_TYPE = 'member' AUTH_LDAP_SENTRY_GROUP_ROLE_MAPPING = { 'owner': ['sysadmins'], 'admin': ['devleads'], 'member': ['developers', 'seniordevelopers'] } AUTH_LDAP_SENTRY_ORGANIZATION_GLOBAL_ACCESS = True

AUTHENTICATION_BACKENDS = AUTHENTICATION_BACKENDS + ( 'sentry-ldap.backend.SentryLdapBackend', )

Optional logging for diagnostics.

LOGGING['disable_existing_loggers'] = False import logging logger = logging.getLogger('django_auth_ldap') logger.setLevel(logging.DEBUG)

Zian502 commented 9 months ago

image 这个报错原因是什么呀?

Zian502 commented 9 months ago

问题解决了,感谢大家。