xuzikun2003 commented on a change in pull request #24421:
[SPARK-12312][SQL]Support Kerberos login in JDBC connector
URL: https://github.com/apache/spark/pull/24421#discussion_r372032531
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala
##########
@@ -61,7 +65,23 @@ object JdbcUtils extends Logging {
throw new IllegalStateException(
s"Did not find registered driver with class $driverClass")
}
- val connection: Connection = driver.connect(options.url,
options.asConnectionProperties)
+
+ val connection: Connection = {
+ if (options.keytab != null && options.principal != null) {
+ val keytabFileName = FilenameUtils.getName(options.keytab)
+ UserGroupInformation
+ .loginUserFromKeytabAndReturnUGI(options.principal, keytabFileName)
+ .doAs(new PrivilegedAction[Connection] {
+ override def run(): Connection = {
+ driver.connect(options.url, options.asConnectionProperties)
+ }
+ })
+ }
+ else {
Review comment:
> I see an issue with
`UserGroupInformation.loginUserFromKeytabAndReturnUGI(options.principal,
keytabFileName)`
>
> This would replace static field on UGI for keytab and principal. So
further call to UGI for for hadoop may not work.
>
> I think better approach would be to not to rely on UGI. instead do login
using LoginContext and wrap call with Subject.doAs(subject,...)
Good suggestion. I will give a try and if it works I will update this PR.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]