Skip to content

Commit 0a3b617

Browse files
authored
Guard blob store local directory creation with doPrivileged (#115459) (#115570)
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 4a32bf0 commit 0a3b617

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
@@ -18,6 +18,8 @@
1818
import java.io.IOException;
1919
import java.nio.file.Files;
2020
import java.nio.file.Path;
21+
import java.security.AccessController;
22+
import java.security.PrivilegedAction;
2123
import java.util.Iterator;
2224
import java.util.List;
2325

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

0 commit comments

Comments
 (0)