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

Checks for user running as root not working in Windows (design) #4601

Closed
dbwiddis opened this issue Sep 26, 2022 · 2 comments · Fixed by #4656
Closed

Checks for user running as root not working in Windows (design) #4601

dbwiddis opened this issue Sep 26, 2022 · 2 comments · Fixed by #4656
Assignees
Labels
distributed framework enhancement Enhancement or improvement to existing feature or request v3.0.0 Issues and PRs related to version 3.0.0

Comments

@dbwiddis
Copy link
Member

dbwiddis commented Sep 26, 2022

Is your feature request related to a problem? Please describe.

Context: I am a committer at the JNA project and have been developing using JNA for 7 years.

The Bootstrap class prevents running OpenSearch as root via the definitelyRunningAsRoot() method:

// check if the user is running as root, and bail
if (Natives.definitelyRunningAsRoot()) {
throw new RuntimeException("can not run opensearch as root");
}

However, this check is failing on Windows by design... there's not even an attempt to check:

/** Returns true if user is root, false if not, or if we don't know */
static boolean definitelyRunningAsRoot() {
if (Constants.WINDOWS) {
return false; // don't know
}
try {
return JNACLibrary.geteuid() == 0;
} catch (UnsatisfiedLinkError e) {
// this will have already been logged by Kernel32Library, no need to repeat it
return false;
}
}

On macOS, if JNA is not available, we aren't sure: JNA Availability is determined here where an UnsatisfiedLinkError indicates failure to load the library. This will occur for two use case:

This is potentially problematic because the JNA dependency for building server is still at 5.5.0.

# when updating the JNA version, also update the version in buildSrc/build.gradle
jna = 5.5.0

// jna
api "net.java.dev.jna:jna:${versions.jna}"

However, it seems to work, possibly because the comment linked buildSrc directory seems to have 5.11.0, which may indicate that published "built" artifacts might work:

api "net.java.dev.jna:jna:5.11.0"

So I'm not clear where the 5.5 fits into the picture, but it could create problems.


Describe the solution you'd like

  1. Upgrade both JNA dependency versions linked above to the current JNA release, 5.12.1.

  2. Implement code to check whether the Windows version is running with elevated permissions by checking the current process's tokens for TOKEN_ELEVATION. I have implemented that code here.

I am happy to submit both changes if this issue is received favorably.

Describe alternatives you've considered
Status quo,and document the lack of checks.

Additional context

Pro: I'm not clear what the reasoning is for prohibiting running as root on Linux, but assuming that's a good thing we should extend it to all operating systems.

Con: This has the potential to break workflows for customers currently using macOS 11.x+ or Windows with elevated permissions, who don't know that's a bad idea.

@dbwiddis dbwiddis added enhancement Enhancement or improvement to existing feature or request untriaged labels Sep 26, 2022
@dbwiddis dbwiddis changed the title Checks for user running as root not working in macOS 11.x+ (bug) or Windows (design) Checks for user running as root not working in Windows (design) Sep 27, 2022
@anasalkouz
Copy link
Member

Hi @dbwiddis, It makes sense to extend this to other operating system, feel free to submit the changes. we would prefer to have those changes into the next major release.

@anasalkouz anasalkouz added v3.0.0 Issues and PRs related to version 3.0.0 and removed untriaged labels Sep 27, 2022
@dblock
Copy link
Member

dblock commented Sep 27, 2022

Upgrading JNA is a no-brainer as far as I am concerned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
distributed framework enhancement Enhancement or improvement to existing feature or request v3.0.0 Issues and PRs related to version 3.0.0
Projects
None yet
4 participants