Skip to content

Commit fb6c729

Browse files
authored
Guard blob store local directory creation with doPrivileged (#115459)
The blob store may be triggered to create a local directory while in a reduced privilege context. This commit guards the creation of directories with doPrivileged.
1 parent 79be69a commit fb6c729

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

docs/changelog/115459.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 115459
2+
summary: Guard blob store local directory creation with `doPrivileged`
3+
area: Infra/Core
4+
type: bug
5+
issues: []

server/src/main/java/org/elasticsearch/common/blobstore/fs/FsBlobStore.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.io.IOException;
2020
import java.nio.file.Files;
2121
import java.nio.file.Path;
22+
import java.security.AccessController;
23+
import java.security.PrivilegedAction;
2224
import java.util.Iterator;
2325
import java.util.List;
2426

@@ -56,11 +58,14 @@ public int bufferSizeInBytes() {
5658
public BlobContainer blobContainer(BlobPath path) {
5759
Path f = buildPath(path);
5860
if (readOnly == false) {
59-
try {
60-
Files.createDirectories(f);
61-
} catch (IOException ex) {
62-
throw new ElasticsearchException("failed to create blob container", ex);
63-
}
61+
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
62+
try {
63+
Files.createDirectories(f);
64+
} catch (IOException ex) {
65+
throw new ElasticsearchException("failed to create blob container", ex);
66+
}
67+
return null;
68+
});
6469
}
6570
return new FsBlobContainer(this, path, f);
6671
}

0 commit comments

Comments
 (0)