Python GSSAPI Wrapper

1.11.1 · active · verified Thu Apr 09

The `gssapi` library provides a Python wrapper for the Generic Security Service Application Programming Interface (GSSAPI), enabling applications to perform secure authentication and communication over various security mechanisms like Kerberos. As of version 1.11.1, it's actively maintained with frequent patch releases and minor updates every few months, often improving platform support and build processes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create GSSAPI Name objects, which are fundamental for identity representation. Note that `gssapi` requires a system-level GSSAPI C library to function correctly.

import gssapi
from gssapi.names import KRB5_NT_PRINCIPAL_NAME, NT_HOSTBASED_SERVICE

# GSSAPI operations heavily rely on an underlying C GSSAPI library
# (e.g., Kerberos dev headers) being installed on the system.
# This example will likely raise GSSError if not properly configured.

try:
    # Example 1: Create a Kerberos principal name
    user_principal = "username@REALM.EXAMPLE.COM"
    name_user = gssapi.Name(user_principal, KRB5_NT_PRINCIPAL_NAME)
    print(f"Created user principal name: {name_user.display_name}")

    # Example 2: Create a host-based service name
    service_principal = "host/hostname.example.com@REALM.EXAMPLE.COM"
    name_service = gssapi.Name(service_principal, NT_HOSTBASED_SERVICE)
    print(f"Created service principal name: {name_service.display_name}")

except gssapi.exceptions.GSSError as e:
    print(f"WARNING: GSSAPI operation failed. "
          f"Ensure a GSSAPI C library (e.g., Kerberos dev headers) is installed and configured on your system. Error: {e}")
except ImportError:
    print("ERROR: 'gssapi' library not found. Please install it using 'pip install gssapi'.")

view raw JSON →