Skip to main content

Auth(n/z) plugin for Django using kerberos + LDAP

Project description

django-kaminarimon

What is it?

django-kaminarimon (or just kaminarimon) is a library for integrating kerberos authentication and ldap authorization into a Django/DRF application.

While users can independently choose to integrate one or the other, it is designed to use both and use JWTs as interface for client<->server auth.

How to use

For Kerberos authentication

Set kaminarimon.auth.KerberosAuthentication as either:

  • REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"]
  • Individually at the view level

This will require the client to send a request with the header Authorization: Negotiate <token> which will initiate the SPNEGO protocol.

If the client does not send the aforementioned header when requesting a view that requires Kerberos authentication, the WWW-Authenticate is sent back to the client, signaling that it should use SPNEGO protocol for authentication.

[!TIP] By default the host or service principal will use the service's FQDN, but it can be overridden by setting the KRB5_HOSTNAME environment variable.

For LDAP authorization

[!NOTE] A lot of the behavior of this authentication backend is currently hardcoded to only work with Red Hat systems.

[!NOTE] Anonymous user access to the LDAP server is required for querying user information.

[!WARNING] Usage of LDAP authorization on its own withour Kerberos authentication is discouraged as it only handles authorization, it does not actually perform any sort of authentication of the user against the LDAP server, i.e. it simply loads the user's groups from the LDAP server.

Simply add the kaminarimon.backend.LDAPRemoteUser to the AUTHENTICATION_BACKENDS django setting.

Required settings:

  • AUTH_LDAP_SERVER_URI -- URI to the LDAP server
  • PUBLIC_READ_GROUPS -- List of names of groups that, if the user is a member of, grant access to the application. SERVICE_MANAGE_GROUP -- Group that denotes a user as staff and/or superuser.

Intended usage (kerberos authentication, ldap authorization)

The same settings, warnings, notes and tips for the previous sections apply.

Ensure kaminarimon.backend.LDAPRemoteUser is in AUTHENTICATION_BACKENDS, and add kaminarimon.views.krb5_obtain_token_pair_view to your urls.py, it is through this view that clients will obtain access and refresh JWT.

In order to protect other views with such authentication tokens, simply mark the authentication method as rest_framework_simplejwt.authentication.JWTAuthentication or similar as, or set it globally using DEFAULT_AUTHENTICATION_CLASSES.

Browser-based applications

If your service will be used by browser-based applications and security of tokens is a concern, you can add kaminarimon.views.refresh_token to your urls.py, this view will accept a cookie set by kaminarimon.views.krb5_obtain_token_pair_view in order to provide a fresh access token without requiring the client to store/handle the refresh token.

The cookie is by default httpOnly, secure and sameSite=Strict.

Running tests

cd tests/
podman compose -f docker-compose.yml up -d
pytest .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_kaminarimon-0.2.2.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_kaminarimon-0.2.2-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file django_kaminarimon-0.2.2.tar.gz.

File metadata

  • Download URL: django_kaminarimon-0.2.2.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.7

File hashes

Hashes for django_kaminarimon-0.2.2.tar.gz
Algorithm Hash digest
SHA256 68bd7b83ac58f40692ff0d05c810940910701a064f73d59d86e370abbb382296
MD5 fc902f015bb8227318efc2e4c7edba9b
BLAKE2b-256 837dc7cc9c6cb2ab9a56767fa0784eba04d95a80c850f5601633e3070d9d5563

See more details on using hashes here.

File details

Details for the file django_kaminarimon-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_kaminarimon-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bc5f27d3466e26d693ecce2d9029d503bde7cbbf652610611819db3bb3f6bce7
MD5 bde9cffd8ef7c230b0565e9b2158f7d1
BLAKE2b-256 fbfa06b06be943a5322b8c93aa6f86d8390bf675b37003be04d9adfb0f14b257

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page