Merge pull request #10970 from rmuir/bad_idea
bail if ES is run as root
This commit is contained in:
commit
f613413ce4
|
@ -90,6 +90,15 @@ public class Bootstrap {
|
||||||
if (mlockAll) {
|
if (mlockAll) {
|
||||||
Natives.tryMlockall();
|
Natives.tryMlockall();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if the user is running as root, and bail
|
||||||
|
if (Natives.definitelyRunningAsRoot()) {
|
||||||
|
if (Boolean.parseBoolean(System.getProperty("es.insecure.allow.root"))) {
|
||||||
|
Loggers.getLogger(Bootstrap.class).warn("running as ROOT user. this is a bad idea!");
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("don't run elasticsearch as root.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// listener for windows close event
|
// listener for windows close event
|
||||||
if (ctrlHandler) {
|
if (ctrlHandler) {
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class CLibrary {
|
||||||
|
|
||||||
public static native int mlockall(int flags);
|
public static native int mlockall(int flags);
|
||||||
|
|
||||||
public static native int munlockall();
|
public static native int geteuid();
|
||||||
|
|
||||||
private CLibrary() {
|
private CLibrary() {
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,19 @@ public class Natives {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns true if user is root, false if not, or if we don't know */
|
||||||
|
public static boolean definitelyRunningAsRoot() {
|
||||||
|
if (Constants.WINDOWS) {
|
||||||
|
return false; // don't know
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return CLibrary.geteuid() == 0;
|
||||||
|
} catch (Throwable error) {
|
||||||
|
logger.warn("unable to determine euid", error);
|
||||||
|
return false; // don't know
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void addConsoleCtrlHandler(ConsoleCtrlHandler handler) {
|
public static void addConsoleCtrlHandler(ConsoleCtrlHandler handler) {
|
||||||
// The console Ctrl handler is necessary on Windows platforms only.
|
// The console Ctrl handler is necessary on Windows platforms only.
|
||||||
|
|
Loading…
Reference in New Issue