Skip to content

Commit d84457e

Browse files
committed
Merge branch 'main' into esql_pragma_load_source
2 parents 2a86568 + ad220c1 commit d84457e

File tree

102 files changed

+659
-301
lines changed

Some content is hidden

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

102 files changed

+659
-301
lines changed

.buildkite/scripts/dra-update-staging.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ for BRANCH in "${BRANCHES[@]}"; do
3737

3838
if [[ "$SHOULD_TRIGGER" == "true" ]]; then
3939
if [[ "$BRANCH" == "9.0" ]]; then
40-
export VERSION_QUALIFIER="beta1"
40+
export VERSION_QUALIFIER="rc1"
4141
fi
4242
echo "Triggering DRA staging workflow for $BRANCH"
4343
cat << EOF | buildkite-agent pipeline upload

.buildkite/scripts/dra-workflow.trigger.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ source .buildkite/scripts/branches.sh
88

99
for BRANCH in "${BRANCHES[@]}"; do
1010
if [[ "$BRANCH" == "9.0" ]]; then
11-
export VERSION_QUALIFIER="beta1"
11+
export VERSION_QUALIFIER="rc1"
1212
fi
1313

1414
INTAKE_PIPELINE_SLUG="elasticsearch-intake"

docs/changelog/122731.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 122731
2+
summary: Fork post-snapshot-delete cleanup off master thread
3+
area: Snapshot/Restore
4+
type: bug
5+
issues: []

docs/changelog/122857.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 122857
2+
summary: Run `TransportGetWatcherSettingsAction` on local node
3+
area: Watcher
4+
type: enhancement
5+
issues: []

libs/core/src/main/java/org/elasticsearch/core/UpdateForV9.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,11 @@
2424
enum Owner {
2525
CORE_INFRA,
2626
DATA_MANAGEMENT,
27-
DISTRIBUTED_COORDINATION,
2827
DISTRIBUTED_INDEXING,
2928
ENTERPRISE_SEARCH,
3029
MACHINE_LEARNING,
3130
PROFILING,
3231
SEARCH_ANALYTICS,
33-
SEARCH_FOUNDATIONS,
34-
SEARCH_RELEVANCE,
3532
SECURITY,
3633
}
3734

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.nio.file.Path;
2929
import java.util.Map;
3030
import java.util.function.Function;
31+
import java.util.stream.Stream;
3132

3233
import static java.util.Objects.requireNonNull;
3334

