import json, os
from hdfs.ext.kerberos import KerberosClient
from krbcontext import krbcontext
def _connect(self, host, port, sso_ticket=None):
try:
hdfs_url = 'http://' + host + ':' + port
active_str = 'kinit -kt {0} {1}'.format(self.keytab_file, self.user)
# 激活当前kerberos用户认证,因为python缓存机制,切换用户,这个缓存不会自动切换,需要手动处理下
os.system(active_str)
with krbcontext(using_keytab=True, keytab_file=self.keytab_file, principal=self.user):
self.client = KerberosClient(hdfs_url)
except Exception as e:
raise e
基于kerberos认证的 python操作hdfs
最新推荐文章于 2024-10-09 09:15:01 发布