Skip to content

Commit b841b5f

Browse files
authored
[discovery-gce] Fix initialisation of transport in FIPS mode (#85817)
Load the the keystore with Google certificates in the JKS format instead of the default p12 which is not compatible with FIPS.
1 parent 1045686 commit b841b5f

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

docs/changelog/85817.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 85817
2+
summary: "[discovery-gce] Fix initialisation of transport in FIPS mode"
3+
area: Discovery-Plugins
4+
type: bug
5+
issues:
6+
- 85803

plugins/discovery-gce/src/main/java/org/elasticsearch/cloud/gce/GceInstancesServiceImpl.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
package org.elasticsearch.cloud.gce;
1010

11+
import com.google.api.client.googleapis.GoogleUtils;
1112
import com.google.api.client.googleapis.compute.ComputeCredential;
12-
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
1313
import com.google.api.client.http.GenericUrl;
1414
import com.google.api.client.http.HttpHeaders;
1515
import com.google.api.client.http.HttpRequest;
@@ -19,6 +19,7 @@
1919
import com.google.api.client.http.javanet.NetHttpTransport;
2020
import com.google.api.client.json.JsonFactory;
2121
import com.google.api.client.json.jackson2.JacksonFactory;
22+
import com.google.api.client.util.SecurityUtils;
2223
import com.google.api.services.compute.Compute;
2324
import com.google.api.services.compute.model.Instance;
2425
import com.google.api.services.compute.model.InstanceList;
@@ -36,6 +37,7 @@
3637

3738
import java.io.IOException;
3839
import java.security.GeneralSecurityException;
40+
import java.security.KeyStore;
3941
import java.util.ArrayList;
4042
import java.util.Collection;
4143
import java.util.Collections;
@@ -173,7 +175,12 @@ private static boolean headerContainsMetadataFlavor(HttpResponse response) {
173175
protected synchronized HttpTransport getGceHttpTransport() throws GeneralSecurityException, IOException {
174176
if (gceHttpTransport == null) {
175177
if (validateCerts) {
176-
gceHttpTransport = GoogleNetHttpTransport.newTrustedTransport();
178+
// Manually load the certificates in the jks format instead of the default p12 which is not compatible with FIPS.
179+
KeyStore certTrustStore = SecurityUtils.getJavaKeyStore();
180+
try (var is = GoogleUtils.class.getResourceAsStream("google.jks")) {
181+
SecurityUtils.loadKeyStore(certTrustStore, is, "notasecret");
182+
}
183+
gceHttpTransport = new NetHttpTransport.Builder().trustCertificates(certTrustStore).build();
177184
} else {
178185
// this is only used for testing - alternative we could use the defaul keystore but this requires special configs too..
179186
gceHttpTransport = new NetHttpTransport.Builder().doNotValidateCertificate().build();

0 commit comments

Comments
 (0)