Skip to content

Commit 9cf033d

Browse files
authored
Merge branch 'main' into cache-interface
2 parents 0e717f8 + 02eea4e commit 9cf033d

File tree

15 files changed

+78
-54
lines changed

15 files changed

+78
-54
lines changed

libs/entitlement/src/main/java/org/elasticsearch/entitlement/bootstrap/EntitlementBootstrap.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ private static PolicyManager createPolicyManager(
161161
PathLookup pathLookup,
162162
Policy serverPolicyPatch,
163163
Function<Class<?>, PolicyManager.PolicyScope> scopeResolver,
164-
Map<String, Collection<Path>> pluginSourcePaths
164+
Map<String, Collection<Path>> pluginSourcePathsResolver
165165
) {
166166
FilesEntitlementsValidation.validate(pluginPolicies, pathLookup);
167167

@@ -170,7 +170,7 @@ private static PolicyManager createPolicyManager(
170170
HardcodedEntitlements.agentEntitlements(),
171171
pluginPolicies,
172172
scopeResolver,
173-
pluginSourcePaths,
173+
pluginSourcePathsResolver::get,
174174
pathLookup
175175
);
176176
}

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/PathLookup.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@
99

1010
package org.elasticsearch.entitlement.runtime.policy;
1111

12+
import org.elasticsearch.core.PathUtils;
13+
1214
import java.nio.file.Path;
1315
import java.util.stream.Stream;
1416

