Registry / auth-security / kerberos

kerberos

JSON →
library1.3.1pypypiunverified

The `kerberos` library provides a high-level Python wrapper for Kerberos (GSSAPI) operations, specifically designed for client/server Kerberos authentication based on RFC 4559. It directly wraps the underlying Kerberos 5 C API, offering a limited set of functions for this purpose. The current version is 1.3.1, and it maintains an active release cadence.

pip install kerberos
INSTALL
IMPORT
SIG · KERBEROS
K
kerberos
auth-securitypythonv1.3.1
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
build_error
glibc
py 3.103.95 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

kerberos
import kerberos
The top-level module exposes functions directly.

This quickstart demonstrates the very basic client-side initialization of a Kerberos GSSAPI context using `kerberos.authGSSClientInit` and `kerberos.authGSSClientStep`. A real Kerberos environment with a Key Distribution Center (KDC), a configured service principal name (SPN), and an active Kerberos ticket (obtained via `kinit`) is required for successful operation. The process typically involves multiple `authGSSClientStep` calls, exchanging tokens with a server.

import kerberos import os # This is a simplified example. A real Kerberos setup with a KDC, service principal, and active tickets (kinit) is required. # Set up a dummy service principal name for illustration. # In a real scenario, this would be 'HTTP/your.service.com@REALM' service_principal = os.environ.get('KERBEROS_SPN', 'HTTP/host.example.com@EXAMPLE.COM') negotiate_token = None try: # Initialize a Kerberos GSSAPI client context. # `gssflags` can be used to specify options like GSS_C_DELEG_FLAG. # `principal` can specify the client principal, if not using default cache. result, context = kerberos.authGSSClientInit(service_principal) # The client sends a 'token' (negotiate_token) to the server. # In a real HTTP exchange, this token would be part of the Authorization header. # This step simulates the client-side generation of the initial token. result = kerberos.authGSSClientStep(context, negotiate_token) # If successful, get the token to send to the server. negotiate_token = kerberos.authGSSClientResponse(context) print(f"Initial GSSAPI token generated: {negotiate_token[:30]}...") # In a real scenario, the server would send back its own token, # which the client would then process in subsequent authGSSClientStep calls. # For this quickstart, we just demonstrate the client init. except kerberos.KerberosError as e: print(f"Kerberos Error: {e}") except Exception as e: print(f"An unexpected error occurred: {e}") finally: # Always clean up the context to free resources. if 'context' in locals() and context is not None: kerberos.authGSSClientClean(context)
Debug
Known issues
breakingThe library primarily supports Python 3.9+. Older Python 2 installations or versions prior to 3.9 are not officially supported and may lead to installation or runtime issues.
fix
Ensure your environment is running Python 3.9 or newer. Consider using a virtual environment to manage Python versions.
affects: < 1.3.0 (Python < 3.9)
gotchaInstallation often fails without system-level Kerberos development libraries and a C compiler. This is a common pitfall on Linux and some Windows environments.
fix
Install required system packages before `pip install kerberos`. For Debian/Ubuntu, this is typically `python3-dev libkrb5-dev gcc`. For RHEL/Fedora, `python3-devel krb5-devel gcc`. macOS and Windows users installing from wheels might bypass this, but source installs will require it.
affects: All versions
deprecatedThe `kerberos.checkPassword` method is explicitly for testing purposes only and should NEVER be used in production code due to its lack of protection against KDC spoofing.
fix
Avoid `checkPassword` in production. Implement proper GSSAPI-based authentication flows or use higher-level libraries like `requests-kerberos` or `python-gssapi` that handle security correctly.
affects: All versions
gotchaThe `kerberos` library is a low-level wrapper around the C GSSAPI. It is complex to use directly for most application-level Kerberos authentication. Higher-level Python libraries like `python-gssapi` or `requests-kerberos` are generally recommended for ease of use and reduced footguns.
fix
For common HTTP Kerberos authentication, consider `pip install requests-kerberos`. For a more comprehensive and Python-friendly GSSAPI interface, explore `pip install gssapi`.
affects: All versions
gotchaSuccessful Kerberos authentication requires a properly configured Kerberos client, an active Kerberos ticket (e.g., from `kinit`), and correct Service Principal Names (SPNs). Missing tickets, incorrect `krb5.conf` settings, or SPN mismatches are frequent causes of `KerberosError`.
fix
Verify Kerberos configuration (`/etc/krb5.conf`), ensure a valid ticket exists (`klist`), and confirm the SPN matches the service being accessed. Debug with Kerberos logging if available.
affects: All versions
Errors
Common errors & fixes
fatal error: Python.h: No such file or directory
The `kerberos` library requires compilation of C extensions during installation, which necessitates the presence of Python development headers and Kerberos C development libraries on the system.
fix
Install the necessary system-level development packages. For Debian/Ubuntu: `sudo apt-get install gcc python3-dev libkrb5-dev`. For Red Hat/CentOS: `sudo dnf install gcc python3-devel krb5-devel`.
ModuleNotFoundError: No module named 'kerberos'
The `kerberos` Python package is not installed in the active Python environment or the environment is not correctly configured, preventing Python from finding the module.
fix
Install the package using pip: `pip install kerberos`. Ensure that you are installing it into the correct Python environment where your application is running.
authGSSClientInit() failed: (('Unspecified GSS failure. Minor code may provide more information', 851968), ("No Kerberos credentials available", -1765328243))
This error indicates that the Python `kerberos` library could not find valid Kerberos credentials (a Ticket-Granting Ticket, TGT) in the system's credential cache, or the Kerberos client configuration (`krb5.conf`) is incorrect.
fix
Before running your Python script, obtain a Kerberos ticket using the `kinit` command (e.g., `kinit youruser@YOUR.REALM`). Verify the ticket's presence and validity with `klist`. Additionally, ensure your system's `krb5.conf` file is correctly configured for your Kerberos realm.
Upgrade
Version history
1.3.1latest on PyPI · released Jan 9, 2021
Audit
Dependencies
Kerberos 5 API (e.g., MIT Kerberos >= 1.17 or Heimdal)requiredThe library is a C extension wrapper and requires a system-level Kerberos 5 API implementation and its development headers.
C Compiler (e.g., GCC)requiredRequired to compile the C extension during installation.
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources