Skip to content

Commit 17383a3

Browse files
committed
Add logsDir to bootstrap params
1 parent 91fc04a commit 17383a3

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public record BootstrapArgs(
3838
Function<Class<?>, String> pluginResolver,
3939
Path[] dataDirs,
4040
Path configDir,
41-
Path tempDir
41+
Path tempDir,
42+
Path logsDir
4243
) {
4344
public BootstrapArgs {
4445
requireNonNull(pluginPolicies);
@@ -64,22 +65,24 @@ public static BootstrapArgs bootstrapArgs() {
6465
*
6566
* @param pluginPolicies a map holding policies for plugins (and modules), by plugin (or module) name.
6667
* @param pluginResolver a functor to map a Java Class to the plugin it belongs to (the plugin name).
67-
* @param dataDirs data directories for Elasticsearch
68-
* @param configDir the config directory for Elasticsearch
69-
* @param tempDir the temp directory for Elasticsearch
68+
* @param dataDirs data directories for Elasticsearch
69+
* @param configDir the config directory for Elasticsearch
70+
* @param tempDir the temp directory for Elasticsearch
71+
* @param logsDir the log directory for Elasticsearch
7072
*/
7173
public static void bootstrap(
7274
Map<String, Policy> pluginPolicies,
7375
Function<Class<?>, String> pluginResolver,
7476
Path[] dataDirs,
7577
Path configDir,
76-
Path tempDir
78+
Path tempDir,
79+
Path logsDir
7780
) {
7881
logger.debug("Loading entitlement agent");
7982
if (EntitlementBootstrap.bootstrapArgs != null) {
8083
throw new IllegalStateException("plugin data is already set");
8184
}
82-
EntitlementBootstrap.bootstrapArgs = new BootstrapArgs(pluginPolicies, pluginResolver, dataDirs, configDir, tempDir);
85+
EntitlementBootstrap.bootstrapArgs = new BootstrapArgs(pluginPolicies, pluginResolver, dataDirs, configDir, tempDir, logsDir);
8386
exportInitializationToAgent();
8487
loadAgent(findAgentJar());
8588
selfTest();

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ private static PolicyManager createPolicyManager() {
129129
Map<String, Policy> pluginPolicies = EntitlementBootstrap.bootstrapArgs().pluginPolicies();
130130
Path[] dataDirs = EntitlementBootstrap.bootstrapArgs().dataDirs();
131131
Path tempDir = EntitlementBootstrap.bootstrapArgs().tempDir();
132+
Path configDir = EntitlementBootstrap.bootstrapArgs().configDir();
133+
Path logsDir = EntitlementBootstrap.bootstrapArgs().logsDir();
132134

133135
// TODO(ES-10031): Decide what goes in the elasticsearch default policy and extend it
134136
var serverPolicy = new Policy(
@@ -147,13 +149,25 @@ private static PolicyManager createPolicyManager() {
147149
new LoadNativeLibrariesEntitlement(),
148150
new ManageThreadsEntitlement(),
149151
new FilesEntitlement(
150-
List.of(new FilesEntitlement.FileData(EntitlementBootstrap.bootstrapArgs().tempDir().toString(), READ_WRITE))
152+
Stream.of(
153+
Stream.of(new FilesEntitlement.FileData(tempDir.toString(), READ_WRITE)),
154+
Stream.of(new FilesEntitlement.FileData(configDir.toString(), READ_WRITE)),
155+
Stream.of(new FilesEntitlement.FileData(logsDir.toString(), READ_WRITE)),
156+
Arrays.stream(dataDirs).map(d -> new FileData(d.toString(), READ_WRITE))
157+
).flatMap(Function.identity()).toList()
151158
)
152159
)
153160
),
154161
new Scope("org.apache.httpcomponents.httpclient", List.of(new OutboundNetworkEntitlement())),
155162
new Scope("io.netty.transport", List.of(new InboundNetworkEntitlement(), new OutboundNetworkEntitlement())),
156-
new Scope("org.apache.lucene.core", List.of(new LoadNativeLibrariesEntitlement(), new ManageThreadsEntitlement())),
163+
new Scope(
164+
"org.apache.lucene.core",
165+
List.of(
166+
new LoadNativeLibrariesEntitlement(),
167+
new ManageThreadsEntitlement(),
168+
new FilesEntitlement(Arrays.stream(dataDirs).map(d -> new FileData(d.toString(), READ_WRITE)).toList())
169+
)
170+
),
157171
new Scope("org.apache.logging.log4j.core", List.of(new ManageThreadsEntitlement())),
158172
new Scope(
159173
"org.elasticsearch.nativeaccess",

server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ private static void initPhase2(Bootstrap bootstrap) throws IOException {
247247
pluginsResolver::resolveClassToPluginName,
248248
nodeEnv.dataDirs(),
249249
nodeEnv.configDir(),
250-
nodeEnv.tmpDir()
250+
nodeEnv.tmpDir(),
251+
nodeEnv.logsDir()
251252
);
252253
} else {
253254
assert RuntimeVersionFeature.isSecurityManagerAvailable();

0 commit comments

Comments
 (0)