Question

I'm trying to communicate with HiveServer2 via ruby TCPSocket. As per Thrift SASL spec, I send START message and then plain auth information. Server returns COMPLETE status with an empty payload. It should return challenge as a payload but an empty string.

START    = 0x01
OK       = 0x02
COMPLETE = 0x05

auth = 'PLAIN'
header = [START, auth.length].pack('cl>')

auth_string = ['anonymous'].pack('u')
auth_message = "[LOGIN] \u0000 #{auth_string} \u0000 #{auth_string}"
auth_header = [OK, auth_message.length].pack('cl>')

socket = TCPSocket.new localhost, 10000
socket.write header + auth
socket.write auth_header + auth_message

socket.read(5).unpack('cl>')
=> [5,0]

HiveServer2 returns 5 status that is COMPLETE. No further communication is possible via this socket as the server returns nothing anymore.

I suspect auth_message constructed in a wrong way or something else is wrong.

Can anyone suggest the way HiveServer2 will understand my requests?

Any help will be appreciated.

UPD: Thrift SASL spec

UPD2: Solved! STARTTLS block should look like following below:

START    = 0x01
OK       = 0x02
COMPLETE = 0x05

auth = 'PLAIN'
header = [START, auth.length].pack('cl>')
auth_message = "[ANONYMOUS]\u0000anonymous\u0000anonymous"
auth_header = [OK, auth_message.length].pack('cl>')

socket = TCPSocket.new localhost, 10000
socket.write header + auth
socket.write auth_header + auth_message
socket.read(5).unpack('cl>')
=> [5,0]

After COMPLETE status received from the server, I can use TCLIService::Client to communicate with the HiveServer2. Only one thing to notice:

All writes to the underlying transport must be prefixed by the 4-byte length of the payload data, followed by the payload. All reads from this transport should read the 4-byte length word, then read the full quantity of bytes specified by this length word.

Was it helpful?

Solution

Try to use thrift gem and consider https://github.com/dallasmarlow/hiveserver2 instead of Ruby sockets.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top