Skip to content

Commit

Permalink
[Entitlements] Add logsDir to entitlement bootstrap parameters (elast…
Browse files Browse the repository at this point in the history
…ic#122605)

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.
  • Loading branch information
ldematte authored Feb 17, 2025
1 parent 8b4f159 commit 191f801
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public record BootstrapArgs(
Function<Class<?>, String> pluginResolver,
Path[] dataDirs,
Path configDir,
Path tempDir
Path tempDir,
Path logsDir
) {
public BootstrapArgs {
requireNonNull(pluginPolicies);
Expand All @@ -64,22 +65,24 @@ public static BootstrapArgs bootstrapArgs() {
*
* @param pluginPolicies a map holding policies for plugins (and modules), by plugin (or module) name.
* @param pluginResolver a functor to map a Java Class to the plugin it belongs to (the plugin name).
* @param dataDirs data directories for Elasticsearch
* @param configDir the config directory for Elasticsearch
* @param tempDir the temp directory for Elasticsearch
* @param dataDirs data directories for Elasticsearch
* @param configDir the config directory for Elasticsearch
* @param tempDir the temp directory for Elasticsearch
* @param logsDir the log directory for Elasticsearch
*/
public static void bootstrap(
Map<String, Policy> pluginPolicies,
Function<Class<?>, String> pluginResolver,
Path[] dataDirs,
Path configDir,
Path tempDir
Path tempDir,
Path logsDir
) {
logger.debug("Loading entitlement agent");
if (EntitlementBootstrap.bootstrapArgs != null) {
throw new IllegalStateException("plugin data is already set");
}
EntitlementBootstrap.bootstrapArgs = new BootstrapArgs(pluginPolicies, pluginResolver, dataDirs, configDir, tempDir);
EntitlementBootstrap.bootstrapArgs = new BootstrapArgs(pluginPolicies, pluginResolver, dataDirs, configDir, tempDir, logsDir);
exportInitializationToAgent();
loadAgent(findAgentJar());
selfTest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ private static PolicyManager createPolicyManager() {
EntitlementBootstrap.BootstrapArgs bootstrapArgs = EntitlementBootstrap.bootstrapArgs();
Map<String, Policy> pluginPolicies = bootstrapArgs.pluginPolicies();
var pathLookup = new PathLookup(bootstrapArgs.configDir(), bootstrapArgs.dataDirs(), bootstrapArgs.tempDir());
Path logsDir = EntitlementBootstrap.bootstrapArgs().logsDir();

// TODO(ES-10031): Decide what goes in the elasticsearch default policy and extend it
var serverPolicy = new Policy(
Expand All @@ -147,7 +148,10 @@ private static PolicyManager createPolicyManager() {
new LoadNativeLibrariesEntitlement(),
new ManageThreadsEntitlement(),
new FilesEntitlement(
List.of(FilesEntitlement.FileData.ofPath(EntitlementBootstrap.bootstrapArgs().tempDir(), READ_WRITE))
List.of(
FilesEntitlement.FileData.ofPath(EntitlementBootstrap.bootstrapArgs().tempDir(), READ_WRITE),
FilesEntitlement.FileData.ofPath(EntitlementBootstrap.bootstrapArgs().logsDir(), READ_WRITE)
)
)
)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ private static void initPhase2(Bootstrap bootstrap) throws IOException {
pluginsResolver::resolveClassToPluginName,
nodeEnv.dataDirs(),
nodeEnv.configDir(),
nodeEnv.tmpDir()
nodeEnv.tmpDir(),
nodeEnv.logsDir()
);
} else {
assert RuntimeVersionFeature.isSecurityManagerAvailable();
Expand Down

0 comments on commit 191f801

Please sign in to comment.