Skip to content

Commit c47a1e1

Browse files
committed
Add pidfile access for server
Server may have a pid file specified which needs write access.
1 parent ad99b0d commit c47a1e1

File tree

2 files changed

+39
-31
lines changed

2 files changed

+39
-31
lines changed

libs/entitlement/src/main/java/org/elasticsearch/entitlement/bootstrap/EntitlementBootstrap.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public record BootstrapArgs(
4444
Path configDir,
4545
Path libDir,
4646
Path logsDir,
47-
Path tempDir
47+
Path tempDir,
48+
Path pidFile
4849
) {
4950
public BootstrapArgs {
5051
requireNonNull(pluginPolicies);
@@ -83,6 +84,7 @@ public static BootstrapArgs bootstrapArgs() {
8384
* @param libDir the lib directory for Elasticsearch
8485
* @param tempDir the temp directory for Elasticsearch
8586
* @param logsDir the log directory for Elasticsearch
87+
* @param pidFile path to a pid file for Elasticsearch, or {@code null} if one was not specified
8688
*/
8789
public static void bootstrap(
8890
Map<String, Policy> pluginPolicies,
@@ -94,7 +96,8 @@ public static void bootstrap(
9496
Path configDir,
9597
Path libDir,
9698
Path logsDir,
97-
Path tempDir
99+
Path tempDir,
100+
Path pidFile
98101
) {
99102
logger.debug("Loading entitlement agent");
100103
if (EntitlementBootstrap.bootstrapArgs != null) {
@@ -110,7 +113,8 @@ public static void bootstrap(
110113
configDir,
111114
libDir,
112115
logsDir,
113-
tempDir
116+
tempDir,
117+
pidFile
114118
);
115119
exportInitializationToAgent();
116120
loadAgent(findAgentJar());

libs/entitlement/src/main/java/org/elasticsearch/entitlement/initialization/EntitlementInitialization.java

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,37 @@ private static PolicyManager createPolicyManager() {
147147
);
148148

149149
List<Scope> serverScopes = new ArrayList<>();
150+
List<FileData> serverModuleFileDatas = new ArrayList<>();
151+
Collections.addAll(
152+
serverModuleFileDatas,
153+
// Base ES directories
154+
FileData.ofPath(bootstrapArgs.tempDir(), READ_WRITE),
155+
FileData.ofPath(bootstrapArgs.configDir(), READ),
156+
FileData.ofPath(bootstrapArgs.logsDir(), READ_WRITE),
157+
FileData.ofRelativePath(Path.of(""), DATA, READ_WRITE),
158+
FileData.ofRelativePath(Path.of(""), SHARED_REPO, READ_WRITE),
159+
160+
// OS release on Linux
161+
FileData.ofPath(Path.of("/etc/os-release"), READ),
162+
FileData.ofPath(Path.of("/etc/system-release"), READ),
163+
FileData.ofPath(Path.of("/usr/lib/os-release"), READ),
164+
// read max virtual memory areas
165+
FileData.ofPath(Path.of("/proc/sys/vm/max_map_count"), READ),
166+
FileData.ofPath(Path.of("/proc/meminfo"), READ),
167+
// load averages on Linux
168+
FileData.ofPath(Path.of("/proc/loadavg"), READ),
169+
// control group stats on Linux. cgroup v2 stats are in an unpredicable
170+
// location under `/sys/fs/cgroup`, so unfortunately we have to allow
171+
// read access to the entire directory hierarchy.
172+
FileData.ofPath(Path.of("/proc/self/cgroup"), READ),
173+
FileData.ofPath(Path.of("/sys/fs/cgroup/"), READ),
174+
// // io stats on Linux
175+
FileData.ofPath(Path.of("/proc/self/mountinfo"), READ),
176+
FileData.ofPath(Path.of("/proc/diskstats"), READ)
177+
);
178+
if (bootstrapArgs.pidFile() != null) {
179+
serverModuleFileDatas.add(FileData.ofPath(bootstrapArgs.pidFile(), READ_WRITE));
180+
}
150181
Collections.addAll(
151182
serverScopes,
152183
new Scope(
@@ -172,34 +203,7 @@ private static PolicyManager createPolicyManager() {
172203
new OutboundNetworkEntitlement(),
173204
new LoadNativeLibrariesEntitlement(),
174205
new ManageThreadsEntitlement(),
175-
new FilesEntitlement(
176-
List.of(
177-
// Base ES directories
178-
FileData.ofPath(bootstrapArgs.tempDir(), READ_WRITE),
179-
FileData.ofPath(bootstrapArgs.configDir(), READ),
180-
FileData.ofPath(bootstrapArgs.logsDir(), READ_WRITE),
181-
FileData.ofRelativePath(Path.of(""), DATA, READ_WRITE),
182-
FileData.ofRelativePath(Path.of(""), SHARED_REPO, READ_WRITE),
183-
184-
// OS release on Linux
185-
FileData.ofPath(Path.of("/etc/os-release"), READ),
186-
FileData.ofPath(Path.of("/etc/system-release"), READ),
187-
FileData.ofPath(Path.of("/usr/lib/os-release"), READ),
188-
// read max virtual memory areas
189-
FileData.ofPath(Path.of("/proc/sys/vm/max_map_count"), READ),
190-
FileData.ofPath(Path.of("/proc/meminfo"), READ),
191-
// load averages on Linux
192-
FileData.ofPath(Path.of("/proc/loadavg"), READ),
193-
// control group stats on Linux. cgroup v2 stats are in an unpredicable
194-
// location under `/sys/fs/cgroup`, so unfortunately we have to allow
195-
// read access to the entire directory hierarchy.
196-
FileData.ofPath(Path.of("/proc/self/cgroup"), READ),
197-
FileData.ofPath(Path.of("/sys/fs/cgroup/"), READ),
198-
// // io stats on Linux
199-
FileData.ofPath(Path.of("/proc/self/mountinfo"), READ),
200-
FileData.ofPath(Path.of("/proc/diskstats"), READ)
201-
)
202-
)
206+
new FilesEntitlement(serverModuleFileDatas)
203207
)
204208
),
205209
new Scope("org.apache.httpcomponents.httpclient", List.of(new OutboundNetworkEntitlement())),

0 commit comments

Comments
 (0)