Skip to content

Commit e5347b4

Browse files
committed
Merge branch 'main' into entitlements/nio-path
2 parents bdf7e6a + 8b4f159 commit e5347b4

File tree

67 files changed

+1113
-391
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1113
-391
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ distribution/docker/src @elastic/es-delivery
4949
# Core/Infra
5050
distribution/tools @elastic/es-core-infra
5151
libs/core @elastic/es-core-infra
52+
libs/entitlement @elastic/es-core-infra
5253
libs/logging @elastic/es-core-infra
5354
libs/native @elastic/es-core-infra
5455
libs/plugin-analysis-api @elastic/es-core-infra

docs/changelog/121942.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 121942
2+
summary: Allow partial results in ES|QL
3+
area: ES|QL
4+
type: enhancement
5+
issues: []

docs/changelog/122610.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 122610
2+
summary: Canonicalize processor names and types in `IngestStats`
3+
area: Ingest Node
4+
type: bug
5+
issues: []

docs/changelog/122653.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 122653
2+
summary: Knn vector rescoring to sort score docs
3+
area: Vector Search
4+
type: bug
5+
issues:
6+
- 119711

libs/entitlement/qa/entitlement-test-plugin/src/main/java/org/elasticsearch/entitlement/qa/test/LoadNativeLibrariesCheckActions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
class LoadNativeLibrariesCheckActions {
1313
static void runtimeLoad() {
1414
try {
15-
Runtime.getRuntime().load("libSomeLibFile.so");
15+
Runtime.getRuntime().load(FileCheckActions.readDir().resolve("libSomeLibFile.so").toString());
1616
} catch (UnsatisfiedLinkError ignored) {
1717
// The library does not exist, so we expect to fail loading it
1818
}
1919
}
2020

2121
static void systemLoad() {
2222
try {
23-
System.load("libSomeLibFile.so");
23+
System.load(FileCheckActions.readDir().resolve("libSomeLibFile.so").toString());
2424
} catch (UnsatisfiedLinkError ignored) {
2525
// The library does not exist, so we expect to fail loading it
2626
}

libs/entitlement/qa/entitlement-test-plugin/src/main/java/org/elasticsearch/entitlement/qa/test/NativeActions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static void memorySegmentReinterpretWithSizeAndCleanup() {
113113
@EntitlementTest(expectedAccess = PLUGINS)
114114
static void symbolLookupWithPath() {
115115
try {
116-
SymbolLookup.libraryLookup(Path.of("/foo/bar/libFoo.so"), Arena.ofAuto());
116+
SymbolLookup.libraryLookup(FileCheckActions.readDir().resolve("libFoo.so"), Arena.ofAuto());
117117
} catch (IllegalArgumentException e) {
118118
// IllegalArgumentException is thrown if path does not point to a valid library (and it does not)
119119
}

libs/entitlement/src/main/java/org/elasticsearch/entitlement/initialization/EntitlementInitialization.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.elasticsearch.entitlement.instrumentation.MethodKey;
1919
import org.elasticsearch.entitlement.instrumentation.Transformer;
2020
import org.elasticsearch.entitlement.runtime.api.ElasticsearchEntitlementChecker;
21+
import org.elasticsearch.entitlement.runtime.policy.PathLookup;
2122
import org.elasticsearch.entitlement.runtime.policy.Policy;
2223
import org.elasticsearch.entitlement.runtime.policy.PolicyManager;
2324
import org.elasticsearch.entitlement.runtime.policy.Scope;
@@ -130,9 +131,9 @@ private static Class<?>[] findClassesToRetransform(Class<?>[] loadedClasses, Set
130131
}
131132

132133
private static PolicyManager createPolicyManager() {
133-
Map<String, Policy> pluginPolicies = EntitlementBootstrap.bootstrapArgs().pluginPolicies();
134-
Path[] dataDirs = EntitlementBootstrap.bootstrapArgs().dataDirs();
135-
Path tempDir = EntitlementBootstrap.bootstrapArgs().tempDir();
134+
EntitlementBootstrap.BootstrapArgs bootstrapArgs = EntitlementBootstrap.bootstrapArgs();
135+
Map<String, Policy> pluginPolicies = bootstrapArgs.pluginPolicies();
136+
var pathLookup = new PathLookup(bootstrapArgs.configDir(), bootstrapArgs.dataDirs(), bootstrapArgs.tempDir());
136137

137138
// TODO(ES-10031): Decide what goes in the elasticsearch default policy and extend it
138139
var serverPolicy = new Policy(
@@ -153,10 +154,10 @@ private static PolicyManager createPolicyManager() {
153154
new FilesEntitlement(
154155
Stream.concat(
155156
Stream.of(
156-
new FileData(EntitlementBootstrap.bootstrapArgs().tempDir().toString(), READ_WRITE),
157-
new FileData(EntitlementBootstrap.bootstrapArgs().configDir().toString(), READ)
157+
FileData.ofPath(bootstrapArgs.tempDir(), READ_WRITE),
158+
FileData.ofPath(bootstrapArgs.configDir(), READ)
158159
),
159-
Arrays.stream(dataDirs).map(d -> new FileData(d.toString(), READ))
160+
Arrays.stream(bootstrapArgs.dataDirs()).map(d -> FileData.ofPath(d, READ))
160161
).toList()
161162
)
162163
)
@@ -170,8 +171,8 @@ private static PolicyManager createPolicyManager() {
170171
new ManageThreadsEntitlement(),
171172
new FilesEntitlement(
172173
Stream.concat(
173-
Stream.of(new FileData(EntitlementBootstrap.bootstrapArgs().configDir().toString(), READ)),
174-
Arrays.stream(dataDirs).map(d -> new FileData(d.toString(), READ_WRITE))
174+
Stream.of(FileData.ofPath(bootstrapArgs.configDir(), READ)),
175+
Arrays.stream(bootstrapArgs.dataDirs()).map(d -> FileData.ofPath(d, READ_WRITE))
175176
).toList()
176177
)
177178
)
@@ -181,7 +182,7 @@ private static PolicyManager createPolicyManager() {
181182
"org.elasticsearch.nativeaccess",
182183
List.of(
183184
new LoadNativeLibrariesEntitlement(),
184-
new FilesEntitlement(Arrays.stream(dataDirs).map(d -> new FileData(d.toString(), READ_WRITE)).toList())
185+
new FilesEntitlement(List.of(FileData.ofRelativePath(Path.of(""), FilesEntitlement.BaseDir.DATA, READ_WRITE)))
185186
)
186187
)
187188
)
@@ -197,7 +198,7 @@ private static PolicyManager createPolicyManager() {
197198
resolver,
198199
AGENTS_PACKAGE_NAME,
199200
ENTITLEMENTS_MODULE,
200-
tempDir
201+
pathLookup
201202
);
202203
}
203204

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/api/ElasticsearchEntitlementChecker.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ public void checkSelectorProviderInheritedChannel(Class<?> callerClass, Selector
840840

841841
@Override
842842
public void check$java_lang_Runtime$load(Class<?> callerClass, Runtime that, String filename) {
843-
// TODO: check filesystem entitlement READ
843+
policyManager.checkFileRead(callerClass, Path.of(filename));
844844
policyManager.checkLoadingNativeLibraries(callerClass);
845845
}
846846

@@ -851,7 +851,7 @@ public void checkSelectorProviderInheritedChannel(Class<?> callerClass, Selector
851851

852852
@Override
853853
public void check$java_lang_System$$load(Class<?> callerClass, String filename) {
854-
// TODO: check filesystem entitlement READ
854+
policyManager.checkFileRead(callerClass, Path.of(filename));
855855
policyManager.checkLoadingNativeLibraries(callerClass);
856856
}
857857

@@ -935,7 +935,7 @@ public void checkSelectorProviderInheritedChannel(Class<?> callerClass, Selector
935935

936936
@Override
937937
public void check$java_lang_foreign_SymbolLookup$$libraryLookup(Class<?> callerClass, Path path, Arena arena) {
938-
// TODO: check filesystem entitlement READ
938+
policyManager.checkFileRead(callerClass, path);
939939
policyManager.checkLoadingNativeLibraries(callerClass);
940940
}
941941

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,30 @@
2020
import static org.elasticsearch.core.PathUtils.getDefaultFileSystem;
2121

2222
public final class FileAccessTree {
23+
2324
private static final String FILE_SEPARATOR = getDefaultFileSystem().getSeparator();
2425

2526
private final String[] readPaths;
2627
private final String[] writePaths;
2728

28-
private FileAccessTree(FilesEntitlement filesEntitlement, Path tempDir) {
29+
private FileAccessTree(FilesEntitlement filesEntitlement, PathLookup pathLookup) {
2930
List<String> readPaths = new ArrayList<>();
3031
List<String> writePaths = new ArrayList<>();
3132
for (FilesEntitlement.FileData fileData : filesEntitlement.filesData()) {
32-
var path = normalizePath(Path.of(fileData.path()));
3333
var mode = fileData.mode();
34-
if (mode == FilesEntitlement.Mode.READ_WRITE) {
35-
writePaths.add(path);
36-
}
37-
readPaths.add(path);
34+
var paths = fileData.resolvePaths(pathLookup);
35+
paths.forEach(path -> {
36+
var normalized = normalizePath(path);
37+
if (mode == FilesEntitlement.Mode.READ_WRITE) {
38+
writePaths.add(normalized);
39+
}
40+
readPaths.add(normalized);
41+
});
3842
}
3943

4044
// everything has access to the temp dir
41-
readPaths.add(tempDir.toString());
42-
writePaths.add(tempDir.toString());
45+
readPaths.add(pathLookup.tempDir().toString());
46+
writePaths.add(pathLookup.tempDir().toString());
4347

4448
readPaths.sort(String::compareTo);
4549
writePaths.sort(String::compareTo);
@@ -48,8 +52,8 @@ private FileAccessTree(FilesEntitlement filesEntitlement, Path tempDir) {
4852
this.writePaths = writePaths.toArray(new String[0]);
4953
}
5054

51-
public static FileAccessTree of(FilesEntitlement filesEntitlement, Path tempDir) {
52-
return new FileAccessTree(filesEntitlement, tempDir);
55+
public static FileAccessTree of(FilesEntitlement filesEntitlement, PathLookup pathLookup) {
56+
return new FileAccessTree(filesEntitlement, pathLookup);
5357
}
5458

5559
boolean canRead(Path path) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.entitlement.runtime.policy;
11+
12+
import java.nio.file.Path;
13+
14+
public record PathLookup(Path configDir, Path[] dataDirs, Path tempDir) {}

0 commit comments

Comments
 (0)