@@ -36,19 +37,24 @@ public class EntitlementBootstrap {
3637
public record BootstrapArgs(
3738
Map<String, Policy> pluginPolicies,
3839
Function<Class<?>, String> pluginResolver,
40+
Function<String, String> settingResolver,
41+
Function<String, Stream<String>> settingGlobResolver,
3942
Path[] dataDirs,
4043
Path configDir,
41-
Path tempDir,
42-
Path logsDir
44+
Path logsDir,
45+
Path tempDir
4346
) {
4447
public BootstrapArgs {
4548
requireNonNull(pluginPolicies);
4649
requireNonNull(pluginResolver);
50+
requireNonNull(settingResolver);
51+
requireNonNull(settingGlobResolver);
4752
requireNonNull(dataDirs);
4853
if (dataDirs.length == 0) {
4954
throw new IllegalArgumentException("must provide at least one data directory");
5055
}
5156
requireNonNull(configDir);
57+
requireNonNull(logsDir);
5258
requireNonNull(tempDir);
5359
}
5460
}
@@ -73,16 +79,27 @@ public static BootstrapArgs bootstrapArgs() {
7379
public static void bootstrap(
7480
Map<String, Policy> pluginPolicies,
7581
Function<Class<?>, String> pluginResolver,
82+
Function<String, String> settingResolver,
83+
Function<String, Stream<String>> settingGlobResolver,
7684
Path[] dataDirs,
7785
Path configDir,
78-
Path tempDir,
79-
Path logsDir
86+
Path logsDir,
87+
Path tempDir
8088
) {
8189
logger.debug("Loading entitlement agent");
8290
if (EntitlementBootstrap.bootstrapArgs != null) {
8391
throw new IllegalStateException("plugin data is already set");
8492
}
85-
EntitlementBootstrap.bootstrapArgs = new BootstrapArgs(pluginPolicies, pluginResolver, dataDirs, configDir, tempDir, logsDir);
93+
EntitlementBootstrap.bootstrapArgs = new BootstrapArgs(
94+
pluginPolicies,
95+
pluginResolver,
96+
settingResolver,
97+
settingGlobResolver,
98+
dataDirs,
99+
configDir,
100+
logsDir,
101+
tempDir
102+
);
86103
exportInitializationToAgent();
87104
loadAgent(findAgentJar());
88105
selfTest();

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,14 @@ private static Class<?>[] findClassesToRetransform(Class<?>[] loadedClasses, Set
135135
private static PolicyManager createPolicyManager() {
136136
EntitlementBootstrap.BootstrapArgs bootstrapArgs = EntitlementBootstrap.bootstrapArgs();
137137
Map<String, Policy> pluginPolicies = bootstrapArgs.pluginPolicies();
138-
var pathLookup = new PathLookup(getUserHome(), bootstrapArgs.configDir(), bootstrapArgs.dataDirs(), bootstrapArgs.tempDir());
139-
Path logsDir = EntitlementBootstrap.bootstrapArgs().logsDir();
138+
var pathLookup = new PathLookup(
139+
getUserHome(),
140+
bootstrapArgs.configDir(),
141+
bootstrapArgs.dataDirs(),
142+
bootstrapArgs.tempDir(),
143+
bootstrapArgs.settingResolver(),
144+
bootstrapArgs.settingGlobResolver()
145+
);
140146

141147
List<Scope> serverScopes = new ArrayList<>();
142148
Collections.addAll(

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ private FileAccessTree(FilesEntitlement filesEntitlement, PathLookup pathLookup)
4242
}
4343

4444
// everything has access to the temp dir
45-
readPaths.add(pathLookup.tempDir().toString());
46-
writePaths.add(pathLookup.tempDir().toString());
45+
String tempDir = normalizePath(pathLookup.tempDir());
46+
readPaths.add(tempDir);
47+
writePaths.add(tempDir);
4748

4849
readPaths.sort(String::compareTo);
4950
writePaths.sort(String::compareTo);

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,14 @@
1010
package org.elasticsearch.entitlement.runtime.policy;
1111

1212
import java.nio.file.Path;
13+
import java.util.function.Function;
14+
import java.util.stream.Stream;
1315

14-
public record PathLookup(Path homeDir, Path configDir, Path[] dataDirs, Path tempDir) {}
16+
public record PathLookup(
17+
Path homeDir,
18+
Path configDir,
19+
Path[] dataDirs,
20+
Path tempDir,
21+
Function<String, String> settingResolver,
22+
Function<String, Stream<String>> settingGlobResolver
23+
) {}

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

Lines changed: 87 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import java.nio.file.Path;
1717
import java.util.ArrayList;
18-
import java.util.Arrays;
1918
import java.util.HashMap;
2019
import java.util.List;
2120
import java.util.Map;
@@ -53,33 +52,81 @@ static FileData ofPath(Path path, Mode mode) {
5352
static FileData ofRelativePath(Path relativePath, BaseDir baseDir, Mode mode) {
5453
return new RelativePathFileData(relativePath, baseDir, mode);
5554
}
56-
}
5755

58-
private record AbsolutePathFileData(Path path, Mode mode) implements FileData {
59-
@Override
60-
public Stream<Path> resolvePaths(PathLookup pathLookup) {
61-
return Stream.of(path);
56+
static FileData ofPathSetting(String setting, Mode mode) {
57+
return new PathSettingFileData(setting, mode);
58+
}
59+
60+
static FileData ofRelativePathSetting(String setting, BaseDir baseDir, Mode mode) {
61+
return new RelativePathSettingFileData(setting, baseDir, mode);
6262
}
6363
}
6464

65-
private record RelativePathFileData(Path relativePath, BaseDir baseDir, Mode mode) implements FileData {
65+
private sealed interface RelativeFileData extends FileData {
66+
BaseDir baseDir();
67+
68+
Stream<Path> resolveRelativePaths(PathLookup pathLookup);
6669

6770
@Override
68-
public Stream<Path> resolvePaths(PathLookup pathLookup) {
71+
default Stream<Path> resolvePaths(PathLookup pathLookup) {
6972
Objects.requireNonNull(pathLookup);
70-
switch (baseDir) {
73+
var relativePaths = resolveRelativePaths(pathLookup);
74+
switch (baseDir()) {
7175
case CONFIG:
72-
return Stream.of(pathLookup.configDir().resolve(relativePath));
76+
return relativePaths.map(relativePath -> pathLookup.configDir().resolve(relativePath));
7377
case DATA:
74-
return Arrays.stream(pathLookup.dataDirs()).map(d -> d.resolve(relativePath));
78+
// multiple data dirs are a pain...we need the combination of relative paths and data dirs
79+
List<Path> paths = new ArrayList<>();
80+
for (var relativePath : relativePaths.toList()) {
81+
for (var dataDir : pathLookup.dataDirs()) {
82+
paths.add(dataDir.resolve(relativePath));
83+
}
84+
}
85+
return paths.stream();
7586
case HOME:
76-
return Stream.of(pathLookup.homeDir().resolve(relativePath));
87+
return relativePaths.map(relativePath -> pathLookup.homeDir().resolve(relativePath));
7788
default:
7889
throw new IllegalArgumentException();
7990
}
8091
}
8192
}
8293

94+
private record AbsolutePathFileData(Path path, Mode mode) implements FileData {
95+
@Override
96+
public Stream<Path> resolvePaths(PathLookup pathLookup) {
97+
return Stream.of(path);
98+
}
99+
}
100+
101+
private record RelativePathFileData(Path relativePath, BaseDir baseDir, Mode mode) implements FileData, RelativeFileData {
102+
@Override
103+
public Stream<Path> resolveRelativePaths(PathLookup pathLookup) {
104+
return Stream.of(relativePath);
105+
}
106+
}
107+
108+
private record PathSettingFileData(String setting, Mode mode) implements FileData {
109+
@Override
110+
public Stream<Path> resolvePaths(PathLookup pathLookup) {
111+
return resolvePathSettings(pathLookup, setting);
112+
}
113+
}
114+
115+
private record RelativePathSettingFileData(String setting, BaseDir baseDir, Mode mode) implements FileData, RelativeFileData {
116+
@Override
117+
public Stream<Path> resolveRelativePaths(PathLookup pathLookup) {
118+
return resolvePathSettings(pathLookup, setting);
119+
}
120+
}
121+
122+
private static Stream<Path> resolvePathSettings(PathLookup pathLookup, String setting) {
123+
if (setting.contains("*")) {
124+
return pathLookup.settingGlobResolver().apply(setting).map(Path::of);
125+
}
126+
String path = pathLookup.settingResolver().apply(setting);
127+
return path == null ? Stream.of() : Stream.of(Path.of(path));
128+
}
129+
83130
private static Mode parseMode(String mode) {
84131
if (mode.equals("read")) {
85132
return Mode.READ;
@@ -113,37 +160,56 @@ public static FilesEntitlement build(List<Object> paths) {
113160
String pathAsString = file.remove("path");
114161
String relativePathAsString = file.remove("relative_path");
115162
String relativeTo = file.remove("relative_to");
116-
String mode = file.remove("mode");
163+
String pathSetting = file.remove("path_setting");
164+
String relativePathSetting = file.remove("relative_path_setting");
165+
String modeAsString = file.remove("mode");
117166

118167
if (file.isEmpty() == false) {
119168
throw new PolicyValidationException("unknown key(s) [" + file + "] in a listed file for files entitlement");
120169
}
121-
if (mode == null) {
170+
int foundKeys = (pathAsString != null ? 1 : 0) + (relativePathAsString != null ? 1 : 0) + (pathSetting != null ? 1 : 0)
171+
+ (relativePathSetting != null ? 1 : 0);
172+
if (foundKeys != 1) {
173+
throw new PolicyValidationException(
174+
"a files entitlement entry must contain one of " + "[path, relative_path, path_setting, relative_path_setting]"
175+
);
176+
}
177+
178+
if (modeAsString == null) {
122179
throw new PolicyValidationException("files entitlement must contain 'mode' for every listed file");
123180
}
124-
if (pathAsString != null && relativePathAsString != null) {
125-
throw new PolicyValidationException("a files entitlement entry cannot contain both 'path' and 'relative_path'");
181+
Mode mode = parseMode(modeAsString);
182+
183+
BaseDir baseDir = null;
184+
if (relativeTo != null) {
185+
baseDir = parseBaseDir(relativeTo);
126186
}
127187

128188
if (relativePathAsString != null) {
129-
if (relativeTo == null) {
189+
if (baseDir == null) {
130190
throw new PolicyValidationException("files entitlement with a 'relative_path' must specify 'relative_to'");
131191
}
132-
final BaseDir baseDir = parseBaseDir(relativeTo);
133192

134193
Path relativePath = Path.of(relativePathAsString);
135194
if (relativePath.isAbsolute()) {
136195
throw new PolicyValidationException("'relative_path' [" + relativePathAsString + "] must be relative");
137196
}
138-
filesData.add(FileData.ofRelativePath(relativePath, baseDir, parseMode(mode)));
197+
filesData.add(FileData.ofRelativePath(relativePath, baseDir, mode));
139198
} else if (pathAsString != null) {
140199
Path path = Path.of(pathAsString);
141200
if (path.isAbsolute() == false) {
142201
throw new PolicyValidationException("'path' [" + pathAsString + "] must be absolute");
143202
}
144-
filesData.add(FileData.ofPath(path, parseMode(mode)));
203+
filesData.add(FileData.ofPath(path, mode));
204+
} else if (pathSetting != null) {
205+
filesData.add(FileData.ofPathSetting(pathSetting, mode));
206+
} else if (relativePathSetting != null) {
207+
if (baseDir == null) {
208+
throw new PolicyValidationException("files entitlement with a 'relative_path_setting' must specify 'relative_to'");
209+
}
210+
filesData.add(FileData.ofRelativePathSetting(relativePathSetting, baseDir, mode));
145211
} else {
146-
throw new PolicyValidationException("files entitlement must contain either 'path' or 'relative_path' for every entry");
212+
throw new AssertionError("File entry validation error");
147213
}
148214
}
149215
return new FilesEntitlement(filesData);

0 commit comments

Comments
 (0)