|
40 | 40 | import org.elasticsearch.env.Environment; |
41 | 41 | import org.elasticsearch.index.IndexVersion; |
42 | 42 | import org.elasticsearch.jdk.JarHell; |
43 | | -import org.elasticsearch.jdk.RuntimeVersionFeature; |
44 | 43 | import org.elasticsearch.monitor.jvm.HotThreads; |
45 | 44 | import org.elasticsearch.monitor.jvm.JvmInfo; |
46 | 45 | import org.elasticsearch.monitor.os.OsProbe; |
|
58 | 57 | import java.lang.reflect.InvocationTargetException; |
59 | 58 | import java.nio.file.Files; |
60 | 59 | import java.nio.file.Path; |
61 | | -import java.security.Permission; |
62 | 60 | import java.security.Security; |
63 | 61 | import java.util.ArrayList; |
64 | 62 | import java.util.HashMap; |
|
72 | 70 | import java.util.stream.Collectors; |
73 | 71 | import java.util.stream.Stream; |
74 | 72 |
|
75 | | -import static org.elasticsearch.bootstrap.BootstrapSettings.SECURITY_FILTER_BAD_DEFAULTS_SETTING; |
76 | 73 | import static org.elasticsearch.nativeaccess.WindowsFunctions.ConsoleCtrlHandler.CTRL_CLOSE_EVENT; |
77 | 74 |
|
78 | 75 | /** |
@@ -128,20 +125,6 @@ private static Bootstrap initPhase1() { |
128 | 125 | final boolean useEntitlements = true; |
129 | 126 | try { |
130 | 127 | initSecurityProperties(); |
131 | | - |
132 | | - /* |
133 | | - * We want the JVM to think there is a security manager installed so that if internal policy decisions that would be based on |
134 | | - * the presence of a security manager or lack thereof act as if there is a security manager present (e.g., DNS cache policy). |
135 | | - * This forces such policies to take effect immediately. |
136 | | - */ |
137 | | - if (useEntitlements == false && RuntimeVersionFeature.isSecurityManagerAvailable()) { |
138 | | - org.elasticsearch.bootstrap.Security.setSecurityManager(new SecurityManager() { |
139 | | - @Override |
140 | | - public void checkPermission(Permission perm) { |
141 | | - // grant all permissions so that we can later set the security manager to the one that we want |
142 | | - } |
143 | | - }); |
144 | | - } |
145 | 128 | LogConfigurator.registerErrorListener(); |
146 | 129 |
|
147 | 130 | BootstrapInfo.init(); |
@@ -230,61 +213,47 @@ private static void initPhase2(Bootstrap bootstrap) throws IOException { |
230 | 213 |
|
231 | 214 | final PluginsLoader pluginsLoader; |
232 | 215 |
|
233 | | - if (bootstrap.useEntitlements()) { |
234 | | - LogManager.getLogger(Elasticsearch.class).info("Bootstrapping Entitlements"); |
235 | | - |
236 | | - var pluginData = Stream.concat( |
237 | | - modulesBundles.stream() |
238 | | - .map(bundle -> new PolicyUtils.PluginData(bundle.getDir(), bundle.pluginDescriptor().isModular(), false)), |
239 | | - pluginsBundles.stream() |
240 | | - .map(bundle -> new PolicyUtils.PluginData(bundle.getDir(), bundle.pluginDescriptor().isModular(), true)) |
241 | | - ).toList(); |
242 | | - |
243 | | - var pluginPolicyPatches = collectPluginPolicyPatches(modulesBundles, pluginsBundles, logger); |
244 | | - var pluginPolicies = PolicyUtils.createPluginPolicies(pluginData, pluginPolicyPatches, Build.current().version()); |
245 | | - var serverPolicyPatch = PolicyUtils.parseEncodedPolicyIfExists( |
246 | | - System.getProperty(SERVER_POLICY_PATCH_NAME), |
247 | | - Build.current().version(), |
248 | | - false, |
249 | | - "server", |
250 | | - PolicyManager.SERVER_LAYER_MODULES.stream().map(Module::getName).collect(Collectors.toUnmodifiableSet()) |
251 | | - ); |
| 216 | + LogManager.getLogger(Elasticsearch.class).info("Bootstrapping Entitlements"); |
| 217 | + |
| 218 | + var pluginData = Stream.concat( |
| 219 | + modulesBundles.stream() |
| 220 | + .map(bundle -> new PolicyUtils.PluginData(bundle.getDir(), bundle.pluginDescriptor().isModular(), false)), |
| 221 | + pluginsBundles.stream().map(bundle -> new PolicyUtils.PluginData(bundle.getDir(), bundle.pluginDescriptor().isModular(), true)) |
| 222 | + ).toList(); |
| 223 | + |
| 224 | + var pluginPolicyPatches = collectPluginPolicyPatches(modulesBundles, pluginsBundles, logger); |
| 225 | + var pluginPolicies = PolicyUtils.createPluginPolicies(pluginData, pluginPolicyPatches, Build.current().version()); |
| 226 | + var serverPolicyPatch = PolicyUtils.parseEncodedPolicyIfExists( |
| 227 | + System.getProperty(SERVER_POLICY_PATCH_NAME), |
| 228 | + Build.current().version(), |
| 229 | + false, |
| 230 | + "server", |
| 231 | + PolicyManager.SERVER_LAYER_MODULES.stream().map(Module::getName).collect(Collectors.toUnmodifiableSet()) |
| 232 | + ); |
252 | 233 |
|
253 | | - pluginsLoader = PluginsLoader.createPluginsLoader(modulesBundles, pluginsBundles, findPluginsWithNativeAccess(pluginPolicies)); |
254 | | - |
255 | | - var scopeResolver = ScopeResolver.create(pluginsLoader.pluginLayers(), APM_AGENT_PACKAGE_NAME); |
256 | | - Map<String, Path> sourcePaths = Stream.concat(modulesBundles.stream(), pluginsBundles.stream()) |
257 | | - .collect(Collectors.toUnmodifiableMap(bundle -> bundle.pluginDescriptor().getName(), PluginBundle::getDir)); |
258 | | - EntitlementBootstrap.bootstrap( |
259 | | - serverPolicyPatch, |
260 | | - pluginPolicies, |
261 | | - scopeResolver::resolveClassToScope, |
262 | | - nodeEnv.settings()::getValues, |
263 | | - nodeEnv.dataDirs(), |
264 | | - nodeEnv.repoDirs(), |
265 | | - nodeEnv.configDir(), |
266 | | - nodeEnv.libDir(), |
267 | | - nodeEnv.modulesDir(), |
268 | | - nodeEnv.pluginsDir(), |
269 | | - sourcePaths, |
270 | | - nodeEnv.logsDir(), |
271 | | - nodeEnv.tmpDir(), |
272 | | - args.pidFile(), |
273 | | - Set.of(EntitlementSelfTester.class) |
274 | | - ); |
275 | | - EntitlementSelfTester.entitlementSelfTest(); |
276 | | - } else { |
277 | | - assert RuntimeVersionFeature.isSecurityManagerAvailable(); |
278 | | - // no need to explicitly enable native access for legacy code |
279 | | - pluginsLoader = PluginsLoader.createPluginsLoader(modulesBundles, pluginsBundles, Map.of()); |
280 | | - // install SM after natives, shutdown hooks, etc. |
281 | | - LogManager.getLogger(Elasticsearch.class).info("Bootstrapping java SecurityManager"); |
282 | | - org.elasticsearch.bootstrap.Security.configure( |
283 | | - nodeEnv, |
284 | | - SECURITY_FILTER_BAD_DEFAULTS_SETTING.get(args.nodeSettings()), |
285 | | - args.pidFile() |
286 | | - ); |
287 | | - } |
| 234 | + pluginsLoader = PluginsLoader.createPluginsLoader(modulesBundles, pluginsBundles, findPluginsWithNativeAccess(pluginPolicies)); |
| 235 | + |
| 236 | + var scopeResolver = ScopeResolver.create(pluginsLoader.pluginLayers(), APM_AGENT_PACKAGE_NAME); |
| 237 | + Map<String, Path> sourcePaths = Stream.concat(modulesBundles.stream(), pluginsBundles.stream()) |
| 238 | + .collect(Collectors.toUnmodifiableMap(bundle -> bundle.pluginDescriptor().getName(), PluginBundle::getDir)); |
| 239 | + EntitlementBootstrap.bootstrap( |
| 240 | + serverPolicyPatch, |
| 241 | + pluginPolicies, |
| 242 | + scopeResolver::resolveClassToScope, |
| 243 | + nodeEnv.settings()::getValues, |
| 244 | + nodeEnv.dataDirs(), |
| 245 | + nodeEnv.repoDirs(), |
| 246 | + nodeEnv.configDir(), |
| 247 | + nodeEnv.libDir(), |
| 248 | + nodeEnv.modulesDir(), |
| 249 | + nodeEnv.pluginsDir(), |
| 250 | + sourcePaths, |
| 251 | + nodeEnv.logsDir(), |
| 252 | + nodeEnv.tmpDir(), |
| 253 | + args.pidFile(), |
| 254 | + Set.of(EntitlementSelfTester.class) |
| 255 | + ); |
| 256 | + EntitlementSelfTester.entitlementSelfTest(); |
288 | 257 |
|
289 | 258 | bootstrap.setPluginsLoader(pluginsLoader); |
290 | 259 | } |
|
0 commit comments