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