diff --git a/libs/entitlement/src/main/java/org/elasticsearch/entitlement/initialization/EntitlementInitialization.java b/libs/entitlement/src/main/java/org/elasticsearch/entitlement/initialization/EntitlementInitialization.java index bdceeca16ae4..c89460d0ea12 100644 --- a/libs/entitlement/src/main/java/org/elasticsearch/entitlement/initialization/EntitlementInitialization.java +++ b/libs/entitlement/src/main/java/org/elasticsearch/entitlement/initialization/EntitlementInitialization.java @@ -9,6 +9,7 @@ package org.elasticsearch.entitlement.initialization; +import org.elasticsearch.core.Booleans; import org.elasticsearch.core.PathUtils; import org.elasticsearch.core.internal.provider.ProviderLocator; import org.elasticsearch.entitlement.bootstrap.EntitlementBootstrap; @@ -241,16 +242,22 @@ public class EntitlementInitialization { ) ); - Path trustStorePath = trustStorePath(); - if (trustStorePath != null) { + // conditionally add FIPS entitlements if FIPS only functionality is enforced + if (Booleans.parseBoolean(System.getProperty("org.bouncycastle.fips.approved_only"), false)) { + // if custom trust store is set, grant read access to its location, otherwise use the default JDK trust store + String trustStore = System.getProperty("javax.net.ssl.trustStore"); + Path trustStorePath = trustStore != null + ? Path.of(trustStore) + : Path.of(System.getProperty("java.home")).resolve("lib/security/jssecacerts"); + Collections.addAll( serverScopes, new Scope( "org.bouncycastle.fips.tls", List.of( new FilesEntitlement(List.of(FileData.ofPath(trustStorePath, READ))), - new OutboundNetworkEntitlement(), - new ManageThreadsEntitlement() + new ManageThreadsEntitlement(), + new OutboundNetworkEntitlement() ) ), new Scope( @@ -302,11 +309,6 @@ public class EntitlementInitialization { return PathUtils.get(userHome); } - private static Path trustStorePath() { - String trustStore = System.getProperty("javax.net.ssl.trustStore"); - return trustStore != null ? Path.of(trustStore) : null; - } - private static Stream fileSystemProviderChecks() throws ClassNotFoundException, NoSuchMethodException { var fileSystemProviderClass = FileSystems.getDefault().provider().getClass();