Can I run a process under impersonation ?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Can I run a process under impersonation ?

canan chen

I'd like to use UGI.doAs to implement impersonation. But it seems I can not run a process in doAs. 

The following is my code,  the impersonation works if I call the FileSystem api directly, but it doesn't work if I run it in a process.  Could anyone help me on that ? Thanks

val ugi = UserGroupInformation.createProxyUser("userA", UserGroupInformation.getLoginUser)

ugi.doAs(new PrivilegedExceptionAction[Void] {
def run(): Void = {
val fs = FileSystem.get(new Configuration())
fs.globStatus(new Path(".")).foreach(println(_)) // it works in impersonation
println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
val processBuilder = new ProcessBuilder()
processBuilder.environment()
processBuilder.command("/Users/cc/hadoop-2.7.2/bin/hadoop", "fs", "-ls", ".") // it doesn't work in impersonation
processBuilder.inheritIO()
val proc = processBuilder.start()
proc.waitFor()
return null
}
})