Skip to content

Commit 5a0b90b

Browse files
authored
Merge branch 'main' into test/fix-bbq-bwc
2 parents 2261655 + d59a0d9 commit 5a0b90b

File tree

22 files changed

+524
-80
lines changed

22 files changed

+524
-80
lines changed

docs/changelog/122610.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 122610
2+
summary: Canonicalize processor names and types in `IngestStats`
3+
area: Ingest Node
4+
type: bug
5+
issues: []

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
class LoadNativeLibrariesCheckActions {
1313
static void runtimeLoad() {
1414
try {
15-
Runtime.getRuntime().load("libSomeLibFile.so");
15+
Runtime.getRuntime().load(FileCheckActions.readDir().resolve("libSomeLibFile.so").toString());
1616
} catch (UnsatisfiedLinkError ignored) {
1717
// The library does not exist, so we expect to fail loading it
1818
}
1919
}
2020

2121
static void systemLoad() {
2222
try {
23-
System.load("libSomeLibFile.so");
23+
System.load(FileCheckActions.readDir().resolve("libSomeLibFile.so").toString());
2424
} catch (UnsatisfiedLinkError ignored) {
2525
// The library does not exist, so we expect to fail loading it
2626
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static void memorySegmentReinterpretWithSizeAndCleanup() {
113113
@EntitlementTest(expectedAccess = PLUGINS)
114114
static void symbolLookupWithPath() {
115115
try {
116-
SymbolLookup.libraryLookup(Path.of("/foo/bar/libFoo.so"), Arena.ofAuto());
116+
SymbolLookup.libraryLookup(FileCheckActions.readDir().resolve("libFoo.so"), Arena.ofAuto());
117117
} catch (IllegalArgumentException e) {
118118
// IllegalArgumentException is thrown if path does not point to a valid library (and it does not)
119119
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.elasticsearch.entitlement.instrumentation.MethodKey;
1919
import org.elasticsearch.entitlement.instrumentation.Transformer;
2020
import org.elasticsearch.entitlement.runtime.api.ElasticsearchEntitlementChecker;
21+
import org.elasticsearch.entitlement.runtime.policy.PathLookup;
2122
import org.elasticsearch.entitlement.runtime.policy.Policy;
2223
import org.elasticsearch.entitlement.runtime.policy.PolicyManager;
2324
import org.elasticsearch.entitlement.runtime.policy.Scope;
@@ -48,7 +49,6 @@
4849
import java.nio.file.attribute.FileAttribute;
4950
import java.nio.file.spi.FileSystemProvider;
5051
import java.util.ArrayList;
51-
import java.util.Arrays;
5252
import java.util.HashMap;
5353
import java.util.List;
5454
import java.util.Map;
@@ -126,9 +126,9 @@ private static Class<?>[] findClassesToRetransform(Class<?>[] loadedClasses, Set
126126
}
127127

128128
private static PolicyManager createPolicyManager() {
129-
Map<String, Policy> pluginPolicies = EntitlementBootstrap.bootstrapArgs().pluginPolicies();
130-
Path[] dataDirs = EntitlementBootstrap.bootstrapArgs().dataDirs();
131-
Path tempDir = EntitlementBootstrap.bootstrapArgs().tempDir();
129+
EntitlementBootstrap.BootstrapArgs bootstrapArgs = EntitlementBootstrap.bootstrapArgs();
130+
Map<String, Policy> pluginPolicies = bootstrapArgs.pluginPolicies();
131+
var pathLookup = new PathLookup(bootstrapArgs.configDir(), bootstrapArgs.dataDirs(), bootstrapArgs.tempDir());
132132

133133
// TODO(ES-10031): Decide what goes in the elasticsearch default policy and extend it
134134
var serverPolicy = new Policy(
@@ -147,7 +147,7 @@ private static PolicyManager createPolicyManager() {
147147
new LoadNativeLibrariesEntitlement(),
148148
new ManageThreadsEntitlement(),
149149
new FilesEntitlement(
150-
List.of(new FilesEntitlement.FileData(EntitlementBootstrap.bootstrapArgs().tempDir().toString(), READ_WRITE))
150+
List.of(FilesEntitlement.FileData.ofPath(EntitlementBootstrap.bootstrapArgs().tempDir(), READ_WRITE))
151151
)
152152
)
153153
),
@@ -159,7 +159,7 @@ private static PolicyManager createPolicyManager() {
159159
"org.elasticsearch.nativeaccess",
160160
List.of(
161161
new LoadNativeLibrariesEntitlement(),
162-
new FilesEntitlement(Arrays.stream(dataDirs).map(d -> new FileData(d.toString(), READ_WRITE)).toList())
162+
new FilesEntitlement(List.of(FileData.ofRelativePath(Path.of(""), FilesEntitlement.BaseDir.DATA, READ_WRITE)))
163163
)
164164
)
165165
)
@@ -175,7 +175,7 @@ private static PolicyManager createPolicyManager() {
175175
resolver,
176176
AGENTS_PACKAGE_NAME,
177177
ENTITLEMENTS_MODULE,
178-
tempDir
178+
pathLookup
179179
);
180180
}
181181

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ public void checkSelectorProviderInheritedChannel(Class<?> callerClass, Selector
836836

837837
@Override
838838
public void check$java_lang_Runtime$load(Class<?> callerClass, Runtime that, String filename) {
839-
// TODO: check filesystem entitlement READ
839+
policyManager.checkFileRead(callerClass, Path.of(filename));
840840
policyManager.checkLoadingNativeLibraries(callerClass);
841841
}
842842

@@ -847,7 +847,7 @@ public void checkSelectorProviderInheritedChannel(Class<?> callerClass, Selector
847847

848848
@Override
849849
public void check$java_lang_System$$load(Class<?> callerClass, String filename) {
850-
// TODO: check filesystem entitlement READ
850+
policyManager.checkFileRead(callerClass, Path.of(filename));
851851
policyManager.checkLoadingNativeLibraries(callerClass);
852852
}
853853

@@ -931,7 +931,7 @@ public void checkSelectorProviderInheritedChannel(Class<?> callerClass, Selector
931931

932932
@Override
933933
public void check$java_lang_foreign_SymbolLookup$$libraryLookup(Class<?> callerClass, Path path, Arena arena) {
934-
// TODO: check filesystem entitlement READ
934+
policyManager.checkFileRead(callerClass, path);
935935
policyManager.checkLoadingNativeLibraries(callerClass);
936936
}
937937

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,30 @@
2020
import static org.elasticsearch.core.PathUtils.getDefaultFileSystem;
2121

2222
public final class FileAccessTree {
23+
2324
private static final String FILE_SEPARATOR = getDefaultFileSystem().getSeparator();
2425

2526
private final String[] readPaths;
2627
private final String[] writePaths;
2728

28-
private FileAccessTree(FilesEntitlement filesEntitlement, Path tempDir) {
29+
private FileAccessTree(FilesEntitlement filesEntitlement, PathLookup pathLookup) {
2930
List<String> readPaths = new ArrayList<>();
3031
List<String> writePaths = new ArrayList<>();
3132
for (FilesEntitlement.FileData fileData : filesEntitlement.filesData()) {
32-
var path = normalizePath(Path.of(fileData.path()));
3333
var mode = fileData.mode();
34-
if (mode == FilesEntitlement.Mode.READ_WRITE) {
35-
writePaths.add(path);
36-
}
37-
readPaths.add(path);
34+
var paths = fileData.resolvePaths(pathLookup);
35+
paths.forEach(path -> {
36+
var normalized = normalizePath(path);
37+
if (mode == FilesEntitlement.Mode.READ_WRITE) {
38+
writePaths.add(normalized);
39+
}
40+
readPaths.add(normalized);
41+
});
3842
}
3943

4044
// everything has access to the temp dir
41-
readPaths.add(tempDir.toString());
42-
writePaths.add(tempDir.toString());
45+
readPaths.add(pathLookup.tempDir().toString());
46+
writePaths.add(pathLookup.tempDir().toString());
4347

4448
readPaths.sort(String::compareTo);
4549
writePaths.sort(String::compareTo);
@@ -48,8 +52,8 @@ private FileAccessTree(FilesEntitlement filesEntitlement, Path tempDir) {
4852
this.writePaths = writePaths.toArray(new String[0]);
4953
}
5054

51-
public static FileAccessTree of(FilesEntitlement filesEntitlement, Path tempDir) {
52-
return new FileAccessTree(filesEntitlement, tempDir);
55+
public static FileAccessTree of(FilesEntitlement filesEntitlement, PathLookup pathLookup) {
56+
return new FileAccessTree(filesEntitlement, pathLookup);
5357
}
5458

5559
boolean canRead(Path path) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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.runtime.policy;
11+
12+
import java.nio.file.Path;
13+
14+
public record PathLookup(Path configDir, Path[] dataDirs, Path tempDir) {}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ ModuleEntitlements policyEntitlements(String componentName, List<Entitlement> en
9999
return new ModuleEntitlements(
100100
componentName,
101101
entitlements.stream().collect(groupingBy(Entitlement::getClass)),
102-
FileAccessTree.of(filesEntitlement, tempDir)
102+
FileAccessTree.of(filesEntitlement, pathLookup)
103103
);
104104
}
105105

@@ -109,7 +109,7 @@ ModuleEntitlements policyEntitlements(String componentName, List<Entitlement> en
109109
private final List<Entitlement> apmAgentEntitlements;
110110
private final Map<String, Map<String, List<Entitlement>>> pluginsEntitlements;
111111
private final Function<Class<?>, String> pluginResolver;
112-
private final Path tempDir;
112+
private final PathLookup pathLookup;
113113
private final FileAccessTree defaultFileAccess;
114114

115115
public static final String ALL_UNNAMED = "ALL-UNNAMED";
@@ -146,7 +146,7 @@ public PolicyManager(
146146
Function<Class<?>, String> pluginResolver,
147147
String apmAgentPackageName,
148148
Module entitlementsModule,
149-
Path tempDir
149+
PathLookup pathLookup
150150
) {
151151
this.serverEntitlements = buildScopeEntitlementsMap(requireNonNull(serverPolicy));
152152
this.apmAgentEntitlements = apmAgentEntitlements;
@@ -156,9 +156,8 @@ public PolicyManager(
156156
this.pluginResolver = pluginResolver;
157157
this.apmAgentPackageName = apmAgentPackageName;
158158
this.entitlementsModule = entitlementsModule;
159-
this.defaultFileAccess = FileAccessTree.of(FilesEntitlement.EMPTY, tempDir);
160-
161-
this.tempDir = tempDir;
159+
this.pathLookup = requireNonNull(pathLookup);
160+
this.defaultFileAccess = FileAccessTree.of(FilesEntitlement.EMPTY, pathLookup);
162161

163162
for (var e : serverEntitlements.entrySet()) {
164163
validateEntitlementsPerModule(SERVER_COMPONENT_NAME, e.getKey(), e.getValue());

0 commit comments

Comments
 (0)