You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hadoop.apache.org by canan chen <cc...@gmail.com> on 2016/08/22 06:22:08 UTC

Can I run a process under impersonation ?

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
  }
})