Skip to content

Commit 707cff4

Browse files
committed
Merge remote-tracking branch 'upstream/main' into entitlements/missing-url-connection-2
2 parents 5cc4a87 + 678738a commit 707cff4

File tree

16 files changed

+127
-62
lines changed

16 files changed

+127
-62
lines changed

libs/cli/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ apply plugin: 'elasticsearch.publish'
1212
dependencies {
1313
api 'net.sf.jopt-simple:jopt-simple:5.0.2'
1414
api project(':libs:core')
15+
api project(':libs:logging')
1516

1617
testImplementation(project(":test:framework")) {
1718
exclude group: 'org.elasticsearch', module: 'cli'

libs/cli/src/main/java/module-info.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
module org.elasticsearch.cli {
1212
requires jopt.simple;
1313
requires org.elasticsearch.base;
14+
requires java.logging;
15+
requires org.elasticsearch.logging;
1416

1517
exports org.elasticsearch.cli;
1618
}

libs/cli/src/main/java/org/elasticsearch/cli/Command.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import joptsimple.OptionSpec;
1616

1717
import org.elasticsearch.core.SuppressForbidden;
18+
import org.elasticsearch.logging.Level;
19+
import org.elasticsearch.logging.internal.spi.LoggerFactory;
1820

1921
import java.io.Closeable;
2022
import java.io.IOException;
@@ -84,12 +86,16 @@ protected void mainWithoutErrorHandling(String[] args, Terminal terminal, Proces
8486
return;
8587
}
8688

89+
LoggerFactory loggerFactory = LoggerFactory.provider();
8790
if (options.has(silentOption)) {
8891
terminal.setVerbosity(Terminal.Verbosity.SILENT);
92+
loggerFactory.setRootLevel(Level.OFF);
8993
} else if (options.has(verboseOption)) {
9094
terminal.setVerbosity(Terminal.Verbosity.VERBOSE);
95+
loggerFactory.setRootLevel(Level.DEBUG);
9196
} else {
9297
terminal.setVerbosity(Terminal.Verbosity.NORMAL);
98+
loggerFactory.setRootLevel(Level.INFO);
9399
}
94100

95101
execute(terminal, options, processInfo);

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ static FileData ofRelativePath(Path relativePath, BaseDir baseDir, Mode mode) {
9191
return new RelativePathFileData(relativePath, baseDir, mode, null, false);
9292
}
9393

94-
static FileData ofPathSetting(String setting, BaseDir baseDir, Mode mode, boolean ignoreUrl) {
95-
return new PathSettingFileData(setting, baseDir, mode, ignoreUrl, null, false);
94+
static FileData ofPathSetting(String setting, BaseDir baseDir, Mode mode) {
95+
return new PathSettingFileData(setting, baseDir, mode, null, false);
9696
}
9797

9898
/**
@@ -220,30 +220,29 @@ public FileData withPlatform(Platform platform) {
220220
}
221221
}
222222

223-
private record PathSettingFileData(String setting, BaseDir baseDir, Mode mode, boolean ignoreUrl, Platform platform, boolean exclusive)
223+
private record PathSettingFileData(String setting, BaseDir baseDir, Mode mode, Platform platform, boolean exclusive)
224224
implements
225225
RelativeFileData {
226226

227227
@Override
228228
public PathSettingFileData withExclusive(boolean exclusive) {
229-
return new PathSettingFileData(setting, baseDir, mode, ignoreUrl, platform, exclusive);
229+
return new PathSettingFileData(setting, baseDir, mode, platform, exclusive);
230230
}
231231

232232
@Override
233233
public Stream<Path> resolveRelativePaths(PathLookup pathLookup) {
234-
Stream<String> result = pathLookup.settingResolver().apply(setting);
235-
if (ignoreUrl) {
236-
result = result.filter(s -> s.toLowerCase(Locale.ROOT).startsWith("https://") == false);
237-
}
238-
return result.map(pathLookup.configDir()::resolve);
234+
Stream<String> result = pathLookup.settingResolver()
235+
.apply(setting)
236+
.filter(s -> s.toLowerCase(Locale.ROOT).startsWith("https://") == false);
237+
return result.map(Path::of);
239238
}
240239

241240
@Override
242241
public FileData withPlatform(Platform platform) {
243242
if (platform == platform()) {
244243
return this;
245244
}
246-
return new PathSettingFileData(setting, baseDir, mode, ignoreUrl, platform, exclusive);
245+
return new PathSettingFileData(setting, baseDir, mode, platform, exclusive);
247246
}
248247
}
249248

@@ -331,8 +330,6 @@ public static FilesEntitlement build(List<Object> paths) {
331330
String settingBaseDirAsString = checkString.apply(file, "basedir_if_relative");
332331
String modeAsString = checkString.apply(file, "mode");
333332
String platformAsString = checkString.apply(file, "platform");
334-
Boolean ignoreUrlAsStringBoolean = checkBoolean.apply(file, "ignore_url");
335-
boolean ignoreUrlAsString = ignoreUrlAsStringBoolean != null && ignoreUrlAsStringBoolean;
336333
Boolean exclusiveBoolean = checkBoolean.apply(file, "exclusive");
337334
boolean exclusive = exclusiveBoolean != null && exclusiveBoolean;
338335

@@ -359,9 +356,6 @@ public static FilesEntitlement build(List<Object> paths) {
359356
throw new PolicyValidationException("'relative_to' may only be used with 'relative_path'");
360357
}
361358

362-
if (ignoreUrlAsStringBoolean != null && pathSetting == null) {
363-
throw new PolicyValidationException("'ignore_url' may only be used with 'path_setting'");
364-
}
365359
if (settingBaseDirAsString != null && pathSetting == null) {
366360
throw new PolicyValidationException("'basedir_if_relative' may only be used with 'path_setting'");
367361
}
@@ -388,7 +382,7 @@ public static FilesEntitlement build(List<Object> paths) {
388382
throw new PolicyValidationException("files entitlement with a 'path_setting' must specify 'basedir_if_relative'");
389383
}
390384
BaseDir baseDir = parseBaseDir(settingBaseDirAsString);
391-
fileData = FileData.ofPathSetting(pathSetting, baseDir, mode, ignoreUrlAsString);
385+
fileData = FileData.ofPathSetting(pathSetting, baseDir, mode);
392386
} else {
393387
throw new AssertionError("File entry validation error");
394388
}

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

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,25 @@ public void testPathSettingResolve() {
101101
List.of(Map.of("path_setting", "foo.bar", "basedir_if_relative", "config", "mode", "read"))
102102
);
103103
var filesData = entitlement.filesData();
104-
assertThat(filesData, contains(FileData.ofPathSetting("foo.bar", CONFIG, READ, false)));
104+
assertThat(filesData, contains(FileData.ofPathSetting("foo.bar", CONFIG, READ)));
105105

106-
var fileData = FileData.ofPathSetting("foo.bar", CONFIG, READ, false);
106+
var fileData = FileData.ofPathSetting("foo.bar", CONFIG, READ);
107107
// empty settings
108108
assertThat(fileData.resolvePaths(TEST_PATH_LOOKUP).toList(), empty());
109109

110-
fileData = FileData.ofPathSetting("foo.bar", CONFIG, READ, false);
110+
fileData = FileData.ofPathSetting("foo.bar", CONFIG, READ);
111111
settings = Settings.builder().put("foo.bar", "/setting/path").build();
112112
assertThat(fileData.resolvePaths(TEST_PATH_LOOKUP).toList(), contains(Path.of("/setting/path")));
113113

114-
fileData = FileData.ofPathSetting("foo.*.bar", CONFIG, READ, false);
114+
fileData = FileData.ofPathSetting("foo.*.bar", CONFIG, READ);
115115
settings = Settings.builder().put("foo.baz.bar", "/setting/path").build();
116116
assertThat(fileData.resolvePaths(TEST_PATH_LOOKUP).toList(), contains(Path.of("/setting/path")));
117117

118-
fileData = FileData.ofPathSetting("foo.*.bar", CONFIG, READ, false);
118+
fileData = FileData.ofPathSetting("foo.*.bar", CONFIG, READ);
119119
settings = Settings.builder().put("foo.baz.bar", "/setting/path").put("foo.baz2.bar", "/other/path").build();
120120
assertThat(fileData.resolvePaths(TEST_PATH_LOOKUP).toList(), containsInAnyOrder(Path.of("/setting/path"), Path.of("/other/path")));
121121

122-
fileData = FileData.ofPathSetting("foo.bar", CONFIG, READ, false);
122+
fileData = FileData.ofPathSetting("foo.bar", CONFIG, READ);
123123
settings = Settings.builder().put("foo.bar", "relative_path").build();
124124
assertThat(fileData.resolvePaths(TEST_PATH_LOOKUP).toList(), contains(Path.of("/config/relative_path")));
125125
}
@@ -140,28 +140,6 @@ public void testPathSettingBasedirValidation() {
140140
assertThat(e.getMessage(), is("'basedir_if_relative' may only be used with 'path_setting'"));
141141
}
142142

143-
public void testPathSettingIgnoreUrl() {
144-
var fileData = FileData.ofPathSetting("foo.*.bar", CONFIG, READ, true);
145-
settings = Settings.builder().put("foo.nonurl.bar", "/setting/path").put("foo.url.bar", "https://mysite").build();
146-
assertThat(fileData.resolvePaths(TEST_PATH_LOOKUP).toList(), contains(Path.of("/setting/path")));
147-
}
148-
149-
public void testIgnoreUrlValidation() {
150-
var e = expectThrows(
151-
PolicyValidationException.class,
152-
() -> FilesEntitlement.build(List.of(Map.of("path", "/foo", "mode", "read", "ignore_url", true)))
153-
);
154-
assertThat(e.getMessage(), is("'ignore_url' may only be used with 'path_setting'"));
155-
156-
e = expectThrows(
157-
PolicyValidationException.class,
158-
() -> FilesEntitlement.build(
159-
List.of(Map.of("relative_path", "foo", "relative_to", "config", "mode", "read", "ignore_url", true))
160-
)
161-
);
162-
assertThat(e.getMessage(), is("'ignore_url' may only be used with 'path_setting'"));
163-
}
164-
165143
public void testExclusiveParsing() throws Exception {
166144
Policy parsedPolicy = new PolicyParser(new ByteArrayInputStream("""
167145
entitlement-module-name:

libs/logging/src/main/java/module-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99

1010
module org.elasticsearch.logging {
1111
exports org.elasticsearch.logging;
12-
exports org.elasticsearch.logging.internal.spi to org.elasticsearch.server;
12+
exports org.elasticsearch.logging.internal.spi to org.elasticsearch.server, org.elasticsearch.cli;
1313
}

libs/logging/src/main/java/org/elasticsearch/logging/internal/spi/LoggerFactory.java

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

1010
package org.elasticsearch.logging.internal.spi;
1111

12+
import org.elasticsearch.logging.Level;
1213
import org.elasticsearch.logging.Logger;
1314

1415
/**
@@ -26,6 +27,10 @@ public static LoggerFactory provider() {
2627

2728
public abstract Logger getLogger(Class<?> clazz);
2829

30+
public abstract void setRootLevel(Level level);
31+
32+
public abstract Level getRootLevel();
33+
2934
public static void setInstance(LoggerFactory INSTANCE) {
3035
LoggerFactory.INSTANCE = INSTANCE;
3136
}

modules/repository-s3/src/main/plugin-metadata/entitlement-policy.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ ALL-UNNAMED:
88
- relative_path: ".aws/"
99
relative_to: "home"
1010
mode: "read"
11+
# The security policy permission states this is "only for tests": org.elasticsearch.repositories.s3.S3RepositoryPlugin
12+
# TODO: check this is actually needed, and if we can isolate it to a test-only policy
13+
- write_system_properties:
14+
properties:
15+
- es.allow_insecure_settings

modules/transport-netty4/src/main/plugin-metadata/entitlement-policy.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ io.netty.transport:
22
- inbound_network
33
- outbound_network
44
- manage_threads
5+
# Netty NioEventLoop wants to change this, because of https://bugs.openjdk.java.net/browse/JDK-6427854
6+
# the bug says it only happened rarely, and that its fixed, but apparently it still happens rarely!
7+
# TODO: copied over from the security policy. Check if this is still valid
8+
- write_system_properties:
9+
properties:
10+
- sun.nio.ch.bugLevel
511
io.netty.common:
612
- inbound_network
713
- outbound_network

muted-tests.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,10 @@ tests:
341341
- class: org.elasticsearch.xpack.searchablesnapshots.FrozenSearchableSnapshotsIntegTests
342342
method: testCreateAndRestorePartialSearchableSnapshot
343343
issue: https://github.com/elastic/elasticsearch/issues/123773
344-
- class: org.elasticsearch.xpack.esql.action.EsqlActionBreakerIT
345-
method: testDropAllColumns
346-
issue: https://github.com/elastic/elasticsearch/issues/123791
344+
345+
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
346+
method: test {p0=snapshot/10_basic/Create a source only snapshot and then restore it}
347+
issue: https://github.com/elastic/elasticsearch/issues/122755
347348

348349
# Examples:
349350
#

0 commit comments

Comments
 (0)