Skip to content

Commit 59d8912

Browse files
authored
[Entitlements] Add logsDir to entitlement bootstrap parameters (elastic#122605) (elastic#122725)
While testing elastic#122591, I realized we need to grand read/write permission to the logs dir to server. This PR adds the `logsDir` to the bootstrap parameters, and uses it in the `server` policy.
1 parent 9aa37f1 commit 59d8912

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ private static PolicyManager createPolicyManager() {
129129
EntitlementBootstrap.BootstrapArgs bootstrapArgs = EntitlementBootstrap.bootstrapArgs();
130130
Map<String, Policy> pluginPolicies = bootstrapArgs.pluginPolicies();
131131
var pathLookup = new PathLookup(bootstrapArgs.configDir(), bootstrapArgs.dataDirs(), bootstrapArgs.tempDir());
132+
Path logsDir = EntitlementBootstrap.bootstrapArgs().logsDir();
132133

133134
// TODO(ES-10031): Decide what goes in the elasticsearch default policy and extend it
134135
var serverPolicy = new Policy(
@@ -147,7 +148,10 @@ private static PolicyManager createPolicyManager() {
147148
new LoadNativeLibrariesEntitlement(),
148149
new ManageThreadsEntitlement(),
149150
new FilesEntitlement(
150-
List.of(FilesEntitlement.FileData.ofPath(EntitlementBootstrap.bootstrapArgs().tempDir(), READ_WRITE))
151+
List.of(
152+
FilesEntitlement.FileData.ofPath(EntitlementBootstrap.bootstrapArgs().tempDir(), READ_WRITE),
153+
FilesEntitlement.FileData.ofPath(EntitlementBootstrap.bootstrapArgs().logsDir(), READ_WRITE)
154+
)
151155
)
152156
)
153157
),

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)