Skip to content

Commit 9875f4f

Browse files
authored
Remove ignoreUrl file setting property (#123718) (#123821)
Urls may make the FileAccessTree invalid. This commit removes the flag for filtering urls, instead always filtering them.
1 parent 426b981 commit 9875f4f

File tree

2 files changed

+16
-44
lines changed

2 files changed

+16
-44
lines changed

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:

0 commit comments

Comments
 (0)