Skip to content

Commit 5fc36ba

Browse files
committed
Merge branch 'main' into prunedups
2 parents 8326027 + b346427 commit 5fc36ba

File tree

24 files changed

+341
-131
lines changed

24 files changed

+341
-131
lines changed

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ public class EntitlementBootstrap {
3535
public record BootstrapArgs(
3636
Map<String, Policy> pluginPolicies,
3737
Function<Class<?>, String> pluginResolver,
38-
Function<String, String> settingResolver,
39-
Function<String, Stream<String>> settingGlobResolver,
38+
Function<String, Stream<String>> settingResolver,
4039
Path[] dataDirs,
4140
Path[] sharedRepoDirs,
4241
Path configDir,
@@ -51,7 +50,6 @@ public record BootstrapArgs(
5150
requireNonNull(pluginPolicies);
5251
requireNonNull(pluginResolver);
5352
requireNonNull(settingResolver);
54-
requireNonNull(settingGlobResolver);
5553
requireNonNull(dataDirs);
5654
if (dataDirs.length == 0) {
5755
throw new IllegalArgumentException("must provide at least one data directory");
@@ -78,8 +76,7 @@ public static BootstrapArgs bootstrapArgs() {
7876
*
7977
* @param pluginPolicies a map holding policies for plugins (and modules), by plugin (or module) name.
8078
* @param pluginResolver a functor to map a Java Class to the plugin it belongs to (the plugin name).
81-
* @param settingResolver a functor to resolve the value of an Elasticsearch setting.
82-
* @param settingGlobResolver a functor to resolve a glob expression for one or more Elasticsearch settings.
79+
* @param settingResolver a functor to resolve a setting name pattern for one or more Elasticsearch settings.
8380
* @param dataDirs data directories for Elasticsearch
8481
* @param sharedRepoDirs shared repository directories for Elasticsearch
8582
* @param configDir the config directory for Elasticsearch
@@ -93,8 +90,7 @@ public static BootstrapArgs bootstrapArgs() {
9390
public static void bootstrap(
9491
Map<String, Policy> pluginPolicies,
9592
Function<Class<?>, String> pluginResolver,
96-
Function<String, String> settingResolver,
97-
Function<String, Stream<String>> settingGlobResolver,
93+
Function<String, Stream<String>> settingResolver,
9894
Path[] dataDirs,
9995
Path[] sharedRepoDirs,
10096
Path configDir,
@@ -113,7 +109,6 @@ public static void bootstrap(
113109
pluginPolicies,
114110
pluginResolver,
115111
settingResolver,
116-
settingGlobResolver,
117112
dataDirs,
118113
sharedRepoDirs,
119114
configDir,

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ private static PolicyManager createPolicyManager() {
144144
bootstrapArgs.dataDirs(),
145145
bootstrapArgs.sharedRepoDirs(),
146146
bootstrapArgs.tempDir(),
147-
bootstrapArgs.settingResolver(),
148-
bootstrapArgs.settingGlobResolver()
147+
bootstrapArgs.settingResolver()
149148
);
150149

151150
List<Scope> serverScopes = new ArrayList<>();

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

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

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

12+
import org.elasticsearch.core.Strings;
1213
import org.elasticsearch.entitlement.runtime.policy.entitlements.FilesEntitlement;
1314
import org.elasticsearch.entitlement.runtime.policy.entitlements.FilesEntitlement.Mode;
1415
import org.elasticsearch.logging.LogManager;
@@ -203,6 +204,7 @@ static String normalizePath(Path path) {
203204
}
204205

205206
private boolean checkPath(String path, String[] paths) {
207+
logger.trace(() -> Strings.format("checking [%s] against [%s]", path, String.join(",", paths)));
206208
if (paths.length == 0) {
207209
return false;
208210
}
@@ -220,6 +222,7 @@ private boolean checkPath(String path, String[] paths) {
220222
}
221223

222224
private static boolean isParent(String maybeParent, String path) {
225+
logger.trace(() -> Strings.format("checking isParent [%s] for [%s]", maybeParent, path));
223226
return path.startsWith(maybeParent) && path.startsWith(FILE_SEPARATOR, maybeParent.length());
224227
}
225228

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,5 @@ public record PathLookup(
1919
Path[] dataDirs,
2020
Path[] sharedRepoDirs,
2121
Path tempDir,
22-
Function<String, String> settingResolver,
23-
Function<String, Stream<String>> settingGlobResolver
22+
Function<String, Stream<String>> settingResolver
2423
) {}

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

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

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

12+
import org.elasticsearch.core.PathUtils;
1213
import org.elasticsearch.core.Strings;
1314
import org.elasticsearch.core.SuppressForbidden;
1415
import org.elasticsearch.entitlement.instrumentation.InstrumentationService;
@@ -61,6 +62,8 @@ public class PolicyManager {
6162
static final String SERVER_COMPONENT_NAME = "(server)";
6263
static final String APM_AGENT_COMPONENT_NAME = "(APM agent)";
6364

65+
static final Class<?> DEFAULT_FILESYSTEM_CLASS = PathUtils.getDefaultFileSystem().getClass();
66+
6467
/**
6568
* @param componentName the plugin name; or else one of the special component names
6669
* like {@link #SERVER_COMPONENT_NAME} or {@link #APM_AGENT_COMPONENT_NAME}.
@@ -305,7 +308,26 @@ public void checkFileRead(Class<?> callerClass, File file) {
305308
checkFileRead(callerClass, file.toPath());
306309
}
307310

311+
private static boolean isPathOnDefaultFilesystem(Path path) {
312+
var pathFileSystemClass = path.getFileSystem().getClass();
313+
if (path.getFileSystem().getClass() != DEFAULT_FILESYSTEM_CLASS) {
314+
logger.trace(
315+
() -> Strings.format(
316+
"File entitlement trivially allowed: path [%s] is for a different FileSystem class [%s], default is [%s]",
317+
path.toString(),
318+
pathFileSystemClass.getName(),
319+
DEFAULT_FILESYSTEM_CLASS.getName()
320+
)
321+
);
322+
return false;
323+
}
324+
return true;
325+
}
326+
308327
public void checkFileRead(Class<?> callerClass, Path path) {
328+
if (isPathOnDefaultFilesystem(path) == false) {
329+
return;
330+
}
309331
var requestingClass = requestingClass(callerClass);
310332
if (isTriviallyAllowed(requestingClass)) {
311333
return;
@@ -332,6 +354,9 @@ public void checkFileWrite(Class<?> callerClass, File file) {
332354
}
333355

334356
public void checkFileWrite(Class<?> callerClass, Path path) {
357+
if (isPathOnDefaultFilesystem(path) == false) {
358+
return;
359+
}
335360
var requestingClass = requestingClass(callerClass);
336361
if (isTriviallyAllowed(requestingClass)) {
337362
return;

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/entitlements/FilesEntitlement.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ static boolean isAbsolutePath(String path) {
108108
// Unix/BSD absolute
109109
return true;
110110
}
111-
112111
return isWindowsAbsolutePath(path);
113112
}
114113

@@ -232,13 +231,7 @@ public PathSettingFileData withExclusive(boolean exclusive) {
232231

233232
@Override
234233
public Stream<Path> resolveRelativePaths(PathLookup pathLookup) {
235-
Stream<String> result;
236-
if (setting.contains("*")) {
237-
result = pathLookup.settingGlobResolver().apply(setting);
238-
} else {
239-
String path = pathLookup.settingResolver().apply(setting);
240-
result = path == null ? Stream.of() : Stream.of(path);
241-
}
234+
Stream<String> result = pathLookup.settingResolver().apply(setting);
242235
if (ignoreUrl) {
243236
result = result.filter(s -> s.toLowerCase(Locale.ROOT).startsWith("https://") == false);
244237
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ private static Path path(String s) {
5050
new Path[] { Path.of("/data1"), Path.of("/data2") },
5151
new Path[] { Path.of("/shared1"), Path.of("/shared2") },
5252
Path.of("/tmp"),
53-
setting -> settings.get(setting),
54-
glob -> settings.getGlobValues(glob)
53+
pattern -> settings.getValues(pattern)
5554
);
5655

5756
public void testEmpty() {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ public static void beforeClass() {
7171
new Path[] { TEST_BASE_DIR.resolve("/data1/"), TEST_BASE_DIR.resolve("/data2") },
7272
new Path[] { TEST_BASE_DIR.resolve("/shared1"), TEST_BASE_DIR.resolve("/shared2") },
7373
TEST_BASE_DIR.resolve("/temp"),
74-
Settings.EMPTY::get,
75-
Settings.EMPTY::getGlobValues
74+
Settings.EMPTY::getValues
7675
);
7776
} catch (Exception e) {
7877
throw new IllegalStateException(e);

libs/entitlement/src/test/java/org/elasticsearch/entitlement/runtime/policy/entitlements/FilesEntitlementTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ public static void setupRoot() {
4848
new Path[] { Path.of("/data1"), Path.of("/data2") },
4949
new Path[] { Path.of("/shared1"), Path.of("/shared2") },
5050
Path.of("/tmp"),
51-
setting -> settings.get(setting),
52-
glob -> settings.getGlobValues(glob)
51+
pattern -> settings.getValues(pattern)
5352
);
5453

5554
public void testEmptyBuild() {

muted-tests.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@ tests:
335335
- class: org.elasticsearch.test.rest.yaml.RcsCcsCommonYamlTestSuiteIT
336336
method: test {p0=search.vectors/41_knn_search_bbq_hnsw/Test knn search}
337337
issue: https://github.com/elastic/elasticsearch/issues/123727
338+
- class: org.elasticsearch.xpack.downsample.DataStreamLifecycleDownsampleDisruptionIT
339+
method: testDataStreamLifecycleDownsampleRollingRestart
340+
issue: https://github.com/elastic/elasticsearch/issues/123769
341+
- class: org.elasticsearch.xpack.searchablesnapshots.FrozenSearchableSnapshotsIntegTests
342+
method: testCreateAndRestorePartialSearchableSnapshot
343+
issue: https://github.com/elastic/elasticsearch/issues/123773
338344

339345
# Examples:
340346
#

0 commit comments

Comments
 (0)