Skip to content

Commit dc7b726

Browse files
committed
Grant read access to the config dir (elastic#123882)
This matches what Security Manager permissions Elasticsearch had for all plugins.
1 parent c77c6a6 commit dc7b726

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
@@ -135,7 +135,7 @@ public void testPathAndFileWithSamePrefix() {
135135
}
136136

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

@@ -152,7 +152,7 @@ public void testReadWithRelativePath() {
152152
}
153153

154154
public void testWriteWithRelativePath() {
155-
for (var dir : List.of("config", "home")) {
155+
for (var dir : List.of("home")) {
156156
var tree = accessTree(entitlement(Map.of("relative_path", "foo", "mode", "read_write", "relative_to", dir)), List.of());
157157
assertThat(tree.canWrite(path("/" + dir + "/foo")), is(true));
158158
assertThat(tree.canWrite(path("/" + dir + "/foo/subdir")), is(true));
@@ -263,6 +263,12 @@ public void testTempDirAccess() {
263263
assertThat(tree.canWrite(TEST_PATH_LOOKUP.tempDir()), is(true));
264264
}
265265

266+
public void testConfigDirAccess() {
267+
var tree = FileAccessTree.of("test-component", "test-module", FilesEntitlement.EMPTY, TEST_PATH_LOOKUP, List.of());
268+
assertThat(tree.canRead(TEST_PATH_LOOKUP.configDir()), is(true));
269+
assertThat(tree.canWrite(TEST_PATH_LOOKUP.configDir()), is(false));
270+
}
271+
266272
public void testBasicExclusiveAccess() {
267273
var tree = accessTree(entitlement("foo", "read"), exclusivePaths("test-component", "test-module", "foo"));
268274
assertThat(tree.canRead(path("foo")), is(true));

0 commit comments

Comments
 (0)