Skip to main content

Kerberos API bindings for Python

Project description

Python Kerberos 5 Library

Test workflow PyPI version License

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.9+

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 the PATH
    • FreeBSD will default to /usr/local/bin/krb5-config instead of /usr/bin/krb5-config
  • KRB5_MAIN_LIB
    • The path to the libkrb5 shared library used to check if any of the optional functions are available
  • 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.

Python Free-Threading (PEP 779)

This library supports Python Free-Threading and will build free-threading-compatible extension files if installed under a free-threading interpreter. Python 3.14t is tested in CI and a wheel for macOS will be created for 3.14t. Python 3.13t is not officially tested or supported but may or may not work. There is limited testing for free-threading in this library and it does not aim to be thread safe out of the box. If you encounter any issues or problems with this scenario please raise an issue and we can look at possible options to fix this.

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

krb5-0.9.0.tar.gz (236.8 kB view details)

Uploaded Source

Built Distributions

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

krb5-0.9.0-cp314-cp314t-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

krb5-0.9.0-cp314-cp314t-macosx_10_15_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.14tmacOS 10.15+ x86-64

krb5-0.9.0-cp311-abi3-macosx_11_0_arm64.whl (939.5 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

krb5-0.9.0-cp311-abi3-macosx_10_9_x86_64.whl (913.5 kB view details)

Uploaded CPython 3.11+macOS 10.9+ x86-64

krb5-0.9.0-cp310-cp310-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

krb5-0.9.0-cp310-cp310-macosx_10_9_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

krb5-0.9.0-cp39-cp39-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

krb5-0.9.0-cp39-cp39-macosx_10_9_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

File details

Details for the file krb5-0.9.0.tar.gz.

File metadata

  • Download URL: krb5-0.9.0.tar.gz
  • Upload date:
  • Size: 236.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for krb5-0.9.0.tar.gz
Algorithm Hash digest
SHA256 4cdd2c85ff4770108edaf48fedf19888cf956ff374e2e97e40f8412b048caee6
MD5 2c9385c73c96e40dc4d9de0b0ee6cdbb
BLAKE2b-256 151555a01be5f1816fe6d7d36fec4c6b2cb6f5264d289a015322562c582a81b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for krb5-0.9.0.tar.gz:

Publisher: ci.yml on jborean93/pykrb5

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file krb5-0.9.0-cp314-cp314t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for krb5-0.9.0-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f9da4558a47ec105a1a2c185bb4b2d1dd90b7c021e3116895171f913ef048d03
MD5 cee76e5d6d434f9754a77f8d1342b04e
BLAKE2b-256 ca9fdf4e24995e0fea7792e8ab152124c65ac845e00ddfb4dd8f7d22907d122b

See more details on using hashes here.

Provenance

The following attestation bundles were made for krb5-0.9.0-cp314-cp314t-macosx_11_0_arm64.whl:

Publisher: ci.yml on jborean93/pykrb5

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file krb5-0.9.0-cp314-cp314t-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for krb5-0.9.0-cp314-cp314t-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 ea2ee73bb5aa7818ce50895fb29c276c7fe478c6eda121a5b66b0cc45fe2d42e
MD5 3094691b36407355d3bff03a7ffd2229
BLAKE2b-256 7db9fd0079f9208738bc09cf99208fc92cdf7d8b6a2a363af9a73256efa76399

See more details on using hashes here.

Provenance

The following attestation bundles were made for krb5-0.9.0-cp314-cp314t-macosx_10_15_x86_64.whl:

Publisher: ci.yml on jborean93/pykrb5

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file krb5-0.9.0-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: krb5-0.9.0-cp311-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 939.5 kB
  • Tags: CPython 3.11+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for krb5-0.9.0-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2bca06e7ce1551f3eb7f674508bc34d9f44fa1c9056f24120878ec9ab8e430cb
MD5 d283964a86d24599a995c2a132ccb75f
BLAKE2b-256 4132d2a9d977d23425777c0c5722947e6f0bc80882c7de15038bd02f9269c01a

See more details on using hashes here.

Provenance

The following attestation bundles were made for krb5-0.9.0-cp311-abi3-macosx_11_0_arm64.whl:

Publisher: ci.yml on jborean93/pykrb5

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file krb5-0.9.0-cp311-abi3-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: krb5-0.9.0-cp311-abi3-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 913.5 kB
  • Tags: CPython 3.11+, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for krb5-0.9.0-cp311-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7a021e869833bfed44ed4c9dfefd25813fab40a381ad4482b79ea36744545f62
MD5 24c1c379c0e5114fc344f5f33386ea61
BLAKE2b-256 1b4e0a35ae4821ca5f0491844d9343c816883b3218a265a4a95ecec66e76f239

See more details on using hashes here.

Provenance

The following attestation bundles were made for krb5-0.9.0-cp311-abi3-macosx_10_9_x86_64.whl:

Publisher: ci.yml on jborean93/pykrb5

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file krb5-0.9.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for krb5-0.9.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6e612e763304bfe4f6845f581030502327da2d0a19efccc840d7c051448ee209
MD5 f173e03fa3445d5e826d977c428fa30f
BLAKE2b-256 b49600a11ef3118690cf3b3c6554127e26c16006525bf34b0e22d6b27dca3dd9

See more details on using hashes here.

Provenance

The following attestation bundles were made for krb5-0.9.0-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: ci.yml on jborean93/pykrb5

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file krb5-0.9.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for krb5-0.9.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b1bde451ddb3a1c064be1da967fa32b1976a06ca43969e9d80ed8b26506ac4e3
MD5 057a3ab283e86b8193608a95043a07c2
BLAKE2b-256 7ded473605378e398642d8f8262544774b6673178325e0166fe56ec7a7884d0a

See more details on using hashes here.

Provenance

The following attestation bundles were made for krb5-0.9.0-cp310-cp310-macosx_10_9_x86_64.whl:

Publisher: ci.yml on jborean93/pykrb5

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file krb5-0.9.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

  • Download URL: krb5-0.9.0-cp39-cp39-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 1.0 MB
  • Tags: CPython 3.9, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for krb5-0.9.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7e78201d4b5a33fb3d12922c05626ffe2791125d26ee7ccdab95c8436bb58912
MD5 c69c9e74efe905c8d82326b6f327bb58
BLAKE2b-256 1ffdf941596aa7e2ddaeae98cdaba7c2568691385a506e39f99497df3f22599a

See more details on using hashes here.

Provenance

The following attestation bundles were made for krb5-0.9.0-cp39-cp39-macosx_11_0_arm64.whl:

Publisher: ci.yml on jborean93/pykrb5

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file krb5-0.9.0-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: krb5-0.9.0-cp39-cp39-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 1.0 MB
  • Tags: CPython 3.9, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for krb5-0.9.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 fecbd3b9187bf13c54955b534f7e938b17f43a7a006aa4158ab0eaeb938c692c
MD5 4e194880e3d1d23f8f95a02be09887a9
BLAKE2b-256 09e9b2c278c006fedb050e60fdedf6f6afc99d620790f68dc76d9424be2fe5fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for krb5-0.9.0-cp39-cp39-macosx_10_9_x86_64.whl:

Publisher: ci.yml on jborean93/pykrb5

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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