Skip to main content

sentry-auth-ldap

GitHub Workflow Status PyPI License

A Django custom authentication backend for Sentry. This module extends the functionality of django-auth-ldap with Sentry specific features.

Features

  • Users created by this backend are managed users. Managed fields are not editable through the Sentry account page.
  • Users may be auto-added to an Organization upon creation.

Prerequisites

  • Sentry < 21.9.0 should work with sentry-ldap-auth==2.9.0 (which is the upstream project for legacy support)
  • 21.9.0 ≤ Sentry < 23.6.0 should work with sentry-auth-ldap==21.9.11
  • 23.6.0 ≤ Sentry should work with the latest release

Since sentry-auth-ldap==24.8.0, we'll strive to ensure backward compatibility.

Installation

To install, simply add sentry-auth-ldap to your requirements.txt for your Sentry environment (or pip install sentry-auth-ldap).

For container environment, because of the minimal base image, it may miss some dependencies.

You can easily enhance the image by sentry/enhance-image.sh script (need getsentry/self-hosted 22.6.0 or higher):

#!/bin/bash

requirements=(
'sentry-auth-ldap>=21.9.0'
# 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 ${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

Configuration

This module extends the django-auth-ldap and all the options it provides are supported (up to v1.2.x, at least).

To configure Sentry to use this module, add sentry_auth_ldap.backend.SentryLdapBackend to your AUTHENTICATION_BACKENDS in your sentry.conf.py, like this:

AUTHENTICATION_BACKENDS = AUTHENTICATION_BACKENDS + (
    'sentry_auth_ldap.backend.SentryLdapBackend',
)

Then, add any applicable configuration options. Depending on your environment, and especially if you are running Sentry in containers, you might consider using python-decouple so you can set these options via environment variables.

sentry-auth-ldap Specific Options

AUTH_LDAP_SENTRY_DEFAULT_ORGANIZATION = 'your-organization-slug'

Auto adds created user to the specified organization (matched by name) if it exists.

WARNING: There is an obsoleted setting named SENTRY_LDAP_DEFAULT_SENTRY_ORGANIZATION. It's used to set the default organization by display name, which is an unsuitable identifier.

AUTH_LDAP_SENTRY_ORGANIZATION_ROLE_TYPE = 'member'

Role type auto-added users are assigned. Valid values in a default installation of Sentry are 'member', 'admin', 'manager' & 'owner'. However, custom roles can also be added to Sentry, in which case these are also valid.

AUTH_LDAP_SENTRY_ORGANIZATION_GLOBAL_ACCESS = True

Whether auto-created users should be granted global access within the default organization.

AUTH_LDAP_SENTRY_SUBSCRIBE_BY_DEFAULT = False

Whether new users should be subscribed to any new projects by default. Disabling this is useful for large organizations where a subscription to each project might be spammy.

AUTH_LDAP_DEFAULT_EMAIL_DOMAIN = 'example.com'

Default domain to append to username as the Sentry user's e-mail address when the LDAP user has no mail attribute.

WARNING: There is an obsoleted setting named AUTH_LDAP_SENTRY_USERNAME_FIELD.
It could be replaced by AUTH_LDAP_USER_QUERY_FIELD and AUTH_LDAP_USER_ATTR_MAP which django-auth-ldap built-in.

Sentry Options

SENTRY_MANAGED_USER_FIELDS = ('email', 'first_name', 'last_name', 'password', )

Fields which managed users may not modify through the Sentry accounts view. Applies to all managed accounts.

Example Configuration

import ldap
from django_auth_ldap.config import LDAPSearch, GroupOfUniqueNamesType

AUTH_LDAP_SERVER_URI = 'ldap://my.ldapserver.com'
AUTH_LDAP_BIND_DN = ''
AUTH_LDAP_BIND_PASSWORD = ''
AUTH_LDAP_USER_QUERY_FIELD = 'username'

AUTH_LDAP_USER_SEARCH = LDAPSearch(
    'dc=domain,dc=com',
    ldap.SCOPE_SUBTREE,
    '(mail=%(user)s)',
)

AUTH_LDAP_USER_ATTR_MAP = {
    'username': 'uid',
    'name': 'cn',
    'email': 'mail'
}

AUTH_LDAP_MAIL_VERIFIED = True

AUTH_LDAP_GROUP_SEARCH = LDAPSearch(
    '',
    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_TIMEOUT = 3600

AUTH_LDAP_SENTRY_DEFAULT_ORGANIZATION = 'your-organization-slug'
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_auth_ldap.backend.SentryLdapBackend',
)

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

Troubleshooting

Work with LDAPS protocol (SSL/TLS)

Put the below content into /etc/ldap/ldap.conf, otherwise the certificate won't be trusted.

TLS_CACERT /etc/ssl/certs/ca-certificates.crt

If your certificate was issued by a private CA, you should change the path.

Don't use OCSP-Must-Staple certificate (SSL/TLS)

Please don't use OCSP-Must-Staple certificate with LDAPS.

Some ldap servers (eg. OpenLDAP) don't support stapling OCSP response. So it will cause the handshake failed.

Metadata

Release files for sentry-auth-ldap 24.8.1.post1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sentry-auth-ldap 24.8.1.post1
File Size Uploaded Provenance
sentry_auth_ldap-24.8.1.post1.tar.gz 9.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for sentry-auth-ldap 24.8.1.post1
File Interpreter ABI Platform
sentry_auth_ldap-24.8.1.post1-py3-none-any.whl Python 3 none any Details

Total release size: 19.9 kB

Release files / sentry_auth_ldap-24.8.1.post1.tar.gz

Download URL sentry_auth_ldap-24.8.1.post1.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
19426434b0e895f56217d835fa222d701f8d5a68d3d0c2008293ea34dbb5ecb7
BLAKE2b-256 checksum
How to use checksums
e063f875332fc5a42073799d9ecbe50db27469adfd3574bf32e22e00e3e9e002
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / sentry_auth_ldap-24.8.1.post1-py3-none-any.whl

Download URL sentry_auth_ldap-24.8.1.post1-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a0bef0b4a1a44d18923f31415d3736e229e6b6d13d8315e1d223511247f425c
BLAKE2b-256 checksum
How to use checksums
68165bc939ee4404745afa6307286ce3f13c07b2dc3d438750a4cdcc15ec06f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Security for sentry-auth-ldap 24.8.1.post1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page