Skip to main content

Django GSSAPI SPNEGO

Project description

A Django application for adding Kerberos/GSS authentication to your existing backend

This Django application provides some View and Mixin classes along with a backend Mixin class to extend your existing AuthenticationBackend with SPNEGO-based authentication.

This provides additional flexibility over a Middleware solution that would require all users to use/support SPNEGO all of the time, and just utilize GSSAPI on a specific login page to create a login session as an alternative to typing in a username and password.

Prereqs

  • A working Kerberos KDC (MIT, Windows AD, Heimdall, whatever)

  • A SPN for your application server(s)

  • A method for mapping Kerberos Principals to User objects in your backend

Installation

You can install the pre-release development version from PyPi by specifying the exact version to pip:

pip install django-gss-spnego==21.10.1dev

Once an official release is uploaded, you will not have to specify an exact version.

Configuration

The following settings must be present:

  • django_gss_spnego in settings.INSTALLED_APPS

  • settings.KERBEROS_SPN may be set to SERVICENAME@HOSTNAME ie HTTP@django-server. Setting it to “” means “try all SPNs in the host keytab”

  • Environment variables to control your KRB5 installation. See the kerberos env documentation for details.

Usage

Mix django_gss_spnego.backends.SpnegoBackendMixin into your backend class(es) of choice. Ensure those backends can resolve a User object from a kerberos principal name.

from django_auth_ldap.backend import LDAPBackend
from django_gss_spnego.backends import SpnegoBackendMixin


class MyBackendClass(SpnegoBackendMixin, LDAPBackend):
    def get_user_from_username(self, username):
        return self.populate_user(username)

Register aforementioned backend class in settings.AUTHENTICATION_BACKENDS

Create a view somewhere on your site that uses SpnegoAuthMixin, and add it to your URL router. If using one of the provided CBV View classes, also include django_gss_spnego and django.contrib.admin in your settings.INSTALLED_APPS for access to the spnego.html template.

from django_gss_spnego.views import SpnegoView

urls.append(r"^auth/spnego$", SpnegoView.as_view(), name="spnego")

Acquire a ticket, and point your favorite supported client at the endpoint

import requests_gssapi
import requests

auth = requests_gssapi.HTTPSPNEGOAuth()
sess = requests.session()
sess.auth = auth
sess.get("http://localhost/auth/spnego")
sess.get("http://localhost/page/that/requires/authorized_user")

Acknowledgements

License

Apache 2.0 – see the LICENSE file for more detail

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-gss-spnego-21.10.1.dev0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

django_gss_spnego-21.10.1.dev0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file django-gss-spnego-21.10.1.dev0.tar.gz.

File metadata

  • Download URL: django-gss-spnego-21.10.1.dev0.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.2

File hashes

Hashes for django-gss-spnego-21.10.1.dev0.tar.gz
Algorithm Hash digest
SHA256 23c0582349cdc980b35fe53cef65b4e9eedfa829f980dd672eaaa8349df78ed1
MD5 7df80e5f2980a278425dd120b0b66b39
BLAKE2b-256 42b5a98c1262ba2b6fdcf70e877c89da46a6aa152a24a6d52422743af78a7f1c

See more details on using hashes here.

File details

Details for the file django_gss_spnego-21.10.1.dev0-py3-none-any.whl.

File metadata

  • Download URL: django_gss_spnego-21.10.1.dev0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.2

File hashes

Hashes for django_gss_spnego-21.10.1.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 e85c2ccff67c9b605a7297a7fe3f449e7b8c79a80be91260ceb1a0b0f8eb8582
MD5 f84d0175846b0532d5f30ce9fce0ae3b
BLAKE2b-256 1b634b138ca3cc829f1b204b438ab5f38a54209a4ecbd669b6dafdb21e46649e

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