From 50864eabce62dc8b8bff0814abb8c573d9b9389a Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Sat, 20 Jan 2018 15:56:00 -0500 Subject: [PATCH] Introduce plugin-specific env scripts With plugins of a meta-plugin now loaded in separate classloaders, we should not be loading all classes in all plugins of a meta-plugin when executing scripts. This is particularly problematic in the case of security extensions where the install plugin extension command would be running with the classpath of all plugins. However, if there is JAR hell in this classpath, installation would fail. This is not realistic though since the plugins are run in separate classloaders. To fix this, for the scripts of a plugin, we only set the classpath to include the JARs for that plugin and the JARs of core. This leads us to the introduction of plugin-specific env scripts. Relates elastic/x-pack-elasticsearch#3649 Original commit: elastic/x-pack-elasticsearch@543df37eedf369969d78ac5facae43d2f4638ad3 --- plugin/core/src/main/bin/x-pack-env | 5 ----- plugin/core/src/main/bin/x-pack-env.bat | 5 ----- plugin/security/src/main/bin/certgen | 2 +- plugin/security/src/main/bin/certgen.bat | 2 +- plugin/security/src/main/bin/certutil | 2 +- plugin/security/src/main/bin/certutil.bat | 2 +- plugin/{core => security}/src/main/bin/extension | 2 +- plugin/{core => security}/src/main/bin/extension.bat | 2 +- plugin/security/src/main/bin/migrate | 2 +- plugin/security/src/main/bin/migrate.bat | 2 +- plugin/security/src/main/bin/setup-passwords | 2 +- plugin/security/src/main/bin/setup-passwords.bat | 2 +- plugin/security/src/main/bin/syskeygen | 2 +- plugin/security/src/main/bin/syskeygen.bat | 2 +- plugin/security/src/main/bin/users | 2 +- plugin/security/src/main/bin/users.bat | 2 +- plugin/security/src/main/bin/x-pack-security-env | 10 ++++++++++ plugin/security/src/main/bin/x-pack-security-env.bat | 7 +++++++ plugin/watcher/src/main/bin/croneval | 2 +- plugin/watcher/src/main/bin/croneval.bat | 2 +- plugin/watcher/src/main/bin/x-pack-watcher-env | 10 ++++++++++ plugin/watcher/src/main/bin/x-pack-watcher-env.bat | 7 +++++++ 22 files changed, 50 insertions(+), 26 deletions(-) rename plugin/{core => security}/src/main/bin/extension (91%) rename plugin/{core => security}/src/main/bin/extension.bat (91%) create mode 100644 plugin/security/src/main/bin/x-pack-security-env create mode 100644 plugin/security/src/main/bin/x-pack-security-env.bat create mode 100644 plugin/watcher/src/main/bin/x-pack-watcher-env create mode 100644 plugin/watcher/src/main/bin/x-pack-watcher-env.bat diff --git a/plugin/core/src/main/bin/x-pack-env b/plugin/core/src/main/bin/x-pack-env index 504014acc4b..9daa1f6a16c 100644 --- a/plugin/core/src/main/bin/x-pack-env +++ b/plugin/core/src/main/bin/x-pack-env @@ -5,8 +5,3 @@ # you may not use this file except in compliance with the Elastic License. ES_CLASSPATH="$ES_CLASSPATH:$ES_HOME/plugins/x-pack/x-pack-core/*" -ES_CLASSPATH="$ES_CLASSPATH:$ES_HOME/plugins/x-pack/x-pack-logstash/*" -ES_CLASSPATH="$ES_CLASSPATH:$ES_HOME/plugins/x-pack/x-pack-ml/*" -ES_CLASSPATH="$ES_CLASSPATH:$ES_HOME/plugins/x-pack/x-pack-monitoring/*" -ES_CLASSPATH="$ES_CLASSPATH:$ES_HOME/plugins/x-pack/x-pack-security/*" -ES_CLASSPATH="$ES_CLASSPATH:$ES_HOME/plugins/x-pack/x-pack-watcher/*" diff --git a/plugin/core/src/main/bin/x-pack-env.bat b/plugin/core/src/main/bin/x-pack-env.bat index f40a0b9b53c..f12b689a724 100644 --- a/plugin/core/src/main/bin/x-pack-env.bat +++ b/plugin/core/src/main/bin/x-pack-env.bat @@ -3,8 +3,3 @@ rem or more contributor license agreements. Licensed under the Elastic License; rem you may not use this file except in compliance with the Elastic License. set ES_CLASSPATH=!ES_CLASSPATH!;!ES_HOME!/plugins/x-pack/x-pack-core/* -set ES_CLASSPATH=!ES_CLASSPATH!;!ES_HOME!/plugins/x-pack/x-pack-logstash* -set ES_CLASSPATH=!ES_CLASSPATH!;!ES_HOME!/plugins/x-pack/x-pack-ml/* -set ES_CLASSPATH=!ES_CLASSPATH!;!ES_HOME!/plugins/x-pack/x-pack-monitoring/* -set ES_CLASSPATH=!ES_CLASSPATH!;!ES_HOME!/plugins/x-pack/x-pack-security/* -set ES_CLASSPATH=!ES_CLASSPATH!;!ES_HOME!/plugins/x-pack/x-pack-watcher/* diff --git a/plugin/security/src/main/bin/certgen b/plugin/security/src/main/bin/certgen index 4bda8ce90f5..e15f01907fd 100644 --- a/plugin/security/src/main/bin/certgen +++ b/plugin/security/src/main/bin/certgen @@ -6,7 +6,7 @@ source "`dirname "$0"`"/../elasticsearch-env -source "`dirname "$0"`"/x-pack-env +source "`dirname "$0"`"/x-pack-security-env exec \ "$JAVA" \ diff --git a/plugin/security/src/main/bin/certgen.bat b/plugin/security/src/main/bin/certgen.bat index 91c3d931853..dc1563930fd 100644 --- a/plugin/security/src/main/bin/certgen.bat +++ b/plugin/security/src/main/bin/certgen.bat @@ -9,7 +9,7 @@ setlocal enableextensions call "%~dp0..\elasticsearch-env.bat" || exit /b 1 -call "%~dp0x-pack-env.bat" || exit /b 1 +call "%~dp0x-pack-security-env.bat" || exit /b 1 %JAVA% ^ %ES_JAVA_OPTS% ^ diff --git a/plugin/security/src/main/bin/certutil b/plugin/security/src/main/bin/certutil index 9e64004a405..1cdf2181594 100644 --- a/plugin/security/src/main/bin/certutil +++ b/plugin/security/src/main/bin/certutil @@ -6,7 +6,7 @@ source "`dirname "$0"`"/../elasticsearch-env -source "`dirname "$0"`"/x-pack-env +source "`dirname "$0"`"/x-pack-security-env exec \ "$JAVA" \ diff --git a/plugin/security/src/main/bin/certutil.bat b/plugin/security/src/main/bin/certutil.bat index e4ee1adb949..3152c2db587 100644 --- a/plugin/security/src/main/bin/certutil.bat +++ b/plugin/security/src/main/bin/certutil.bat @@ -9,7 +9,7 @@ setlocal enableextensions call "%~dp0..\elasticsearch-env.bat" || exit /b 1 -call "%~dp0x-pack-env.bat" || exit /b 1 +call "%~dp0x-pack-security-env.bat" || exit /b 1 %JAVA% ^ %ES_JAVA_OPTS% ^ diff --git a/plugin/core/src/main/bin/extension b/plugin/security/src/main/bin/extension similarity index 91% rename from plugin/core/src/main/bin/extension rename to plugin/security/src/main/bin/extension index 9a2c103bf14..9a0773f8a06 100755 --- a/plugin/core/src/main/bin/extension +++ b/plugin/security/src/main/bin/extension @@ -6,7 +6,7 @@ source "`dirname "$0"`"/../elasticsearch-env -source "`dirname "$0"`"/x-pack-env +source "`dirname "$0"`"/x-pack-security-env exec \ "$JAVA" \ diff --git a/plugin/core/src/main/bin/extension.bat b/plugin/security/src/main/bin/extension.bat similarity index 91% rename from plugin/core/src/main/bin/extension.bat rename to plugin/security/src/main/bin/extension.bat index 663d480bbe3..f9daf77f3db 100644 --- a/plugin/core/src/main/bin/extension.bat +++ b/plugin/security/src/main/bin/extension.bat @@ -9,7 +9,7 @@ setlocal enableextensions call "%~dp0..\elasticsearch-env.bat" || exit /b 1 -call "%~dp0x-pack-env.bat" || exit /b 1 +call "%~dp0x-pack-security-env.bat" || exit /b 1 %JAVA% ^ %ES_JAVA_OPTS% ^ diff --git a/plugin/security/src/main/bin/migrate b/plugin/security/src/main/bin/migrate index 640363d8815..f87b50aec0a 100755 --- a/plugin/security/src/main/bin/migrate +++ b/plugin/security/src/main/bin/migrate @@ -6,7 +6,7 @@ source "`dirname "$0"`"/../elasticsearch-env -source "`dirname "$0"`"/x-pack-env +source "`dirname "$0"`"/x-pack-security-env exec \ "$JAVA" \ diff --git a/plugin/security/src/main/bin/migrate.bat b/plugin/security/src/main/bin/migrate.bat index fc39dad84f0..e0aa1579421 100644 --- a/plugin/security/src/main/bin/migrate.bat +++ b/plugin/security/src/main/bin/migrate.bat @@ -9,7 +9,7 @@ setlocal enableextensions call "%~dp0..\elasticsearch-env.bat" || exit /b 1 -call "%~dp0x-pack-env.bat" || exit /b 1 +call "%~dp0x-pack-security-env.bat" || exit /b 1 %JAVA% ^ %ES_JAVA_OPTS% ^ diff --git a/plugin/security/src/main/bin/setup-passwords b/plugin/security/src/main/bin/setup-passwords index d434271c834..01f1020ffee 100644 --- a/plugin/security/src/main/bin/setup-passwords +++ b/plugin/security/src/main/bin/setup-passwords @@ -6,7 +6,7 @@ source "`dirname "$0"`"/../elasticsearch-env -source "`dirname "$0"`"/x-pack-env +source "`dirname "$0"`"/x-pack-security-env exec \ "$JAVA" \ diff --git a/plugin/security/src/main/bin/setup-passwords.bat b/plugin/security/src/main/bin/setup-passwords.bat index 78245b32db9..2ebbfd26760 100644 --- a/plugin/security/src/main/bin/setup-passwords.bat +++ b/plugin/security/src/main/bin/setup-passwords.bat @@ -9,7 +9,7 @@ setlocal enableextensions call "%~dp0..\elasticsearch-env.bat" || exit /b 1 -call "%~dp0x-pack-env.bat" || exit /b 1 +call "%~dp0x-pack-security-env.bat" || exit /b 1 %JAVA% ^ %ES_JAVA_OPTS% ^ diff --git a/plugin/security/src/main/bin/syskeygen b/plugin/security/src/main/bin/syskeygen index b03c299e77d..1efbd997ea2 100755 --- a/plugin/security/src/main/bin/syskeygen +++ b/plugin/security/src/main/bin/syskeygen @@ -6,7 +6,7 @@ source "`dirname "$0"`"/../elasticsearch-env -source "`dirname "$0"`"/x-pack-env +source "`dirname "$0"`"/x-pack-security-env exec \ "$JAVA" \ diff --git a/plugin/security/src/main/bin/syskeygen.bat b/plugin/security/src/main/bin/syskeygen.bat index 95b225ccd37..0cfbb65eed9 100644 --- a/plugin/security/src/main/bin/syskeygen.bat +++ b/plugin/security/src/main/bin/syskeygen.bat @@ -9,7 +9,7 @@ setlocal enableextensions call "%~dp0..\elasticsearch-env.bat" || exit /b 1 -call "%~dp0x-pack-env.bat" || exit /b 1 +call "%~dp0x-pack-security-env.bat" || exit /b 1 %JAVA% ^ %ES_JAVA_OPTS% ^ diff --git a/plugin/security/src/main/bin/users b/plugin/security/src/main/bin/users index 8729cdb3910..228bde3f1a7 100755 --- a/plugin/security/src/main/bin/users +++ b/plugin/security/src/main/bin/users @@ -6,7 +6,7 @@ source "`dirname "$0"`"/../elasticsearch-env -source "`dirname "$0"`"/x-pack-env +source "`dirname "$0"`"/x-pack-security-env exec \ "$JAVA" \ diff --git a/plugin/security/src/main/bin/users.bat b/plugin/security/src/main/bin/users.bat index 62f0efff877..48a6d9f7bf2 100644 --- a/plugin/security/src/main/bin/users.bat +++ b/plugin/security/src/main/bin/users.bat @@ -9,7 +9,7 @@ setlocal enableextensions call "%~dp0..\elasticsearch-env.bat" || exit /b 1 -call "%~dp0x-pack-env.bat" || exit /b 1 +call "%~dp0x-pack-security-env.bat" || exit /b 1 %JAVA% ^ %ES_JAVA_OPTS% ^ diff --git a/plugin/security/src/main/bin/x-pack-security-env b/plugin/security/src/main/bin/x-pack-security-env new file mode 100644 index 00000000000..a38eff3da14 --- /dev/null +++ b/plugin/security/src/main/bin/x-pack-security-env @@ -0,0 +1,10 @@ +#!/bin/bash + +# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +# or more contributor license agreements. Licensed under the Elastic License; +# you may not use this file except in compliance with the Elastic License. + +source "`dirname "$0"`"/x-pack-env + +# include x-pack-security jars in classpath +ES_CLASSPATH="$ES_CLASSPATH:$ES_HOME/plugins/x-pack/x-pack-security/*" diff --git a/plugin/security/src/main/bin/x-pack-security-env.bat b/plugin/security/src/main/bin/x-pack-security-env.bat new file mode 100644 index 00000000000..6836612feb3 --- /dev/null +++ b/plugin/security/src/main/bin/x-pack-security-env.bat @@ -0,0 +1,7 @@ +rem Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +rem or more contributor license agreements. Licensed under the Elastic License; +rem you may not use this file except in compliance with the Elastic License. + +call "%~dp0x-pack-env.bat" || exit /b 1 + +set ES_CLASSPATH=!ES_CLASSPATH!;!ES_HOME!/plugins/x-pack/x-pack-security/* diff --git a/plugin/watcher/src/main/bin/croneval b/plugin/watcher/src/main/bin/croneval index 0bca5c2defb..de0bcd86859 100755 --- a/plugin/watcher/src/main/bin/croneval +++ b/plugin/watcher/src/main/bin/croneval @@ -6,7 +6,7 @@ source "`dirname "$0"`"/../elasticsearch-env -source "`dirname "$0"`"/x-pack-env +source "`dirname "$0"`"/x-pack-watcher-env exec \ "$JAVA" \ diff --git a/plugin/watcher/src/main/bin/croneval.bat b/plugin/watcher/src/main/bin/croneval.bat index a4fa9b11335..cc6d5fd80a0 100644 --- a/plugin/watcher/src/main/bin/croneval.bat +++ b/plugin/watcher/src/main/bin/croneval.bat @@ -9,7 +9,7 @@ setlocal enableextensions call "%~dp0..\elasticsearch-env.bat" || exit /b 1 -call "%~dp0x-pack-env.bat" || exit /b 1 +call "%~dp0x-pack-watcher-env.bat" || exit /b 1 %JAVA% ^ %ES_JAVA_OPTS% ^ diff --git a/plugin/watcher/src/main/bin/x-pack-watcher-env b/plugin/watcher/src/main/bin/x-pack-watcher-env new file mode 100644 index 00000000000..78bcbe61c32 --- /dev/null +++ b/plugin/watcher/src/main/bin/x-pack-watcher-env @@ -0,0 +1,10 @@ +#!/bin/bash + +# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +# or more contributor license agreements. Licensed under the Elastic License; +# you may not use this file except in compliance with the Elastic License. + +source "`dirname "$0"`"/x-pack-env + +# include x-pack-security jars in classpath +ES_CLASSPATH="$ES_CLASSPATH:$ES_HOME/plugins/x-pack/x-pack-watcher/*" diff --git a/plugin/watcher/src/main/bin/x-pack-watcher-env.bat b/plugin/watcher/src/main/bin/x-pack-watcher-env.bat new file mode 100644 index 00000000000..a55e6964705 --- /dev/null +++ b/plugin/watcher/src/main/bin/x-pack-watcher-env.bat @@ -0,0 +1,7 @@ +rem Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +rem or more contributor license agreements. Licensed under the Elastic License; +rem you may not use this file except in compliance with the Elastic License. + +call "%~dp0x-pack-env.bat" || exit /b 1 + +set ES_CLASSPATH=!ES_CLASSPATH!;!ES_HOME!/plugins/x-pack/x-pack-watcher/*