Skip to content

Commit 4a7ab65

Browse files
authored
Merge branch 'main' into entitlements/relative-home-path
2 parents 6a5fcac + b181164 commit 4a7ab65

File tree

56 files changed

+1749
-417
lines changed

Some content is hidden

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

56 files changed

+1749
-417
lines changed

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/RestrictedBuildApiService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ private static ListMultimap<Class<?>, String> createLegacyRestTestBasePluginUsag
9393
map.put(LegacyRestTestBasePlugin.class, ":x-pack:qa:smoke-test-security-with-mustache");
9494
map.put(LegacyRestTestBasePlugin.class, ":x-pack:qa:xpack-prefix-rest-compat");
9595
map.put(LegacyRestTestBasePlugin.class, ":modules:ingest-geoip:qa:file-based-update");
96-
map.put(LegacyRestTestBasePlugin.class, ":plugins:discovery-ec2:qa:amazon-ec2");
9796
map.put(LegacyRestTestBasePlugin.class, ":plugins:discovery-gce:qa:gce");
9897
map.put(LegacyRestTestBasePlugin.class, ":x-pack:qa:multi-cluster-search-security:legacy-with-basic-license");
9998
map.put(LegacyRestTestBasePlugin.class, ":x-pack:qa:multi-cluster-search-security:legacy-with-full-license");

docs/changelog/121784.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 121784
2+
summary: Optionally allow text similarity reranking to fail
3+
area: Search
4+
type: enhancement
5+
issues: []

docs/changelog/121971.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 121971
2+
summary: Do not fetch reserved roles from native store when Get Role API is called
3+
area: Authorization
4+
type: enhancement
5+
issues: []

docs/changelog/122640.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 122640
2+
summary: Fix redact processor arraycopy bug
3+
area: Ingest Node
4+
type: bug
5+
issues: []

