Skip to content

Commit 0482f14

Browse files
authored
Merge branch 'main' into arpadkiraly-remove-entsearch-updateforv9
2 parents a1f0ccb + 8aaca61 commit 0482f14

File tree

20 files changed

+178
-209
lines changed

20 files changed

+178
-209
lines changed

libs/entitlement/qa/entitled-plugin/src/main/java/org/elasticsearch/entitlement/qa/entitled/EntitledActions.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ public static Path createTempSymbolicLink() throws IOException {
6666
return Files.createSymbolicLink(readDir().resolve("entitlements-link-" + random.nextLong()), readWriteDir());
6767
}
6868

69+
public static Path createK8sLikeMount() throws IOException {
70+
Path baseDir = readDir().resolve("k8s");
71+
var versionedDir = Files.createDirectories(baseDir.resolve("..version"));
72+
var actualFileMount = Files.createFile(versionedDir.resolve("mount-" + random.nextLong() + ".tmp"));
73+
74+
var dataDir = Files.createSymbolicLink(baseDir.resolve("..data"), versionedDir.getFileName());
75+
// mount-0.tmp -> ..data/mount-0.tmp -> ..version/mount-0.tmp
76+
return Files.createSymbolicLink(
77+
baseDir.resolve(actualFileMount.getFileName()),
78+
dataDir.getFileName().resolve(actualFileMount.getFileName())
79+
);
80+
}
81+
6982
public static URLConnection createHttpURLConnection() throws IOException {
7083
return URI.create("http://127.0.0.1:12345/").toURL().openConnection();
7184
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ static void checkFilesCreateSymbolicLink() throws IOException {
140140
}
141141
}
142142

143+
@EntitlementTest(expectedAccess = PLUGINS)
144+
static void checkFilesCreateRelativeSymbolicLink() throws IOException {
145+
var directory = EntitledActions.createTempDirectoryForWrite();
146+
try {
147+
Files.createSymbolicLink(directory.resolve("link"), Path.of("target"));
148+
} catch (UnsupportedOperationException | FileSystemException e) {
149+
// OK not to implement symbolic link in the filesystem
150+
}
151+
}
152+
143153
@EntitlementTest(expectedAccess = PLUGINS)
144154
static void checkFilesCreateLink() throws IOException {
145155
var directory = EntitledActions.createTempDirectoryForWrite();
@@ -150,6 +160,17 @@ static void checkFilesCreateLink() throws IOException {
150160
}
151161
}
152162

