Skip to content

Commit c730f21

Browse files
authored
Merge branch 'main' into fix-filter-ccs
2 parents 9f432eb + b98a4fa commit c730f21

File tree

59 files changed

+905
-957
lines changed

Some content is hidden

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

59 files changed

+905
-957
lines changed

docs/changelog/126035.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 126035
2+
summary: Fix top level knn search with scroll
3+
area: Vector Search
4+
type: bug
5+
issues: []

docs/changelog/126629.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.

docs/reference/elasticsearch/mapping-reference/mapping-date-format.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Many APIs which support date values also support [date math](/reference/elastics
2727

2828
## Custom date formats [custom-date-formats]
2929

30-
Completely customizable date formats are supported. The syntax for these is explained in [DateTimeFormatter docs](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/time/format/DateTimeFormatter.md).
30+
Completely customizable date formats are supported. The syntax for these is explained in [DateTimeFormatter docs](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/time/format/DateTimeFormatter.html).
3131

3232
Note that while the built-in formats for week dates use the ISO definition of weekyears, custom formatters using the `Y`, `W`, or `w` field specifiers use the JDK locale definition of weekyears. This can result in different values between the built-in formats and custom formats for week dates.
3333

docs/reference/query-languages/esql/_snippets/functions/layout/st_xmax.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/layout/st_xmin.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/layout/st_ymax.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/layout/st_ymin.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/lists/spatial-functions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* [`ST_X`](../../functions-operators/spatial-functions.md#esql-st_x)
77
* [`ST_Y`](../../functions-operators/spatial-functions.md#esql-st_y)
88
* [preview] [`ST_ENVELOPE`](../../functions-operators/spatial-functions.md#esql-st_envelope)
9-
* [preview] [`ST_XMAX`](../../functions-operators/spatial-functions.md#esql-st_xmax)
10-
* [preview] [`ST_XMIN`](../../functions-operators/spatial-functions.md#esql-st_xmin)
11-
* [preview] [`ST_YMAX`](../../functions-operators/spatial-functions.md#esql-st_ymax)
12-
* [preview] [`ST_YMIN`](../../functions-operators/spatial-functions.md#esql-st_ymin)
9+
* [preview] [`ST_XMAX`](../../functions-operators/spatial-functions.md#esql-st_xmax)
10+
* [preview] [`ST_XMIN`](../../functions-operators/spatial-functions.md#esql-st_xmin)
11+
* [preview] [`ST_YMAX`](../../functions-operators/spatial-functions.md#esql-st_ymax)
12+
* [preview] [`ST_YMIN`](../../functions-operators/spatial-functions.md#esql-st_ymin)

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

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@
1515
import com.sun.tools.attach.VirtualMachine;
1616

1717
import org.elasticsearch.core.Nullable;
18+
import org.elasticsearch.core.PathUtils;
1819
import org.elasticsearch.core.SuppressForbidden;
1920
import org.elasticsearch.entitlement.initialization.EntitlementInitialization;
21+
import org.elasticsearch.entitlement.runtime.policy.PathLookup;
22+
import org.elasticsearch.entitlement.runtime.policy.PathLookupImpl;
2023
import org.elasticsearch.entitlement.runtime.policy.Policy;
24+
import org.elasticsearch.entitlement.runtime.policy.PolicyManager;
2125
import org.elasticsearch.logging.LogManager;
2226
import org.elasticsearch.logging.Logger;
2327

@@ -36,36 +40,16 @@ public class EntitlementBootstrap {
3640
public record BootstrapArgs(
3741
@Nullable Policy serverPolicyPatch,
3842
Map<String, Policy> pluginPolicies,
39-
Function<Class<?>, String> pluginResolver,
40-
Function<String, Stream<String>> settingResolver,
41-
Path[] dataDirs,
42-
Path[] sharedRepoDirs,
43-
Path configDir,
44-
Path libDir,
45-
Path modulesDir,
46-
Path pluginsDir,
43+
Function<Class<?>, PolicyManager.PolicyScope> scopeResolver,
44+
PathLookup pathLookup,
4745
Map<String, Path> sourcePaths,
48-
Path logsDir,
49-
Path tempDir,
50-
Path pidFile,
5146
Set<Class<?>> suppressFailureLogClasses
5247
) {
5348
public BootstrapArgs {
5449
requireNonNull(pluginPolicies);
55-
requireNonNull(pluginResolver);
56-
requireNonNull(settingResolver);
57-
requireNonNull(dataDirs);
58-
if (dataDirs.length == 0) {
59-
throw new IllegalArgumentException("must provide at least one data directory");
60-
}
61-
requireNonNull(sharedRepoDirs);
62-
requireNonNull(configDir);
63-
requireNonNull(libDir);
64-
requireNonNull(modulesDir);
65-
requireNonNull(pluginsDir);
50+
requireNonNull(scopeResolver);
51+
requireNonNull(pathLookup);
6652
requireNonNull(sourcePaths);
67-
requireNonNull(logsDir);
68-
requireNonNull(tempDir);
6953
requireNonNull(suppressFailureLogClasses);
7054
}
7155
}
@@ -82,7 +66,7 @@ public static BootstrapArgs bootstrapArgs() {
8266
*
8367
* @param serverPolicyPatch a policy with additional entitlements to patch the embedded server layer policy
8468
* @param pluginPolicies a map holding policies for plugins (and modules), by plugin (or module) name.
85-
* @param pluginResolver a functor to map a Java Class to the plugin it belongs to (the plugin name).
69+
* @param scopeResolver a functor to map a Java Class to the component and module it belongs to.
8670
* @param settingResolver a functor to resolve a setting name pattern for one or more Elasticsearch settings.
8771
* @param dataDirs data directories for Elasticsearch
8872
* @param sharedRepoDirs shared repository directories for Elasticsearch
@@ -99,7 +83,7 @@ public static BootstrapArgs bootstrapArgs() {
9983
public static void bootstrap(
10084
Policy serverPolicyPatch,
10185
Map<String, Policy> pluginPolicies,
102-
Function<Class<?>, String> pluginResolver,
86+
Function<Class<?>, PolicyManager.PolicyScope> scopeResolver,
10387
Function<String, Stream<String>> settingResolver,
10488
Path[] dataDirs,
10589
Path[] sharedRepoDirs,
@@ -120,24 +104,35 @@ public static void bootstrap(
120104
EntitlementBootstrap.bootstrapArgs = new BootstrapArgs(
121105
serverPolicyPatch,
122106
pluginPolicies,
123-
pluginResolver,
124-
settingResolver,
125-
dataDirs,
126-
sharedRepoDirs,
127-
configDir,
128-
libDir,
129-
modulesDir,
130-
pluginsDir,
107+
scopeResolver,
108+
new PathLookupImpl(
109+
getUserHome(),
110+
configDir,
111+
dataDirs,
112+
sharedRepoDirs,
113+
libDir,
114+
modulesDir,
115+
pluginsDir,
116+
logsDir,
117+
tempDir,
118+
pidFile,
119+
settingResolver
120+
),
131121
sourcePaths,
132-
logsDir,
133-
tempDir,
134-
pidFile,
135122
suppressFailureLogClasses
136123
);
137124
exportInitializationToAgent();
138125
loadAgent(findAgentJar());
139126
}
140127

128+
private static Path getUserHome() {
129+
String userHome = System.getProperty("user.home");
130+
if (userHome == null) {
131+
throw new IllegalStateException("user.home system property is required");
132+
}
133+
return PathUtils.get(userHome);
134+
}
135+
141136
@SuppressForbidden(reason = "The VirtualMachine API is the only way to attach a java agent dynamically")
142137
private static void loadAgent(String agentPath) {
143138
try {

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

Lines changed: 35 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858
import java.nio.file.attribute.FileAttribute;
5959
import java.nio.file.spi.FileSystemProvider;
6060
import java.util.ArrayList;
61-
import java.util.Arrays;
6261
import java.util.Collections;
6362
import java.util.HashMap;
63+
import java.util.HashSet;
6464
import java.util.List;
6565
import java.util.Map;
6666
import java.util.Set;
@@ -70,10 +70,14 @@
7070
import java.util.stream.Stream;
7171
import java.util.stream.StreamSupport;
7272

73+
import static org.elasticsearch.entitlement.runtime.policy.PathLookup.BaseDir.CONFIG;
74+
import static org.elasticsearch.entitlement.runtime.policy.PathLookup.BaseDir.DATA;
75+
import static org.elasticsearch.entitlement.runtime.policy.PathLookup.BaseDir.LIB;
76+
import static org.elasticsearch.entitlement.runtime.policy.PathLookup.BaseDir.LOGS;
77+
import static org.elasticsearch.entitlement.runtime.policy.PathLookup.BaseDir.MODULES;
78+
import static org.elasticsearch.entitlement.runtime.policy.PathLookup.BaseDir.PLUGINS;
79+
import static org.elasticsearch.entitlement.runtime.policy.PathLookup.BaseDir.SHARED_REPO;
7380
import static org.elasticsearch.entitlement.runtime.policy.Platform.LINUX;
74-
import static org.elasticsearch.entitlement.runtime.policy.entitlements.FilesEntitlement.BaseDir.CONFIG;
75-
import static org.elasticsearch.entitlement.runtime.policy.entitlements.FilesEntitlement.BaseDir.DATA;
76-
import static org.elasticsearch.entitlement.runtime.policy.entitlements.FilesEntitlement.BaseDir.SHARED_REPO;
7781
import static org.elasticsearch.entitlement.runtime.policy.entitlements.FilesEntitlement.Mode.READ;
7882
import static org.elasticsearch.entitlement.runtime.policy.entitlements.FilesEntitlement.Mode.READ_WRITE;
7983

@@ -86,7 +90,6 @@
8690
*/
8791
public class EntitlementInitialization {
8892

89-
private static final String AGENTS_PACKAGE_NAME = "co.elastic.apm.agent";
9093
private static final Module ENTITLEMENTS_MODULE = PolicyManager.class.getModule();
9194

9295
private static ElasticsearchEntitlementChecker manager;
@@ -165,27 +168,20 @@ private static Class<?>[] findClassesToRetransform(Class<?>[] loadedClasses, Set
165168
private static PolicyManager createPolicyManager() {
166169
EntitlementBootstrap.BootstrapArgs bootstrapArgs = EntitlementBootstrap.bootstrapArgs();
167170
Map<String, Policy> pluginPolicies = bootstrapArgs.pluginPolicies();
168-
var pathLookup = new PathLookup(
169-
getUserHome(),
170-
bootstrapArgs.configDir(),
171-
bootstrapArgs.dataDirs(),
172-
bootstrapArgs.sharedRepoDirs(),
173-
bootstrapArgs.tempDir(),
174-
bootstrapArgs.settingResolver()
175-
);
171+
PathLookup pathLookup = bootstrapArgs.pathLookup();
176172

177173
List<Scope> serverScopes = new ArrayList<>();
178174
List<FileData> serverModuleFileDatas = new ArrayList<>();
179175
Collections.addAll(
180176
serverModuleFileDatas,
181177
// Base ES directories
182-
FileData.ofPath(bootstrapArgs.pluginsDir(), READ),
183-
FileData.ofPath(bootstrapArgs.modulesDir(), READ),
184-
FileData.ofPath(bootstrapArgs.configDir(), READ),
185-
FileData.ofPath(bootstrapArgs.logsDir(), READ_WRITE),
186-
FileData.ofPath(bootstrapArgs.libDir(), READ),
187-
FileData.ofRelativePath(Path.of(""), DATA, READ_WRITE),
188-
FileData.ofRelativePath(Path.of(""), SHARED_REPO, READ_WRITE),
178+
FileData.ofBaseDirPath(PLUGINS, READ),
179+
FileData.ofBaseDirPath(MODULES, READ),
180+
FileData.ofBaseDirPath(CONFIG, READ),
181+
FileData.ofBaseDirPath(LOGS, READ_WRITE),
182+
FileData.ofBaseDirPath(LIB, READ),
183+
FileData.ofBaseDirPath(DATA, READ_WRITE),
184+
FileData.ofBaseDirPath(SHARED_REPO, READ_WRITE),
189185
// exclusive settings file
190186
FileData.ofRelativePath(Path.of("operator/settings.json"), CONFIG, READ_WRITE).withExclusive(true),
191187
// OS release on Linux
@@ -206,8 +202,8 @@ private static PolicyManager createPolicyManager() {
206202
FileData.ofPath(Path.of("/proc/self/mountinfo"), READ).withPlatform(LINUX),
207203
FileData.ofPath(Path.of("/proc/diskstats"), READ).withPlatform(LINUX)
208204
);
209-
if (bootstrapArgs.pidFile() != null) {
210-
serverModuleFileDatas.add(FileData.ofPath(bootstrapArgs.pidFile(), READ_WRITE));
205+
if (pathLookup.pidFile() != null) {
206+
serverModuleFileDatas.add(FileData.ofPath(pathLookup.pidFile(), READ_WRITE));
211207
}
212208

213209
Collections.addAll(
@@ -219,8 +215,8 @@ private static PolicyManager createPolicyManager() {
219215
new FilesEntitlement(
220216
List.of(
221217
// TODO: what in es.base is accessing shared repo?
222-
FileData.ofRelativePath(Path.of(""), SHARED_REPO, READ_WRITE),
223-
FileData.ofRelativePath(Path.of(""), DATA, READ_WRITE)
218+
FileData.ofBaseDirPath(SHARED_REPO, READ_WRITE),
219+
FileData.ofBaseDirPath(DATA, READ_WRITE)
224220
)
225221
)
226222
)
@@ -245,25 +241,17 @@ private static PolicyManager createPolicyManager() {
245241
List.of(
246242
new LoadNativeLibrariesEntitlement(),
247243
new ManageThreadsEntitlement(),
248-
new FilesEntitlement(
249-
List.of(FileData.ofPath(bootstrapArgs.configDir(), READ), FileData.ofRelativePath(Path.of(""), DATA, READ_WRITE))
250-
)
244+
new FilesEntitlement(List.of(FileData.ofBaseDirPath(CONFIG, READ), FileData.ofBaseDirPath(DATA, READ_WRITE)))
251245
)
252246
),
253-
new Scope(
254-
"org.apache.lucene.misc",
255-
List.of(new FilesEntitlement(List.of(FileData.ofRelativePath(Path.of(""), DATA, READ_WRITE))))
256-
),
247+
new Scope("org.apache.lucene.misc", List.of(new FilesEntitlement(List.of(FileData.ofBaseDirPath(DATA, READ_WRITE))))),
257248
new Scope(
258249
"org.apache.logging.log4j.core",
259-
List.of(new ManageThreadsEntitlement(), new FilesEntitlement(List.of(FileData.ofPath(bootstrapArgs.logsDir(), READ_WRITE))))
250+
List.of(new ManageThreadsEntitlement(), new FilesEntitlement(List.of(FileData.ofBaseDirPath(LOGS, READ_WRITE))))
260251
),
261252
new Scope(
262253
"org.elasticsearch.nativeaccess",
263-
List.of(
264-
new LoadNativeLibrariesEntitlement(),
265-
new FilesEntitlement(List.of(FileData.ofRelativePath(Path.of(""), DATA, READ_WRITE)))
266-
)
254+
List.of(new LoadNativeLibrariesEntitlement(), new FilesEntitlement(List.of(FileData.ofBaseDirPath(DATA, READ_WRITE))))
267255
)
268256
);
269257

@@ -288,7 +276,7 @@ private static PolicyManager createPolicyManager() {
288276
new Scope(
289277
"org.bouncycastle.fips.core",
290278
// read to lib dir is required for checksum validation
291-
List.of(new FilesEntitlement(List.of(FileData.ofPath(bootstrapArgs.libDir(), READ))), new ManageThreadsEntitlement())
279+
List.of(new FilesEntitlement(List.of(FileData.ofBaseDirPath(LIB, READ))), new ManageThreadsEntitlement())
292280
)
293281
);
294282
}
@@ -312,50 +300,35 @@ private static PolicyManager createPolicyManager() {
312300
new LoadNativeLibrariesEntitlement(),
313301
new FilesEntitlement(
314302
List.of(
315-
FileData.ofPath(bootstrapArgs.logsDir(), READ_WRITE),
303+
FileData.ofBaseDirPath(LOGS, READ_WRITE),
316304
FileData.ofPath(Path.of("/proc/meminfo"), READ),
317305
FileData.ofPath(Path.of("/sys/fs/cgroup/"), READ)
318306
)
319307
)
320308
);
321309

322-
validateFilesEntitlements(
323-
pluginPolicies,
324-
pathLookup,
325-
bootstrapArgs.configDir(),
326-
bootstrapArgs.pluginsDir(),
327-
bootstrapArgs.modulesDir(),
328-
bootstrapArgs.libDir()
329-
);
310+
validateFilesEntitlements(pluginPolicies, pathLookup);
330311

331312
return new PolicyManager(
332313
serverPolicy,
333314
agentEntitlements,
334315
pluginPolicies,
335-
EntitlementBootstrap.bootstrapArgs().pluginResolver(),
316+
EntitlementBootstrap.bootstrapArgs().scopeResolver(),
336317
EntitlementBootstrap.bootstrapArgs().sourcePaths(),
337-
AGENTS_PACKAGE_NAME,
338318
ENTITLEMENTS_MODULE,
339319
pathLookup,
340320
bootstrapArgs.suppressFailureLogClasses()
341321
);
342322
}
343323

344-
private static Set<Path> pathSet(Path... paths) {
345-
return Arrays.stream(paths).map(x -> x.toAbsolutePath().normalize()).collect(Collectors.toUnmodifiableSet());
346-
}
347-
348324
// package visible for tests
349-
static void validateFilesEntitlements(
350-
Map<String, Policy> pluginPolicies,
351-
PathLookup pathLookup,
352-
Path configDir,
353-
Path pluginsDir,
354-
Path modulesDir,
355-
Path libDir
356-
) {
357-
var readAccessForbidden = pathSet(pluginsDir, modulesDir, libDir);
358-
var writeAccessForbidden = pathSet(configDir);
325+
static void validateFilesEntitlements(Map<String, Policy> pluginPolicies, PathLookup pathLookup) {
326+
Set<Path> readAccessForbidden = new HashSet<>();
327+
pathLookup.getBaseDirPaths(PLUGINS).forEach(p -> readAccessForbidden.add(p.toAbsolutePath().normalize()));
328+
pathLookup.getBaseDirPaths(MODULES).forEach(p -> readAccessForbidden.add(p.toAbsolutePath().normalize()));
329+
pathLookup.getBaseDirPaths(LIB).forEach(p -> readAccessForbidden.add(p.toAbsolutePath().normalize()));
330+
Set<Path> writeAccessForbidden = new HashSet<>();
331+
pathLookup.getBaseDirPaths(CONFIG).forEach(p -> writeAccessForbidden.add(p.toAbsolutePath().normalize()));
359332
for (var pluginPolicy : pluginPolicies.entrySet()) {
360333
for (var scope : pluginPolicy.getValue().scopes()) {
361334
var filesEntitlement = scope.entitlements()

0 commit comments

Comments
 (0)