Skip to content

Commit ba959d2

Browse files
authored
Merge branch '9.0' into backport/9.0/pr-120754
2 parents 9038d6f + 1bb7154 commit ba959d2

File tree

48 files changed

+563
-990
lines changed

Some content is hidden

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

48 files changed

+563
-990
lines changed

docs/changelog/120852.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 120852
2+
summary: Correct line and column numbers of missing named parameters
3+
area: ES|QL
4+
type: bug
5+
issues: []

docs/changelog/121325.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 121325
2+
summary: '`ReindexDataStreamIndex` bug in assertion caused by reference equality'
3+
area: Data streams
4+
type: bug
5+
issues: []

docs/internal/Versioning.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ Every change to the transport protocol is represented by a new transport version
3535
higher than all previous transport versions, which then becomes the highest version
3636
recognized by that build of Elasticsearch. The version ids are stored
3737
as constants in the `TransportVersions` class.
38-
Each id has a standard pattern `M_NNN_SS_P`, where:
38+
Each id has a standard pattern `M_NNN_S_PP`, where:
3939
* `M` is the major version
4040
* `NNN` is an incrementing id
41-
* `SS` is used in subsidiary repos amending the default transport protocol
42-
* `P` is used for patches and backports
41+
* `S` is used in subsidiary repos amending the default transport protocol
42+
* `PP` is used for patches and backports
4343

4444
When you make a change to the serialization form of any object,
4545
you need to create a new sequential constant in `TransportVersions`,
4646
introduced in the same PR that adds the change, that increments
4747
the `NNN` component from the previous highest version,
4848
with other components set to zero.
49-
For example, if the previous version number is `8_413_00_1`,
50-
the next version number should be `8_414_00_0`.
49+
For example, if the previous version number is `8_413_0_01`,
50+
the next version number should be `8_414_0_00`.
5151

5252
Once you have defined your constant, you then need to use it
5353
in serialization code. If the transport version is at or above the new id,
@@ -166,7 +166,7 @@ also has that change, and knows about the patch backport ids and what they mean.
166166

167167
Index version is a single incrementing version number for the index data format,
168168
metadata, and associated mappings. It is declared the same way as the
169-
transport version - with the pattern `M_NNN_SS_P`, for the major version, version id,
169+
transport version - with the pattern `M_NNN_S_PP`, for the major version, version id,
170170
subsidiary version id, and patch number respectively.
171171