163+
@EntitlementTest(expectedAccess = PLUGINS)
164+
static void checkFilesCreateRelativeLink() throws IOException {
165+
var directory = EntitledActions.createTempDirectoryForWrite();
166+
var target = directory.resolve("target");
167+
try {
168+
Files.createLink(directory.resolve("link"), Path.of("target"));
169+
} catch (UnsupportedOperationException | FileSystemException e) {
170+
// OK not to implement symbolic link in the filesystem
171+
}
172+
}
173+
153174
@EntitlementTest(expectedAccess = PLUGINS)
154175
static void checkFilesDelete() throws IOException {
155176
var file = EntitledActions.createTempFileForWrite();

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

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

1010
package org.elasticsearch.entitlement.qa.test;
1111

12+
import org.elasticsearch.entitlement.qa.entitled.EntitledActions;
13+
1214
import java.io.IOException;
1315
import java.nio.file.FileSystems;
1416
import java.nio.file.LinkOption;
@@ -24,6 +26,11 @@ static void checkToRealPath() throws IOException {
2426
FileCheckActions.readFile().toRealPath();
2527
}
2628

29+
@EntitlementTest(expectedAccess = PLUGINS)
30+
static void checkToRealPathWithK8sLikeMount() throws IOException, Exception {
31+
EntitledActions.createK8sLikeMount().toRealPath();
32+
}
33+
2734
@EntitlementTest(expectedAccess = PLUGINS)
2835
static void checkToRealPathNoFollow() throws IOException {
2936
FileCheckActions.readFile().toRealPath(LinkOption.NOFOLLOW_LINKS);

libs/entitlement/qa/src/javaRestTest/java/org/elasticsearch/entitlement/qa/EntitlementsTestRule.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class EntitlementsTestRule implements TestRule {
4040
"files",
4141
List.of(
4242
Map.of("path", tempDir.resolve("read_dir"), "mode", "read_write"),
43+
Map.of("path", tempDir.resolve("read_dir").resolve("k8s").resolve("..data"), "mode", "read", "exclusive", true),
4344
Map.of("path", tempDir.resolve("read_write_dir"), "mode", "read_write"),
4445
Map.of("path", tempDir.resolve("read_file"), "mode", "read"),
4546
Map.of("path", tempDir.resolve("read_write_file"), "mode", "read_write")

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.io.FileDescriptor;
2020
import java.io.FileFilter;
2121
import java.io.FilenameFilter;
22-
import java.io.IOException;
2322
import java.io.InputStream;
2423
import java.io.OutputStream;
2524
import java.io.PrintStream;
@@ -74,7 +73,6 @@
7473
import java.nio.file.FileStore;
7574
import java.nio.file.FileVisitOption;
7675
import java.nio.file.FileVisitor;
77-
import java.nio.file.Files;
7876
import java.nio.file.LinkOption;
7977
import java.nio.file.OpenOption;
8078
import java.nio.file.Path;
@@ -2050,16 +2048,21 @@ public void checkSelectorProviderInheritedChannel(Class<?> callerClass, Selector
20502048
policyManager.checkCreateTempFile(callerClass);
20512049
}
20522050

2051+
private static Path resolveLinkTarget(Path path, Path target) {
2052+
var parent = path.getParent();
2053+
return parent == null ? target : parent.resolve(target);
2054+
}
2055+
20532056
@Override
20542057
public void check$java_nio_file_Files$$createSymbolicLink(Class<?> callerClass, Path link, Path target, FileAttribute<?>... attrs) {
2055-
policyManager.checkFileRead(callerClass, target);
20562058
policyManager.checkFileWrite(callerClass, link);
2059+
policyManager.checkFileRead(callerClass, resolveLinkTarget(link, target));
20572060
}
20582061

20592062
@Override
20602063
public void check$java_nio_file_Files$$createLink(Class<?> callerClass, Path link, Path existing) {
2061-
policyManager.checkFileRead(callerClass, existing);
20622064
policyManager.checkFileWrite(callerClass, link);
2065+
policyManager.checkFileRead(callerClass, resolveLinkTarget(link, existing));
20632066
}
20642067

20652068
@Override
@@ -2548,13 +2551,13 @@ public void checkCreateDirectory(Class<?> callerClass, FileSystemProvider that,
25482551
@Override
25492552
public void checkCreateSymbolicLink(Class<?> callerClass, FileSystemProvider that, Path link, Path target, FileAttribute<?>... attrs) {
25502553
policyManager.checkFileWrite(callerClass, link);
2551-
policyManager.checkFileRead(callerClass, target);
2554+
policyManager.checkFileRead(callerClass, resolveLinkTarget(link, target));
25522555
}
25532556

25542557
@Override
25552558
public void checkCreateLink(Class<?> callerClass, FileSystemProvider that, Path link, Path existing) {
25562559
policyManager.checkFileWrite(callerClass, link);
2557-
policyManager.checkFileRead(callerClass, existing);
2560+
policyManager.checkFileRead(callerClass, resolveLinkTarget(link, existing));
25582561
}
25592562

25602563
@Override
@@ -2748,14 +2751,7 @@ public void checkPathToRealPath(Class<?> callerClass, Path that, LinkOption... o
27482751
followLinks = false;
27492752
}
27502753
}
2751-
if (followLinks) {
2752-
try {
2753-
policyManager.checkFileRead(callerClass, Files.readSymbolicLink(that));
2754-
} catch (IOException | UnsupportedOperationException e) {
2755-
// that is not a link, or unrelated IOException or unsupported
2756-
}
2757-
}
2758-
policyManager.checkFileRead(callerClass, that);
2754+
policyManager.checkFileRead(callerClass, that, followLinks);
27592755
}
27602756

27612757
@Override

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.elasticsearch.logging.Logger;
3232

3333
import java.io.File;
34+
import java.io.IOException;
3435
import java.lang.StackWalker.StackFrame;
3536
import java.lang.module.ModuleFinder;
3637
import java.lang.module.ModuleReference;
@@ -325,6 +326,10 @@ private static boolean isPathOnDefaultFilesystem(Path path) {
325326
}
326327

327328
public void checkFileRead(Class<?> callerClass, Path path) {
329+
checkFileRead(callerClass, path, false);
330+
}
331+
332+
public void checkFileRead(Class<?> callerClass, Path path, boolean followLinks) {
328333
if (isPathOnDefaultFilesystem(path) == false) {
329334
return;
330335
}
@@ -334,14 +339,28 @@ public void checkFileRead(Class<?> callerClass, Path path) {
334339
}
335340

336341
ModuleEntitlements entitlements = getEntitlements(requestingClass);
337-
if (entitlements.fileAccess().canRead(path) == false) {
342+
343+
Path realPath = null;
344+
boolean canRead = entitlements.fileAccess().canRead(path);
345+
if (canRead && followLinks) {
346+
try {
347+
realPath = path.toRealPath();
348+
} catch (IOException e) {
349+
// target not found or other IO error
350+
}
351+
if (realPath != null && realPath.equals(path) == false) {
352+
canRead = entitlements.fileAccess().canRead(realPath);
353+
}
354+
}
355+
356+
if (canRead == false) {
338357
notEntitled(
339358
Strings.format(
340359
"Not entitled: component [%s], module [%s], class [%s], entitlement [file], operation [read], path [%s]",
341360
entitlements.componentName(),
342361
requestingClass.getModule().getName(),
343362
requestingClass,
344-
path
363+
realPath == null ? path : Strings.format("%s -> %s", path, realPath)
345364
),
346365
callerClass
347366
);

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ static TransportVersion def(int id) {
6060
public static final TransportVersion V_7_8_1 = def(7_08_01_99);
6161
public static final TransportVersion V_7_9_0 = def(7_09_00_99);
6262
public static final TransportVersion V_7_10_0 = def(7_10_00_99);
63-
public static final TransportVersion V_7_15_0 = def(7_15_00_99);
64-
public static final TransportVersion V_7_15_1 = def(7_15_01_99);
6563
public static final TransportVersion V_7_17_0 = def(7_17_00_99);
6664
public static final TransportVersion V_7_17_1 = def(7_17_01_99);
6765
public static final TransportVersion V_7_17_8 = def(7_17_08_99);

server/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplanation.java

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

1010
package org.elasticsearch.action.admin.cluster.allocation;
1111

12-
import org.elasticsearch.TransportVersions;
1312
import org.elasticsearch.cluster.ClusterInfo;
1413
import org.elasticsearch.cluster.node.DiscoveryNode;
1514
import org.elasticsearch.cluster.routing.ShardRouting;
@@ -80,11 +79,7 @@ public ClusterAllocationExplanation(
8079
}
8180

8281
public ClusterAllocationExplanation(StreamInput in) throws IOException {
83-
if (in.getTransportVersion().onOrAfter(TransportVersions.V_7_15_0)) {
84-
this.specificShard = in.readBoolean();
85-
} else {
86-
this.specificShard = true; // suppress "this is a random shard" warning in BwC situations
87-
}
82+
this.specificShard = in.readBoolean();
8883
this.shardRouting = new ShardRouting(in);
8984
this.currentNode = in.readOptionalWriteable(DiscoveryNode::new);
9085
this.relocationTargetNode = in.readOptionalWriteable(DiscoveryNode::new);
@@ -94,9 +89,7 @@ public ClusterAllocationExplanation(StreamInput in) throws IOException {
9489

9590
@Override
9691
public void writeTo(StreamOutput out) throws IOException {
97-
if (out.getTransportVersion().onOrAfter(TransportVersions.V_7_15_0)) {
98-
out.writeBoolean(specificShard);
99-
} // else suppress "this is a random shard" warning in BwC situations
92+
out.writeBoolean(specificShard);
10093
shardRouting.writeTo(out);
10194
out.writeOptionalWriteable(currentNode);
10295
out.writeOptionalWriteable(relocationTargetNode);

server/src/main/java/org/elasticsearch/cluster/routing/UnassignedInfo.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@ public record UnassignedInfo(
7777
@Nullable String lastAllocatedNodeId
7878
) implements ToXContentFragment, Writeable {
7979

80-
/**
81-
* The version that the {@code lastAllocatedNode} field was added in. Used to adapt streaming of this class as appropriate for the
82-
* version of the node sending/receiving it. Should be removed once wire compatibility with this version is no longer necessary.
83-
*/
84-
private static final TransportVersion VERSION_LAST_ALLOCATED_NODE_ADDED = TransportVersions.V_7_15_0;
8580
private static final TransportVersion VERSION_UNPROMOTABLE_REPLICA_ADDED = TransportVersions.V_8_7_0;
8681

8782
public static final DateFormatter DATE_TIME_FORMATTER = DateFormatter.forPattern("date_optional_time").withZone(ZoneOffset.UTC);
@@ -315,11 +310,7 @@ public static UnassignedInfo fromStreamInput(StreamInput in) throws IOException
315310
var lastAllocationStatus = AllocationStatus.readFrom(in);
316311
var failedNodeIds = in.readCollectionAsImmutableSet(StreamInput::readString);
317312
String lastAllocatedNodeId;
318-
if (in.getTransportVersion().onOrAfter(VERSION_LAST_ALLOCATED_NODE_ADDED)) {
319-
lastAllocatedNodeId = in.readOptionalString();
320-
} else {
321-
lastAllocatedNodeId = null;
322-
}
313+
lastAllocatedNodeId = in.readOptionalString();
323314
return new UnassignedInfo(
324315
reason,
325316
message,
@@ -335,9 +326,7 @@ public static UnassignedInfo fromStreamInput(StreamInput in) throws IOException
335326
}
336327

337328
public void writeTo(StreamOutput out) throws IOException {
338-
if (reason.equals(Reason.NODE_RESTARTING) && out.getTransportVersion().before(VERSION_LAST_ALLOCATED_NODE_ADDED)) {
339-
out.writeByte((byte) Reason.NODE_LEFT.ordinal());
340-
} else if (reason.equals(Reason.UNPROMOTABLE_REPLICA) && out.getTransportVersion().before(VERSION_UNPROMOTABLE_REPLICA_ADDED)) {
329+
if (reason.equals(Reason.UNPROMOTABLE_REPLICA) && out.getTransportVersion().before(VERSION_UNPROMOTABLE_REPLICA_ADDED)) {
341330
out.writeByte((byte) Reason.PRIMARY_FAILED.ordinal());
342331
} else if (reason.equals(Reason.RESHARD_ADDED)
343332
&& out.getTransportVersion().before(TransportVersions.UNASSIGENEDINFO_RESHARD_ADDED)) {
@@ -355,9 +344,7 @@ public void writeTo(StreamOutput out) throws IOException {
355344
out.writeVInt(failedAllocations);
356345
lastAllocationStatus.writeTo(out);
357346
out.writeStringCollection(failedNodeIds);
358-
if (out.getTransportVersion().onOrAfter(VERSION_LAST_ALLOCATED_NODE_ADDED)) {
359-
out.writeOptionalString(lastAllocatedNodeId);
360-
}
347+
out.writeOptionalString(lastAllocatedNodeId);
361348
}
362349

363350
/**

server/src/main/java/org/elasticsearch/indices/recovery/RecoverySettings.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import org.apache.logging.log4j.Logger;
1414
import org.apache.lucene.store.RateLimiter;
1515
import org.apache.lucene.store.RateLimiter.SimpleRateLimiter;
16-
import org.elasticsearch.TransportVersion;
17-
import org.elasticsearch.TransportVersions;
1816
import org.elasticsearch.cluster.node.DiscoveryNode;
1917
import org.elasticsearch.cluster.node.DiscoveryNodeRole;
2018
import org.elasticsearch.common.settings.ClusterSettings;
@@ -50,7 +48,6 @@
5048

5149
public class RecoverySettings {
5250
public static final IndexVersion SNAPSHOT_RECOVERIES_SUPPORTED_INDEX_VERSION = IndexVersions.V_7_15_0;
53-
public static final TransportVersion SNAPSHOT_RECOVERIES_SUPPORTED_TRANSPORT_VERSION = TransportVersions.V_7_15_0;
5451
public static final IndexVersion SEQ_NO_SNAPSHOT_RECOVERIES_SUPPORTED_VERSION = IndexVersions.V_7_16_0;
5552

5653
private static final Logger logger = LogManager.getLogger(RecoverySettings.class);

0 commit comments

Comments
 (0)