Skip to content

Commit f9cac7c

Browse files
committed
Install a security manager on startup
When Elasticsearch starts, we go through some initialization before we install a security manager. Yet, the JVM makes internal policy decisions on the basis of whether or not a security manager is present. This commit installs a security manager immediately on startup so that the JVM always thinks a security manager is present when making such policy decisions. Relates #21716
1 parent 26b9713 commit f9cac7c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

core/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import java.io.IOException;
3535
import java.nio.file.Path;
36+
import java.security.Permission;
3637
import java.util.Arrays;
3738
import java.util.Map;
3839

@@ -69,6 +70,14 @@ class Elasticsearch extends SettingCommand {
6970
* Main entry point for starting elasticsearch
7071
*/
7172
public static void main(final String[] args) throws Exception {
73+
// we want the JVM to think there is a security manager installed so that if internal policy decisions that would be based on the
74+
// presence of a security manager or lack thereof act as if there is a security manager present (e.g., DNS cache policy)
75+
System.setSecurityManager(new SecurityManager() {
76+
@Override
77+
public void checkPermission(Permission perm) {
78+
// grant all permissions so that we can later set the security manager to the one that we want
79+
}
80+
});
7281
final Elasticsearch elasticsearch = new Elasticsearch();
7382
int status = main(args, elasticsearch, Terminal.DEFAULT);
7483
if (status != ExitCodes.OK) {

0 commit comments

Comments
 (0)