libs/entitlement/bridge/src/main/java/org/elasticsearch/entitlement/bridge/EntitlementChecker.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
import java.nio.file.LinkOption;
5959
import java.nio.file.OpenOption;
6060
import java.nio.file.Path;
61+
import java.nio.file.WatchEvent;
62+
import java.nio.file.WatchService;
6163
import java.nio.file.attribute.FileAttribute;
6264
import java.nio.file.attribute.UserPrincipal;
6365
import java.nio.file.spi.FileSystemProvider;
@@ -654,6 +656,19 @@ void checkNewByteChannel(
654656

655657
void checkType(Class<?> callerClass, FileStore that);
656658

659+
// path
660+
void checkPathToRealPath(Class<?> callerClass, Path that, LinkOption... options);
661+
662+
void checkPathRegister(Class<?> callerClass, Path that, WatchService watcher, WatchEvent.Kind<?>... events);
663+
664+
void checkPathRegister(
665+
Class<?> callerClass,
666+
Path that,
667+
WatchService watcher,
668+
WatchEvent.Kind<?>[] events,
669+
WatchEvent.Modifier... modifiers
670+
);
671+
657672
////////////////////
658673
//
659674
// Thread management
@@ -674,5 +689,4 @@ void checkNewByteChannel(
674689
void check$java_lang_Thread$setUncaughtExceptionHandler(Class<?> callerClass, Thread thread, Thread.UncaughtExceptionHandler ueh);
675690

676691
void check$java_lang_ThreadGroup$setMaxPriority(Class<?> callerClass, ThreadGroup threadGroup, int pri);
677-
678692
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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.qa.test;
11+
12+
import java.io.IOException;
13+
import java.nio.file.FileSystems;
14+
import java.nio.file.LinkOption;
15+
import java.nio.file.WatchEvent;
16+
17+
import static org.elasticsearch.entitlement.qa.test.EntitlementTest.ExpectedAccess.PLUGINS;
18+
19+
class PathActions {
20+
21+
@EntitlementTest(expectedAccess = PLUGINS)
22+
static void checkToRealPath() throws IOException {
23+
FileCheckActions.readFile().toRealPath();
24+
}
25+
26+
@EntitlementTest(expectedAccess = PLUGINS)
27+
static void checkToRealPathNoFollow() throws IOException {
28+
FileCheckActions.readFile().toRealPath(LinkOption.NOFOLLOW_LINKS);
29+
}
30+
31+
@SuppressWarnings("rawtypes")
32+
@EntitlementTest(expectedAccess = PLUGINS)
33+
static void checkRegister() throws IOException {
34+
try (var watchService = FileSystems.getDefault().newWatchService()) {
35+
FileCheckActions.readFile().register(watchService, new WatchEvent.Kind[0]);
36+
} catch (IllegalArgumentException e) {
37+
// intentionally no events registered
38+
}
39+
}
40+
41+
@SuppressWarnings("rawtypes")
42+
@EntitlementTest(expectedAccess = PLUGINS)
43+
static void checkRegisterWithModifiers() throws IOException {
44+
try (var watchService = FileSystems.getDefault().newWatchService()) {
45+
FileCheckActions.readFile().register(watchService, new WatchEvent.Kind[0], new WatchEvent.Modifier[0]);
46+
} catch (IllegalArgumentException e) {
47+
// intentionally no events registered
48+
}
49+
}
50+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ static CheckAction alwaysDenied(CheckedRunnable<Exception> action) {
190190
getTestEntries(ManageThreadsActions.class),
191191
getTestEntries(NativeActions.class),
192192
getTestEntries(NioFileSystemActions.class),
193+
getTestEntries(PathActions.class),
193194
getTestEntries(SpiActions.class),
194195
getTestEntries(SystemActions.class)
195196
)

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

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@
4848
import java.nio.file.LinkOption;
4949
import java.nio.file.OpenOption;
5050
import java.nio.file.Path;
51+
import java.nio.file.WatchEvent;
52+
import java.nio.file.WatchService;
5153
import java.nio.file.attribute.FileAttribute;
5254
import java.nio.file.spi.FileSystemProvider;
5355
import java.util.ArrayList;
56+
import java.util.Arrays;
5457
import java.util.HashMap;
5558
import java.util.List;
5659
import java.util.Map;
@@ -61,6 +64,7 @@
6164
import java.util.stream.Stream;
6265
import java.util.stream.StreamSupport;
6366

67+
import static org.elasticsearch.entitlement.runtime.policy.entitlements.FilesEntitlement.Mode.READ;
6468
import static org.elasticsearch.entitlement.runtime.policy.entitlements.FilesEntitlement.Mode.READ_WRITE;
6569

6670
/**
@@ -97,6 +101,7 @@ public static void initialize(Instrumentation inst) throws Exception {
97101
Stream.of(
98102
fileSystemProviderChecks(),
99103
fileStoreChecks(),
104+
pathChecks(),
100105
Stream.of(
101106
INSTRUMENTATION_SERVICE.lookupImplementationMethod(
102107
SelectorProvider.class,
@@ -150,16 +155,49 @@ private static PolicyManager createPolicyManager() {
150155
new LoadNativeLibrariesEntitlement(),
151156
new ManageThreadsEntitlement(),
152157
new FilesEntitlement(
153-
List.of(
154-
FilesEntitlement.FileData.ofPath(EntitlementBootstrap.bootstrapArgs().tempDir(), READ_WRITE),
155-
FilesEntitlement.FileData.ofPath(EntitlementBootstrap.bootstrapArgs().logsDir(), READ_WRITE)
156-
)
158+
Stream.concat(
159+
Stream.of(
160+
FileData.ofPath(bootstrapArgs.tempDir(), READ_WRITE),
161+
FileData.ofPath(bootstrapArgs.configDir(), READ),
162+
FileData.ofPath(bootstrapArgs.logsDir(), READ_WRITE),
163+
// OS release on Linux
164+
FileData.ofPath(Path.of("/etc/os-release"), READ),
165+
FileData.ofPath(Path.of("/etc/system-release"), READ),
166+
FileData.ofPath(Path.of("/usr/lib/os-release"), READ),
167+
// read max virtual memory areas
168+
FileData.ofPath(Path.of("/proc/sys/vm/max_map_count"), READ),
169+
FileData.ofPath(Path.of("/proc/meminfo"), READ),
170+
// load averages on Linux
171+
FileData.ofPath(Path.of("/proc/loadavg"), READ),
172+
// control group stats on Linux. cgroup v2 stats are in an unpredicable
173+
// location under `/sys/fs/cgroup`, so unfortunately we have to allow
174+
// read access to the entire directory hierarchy.
175+
FileData.ofPath(Path.of("/proc/self/cgroup"), READ),
176+
FileData.ofPath(Path.of("/sys/fs/cgroup/"), READ),
177+
// // io stats on Linux
178+
FileData.ofPath(Path.of("/proc/self/mountinfo"), READ),
179+
FileData.ofPath(Path.of("/proc/diskstats"), READ)
180+
),
181+
Arrays.stream(bootstrapArgs.dataDirs()).map(d -> FileData.ofPath(d, READ))
182+
).toList()
157183
)
158184
)
159185
),
160186
new Scope("org.apache.httpcomponents.httpclient", List.of(new OutboundNetworkEntitlement())),
161187
new Scope("io.netty.transport", List.of(new InboundNetworkEntitlement(), new OutboundNetworkEntitlement())),
162-
new Scope("org.apache.lucene.core", List.of(new LoadNativeLibrariesEntitlement(), new ManageThreadsEntitlement())),
188+
new Scope(
189+
"org.apache.lucene.core",
190+
List.of(
191+
new LoadNativeLibrariesEntitlement(),
192+
new ManageThreadsEntitlement(),
193+
new FilesEntitlement(
194+
Stream.concat(
195+
Stream.of(FileData.ofPath(bootstrapArgs.configDir(), READ)),
196+
Arrays.stream(bootstrapArgs.dataDirs()).map(d -> FileData.ofPath(d, READ_WRITE))
197+
).toList()
198+
)
199+
)
200+
),
163201
new Scope("org.apache.logging.log4j.core", List.of(new ManageThreadsEntitlement())),
164202
new Scope(
165203
"org.elasticsearch.nativeaccess",
@@ -278,6 +316,33 @@ public InstrumentationService.InstrumentationInfo of(String methodName, Class<?>
278316
});
279317
}
280318

319+
private static Stream<InstrumentationService.InstrumentationInfo> pathChecks() {
320+
var pathClasses = StreamSupport.stream(FileSystems.getDefault().getRootDirectories().spliterator(), false)
321+
.map(Path::getClass)
322+
.distinct();
323+
return pathClasses.flatMap(pathClass -> {
324+
InstrumentationInfoFactory instrumentation = (String methodName, Class<?>... parameterTypes) -> INSTRUMENTATION_SERVICE
325+
.lookupImplementationMethod(
326+
Path.class,
327+
methodName,
328+
pathClass,
329+
EntitlementChecker.class,
330+
"checkPath" + Character.toUpperCase(methodName.charAt(0)) + methodName.substring(1),
331+
parameterTypes
332+
);
333+
334+
try {
335+
return Stream.of(
336+
instrumentation.of("toRealPath", LinkOption[].class),
337+
instrumentation.of("register", WatchService.class, WatchEvent.Kind[].class),
338+
instrumentation.of("register", WatchService.class, WatchEvent.Kind[].class, WatchEvent.Modifier[].class)
339+
);
340+
} catch (NoSuchMethodException | ClassNotFoundException e) {
341+
throw new RuntimeException(e);
342+
}
343+
});
344+
}
345+
281346
/**
282347
* Returns the "most recent" checker class compatible with the current runtime Java version.
283348
* For checkers, we have (optionally) version specific classes, each with a prefix (e.g. Java23).

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.elasticsearch.entitlement.runtime.policy.PolicyManager;
1515

1616
import java.io.File;
17+
import java.io.IOException;
1718
import java.io.InputStream;
1819
import java.io.PrintStream;
1920
import java.io.PrintWriter;
@@ -60,10 +61,13 @@
6061
import java.nio.file.CopyOption;
6162
import java.nio.file.DirectoryStream;
6263
import java.nio.file.FileStore;
64+
import java.nio.file.Files;
6365
import java.nio.file.LinkOption;
6466
import java.nio.file.OpenOption;
6567
import java.nio.file.Path;
6668
import java.nio.file.StandardOpenOption;
69+
import java.nio.file.WatchEvent;
70+
import java.nio.file.WatchService;
6771
import java.nio.file.attribute.FileAttribute;
6872
import java.nio.file.attribute.UserPrincipal;
6973
import java.nio.file.spi.FileSystemProvider;
@@ -1369,4 +1373,38 @@ public void checkName(Class<?> callerClass, FileStore that) {
13691373
public void checkType(Class<?> callerClass, FileStore that) {
13701374
policyManager.checkReadStoreAttributes(callerClass);
13711375
}
1376+
1377+
@Override
1378+
public void checkPathToRealPath(Class<?> callerClass, Path that, LinkOption... options) {
1379+
boolean followLinks = true;
1380+
for (LinkOption option : options) {
1381+
if (option == LinkOption.NOFOLLOW_LINKS) {
1382+
followLinks = false;
1383+
}
1384+
}
1385+
if (followLinks) {
1386+
try {
1387+
policyManager.checkFileRead(callerClass, Files.readSymbolicLink(that));
1388+
} catch (IOException | UnsupportedOperationException e) {
1389+
// that is not a link, or unrelated IOException or unsupported
1390+
}
1391+
}
1392+
policyManager.checkFileRead(callerClass, that);
1393+
}
1394+
1395+
@Override
1396+
public void checkPathRegister(Class<?> callerClass, Path that, WatchService watcher, WatchEvent.Kind<?>... events) {
1397+
policyManager.checkFileRead(callerClass, that);
1398+
}
1399+
1400+
@Override
1401+
public void checkPathRegister(
1402+
Class<?> callerClass,
1403+
Path that,
1404+
WatchService watcher,
1405+
WatchEvent.Kind<?>[] events,
1406+
WatchEvent.Modifier... modifiers
1407+
) {
1408+
policyManager.checkFileRead(callerClass, that);
1409+
}
13721410
}

0 commit comments

Comments
 (0)