Skip to main content

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 IPA LDAP systems (dc=ipa,dc=redhat,dc=com).

[!WARNING] Usage of LDAP authorization on its own without 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.

LDAP connection

The following settings configure the LDAP connection:

Setting Type Required Default Description
KAMINARIMON_LDAP_SERVERS list[str] Yes — LDAP server URIs
KAMINARIMON_LDAP_BIND_DN str No None Bind DN for simple bind (if unset, GSSAPI is used)
KAMINARIMON_LDAP_BIND_PASSWORD str No — Bind password for simple bind (required when BIND_DN is set)
KAMINARIMON_LDAP_TIMEOUT int No 10 LDAP network and operation timeout in seconds
KAMINARIMON_LDAP_BASE_DN str No dc=ipa,dc=redhat,dc=com Base DN for LDAP searches

When KAMINARIMON_LDAP_BIND_DN is not set, kaminarimon uses GSSAPI (Kerberos) to authenticate to the LDAP server. When set, it uses simple bind with the provided DN and password. Simple bind is useful for test and development environments where Kerberos is not available.

Required application settings

  • 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 .

Metadata

Release files for django-kaminarimon 0.3.0

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

Source distribution (sdist)

Source distribution for django-kaminarimon 0.3.0
File Size Uploaded
django_kaminarimon-0.3.0.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-kaminarimon 0.3.0
File Interpreter ABI Platform
django_kaminarimon-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.2 kB

Release files / django_kaminarimon-0.3.0.tar.gz

Download URL django_kaminarimon-0.3.0.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a6d4ba7f84099e896af17655c63ee365f045f30bb59b2100f95996141417a449
BLAKE2b-256 checksum
How to use checksums
73b686f76dbdcf7e602dcba287757c8d813a1b5abf95dc8ddc43c2b0cedbb0ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.7

Release files / django_kaminarimon-0.3.0-py3-none-any.whl

Download URL django_kaminarimon-0.3.0-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e2acf2614b70fb7f5509524ff03b4325ed7aa8bcb38b60fdcbbd1437e2f5662
BLAKE2b-256 checksum
How to use checksums
e10837e2a101eb4c5f2618018a9ed8bdad253769c16db83379bcacb0cfeb38b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.7

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

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