Skip to content

Commit 0d2ffb4

Browse files
authored
Merge main into multi-project
2 parents ffe5d61 + b6a371b commit 0d2ffb4

File tree

283 files changed

+8462
-8350
lines changed

Some content is hidden

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

283 files changed

+8462
-8350
lines changed

docs/changelog/122860.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 122860
2+
summary: Improved error message when index field type is invalid
3+
area: Mapping
4+
type: enhancement
5+
issues: []

docs/changelog/123079.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 123079
2+
summary: Register `IngestGeoIpMetadata` as a NamedXContent
3+
area: Ingest Node
4+
type: bug
5+
issues: []

docs/changelog/123197.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 123197
2+
summary: Fix early termination in `LuceneSourceOperator`
3+
area: ES|QL
4+
type: bug
5+
issues: []

docs/changelog/123272.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 123272
2+
summary: Set Connect Timeout to 5s
3+
area: Machine Learning
4+
type: bug
5+
issues: []

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public record BootstrapArgs(
3939
Function<Class<?>, String> pluginResolver,
4040
Function<String, String> settingResolver,
4141
Function<String, Stream<String>> settingGlobResolver,
42-
Function<String, Path> repoDirResolver,
4342
Path[] dataDirs,
43+
Path[] sharedRepoDirs,
4444
Path configDir,
4545
Path libDir,
4646
Path logsDir,
@@ -51,11 +51,11 @@ public record BootstrapArgs(
5151
requireNonNull(pluginResolver);
5252
requireNonNull(settingResolver);
5353
requireNonNull(settingGlobResolver);
54-
requireNonNull(repoDirResolver);
5554
requireNonNull(dataDirs);
5655
if (dataDirs.length == 0) {
5756
throw new IllegalArgumentException("must provide at least one data directory");
5857
}
58+
requireNonNull(sharedRepoDirs);
5959
requireNonNull(configDir);
6060
requireNonNull(libDir);
6161
requireNonNull(logsDir);
@@ -77,8 +77,8 @@ public static BootstrapArgs bootstrapArgs() {
7777
* @param pluginResolver a functor to map a Java Class to the plugin it belongs to (the plugin name).
7878
* @param settingResolver a functor to resolve the value of an Elasticsearch setting.
7979
* @param settingGlobResolver a functor to resolve a glob expression for one or more Elasticsearch settings.
80-
* @param repoDirResolver a functor to map a repository location to its Elasticsearch path.
8180
* @param dataDirs data directories for Elasticsearch
81+
* @param sharedRepoDirs shared repository directories for Elasticsearch
8282
* @param configDir the config directory for Elasticsearch
8383
* @param libDir the lib directory for Elasticsearch
8484
* @param tempDir the temp directory for Elasticsearch
@@ -89,8 +89,8 @@ public static void bootstrap(
8989
Function<Class<?>, String> pluginResolver,
9090
Function<String, String> settingResolver,
9191
Function<String, Stream<String>> settingGlobResolver,
92-
Function<String, Path> repoDirResolver,
9392
Path[] dataDirs,
93+
Path[] sharedRepoDirs,
9494
Path configDir,
9595
Path libDir,
9696
Path logsDir,
@@ -105,8 +105,8 @@ public static void bootstrap(
105105
pluginResolver,
106106
settingResolver,
107107
settingGlobResolver,
108-
repoDirResolver,
109108
dataDirs,
109+
sharedRepoDirs,
110110
configDir,
111111
libDir,
112112
logsDir,

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

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@
6363
import java.util.stream.Stream;
6464
import java.util.stream.StreamSupport;
6565

66+
import static org.elasticsearch.entitlement.runtime.policy.entitlements.FilesEntitlement.BaseDir.DATA;
67+
import static org.elasticsearch.entitlement.runtime.policy.entitlements.FilesEntitlement.BaseDir.SHARED_REPO;
6668
import static org.elasticsearch.entitlement.runtime.policy.entitlements.FilesEntitlement.Mode.READ;
6769
import static org.elasticsearch.entitlement.runtime.policy.entitlements.FilesEntitlement.Mode.READ_WRITE;
70+
import static org.elasticsearch.entitlement.runtime.policy.entitlements.FilesEntitlement.Platform.LINUX;
6871

6972
/**
7073
* Called by the agent during {@code agentmain} to configure the entitlement system,
@@ -138,6 +141,7 @@ private static PolicyManager createPolicyManager() {
138141
getUserHome(),
139142
bootstrapArgs.configDir(),
140143
bootstrapArgs.dataDirs(),
144+
bootstrapArgs.sharedRepoDirs(),
141145
bootstrapArgs.tempDir(),
142146
bootstrapArgs.settingResolver(),
143147
bootstrapArgs.settingGlobResolver()
@@ -152,8 +156,8 @@ private static PolicyManager createPolicyManager() {
152156
new CreateClassLoaderEntitlement(),
153157
new FilesEntitlement(
154158
List.of(
155-
FileData.ofPath(bootstrapArgs.repoDirResolver().apply(""), READ_WRITE),
156-
FileData.ofRelativePath(Path.of(""), FilesEntitlement.BaseDir.DATA, READ_WRITE)
159+
FileData.ofRelativePath(Path.of(""), SHARED_REPO, READ_WRITE),
160+
FileData.ofRelativePath(Path.of(""), DATA, READ_WRITE)
157161
)
158162
)
159163
)
@@ -175,26 +179,26 @@ private static PolicyManager createPolicyManager() {
175179
FileData.ofPath(bootstrapArgs.tempDir(), READ_WRITE),
176180
FileData.ofPath(bootstrapArgs.configDir(), READ),
177181
FileData.ofPath(bootstrapArgs.logsDir(), READ_WRITE),
178-
FileData.ofRelativePath(Path.of(""), FilesEntitlement.BaseDir.DATA, READ_WRITE),
179-
FileData.ofPath(bootstrapArgs.repoDirResolver().apply(""), READ_WRITE),
182+
FileData.ofRelativePath(Path.of(""), DATA, READ_WRITE),
183+
FileData.ofRelativePath(Path.of(""), SHARED_REPO, READ_WRITE),
180184

181185
// OS release on Linux
182-
FileData.ofPath(Path.of("/etc/os-release"), READ),
183-
FileData.ofPath(Path.of("/etc/system-release"), READ),
184-
FileData.ofPath(Path.of("/usr/lib/os-release"), READ),
186+
FileData.ofPath(Path.of("/etc/os-release"), READ).withPlatform(LINUX),
187+
FileData.ofPath(Path.of("/etc/system-release"), READ).withPlatform(LINUX),
188+
FileData.ofPath(Path.of("/usr/lib/os-release"), READ).withPlatform(LINUX),
185189
// read max virtual memory areas
186-
FileData.ofPath(Path.of("/proc/sys/vm/max_map_count"), READ),
187-
FileData.ofPath(Path.of("/proc/meminfo"), READ),
190+
FileData.ofPath(Path.of("/proc/sys/vm/max_map_count"), READ).withPlatform(LINUX),
191+
FileData.ofPath(Path.of("/proc/meminfo"), READ).withPlatform(LINUX),
188192
// load averages on Linux
189-
FileData.ofPath(Path.of("/proc/loadavg"), READ),
193+
FileData.ofPath(Path.of("/proc/loadavg"), READ).withPlatform(LINUX),
190194
// control group stats on Linux. cgroup v2 stats are in an unpredicable
191195
// location under `/sys/fs/cgroup`, so unfortunately we have to allow
192196
// read access to the entire directory hierarchy.
193-
FileData.ofPath(Path.of("/proc/self/cgroup"), READ),
194-
FileData.ofPath(Path.of("/sys/fs/cgroup/"), READ),
197+
FileData.ofPath(Path.of("/proc/self/cgroup"), READ).withPlatform(LINUX),
198+
FileData.ofPath(Path.of("/sys/fs/cgroup/"), READ).withPlatform(LINUX),
195199
// // io stats on Linux
196-
FileData.ofPath(Path.of("/proc/self/mountinfo"), READ),
197-
FileData.ofPath(Path.of("/proc/diskstats"), READ)
200+
FileData.ofPath(Path.of("/proc/self/mountinfo"), READ).withPlatform(LINUX),
201+
FileData.ofPath(Path.of("/proc/diskstats"), READ).withPlatform(LINUX)
198202
)
199203
)
200204
)
@@ -210,21 +214,21 @@ private static PolicyManager createPolicyManager() {
210214
List.of(
211215
FileData.ofPath(bootstrapArgs.configDir(), READ),
212216
FileData.ofPath(bootstrapArgs.tempDir(), READ),
213-
FileData.ofRelativePath(Path.of(""), FilesEntitlement.BaseDir.DATA, READ_WRITE)
217+
FileData.ofRelativePath(Path.of(""), DATA, READ_WRITE)
214218
)
215219
)
216220
)
217221
),
218222
new Scope(
219223
"org.apache.lucene.misc",
220-
List.of(new FilesEntitlement(List.of(FileData.ofRelativePath(Path.of(""), FilesEntitlement.BaseDir.DATA, READ_WRITE))))
224+
List.of(new FilesEntitlement(List.of(FileData.ofRelativePath(Path.of(""), DATA, READ_WRITE))))
221225
),
222226
new Scope("org.apache.logging.log4j.core", List.of(new ManageThreadsEntitlement())),
223227
new Scope(
224228
"org.elasticsearch.nativeaccess",
225229
List.of(
226230
new LoadNativeLibrariesEntitlement(),
227-
new FilesEntitlement(List.of(FileData.ofRelativePath(Path.of(""), FilesEntitlement.BaseDir.DATA, READ_WRITE)))
231+
new FilesEntitlement(List.of(FileData.ofRelativePath(Path.of(""), DATA, READ_WRITE)))
228232
)
229233
)
230234
);

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

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.nio.file.Path;
1515
import java.util.ArrayList;
1616
import java.util.Arrays;
17+
import java.util.Comparator;
1718
import java.util.List;
1819
import java.util.Objects;
1920

@@ -30,6 +31,10 @@ private FileAccessTree(FilesEntitlement filesEntitlement, PathLookup pathLookup)
3031
List<String> readPaths = new ArrayList<>();
3132
List<String> writePaths = new ArrayList<>();
3233
for (FilesEntitlement.FileData fileData : filesEntitlement.filesData()) {
34+
var platform = fileData.platform();
35+
if (platform != null && platform.isCurrent() == false) {
36+
continue;
37+
}
3338
var mode = fileData.mode();
3439
var paths = fileData.resolvePaths(pathLookup);
3540
paths.forEach(path -> {
@@ -46,8 +51,8 @@ private FileAccessTree(FilesEntitlement filesEntitlement, PathLookup pathLookup)
4651
readPaths.add(tempDir);
4752
writePaths.add(tempDir);
4853

49-
readPaths.sort(String::compareTo);
50-
writePaths.sort(String::compareTo);
54+
readPaths.sort(PATH_ORDER);
55+
writePaths.sort(PATH_ORDER);
5156

5257
this.readPaths = pruneSortedPaths(readPaths).toArray(new String[0]);
5358
this.writePaths = pruneSortedPaths(writePaths).toArray(new String[0]);
@@ -60,7 +65,7 @@ private static List<String> pruneSortedPaths(List<String> paths) {
6065
prunedReadPaths.add(currentPath);
6166
for (int i = 1; i < paths.size(); ++i) {
6267
String nextPath = paths.get(i);
63-
if (nextPath.startsWith(currentPath) == false) {
68+
if (isParent(currentPath, nextPath) == false) {
6469
prunedReadPaths.add(nextPath);
6570
currentPath = nextPath;
6671
}
@@ -88,21 +93,28 @@ static String normalizePath(Path path) {
8893
// Note that toAbsolutePath produces paths separated by the default file separator,
8994
// so on Windows, if the given path uses forward slashes, this consistently
9095
// converts it to backslashes.
91-
return path.toAbsolutePath().normalize().toString();
96+
String result = path.toAbsolutePath().normalize().toString();
97+
while (result.endsWith(FILE_SEPARATOR)) {
98+
result = result.substring(0, result.length() - FILE_SEPARATOR.length());
99+
}
100+
return result;
92101
}
93102

94103
private static boolean checkPath(String path, String[] paths) {
95104
if (paths.length == 0) {
96105
return false;
97106
}
98-
int ndx = Arrays.binarySearch(paths, path);
107+
int ndx = Arrays.binarySearch(paths, path, PATH_ORDER);
99108
if (ndx < -1) {
100-
String maybeParent = paths[-ndx - 2];
101-
return path.startsWith(maybeParent) && path.startsWith(FILE_SEPARATOR, maybeParent.length());
109+
return isParent(paths[-ndx - 2], path);
102110
}
103111
return ndx >= 0;
104112
}
105113

114+
private static boolean isParent(String maybeParent, String path) {
115+
return path.startsWith(maybeParent) && path.startsWith(FILE_SEPARATOR, maybeParent.length());
116+
}
117+
106118
@Override
107119
public boolean equals(Object o) {
108120
if (o == null || getClass() != o.getClass()) return false;
@@ -114,4 +126,30 @@ public boolean equals(Object o) {
114126
public int hashCode() {
115127
return Objects.hash(Arrays.hashCode(readPaths), Arrays.hashCode(writePaths));
116128
}
129+
130+
/**
131+
* For our lexicographic sort trick to work correctly, we must have path separators sort before
132+
* any other character so that files in a directory appear immediately after that directory.
133+
* For example, we require [/a, /a/b, /a.xml] rather than the natural order [/a, /a.xml, /a/b].
134+
*/
135+
private static final Comparator<String> PATH_ORDER = (s1, s2) -> {
136+
Path p1 = Path.of(s1);
137+
Path p2 = Path.of(s2);
138+
var i1 = p1.iterator();
139+
var i2 = p2.iterator();
140+
while (i1.hasNext() && i2.hasNext()) {
141+
int cmp = i1.next().compareTo(i2.next());
142+
if (cmp != 0) {
143+
return cmp;
144+
}
145+
}
146+
if (i1.hasNext()) {
147+
return 1;
148+
} else if (i2.hasNext()) {
149+
return -1;
150+
} else {
151+
assert p1.equals(p2);
152+
return 0;
153+
}
154+
};
117155
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public record PathLookup(
1717
Path homeDir,
1818
Path configDir,
1919
Path[] dataDirs,
20+
Path[] sharedRepoDirs,
2021
Path tempDir,
2122
Function<String, String> settingResolver,
2223
Function<String, Stream<String>> settingGlobResolver

0 commit comments

Comments
 (0)