172172
Index version is stored in index metadata when an index is created,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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.core;
11+
12+
/**
13+
* A {@link java.util.function.Supplier}-like interface which allows throwing checked exceptions.
14+
*/
15+
@FunctionalInterface
16+
public interface CheckedSupplier<T, E extends Exception> {
17+
T get() throws E;
18+
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@
5252
* <p>
5353
* A bit like Mockito but way more painful.
5454
*/
55-
class DummyImplementations {
56-
57-
static class DummyLocaleServiceProvider extends LocaleServiceProvider {
55+
public class DummyImplementations {
5856

57+
public static class DummyLocaleServiceProvider extends LocaleServiceProvider {
5958
@Override
6059
public Locale[] getAvailableLocales() {
6160
throw unexpected();

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ static CheckAction alwaysDenied(CheckedRunnable<Exception> action) {
9696

9797
private static final Map<String, CheckAction> checkActions = Stream.concat(
9898
Stream.<Entry<String, CheckAction>>of(
99+
entry("static_reflection", deniedToPlugins(RestEntitlementsCheckAction::staticMethodNeverEntitledViaReflection)),
100+
entry("nonstatic_reflection", deniedToPlugins(RestEntitlementsCheckAction::nonstaticMethodNeverEntitledViaReflection)),
101+
entry("constructor_reflection", deniedToPlugins(RestEntitlementsCheckAction::constructorNeverEntitledViaReflection)),
99102
entry("runtime_exit", deniedToPlugins(RestEntitlementsCheckAction::runtimeExit)),
100103
entry("runtime_halt", deniedToPlugins(RestEntitlementsCheckAction::runtimeHalt)),
101104
entry("system_exit", deniedToPlugins(RestEntitlementsCheckAction::systemExit)),
@@ -338,6 +341,11 @@ private static void systemExit() {
338341
System.exit(123);
339342
}
340343

344+
private static void staticMethodNeverEntitledViaReflection() throws Exception {
345+
Method systemExit = System.class.getMethod("exit", int.class);
346+
systemExit.invoke(null, 123);
347+
}
348+
341349
private static void createClassLoader() throws IOException {
342350
try (var classLoader = new URLClassLoader("test", new URL[0], RestEntitlementsCheckAction.class.getClassLoader())) {
343351
logger.info("Created URLClassLoader [{}]", classLoader.getName());
@@ -348,6 +356,11 @@ private static void processBuilder_start() throws IOException {
348356
new ProcessBuilder("").start();
349357
}
350358

359+
private static void nonstaticMethodNeverEntitledViaReflection() throws Exception {
360+
Method processBuilderStart = ProcessBuilder.class.getMethod("start");
361+
processBuilderStart.invoke(new ProcessBuilder(""));
362+
}
363+
351364
private static void processBuilder_startPipeline() throws IOException {
352365
ProcessBuilder.startPipeline(List.of());
353366
}
@@ -386,6 +399,10 @@ private static void setHttpsConnectionProperties() {
386399
new DummyLocaleServiceProvider();
387400
}
388401

402+
private static void constructorNeverEntitledViaReflection() throws Exception {
403+
DummyLocaleServiceProvider.class.getConstructor().newInstance();
404+
}
405+
389406
private static void breakIteratorProvider$() {
390407
new DummyBreakIteratorProvider();
391408
}

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

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import com.sun.tools.attach.AttachNotSupportedException;
1515
import com.sun.tools.attach.VirtualMachine;
1616

17+
import org.elasticsearch.core.CheckedConsumer;
18+
import org.elasticsearch.core.CheckedSupplier;
1719
import org.elasticsearch.core.SuppressForbidden;
1820
import org.elasticsearch.entitlement.initialization.EntitlementInitialization;
1921
import org.elasticsearch.entitlement.runtime.api.NotEntitledException;
@@ -22,8 +24,10 @@
2224
import org.elasticsearch.logging.Logger;
2325

2426
import java.io.IOException;
27+
import java.lang.reflect.InvocationTargetException;
2528
import java.nio.file.Files;
2629
import java.nio.file.Path;
30+
import java.nio.file.attribute.FileAttribute;
2731
import java.util.Map;
2832
import java.util.function.Function;
2933

@@ -144,30 +148,31 @@ private static String findAgentJar() {
144148
* @throws IllegalStateException if the entitlements system can't prevent an unauthorized action of our choosing
145149
*/
146150
private static void selfTest() {
147-
ensureCannotStartProcess();
148-
ensureCanCreateTempFile();
151+
ensureCannotStartProcess(ProcessBuilder::start);
152+
ensureCanCreateTempFile(EntitlementBootstrap::createTempFile);
153+
154+
// Try again with reflection
155+
ensureCannotStartProcess(EntitlementBootstrap::reflectiveStartProcess);
156+
ensureCanCreateTempFile(EntitlementBootstrap::reflectiveCreateTempFile);
149157
}
150158

151-
private static void ensureCannotStartProcess() {
159+
private static void ensureCannotStartProcess(CheckedConsumer<ProcessBuilder, ?> startProcess) {
152160
try {
153161
// The command doesn't matter; it doesn't even need to exist
154-
new ProcessBuilder("").start();
162+
startProcess.accept(new ProcessBuilder(""));
155163
} catch (NotEntitledException e) {
156164
logger.debug("Success: Entitlement protection correctly prevented process creation");
157165
return;
158-
} catch (IOException e) {
166+
} catch (Exception e) {
159167
throw new IllegalStateException("Failed entitlement protection self-test", e);
160168
}
161169
throw new IllegalStateException("Entitlement protection self-test was incorrectly permitted");
162170
}
163171

164-
/**
165-
* Originally {@code Security.selfTest}.
166-
*/
167172
@SuppressForbidden(reason = "accesses jvm default tempdir as a self-test")
168-
private static void ensureCanCreateTempFile() {
173+
private static void ensureCanCreateTempFile(CheckedSupplier<Path, ?> createTempFile) {
169174
try {
170-
Path p = Files.createTempFile(null, null);
175+
Path p = createTempFile.get();
171176
p.toFile().deleteOnExit();
172177

173178
// Make an effort to clean up the file immediately; also, deleteOnExit leaves the file if the JVM exits abnormally.
@@ -184,5 +189,24 @@ private static void ensureCanCreateTempFile() {
184189
logger.debug("Success: Entitlement protection correctly permitted temp file creation");
185190
}
186191

192+
@SuppressForbidden(reason = "accesses jvm default tempdir as a self-test")
193+
private static Path createTempFile() throws Exception {
194+
return Files.createTempFile(null, null);
195+
}
196+
197+
private static void reflectiveStartProcess(ProcessBuilder pb) throws Exception {
198+
try {
199+
var start = ProcessBuilder.class.getMethod("start");
200+
start.invoke(pb);
201+
} catch (InvocationTargetException e) {
202+
throw (Exception) e.getCause();
203+
}
204+
}
205+
206+
private static Path reflectiveCreateTempFile() throws Exception {
207+
return (Path) Files.class.getMethod("createTempFile", String.class, String.class, FileAttribute[].class)
208+
.invoke(null, null, null, new FileAttribute<?>[0]);
209+
}
210+
187211
private static final Logger logger = LogManager.getLogger(EntitlementBootstrap.class);
188212
}

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

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

1010
package org.elasticsearch.entitlement.runtime.policy;
1111

12-
import org.elasticsearch.core.SuppressForbidden;
1312
import org.elasticsearch.entitlement.runtime.policy.entitlements.FileEntitlement;
1413

15-
import java.io.File;
1614
import java.nio.file.Path;
1715
import java.util.ArrayList;
1816
import java.util.Arrays;
@@ -51,20 +49,10 @@ boolean canRead(Path path) {
5149
return checkPath(normalize(path), readPaths);
5250
}
5351

54-
@SuppressForbidden(reason = "Explicitly checking File apis")
55-
boolean canRead(File file) {
56-
return checkPath(normalize(file.toPath()), readPaths);
57-
}
58-
5952
boolean canWrite(Path path) {
6053
return checkPath(normalize(path), writePaths);
6154
}
6255

63-
@SuppressForbidden(reason = "Explicitly checking File apis")
64-
boolean canWrite(File file) {
65-
return checkPath(normalize(file.toPath()), writePaths);
66-
}
67-
6856
private static String normalize(Path path) {
6957
return path.toAbsolutePath().normalize().toString();
7058
}

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

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -169,23 +169,7 @@ private static void validateEntitlementsPerModule(String sourceName, String modu
169169
}
170170

171171
public void checkStartProcess(Class<?> callerClass) {
172-
neverEntitled(callerClass, "start process");
173-
}
174-
175-
private void neverEntitled(Class<?> callerClass, String operationDescription) {
176-
var requestingClass = requestingClass(callerClass);
177-
if (isTriviallyAllowed(requestingClass)) {
178-
return;
179-
}
180-
181-
throw new NotEntitledException(
182-
Strings.format(
183-
"Not entitled: caller [%s], module [%s], operation [%s]",
184-
callerClass,
185-
requestingClass.getModule() == null ? "<none>" : requestingClass.getModule().getName(),
186-
operationDescription
187-
)
188-
);
172+
neverEntitled(callerClass, () -> "start process");
189173
}
190174

191175
/**
@@ -241,31 +225,9 @@ public void checkChangeNetworkHandling(Class<?> callerClass) {
241225
checkChangeJVMGlobalState(callerClass);
242226
}
243227

244-
/**
245-
* Check for operations that can access sensitive network information, e.g. secrets, tokens or SSL sessions
246-
*/
247-
public void checkReadSensitiveNetworkInformation(Class<?> callerClass) {
248-
neverEntitled(callerClass, "access sensitive network information");
249-
}
250-
251228
@SuppressForbidden(reason = "Explicitly checking File apis")
252229
public void checkFileRead(Class<?> callerClass, File file) {
253-
var requestingClass = requestingClass(callerClass);
254-
if (isTriviallyAllowed(requestingClass)) {
255-
return;
256-
}
257-
258-
ModuleEntitlements entitlements = getEntitlements(requestingClass);
259-
if (entitlements.fileAccess().canRead(file) == false) {
260-
throw new NotEntitledException(
261-
Strings.format(
262-
"Not entitled: caller [%s], module [%s], entitlement [file], operation [read], path [%s]",
263-
callerClass,
264-
requestingClass.getModule(),
265-
file
266-
)
267-
);
268-
}
230+
checkFileRead(callerClass, file.toPath());
269231
}
270232

271233
public void checkFileRead(Class<?> callerClass, Path path) {
@@ -289,22 +251,7 @@ public void checkFileRead(Class<?> callerClass, Path path) {
289251

290252
@SuppressForbidden(reason = "Explicitly checking File apis")
291253
public void checkFileWrite(Class<?> callerClass, File file) {
292-
var requestingClass = requestingClass(callerClass);
293-
if (isTriviallyAllowed(requestingClass)) {
294-
return;
295-
}
296-
297-
ModuleEntitlements entitlements = getEntitlements(requestingClass);
298-
if (entitlements.fileAccess().canWrite(file) == false) {
299-
throw new NotEntitledException(
300-
Strings.format(
301-
"Not entitled: caller [%s], module [%s], entitlement [file], operation [write], path [%s]",
302-
callerClass,
303-
requestingClass.getModule(),
304-
file
305-
)
306-
);
307-
}
254+
checkFileWrite(callerClass, file.toPath());
308255
}
309256

310257
public void checkFileWrite(Class<?> callerClass, Path path) {

libs/entitlement/src/test/java/org/elasticsearch/entitlement/runtime/policy/PolicyManagerTests.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ public void testRequestingClassFastPath() throws IOException, ClassNotFoundExcep
238238
}
239239

240240
public void testRequestingModuleWithStackWalk() throws IOException, ClassNotFoundException {
241-
var agentsClass = new TestAgent();
242241
var entitlementsClass = makeClassInItsOwnModule(); // A class in the entitlements library itself
243242
var requestingClass = makeClassInItsOwnModule(); // This guy is always the right answer
244243
var instrumentedClass = makeClassInItsOwnModule(); // The class that called the check method
@@ -365,13 +364,6 @@ private static Class<?> makeClassInItsOwnModule() throws IOException, ClassNotFo
365364
return layer.findLoader("org.example.plugin").loadClass("q.B");
366365
}
367366

368-
private static Class<?> makeClassInItsOwnUnnamedModule() throws IOException, ClassNotFoundException {
369-
final Path home = createTempDir();
370-
Path jar = createMockPluginJar(home);
371-
var layer = createLayerForJar(jar, "org.example.plugin");
372-
return layer.findLoader("org.example.plugin").loadClass("q.B");
373-
}
374-
375367
private static PolicyManager policyManager(String agentsPackageName, Module entitlementsModule) {
376368
return new PolicyManager(createEmptyTestServerPolicy(), List.of(), Map.of(), c -> "test", agentsPackageName, entitlementsModule);
377369
}

0 commit comments

Comments
 (0)