I am writing a server program in Java that will allow users to submit jobs using DRMAA. Although the main server process works as it is root, all it does is authenticate the user and then run another Java program that works as that user, and actually does the job to comply with the principle of minimizing privileges. Initially, I did this with Runtime.exec()and sudo(example below), which works fine until the process is fixed, and at that moment it is sudofrustrated because it does not have a terminal.
String[] command = {"sudo", "-i", "-u", username, java, theOtherJavaProgram};
Runtime.getRuntime().exec(command, null, getHomeDirectory(username));
What is the best way to make this fork and drop privilege pattern in Java when running as a daemon? Is there any way? Should I break out of C and learn how to create JVMs with JNI?
source
share