Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bail if ES is run as root #10970

Merged
merged 1 commit into from May 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/main/java/org/elasticsearch/bootstrap/Bootstrap.java
Expand Up @@ -90,6 +90,15 @@ public static void initializeNatives(boolean mlockAll, boolean ctrlHandler) {
if (mlockAll) {
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
if (ctrlHandler) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/elasticsearch/common/jna/CLibrary.java
Expand Up @@ -48,7 +48,7 @@ public class CLibrary {

public static native int mlockall(int flags);

public static native int munlockall();
public static native int geteuid();

private CLibrary() {
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/elasticsearch/common/jna/Natives.java
Expand Up @@ -61,6 +61,19 @@ public static void tryMlockall() {
}
}
}

/** 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) {
// The console Ctrl handler is necessary on Windows platforms only.
Expand Down