This is a Python library (version 0.4.3) that provides SASL (Simple Authentication and Security Layer) transport for Apache Thrift clients. It enables secure communication by implementing `TSaslClientTransport`, allowing Thrift applications to use authentication mechanisms like Kerberos. The library has a maintenance release cadence, with the latest update in May 2021.
pip install thrift-saslVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `TSaslClientTransport` using `TSocket` and `TBufferedTransport`, configure it for a SASL mechanism (like PLAIN), and open the connection. This setup is the foundational step before creating a Thrift client and making RPC calls.
Upgrade to `thrift-sasl>=0.4.3`. If using an older version, consider installing `pure-sasl` manually and ensuring your environment is correctly configured, or ideally, upgrade.
Consult your Thrift server's SASL configuration documentation. Verify the SASL mechanism, authentication credentials, and any required service principals. Use `os.environ.get` for sensitive data like passwords/principals.
Always use `TTransport.TBufferedTransport(TSocket.TSocket(...))` when initializing `TSaslClientTransport` to prevent potential data framing or read issues.
Instead of passing authentication parameters directly to `TSaslClientTransport`, create and configure a `TSaslClient` instance (e.g., `sasl_client = TSaslClient(mechanism='PLAIN'); sasl_client.setUname('your_username'); sasl_client.setPasswd('your_password')`). Then, pass this configured `TSaslClient` object as the second argument to `TSaslClientTransport` (e.g., `TSaslClientTransport(buffered_transport, sasl_client)`). Consult `thrift-sasl` documentation for specific API usage.Consult the `thrift-sasl` documentation for version 0.5.0 or later. For SASL mechanisms requiring username/password (e.g., PLAIN, LOGIN), these credentials must now be passed within the `mechanism_properties` dictionary. For example: `TSaslClientTransport(..., mechanism='PLAIN', mechanism_properties={'username': 'user', 'password': 'pass'})`. For GSSAPI, ensure Kerberos tickets are configured externally.Install `python-sasl` and ensure the necessary system development libraries for SASL (e.g., `libsasl2-dev` on Debian/Ubuntu, `cyrus-sasl-devel` on CentOS/RHEL) are present before installing it. ```bash pip install python-sasl # On Debian/Ubuntu: # sudo apt-get install libsasl2-dev python3-dev libkrb5-dev # On CentOS/RHEL: # sudo yum install cyrus-sasl-devel python3-devel krb5-devel ```
Obtain a valid Kerberos ticket for your principal by running the `kinit` command before attempting to connect. ```bash kinit your_principal@YOUR.REALM ```
Install the library using pip. ```bash pip install thrift-sasl ```
Ensure the GSSAPI SASL plugin is installed (e.g., `libsasl2-modules-gssapi-mit` on Debian/Ubuntu), and verify that the `service` parameter in `TSaslClientTransport` matches the Kerberos service principal for the server (e.g., 'impala' for `impala/host@REALM`).
```python
# In your Python code:
from thrift_sasl import TSaslClientTransport
# ... (inner_transport setup)
sasl_transport = TSaslClientTransport(
inner_transport,
host='your_server_host',
service='impala' # Example: For a service principal like 'impala/host@REALM'
)
```