1

I want to access HDFS jceks (password alias is created) in python script for secure login. Can anyone help with with python code /steps to do so.

Thank you

shah
  • 35
  • 8

1 Answers1

4

You may use the hadoop configuration to access the password from python code.

Only thing you would need is to instanciate a hadoop configuration and use the property hadoop.security.credential.provider.path to set and retrieve the password using getPassword

You could use Spark also to read the jecks password from inside your code:

Python:

spark1 = SparkSession.builder.appName("xyz").master("yarn").enableHiveSupport().config("hive.exec.dynamic.partition", "true").config("hive.exec.dynamic.partition.mode", "nonstrict").getOrCreate()
x = spark1.sparkContext._jsc.hadoopConfiguration()
x.set("hadoop.security.credential.provider.path", "jceks://file///localpathtopassword")
a = x.getPassword("<password alias>")
passw = ""
for i in range(a.__len__()):
   passw = passw + str(a.__getitem__(i))

In the above code you shall get the password string in passw

jps
  • 20,041
  • 15
  • 75
  • 79
Rahul
  • 71
  • 3