Skip to content

Commit 050fc6c

Browse files
rjernstgeorgewallace
authored andcommitted
Grant read access to the config dir (elastic#123882)
This matches what Security Manager permissions Elasticsearch had for all plugins.
1 parent fb28191 commit 050fc6c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,10 @@ private FileAccessTree(
138138
});
139139
}
140140

141-
// everything has access to the temp dir and the jdk
141+
// everything has access to the temp dir, config dir and the jdk
142142
addPathAndMaybeLink.accept(pathLookup.tempDir(), Mode.READ_WRITE);
143+
// TODO: this grants read access to the config dir for all modules until explicit read entitlements can be added
144+
addPathAndMaybeLink.accept(pathLookup.configDir(), Mode.READ);
143145

144146
// TODO: watcher uses javax.activation which looks for known mime types configuration, should this be global or explicit in watcher?
145147
Path jdk = Paths.get(System.getProperty("java.home"));

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public void testPathAndFileWithSamePrefix() {
136136
}
137137

138138
public void testReadWithRelativePath() {
139-
for (var dir : List.of("config", "home")) {
139+
for (var dir : List.of("home")) {
140140
var tree = accessTree(entitlement(Map.of("relative_path", "foo", "mode", "read", "relative_to", dir)), List.of());
141141
assertThat(tree.canRead(path("foo")), is(false));
142142

@@ -153,7 +153,7 @@ public void testReadWithRelativePath() {
153153
}
154154

155155
public void testWriteWithRelativePath() {
156-
for (var dir : List.of("config", "home")) {
156+
for (var dir : List.of("home")) {
157157
var tree = accessTree(entitlement(Map.of("relative_path", "foo", "mode", "read_write", "relative_to", dir)), List.of());
158158
assertThat(tree.canWrite(path("/" + dir + "/foo")), is(true));
159159
assertThat(tree.canWrite(path("/" + dir + "/foo/subdir")), is(true));
@@ -289,6 +289,12 @@ public void testTempDirAccess() {
289289
assertThat(tree.canWrite(TEST_PATH_LOOKUP.tempDir()), is(true));
290290
}
291291

292+
public void testConfigDirAccess() {
293+
var tree = FileAccessTree.of("test-component", "test-module", FilesEntitlement.EMPTY, TEST_PATH_LOOKUP, List.of());
294+
assertThat(tree.canRead(TEST_PATH_LOOKUP.configDir()), is(true));
295+
assertThat(tree.canWrite(TEST_PATH_LOOKUP.configDir()), is(false));
296+
}
297+
292298
public void testBasicExclusiveAccess() {
293299
var tree = accessTree(entitlement("foo", "read"), exclusivePaths("test-component", "test-module", "foo"));
294300
assertThat(tree.canRead(path("foo")), is(true));

0 commit comments

Comments
 (0)