Skip to content

Commit c41caeb

Browse files
authored
Enable FIPS entitlements based on org.bouncycastle.fips.approved_only. (#124577)
When enabling FIPS `javax.net.ssl.trustStore` is not necessarily set. This change adds FIPS entitlements based on `org.bouncycastle.fips.approved_only=true`, which enforces usage of FIPS approved functionality only. Additionally, this PR grants read access to a custom trust store if provided via `javax.net.ssl.trustStore`, otherwise read access to the default JDK trust store is granted. Relates to ES-11025.
1 parent 37a3630 commit c41caeb

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package org.elasticsearch.entitlement.initialization;
1111

12+
import org.elasticsearch.core.Booleans;
1213
import org.elasticsearch.core.PathUtils;
1314
import org.elasticsearch.core.internal.provider.ProviderLocator;
1415
import org.elasticsearch.entitlement.bootstrap.EntitlementBootstrap;
@@ -241,16 +242,22 @@ private static PolicyManager createPolicyManager() {
241242
)
242243
);
243244

244-
Path trustStorePath = trustStorePath();
245-
if (trustStorePath != null) {
245+
// conditionally add FIPS entitlements if FIPS only functionality is enforced
246+
if (Booleans.parseBoolean(System.getProperty("org.bouncycastle.fips.approved_only"), false)) {
247+
// if custom trust store is set, grant read access to its location, otherwise use the default JDK trust store
248+
String trustStore = System.getProperty("javax.net.ssl.trustStore");
249+
Path trustStorePath = trustStore != null
250+
? Path.of(trustStore)
251+
: Path.of(System.getProperty("java.home")).resolve("lib/security/jssecacerts");
252+
246253
Collections.addAll(
247254
serverScopes,
248255
new Scope(
249256
"org.bouncycastle.fips.tls",
250257
List.of(
251258
new FilesEntitlement(List.of(FileData.ofPath(trustStorePath, READ))),
252-
new OutboundNetworkEntitlement(),
253-
new ManageThreadsEntitlement()
259+
new ManageThreadsEntitlement(),
260+
new OutboundNetworkEntitlement()
254261
)
255262
),
256263
new Scope(
@@ -302,11 +309,6 @@ private static Path getUserHome() {
302309
return PathUtils.get(userHome);
303310
}
304311

305-
private static Path trustStorePath() {
306-
String trustStore = System.getProperty("javax.net.ssl.trustStore");
307-
return trustStore != null ? Path.of(trustStore) : null;
308-
}
309-
310312
private static Stream<InstrumentationService.InstrumentationInfo> fileSystemProviderChecks() throws ClassNotFoundException,
311313
NoSuchMethodException {
312314
var fileSystemProviderClass = FileSystems.getDefault().provider().getClass();

0 commit comments

Comments
 (0)