[ 
https://issues.apache.org/jira/browse/HDFS-16441?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17482907#comment-17482907
 ] 

xiaoqiuqiu commented on HDFS-16441:
-----------------------------------

from hdfs.ext.kerberos import KerberosClient
from krbcontext import krbcontext
import requests
import subprocess
keytab_file = '/home/xx/hadoop.keytab'
principal = '[email protected]'
session = requests.Session()
session.verify = False
class KerberosHdfsClient(object):
def __init__(self, keytab_path, principal, *args, **kwargs):
kt_cmd = 'kinit -kt ' + keytab_path + ' ' + principal # 
通过命令认证kerberos用户,且有效期为24小时
status = subprocess.call([kt_cmd], shell=True)
if status != 0:
print("kinit ERROR:")
print(subprocess.call([kt_cmd], shell=True))
self.generate_client("https://xx.xx.xx.xx:9871";)
exit()
def generate_client(self, hdfs_address):
client = KerberosClient(url=hdfs_address, session=session)
hdfs_save_path = '/user/hadoop/backup/2020-06-10'
client.makedirs(hdfs_save_path)
client.list("/")
# client = KerberosClient(hdfs_address, hostname_ov erride=hostname_override)
return client
client=KerberosHdfsClient('/home/xx/hadoop.keytab','hdfs/[email protected]')

> The following error occurs when accessing webhdfs in Kerberos security 
> mode:Failed to obtain user group information: java.io.IOException: Security 
> enabled but user not authenticated by filter
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HDFS-16441
>                 URL: https://issues.apache.org/jira/browse/HDFS-16441
>             Project: Hadoop HDFS
>          Issue Type: Bug
>          Components: 3.1.1
>    Affects Versions: 3.3.1
>            Reporter: xiaoqiuqiu
>            Priority: Major
>
> The following error occurs when accessing webhdfs in Kerberos security 
> mode:Failed to obtain user group information: java.io.IOException: Security 
> enabled but user not authenticated by filter



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to