Skip to content

Commit 128224f

Browse files
author
tangkai55
committed
Add fips.mode configuration to control truststore check in FIPS mode
1 parent 2675b44 commit 128224f

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

plugins/repository-gcs/src/main/java/org/opensearch/repositories/gcs/GoogleCloudStorageClientSettings.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@ public class GoogleCloudStorageClientSettings {
189189
key -> Setting.simpleString(key, Setting.Property.NodeScope)
190190
);
191191

192+
/**
193+
* Whether to enable FIPS mode validation for the GCS client.
194+
* Set to false to bypass custom truststore check in FIPS-enabled environments.
195+
*/
196+
static final Setting.AffixSetting<Boolean> FIPS_MODE_SETTING = Setting.affixKeySetting(
197+
PREFIX,
198+
"fips.mode",
199+
key -> Setting.boolSetting(key, true, Setting.Property.NodeScope)
200+
);
201+
192202
/** The credentials used by the client to connect to the Storage endpoint. */
193203
private final ServiceAccountCredentials credential;
194204

@@ -216,6 +226,12 @@ public class GoogleCloudStorageClientSettings {
216226
/** The GCS SDK Truststore settings. */
217227
private final TruststoreSettings truststoreSettings;
218228

229+
/**
230+
* Whether to enforce FIPS mode validation for this GCS client.
231+
* When true and running in a FIPS-enabled JVM, a custom truststore must be configured.
232+
*/
233+
private final boolean fipsMode;
234+
219235
GoogleCloudStorageClientSettings(
220236
final ServiceAccountCredentials credential,
221237
final String endpoint,
@@ -225,7 +241,8 @@ public class GoogleCloudStorageClientSettings {
225241
final String applicationName,
226242
final URI tokenUri,
227243
final ProxySettings proxySettings,
228-
final TruststoreSettings truststoreSettings
244+
final TruststoreSettings truststoreSettings,
245+
final boolean fipsMode
229246
) {
230247
this.credential = credential;
231248
this.endpoint = endpoint;
@@ -236,6 +253,7 @@ public class GoogleCloudStorageClientSettings {
236253
this.tokenUri = tokenUri;
237254
this.proxySettings = proxySettings;
238255
this.truststoreSettings = truststoreSettings;
256+
this.fipsMode = fipsMode;
239257
}
240258

241259
public ServiceAccountCredentials getCredential() {
@@ -297,7 +315,8 @@ static GoogleCloudStorageClientSettings getClientSettings(final Settings setting
297315
getConfigValue(settings, clientName, APPLICATION_NAME_SETTING),
298316
getConfigValue(settings, clientName, TOKEN_URI_SETTING),
299317
validateAndCreateProxySettings(settings, clientName),
300-
validateAndCreateTruststoreSettings(settings, clientName)
318+
validateAndCreateTruststoreSettings(settings, clientName),
319+
getConfigValue(settings, clientName, FIPS_MODE_SETTING)
301320
);
302321
}
303322

@@ -397,4 +416,12 @@ private static <T> T getConfigValue(final Settings settings, final String client
397416
final Setting<T> concreteSetting = clientSetting.getConcreteSettingForNamespace(clientName);
398417
return concreteSetting.get(settings);
399418
}
419+
420+
/**
421+
* Returns whether FIPS mode validation is enabled for this client.
422+
* @return true if FIPS mode validation is enabled, false otherwise
423+
*/
424+
public boolean isFipsMode() {
425+
return fipsMode;
426+
}
400427
}

plugins/repository-gcs/src/main/java/org/opensearch/repositories/gcs/GoogleCloudStorageService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ private HttpTransport createHttpTransport(final GoogleCloudStorageClientSettings
193193
return AccessController.doPrivilegedChecked(() -> {
194194
try {
195195
final NetHttpTransport.Builder builder = new NetHttpTransport.Builder();
196-
final TruststoreSettings truststoreSettings = clientSettings.getTruststoreSettings();
197-
builder.trustCertificates(loadTrustStore(truststoreSettings));
196+
builder.trustCertificates(loadTrustStore(clientSettings));
198197

199198
final ProxySettings proxySettings = clientSettings.getProxySettings();
200199
if (proxySettings != ProxySettings.NO_PROXY_SETTINGS) {
@@ -219,7 +218,8 @@ protected PasswordAuthentication getPasswordAuthentication() {
219218
});
220219
}
221220

222-
private KeyStore loadTrustStore(TruststoreSettings truststoreSettings) throws GeneralSecurityException, IOException {
221+
private KeyStore loadTrustStore(GoogleCloudStorageClientSettings clientSettings) throws GeneralSecurityException, IOException {
222+
TruststoreSettings truststoreSettings = clientSettings.getTruststoreSettings();
223223
KeyStore certTrustStore;
224224
if (truststoreSettings.isConfigured()) {
225225
final var truststorePath = truststoreSettings.path();
@@ -230,7 +230,7 @@ private KeyStore loadTrustStore(TruststoreSettings truststoreSettings) throws Ge
230230
SecurityUtils.loadKeyStore(certTrustStore, trustStoreStream, truststorePassword.toString());
231231
}
232232
logger.debug("Loaded custom truststore from path: {} with type: {}", truststorePath, truststoreType);
233-
} else if (Security.getProvider("BCFIPS") != null) {
233+
} else if (clientSettings.isFipsMode() && Security.getProvider("BCFIPS") != null) {
234234
throw new IllegalStateException(
235235
"FIPS mode is active but no custom truststore is configured. "
236236
+ "Please configure gcs.client.<client-name>.truststore.path and "

0 commit comments

Comments
 (0)