Kerberos API bindings for Python
Project description
Python Kerberos 5 Library
This library provides Python functions that wraps the Kerberos 5 C API. Due to the complex nature of this API it is highly recommended to use something like python-gssapi which exposes the Kerberos authentication details through GSSAPI.
Requirements
- An implementation of the Kerberos 5 API - including the header files
- A C compiler, such as GCC
- Python 3.6+
Note: macOS includes their own implementation of Heimdal and a compiler isn't needed on that platform if installing from the wheel.
Installation
Simply run:
pip install krb5
To install from source run the following:
git clone https://github.com/jborean93/pykrb5.git
python -m pip install build
python -m build
pip install dist/krb5-*.whl
Compiling the code should automatically pick up the proper paths for the KRB5 headers and locations. If further customisation is needed, the following environment variables can be set when building the wheel:
KRB5_KRB5CONFIG
- The path to
krb5-config
to use for detecting the Kerberos library to link to - The compiler and linker args are derived from what this function outputs
- Defaults to whatever
krb5-config
is on thePATH
- FreeBSD will default to
/usr/local/bin/krb5-config
instead of/usr/bin/krb5-config
- The path to
KRB5_MAIN_LIB
- The path to the
libkrb5
shared library used to check if any of the optional functions are available
- The path to the
KRB5_COMPILER_ARGS
- Compiler flags to use when compiling the extensions
- Defaults to the output of
krb5-config --cflags krb5
if not set
KRB5_LINKER_ARGS
- Linker flags to use when compiling the extensions
- Defaults to the output of
krb5-config --libs krb5
if not set
KRB5_SKIP_MODULE_CHECK
- Skips the checks used to detect if optional functions are available - will treat them all as available
- This is only really useful when building the sdist as no implementation provides all these functions
KRB5_CYTHON_TRACING
- Used to generate the Cython extensions with line tracing for coverage collection
KRB5_MACOS_HEIMDAL_DIR
- Used when compiling on macOS to point to the Heimdal install directory
- Used to find the Heimdal header files as macOS does not include, or provide a way to obtain, these header files for their Heimdal framework
- Defaults to
{git_root}/build_helpers/heimdal
Development
To run the tests or make changes to this repo run the following:
git clone https://github.com/jborean93/pykrb5.git
pip install -r requirements-dev.txt
pre-commit install
python -m pip install -e .
# Can compile the krb5 extensions on an adhoc basis
# python setup.py build_ext --inplace
From there an editor like VSCode can be used to make changes and run the test suite.
To recompile the Cython files after a change run the build_ext --inplace
command.
Structure
This library is merely a wrapper around the Kerberos 5 APIs.
The functions under the krb5
namespace match the KRB5 API specification but with the krb5_
prefix remove.
For example the krb5_init_context function is called through krb5.init_context()
.
Errors are raised as a Krb5Error
which contains the message as formatted by the KRB5 implementation and the error code for that error.
Some of the structures returned by these functions are represented by a Python class and are freed once they are deallocated once all references to that object is removed.
Some classes expose an addr
property that returns the raw pointer address of the structure it is wrapping.
This is so the structure can be used in other libraries like python-gssapi
but great care must be taken that nothing else frees the structure as that could cause a segmentation fault.
Not all the functions exposed in this library are available on every KRB5 API implementation. To check if a function is available run the following:
import krb5
if not hasattr(krb5, "kt_dup"):
raise Exception("Current implementation does not support krb5_kt_dup")
There may also be some difference in behaviour, error codes, error messages, between te different implementations. It is up to the caller to paper over these differences when required.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for krb5-0.5.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0412d84484bf37158f040baa86ac3c08604251f9d0afdf2e9659b237ce3cdfa |
|
MD5 | f42a4c7831e7798e301683453e9d99b2 |
|
BLAKE2b-256 | d3ee78ee3705300b368fa381399f97703efc3d1d137560bda07b384fd93ce7a7 |
Hashes for krb5-0.5.1-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f65fbbcf6de0fecee56a05370b6f65230c121a0cadad8e6a56f5a852bdeecaa6 |
|
MD5 | a123c97a0b45a327f6891934cf2893c7 |
|
BLAKE2b-256 | 858279c5dc2c81fb881ee8bc408a55fa95a6c732eb54fc71091238ef64d440d7 |
Hashes for krb5-0.5.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2269fb6c0813cd7f58526a152d746aebb8e48026b92856093865414395c185e9 |
|
MD5 | 82e1ac0f6c9932c5b2ac14eefdeee3e2 |
|
BLAKE2b-256 | 139b1cdca966e543624a44c77e106c6d4bdf0e9a0f46694f8f5ce092742a31c9 |
Hashes for krb5-0.5.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83d0a7d44130681f6a8168fc3609d783c77868fe1ab4a9861da30ae8212d632a |
|
MD5 | 435d08a5da9a10e696c3e074e9328709 |
|
BLAKE2b-256 | c1439974a6898c0447bcb0ff742d8f660507235928708b33acc467a075d27296 |
Hashes for krb5-0.5.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ca9dcb23dc0014f79af0f151bb501bfe4f371b3e54bde78e79ea73dad272eda |
|
MD5 | ecc3a08b61c43a51f5cbacf3f8a94682 |
|
BLAKE2b-256 | 565eb73fdc7a2275bdbb739935e74a175668a6e6ef2deee2f9e37ec4cbdf57fa |
Hashes for krb5-0.5.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e51c700cf148e63fef60bc4b2c453018218a3170dedbfe2840f122aee5a453e7 |
|
MD5 | a839d6aad6f6e966d0096172c161007d |
|
BLAKE2b-256 | 6c9e10f1c7d6404894db1472424c684eaa3abbbc9e9c81a48171beead3808f7b |
Hashes for krb5-0.5.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3008124d01da50559ee7ac2ce0045ee069963f3086ec5c2460b07da6fae4fdda |
|
MD5 | cdfb4a01f3356928d845639d4afbe0ab |
|
BLAKE2b-256 | 1bca2192652b62b40b1f8853643369ff00a8ed305b18968ed33c8bc0dd710031 |
Hashes for krb5-0.5.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df15e3fe8b1d03cf715b5866215da6b131e1fd5ddd6e7f659e74bb79498033b2 |
|
MD5 | b412bd8b78e886472e8fcf06fcc0da53 |
|
BLAKE2b-256 | 8870ed90b1f206022ff11e7c14b4d1cbdc1ab421fa62aec54c0b1a113bf30ef3 |
Hashes for krb5-0.5.1-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9b4109adf9f02d0885c96611aba1945970b5319a93cb427617049d6536921ac |
|
MD5 | d2281bc392ee37aeaf8fd92a42217a0b |
|
BLAKE2b-256 | fd912877664b7913ec3c87b9a98d02e15704c6177b200450b27de3eab34e7eea |
Hashes for krb5-0.5.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73badd6982e8af81e4cca82c4f1a6dbcc50257d700072b8df7c84ea003c1b5e4 |
|
MD5 | 4d6fe65c2a57b42d3562fbe3c0f3fb0a |
|
BLAKE2b-256 | 657a853a63f87339c6956715bbb452923140542aed450186a6876668399256dc |
Hashes for krb5-0.5.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb69fe96be7197f007b5b20172346728349d0b03a39b3343e8793fabb3d28626 |
|
MD5 | a41d88766a16805c3d659b3c75d006db |
|
BLAKE2b-256 | 4a089b0eaf0b72b0e3c9a8c9c9ca471660e107a851f02ec613cd63d3e9169527 |