1517
/**
1618
* Resolves paths for known directories checked by entitlements.
1719
*/
1820
public interface PathLookup {
21+
Class<?> DEFAULT_FILESYSTEM_CLASS = PathUtils.getDefaultFileSystem().getClass();
22+
1923
enum BaseDir {
2024
USER_HOME,
2125
CONFIG,
@@ -37,4 +41,6 @@ enum BaseDir {
3741
* paths of the given {@code baseDir}.
3842
*/
3943
Stream<Path> resolveSettingPaths(BaseDir baseDir, String settingName);
44+
45+
boolean isPathOnDefaultFilesystem(Path path);
4046
}

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/PathLookupImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,9 @@ public Stream<Path> resolveSettingPaths(BaseDir baseDir, String settingName) {
7575
.toList();
7676
return getBaseDirPaths(baseDir).flatMap(path -> relativePaths.stream().map(path::resolve));
7777
}
78+
79+
@Override
80+
public boolean isPathOnDefaultFilesystem(Path path) {
81+
return path.getFileSystem().getClass() == DEFAULT_FILESYSTEM_CLASS;
82+
}
7883
}

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/PolicyCheckerImpl.java

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

1010
package org.elasticsearch.entitlement.runtime.policy;
1111

12-
import org.elasticsearch.core.PathUtils;
1312
import org.elasticsearch.core.Strings;
1413
import org.elasticsearch.core.SuppressForbidden;
1514
import org.elasticsearch.entitlement.instrumentation.InstrumentationService;
@@ -58,7 +57,7 @@
5857
*/
5958
@SuppressForbidden(reason = "Explicitly checking APIs that are forbidden")
6059
public class PolicyCheckerImpl implements PolicyChecker {
61-
static final Class<?> DEFAULT_FILESYSTEM_CLASS = PathUtils.getDefaultFileSystem().getClass();
60+
6261
protected final Set<Package> suppressFailureLogPackages;
6362
/**
6463
* Frames originating from this module are ignored in the permission logic.
@@ -81,15 +80,14 @@ public PolicyCheckerImpl(
8180
this.pathLookup = pathLookup;
8281
}
8382

84-
private static boolean isPathOnDefaultFilesystem(Path path) {
85-
var pathFileSystemClass = path.getFileSystem().getClass();
86-
if (path.getFileSystem().getClass() != DEFAULT_FILESYSTEM_CLASS) {
83+
private boolean isPathOnDefaultFilesystem(Path path) {
84+
if (pathLookup.isPathOnDefaultFilesystem(path) == false) {
8785
PolicyManager.generalLogger.trace(
8886
() -> Strings.format(
8987
"File entitlement trivially allowed: path [%s] is for a different FileSystem class [%s], default is [%s]",
9088
path.toString(),
91-
pathFileSystemClass.getName(),
92-
DEFAULT_FILESYSTEM_CLASS.getName()
89+
path.getFileSystem().getClass().getName(),
90+
PathLookup.DEFAULT_FILESYSTEM_CLASS.getName()
9391
)
9492
);
9593
return false;
@@ -217,7 +215,7 @@ public void checkFileRead(Class<?> callerClass, Path path) {
217215

218216
@Override
219217
public void checkFileRead(Class<?> callerClass, Path path, boolean followLinks) throws NoSuchFileException {
220-
if (PolicyCheckerImpl.isPathOnDefaultFilesystem(path) == false) {
218+
if (isPathOnDefaultFilesystem(path) == false) {
221219
return;
222220
}
223221
var requestingClass = requestingClass(callerClass);
@@ -265,7 +263,7 @@ public void checkFileWrite(Class<?> callerClass, File file) {
265263

266264
@Override
267265
public void checkFileWrite(Class<?> callerClass, Path path) {
268-
if (PolicyCheckerImpl.isPathOnDefaultFilesystem(path) == false) {
266+
if (isPathOnDefaultFilesystem(path) == false) {
269267
return;
270268
}
271269
var requestingClass = requestingClass(callerClass);

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/PolicyManager.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
import java.nio.file.Paths;
2323
import java.util.ArrayList;
2424
import java.util.Collection;
25+
import java.util.Collections;
2526
import java.util.HashSet;
2627
import java.util.List;
2728
import java.util.Map;
29+
import java.util.Objects;
2830
import java.util.Set;
2931
import java.util.concurrent.ConcurrentHashMap;
3032
import java.util.function.Function;
@@ -217,7 +219,7 @@ private static Set<Module> findSystemLayerModules() {
217219
.filter(m -> SYSTEM_LAYER_MODULES.contains(m) == false)
218220
.collect(Collectors.toUnmodifiableSet());
219221

220-
private final Map<String, Collection<Path>> pluginSourcePaths;
222+
private final Function<String, Collection<Path>> pluginSourcePathsResolver;
221223

222224
/**
223225
* Paths that are only allowed for a single module. Used to generate
@@ -231,7 +233,7 @@ public PolicyManager(
231233
List<Entitlement> apmAgentEntitlements,
232234
Map<String, Policy> pluginPolicies,
233235
Function<Class<?>, PolicyScope> scopeResolver,
234-
Map<String, Collection<Path>> pluginSourcePaths,
236+
Function<String, Collection<Path>> pluginSourcePathsResolver,
235237
PathLookup pathLookup
236238
) {
237239
this.serverEntitlements = buildScopeEntitlementsMap(requireNonNull(serverPolicy));
@@ -240,7 +242,7 @@ public PolicyManager(
240242
.stream()
241243
.collect(toUnmodifiableMap(Map.Entry::getKey, e -> buildScopeEntitlementsMap(e.getValue())));
242244
this.scopeResolver = scopeResolver;
243-
this.pluginSourcePaths = pluginSourcePaths;
245+
this.pluginSourcePathsResolver = pluginSourcePathsResolver;
244246
this.pathLookup = requireNonNull(pathLookup);
245247

246248
List<ExclusiveFileEntitlement> exclusiveFileEntitlements = new ArrayList<>();
@@ -334,7 +336,10 @@ protected final ModuleEntitlements computeEntitlements(Class<?> requestingClass)
334336
default -> {
335337
assert policyScope.kind() == PLUGIN;
336338
var pluginEntitlements = pluginsEntitlements.get(componentName);
337-
Collection<Path> componentPaths = pluginSourcePaths.getOrDefault(componentName, List.of());
339+
Collection<Path> componentPaths = Objects.requireNonNullElse(
340+
pluginSourcePathsResolver.apply(componentName),
341+
Collections.emptyList()
342+
);
338343
if (pluginEntitlements == null) {
339344
return defaultEntitlements(componentName, componentPaths, moduleName);
340345
} else {

libs/entitlement/src/test/java/org/elasticsearch/entitlement/runtime/policy/PolicyManagerTests.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.net.URLClassLoader;
3434
import java.nio.file.Path;
3535
import java.util.Collection;
36+
import java.util.Collections;
3637
import java.util.List;
3738
import java.util.Map;
3839
import java.util.Set;
@@ -95,7 +96,7 @@ public void testGetEntitlements() {
9596
List.of(),
9697
Map.of("plugin1", new Policy("plugin1", List.of(new Scope("plugin.module1", List.of(new ExitVMEntitlement()))))),
9798
c -> policyScope.get(),
98-
Map.of("plugin1", plugin1SourcePaths),
99+
Map.of("plugin1", plugin1SourcePaths)::get,
99100
TEST_PATH_LOOKUP
100101
);
101102
Collection<Path> thisSourcePaths = policyManager.getComponentPathsFromClass(getClass());
@@ -170,7 +171,7 @@ public void testAgentsEntitlements() throws IOException, ClassNotFoundException
170171
c -> c.getPackageName().startsWith(TEST_AGENTS_PACKAGE_NAME)
171172
? PolicyScope.apmAgent("test.agent.module")
172173
: PolicyScope.plugin("test", "test.plugin.module"),
173-
Map.of(),
174+
name -> Collections.emptyList(),
174175
TEST_PATH_LOOKUP
175176
);
176177
ModuleEntitlements agentsEntitlements = policyManager.getEntitlements(TestAgent.class);
@@ -197,7 +198,7 @@ public void testDuplicateEntitlements() {
197198
List.of(),
198199
Map.of(),
199200
c -> PolicyScope.plugin("test", moduleName(c)),
200-
Map.of(),
201+
name -> Collections.emptyList(),
201202
TEST_PATH_LOOKUP
202203
)
203204
);
@@ -213,7 +214,7 @@ public void testDuplicateEntitlements() {
213214
List.of(new CreateClassLoaderEntitlement(), new CreateClassLoaderEntitlement()),
214215
Map.of(),
215216
c -> PolicyScope.plugin("test", moduleName(c)),
216-
Map.of(),
217+
name -> Collections.emptyList(),
217218
TEST_PATH_LOOKUP
218219
)
219220
);
@@ -249,7 +250,7 @@ public void testDuplicateEntitlements() {
249250
)
250251
),
251252
c -> PolicyScope.plugin("plugin1", moduleName(c)),
252-
Map.of("plugin1", List.of(Path.of("modules", "plugin1"))),
253+
Map.of("plugin1", List.of(Path.of("modules", "plugin1")))::get,
253254
TEST_PATH_LOOKUP
254255
)
255256
);
@@ -299,7 +300,7 @@ public void testFilesEntitlementsWithExclusive() {
299300
)
300301
),
301302
c -> PolicyScope.plugin("", moduleName(c)),
302-
Map.of("plugin1", List.of(Path.of("modules", "plugin1")), "plugin2", List.of(Path.of("modules", "plugin2"))),
303+
Map.of("plugin1", List.of(Path.of("modules", "plugin1")), "plugin2", List.of(Path.of("modules", "plugin2")))::get,
303304
TEST_PATH_LOOKUP
304305
)
305306
);
@@ -350,7 +351,7 @@ public void testFilesEntitlementsWithExclusive() {
350351
)
351352
),
352353
c -> PolicyScope.plugin("", moduleName(c)),
353-
Map.of(),
354+
name -> Collections.emptyList(),
354355
TEST_PATH_LOOKUP
355356
)
356357
);

muted-tests.yml

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -489,21 +489,6 @@ tests:
489489
- class: org.elasticsearch.test.rest.yaml.RcsCcsCommonYamlTestSuiteIT
490490
method: test {p0=msearch/20_typed_keys/Multisearch test with typed_keys parameter for sampler and significant terms}
491491
issue: https://github.com/elastic/elasticsearch/issues/130472
492-
- class: org.elasticsearch.xpack.ssl.SSLErrorMessageFileTests
493-
method: testMessageForKeyStoreOutsideConfigDir
494-
issue: https://github.com/elastic/elasticsearch/issues/127192
495-
- class: org.elasticsearch.xpack.ssl.SSLErrorMessageFileTests
496-
method: testMessageForPemKeyOutsideConfigDir
497-
issue: https://github.com/elastic/elasticsearch/issues/127192
498-
- class: org.elasticsearch.xpack.ssl.SSLErrorMessageFileTests
499-
method: testMessageForPemCertificateOutsideConfigDir
500-
issue: https://github.com/elastic/elasticsearch/issues/127192
501-
- class: org.elasticsearch.xpack.ssl.SSLErrorMessageFileTests
502-
method: testMessageForTrustStoreOutsideConfigDir
503-
issue: https://github.com/elastic/elasticsearch/issues/127192
504-
- class: org.elasticsearch.xpack.ssl.SSLErrorMessageFileTests
505-
method: testMessageForCertificateAuthoritiesOutsideConfigDir
506-
issue: https://github.com/elastic/elasticsearch/issues/127192
507492
- class: org.elasticsearch.index.codec.vectors.cluster.HierarchicalKMeansTests
508493
method: testHKmeans
509494
issue: https://github.com/elastic/elasticsearch/issues/130497
@@ -552,6 +537,18 @@ tests:
552537
- class: org.elasticsearch.common.util.concurrent.TaskExecutionTimeTrackingEsThreadPoolExecutorTests
553538
method: testMaxQueueLatency
554539
issue: https://github.com/elastic/elasticsearch/issues/131093
540+
- class: org.elasticsearch.xpack.esql.action.CrossClusterAsyncQueryStopIT
541+
method: testStopQueryLocal
542+
issue: https://github.com/elastic/elasticsearch/issues/121672
543+
- class: org.elasticsearch.xpack.esql.qa.multi_node.EsqlSpecIT
544+
method: test {lookup-join.MvJoinKeyOnFromAfterStats ASYNC}
545+
issue: https://github.com/elastic/elasticsearch/issues/131148
546+
- class: org.elasticsearch.xpack.esql.qa.multi_node.GenerativeIT
547+
method: test
548+
issue: https://github.com/elastic/elasticsearch/issues/131154
549+
- class: org.elasticsearch.xpack.esql.ccq.MultiClustersIT
550+
method: testNotLikeListKeyword
551+
issue: https://github.com/elastic/elasticsearch/issues/131155
555552

556553
# Examples:
557554
#

server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconciler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.elasticsearch.cluster.routing.UnassignedInfo.AllocationStatus;
2424
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
2525
import org.elasticsearch.cluster.routing.allocation.decider.Decision;
26+
import org.elasticsearch.common.FrequencyCappedAction;
2627
import org.elasticsearch.common.Strings;
2728
import org.elasticsearch.common.settings.ClusterSettings;
2829
import org.elasticsearch.common.settings.Setting;

server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/FrequencyCappedAction.java renamed to server/src/main/java/org/elasticsearch/common/FrequencyCappedAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
99

10-
package org.elasticsearch.cluster.routing.allocation.allocator;
10+
package org.elasticsearch.common;
1111

1212
import org.elasticsearch.core.TimeValue;
1313

server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/FrequencyCappedActionTests.java renamed to server/src/test/java/org/elasticsearch/common/FrequencyCappedActionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
99

10-
package org.elasticsearch.cluster.routing.allocation.allocator;
10+
package org.elasticsearch.common;
1111

1212
import org.elasticsearch.core.TimeValue;
1313
import org.elasticsearch.test.ESTestCase;

0 commit comments

Comments
 (0)