Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for async TSaslClientTransport #297

Open
fireyyouth opened this issue Dec 24, 2024 · 2 comments
Open

support for async TSaslClientTransport #297

fireyyouth opened this issue Dec 24, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@fireyyouth
Copy link

fireyyouth commented Dec 24, 2024

  • background
    Our team used to rely on official python thrift client to access big data services (i.e. hbase, kafka, hive), through sasl authentication.
    We are planning to make everything async and thriftpy2 appears very suitable to our need af first glance.
  • problem
    there is a TSaslClientTransport class for sasl authentication, but can't be used in async mode.
  1. There is no example of how to use TSaslClientTransport , please provide one
  2. Is there any plan to support async version of of TSaslClientTransport ?
  3. Is there any workaround to make async and sasl work together?
@aisk aisk added the enhancement New feature or request label Jan 4, 2025
@aisk
Copy link
Member

aisk commented Jan 4, 2025

It's not very hard to implement a async version of TSaslClientTransport, you can try to just copy the https://github.com/Thriftpy/thriftpy2/blob/master/thriftpy2/transport/sasl/__init__.py to the async version folder of transport, and make some modifications (see the difference between async and non async version of framed and buffered transport class).

If you make it's done, please make a pull request and maybe we can merge it to the current codebase.

@fireyyouth
Copy link
Author

fireyyouth commented Jan 8, 2025

I tried implementing this feature as the above guide suggests, but could not make it work. I suspected the way I test might be wrong, so I decided to write a test for the exisiting TSaslClientTransport first. It turned out that I couldn't even get the existing TSaslClientTransport to work, the script I use to test is the following

  • main.sh
export KRB5_KTNAME=/path/to/my.keytab
export KRB5_CLIENT_KTNAME=/path/to/my.keytab
export KRB5_CONFIG=/path/to/krb5.conf
kinit -kt /path/to/my.keytab my-name
klist -kt
python3 hbase_client_sync.py
  • hbase_client_sync.py
import thriftpy2
import thriftpy2.rpc as rpc
import asyncio
from thriftpy2.transport import TSaslClientTransport
import sasl

HOST = 'hbase-thrift.mycompany.com'
PORT = 9090
USER = 'my-name'

class TSaslClientTransportFactory:
    def get_transport(self, trans):
        def make_sasl_client():
            client = sasl.Client()
            if not client.setAttr('host', HOST):
                raise 'error'
            if not client.setAttr('service', 'hbase'):
                raise 'error'
            if not client.setAttr('username', USER):
                raise 'error'
            if not client.setAttr('authname', USER):
                raise 'error'
            if not client.init():
                raise 'error'
            return client
        return TSaslClientTransport(make_sasl_client, 'GSSAPI', trans)

hbase_thrift = thriftpy2.load("Hbase.thrift", module_name="hbase_thrift")

def request():
    client = rpc.make_client(
        hbase_thrift.Hbase, HOST, PORT, trans_factory=TSaslClientTransportFactory())
    print(client.getTableNames())
    client.close()

request()
  • the python script throws exeption
Traceback (most recent call last):
  File "/thrift_demo/hbase_client_sync.py", line 35, in <module>
    request()
  File "/thrift_demo/hbase_client_sync.py", line 30, in request
    client = rpc.make_client(
  File "/usr/local/lib/python3.10/site-packages/thriftpy2/rpc.py", line 54, in make_client
    transport.open()
  File "thriftpy2/transport/sasl/cysasl.pyx", line 71, in thriftpy2.transport.sasl.cysasl.TCySaslClientTransport.open
thriftpy2.transport.base.TTransportException: TTransportException(type=1, message="Bad status: 3 (b'Failure to initialize security context')")

It would be very helpful if someone could provide a working example of TSaslClientTransport

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants