Skip to content

Commit 24e43df

Browse files
authored
[7.x] Refactor FIPS BootstrapChecks to simple checks (#47499) (#48333)
FIPS 140 bootstrap checks should not be bootstrap checks as they are always enforced. This commit moves the validation logic within the security plugin. The FIPS140SecureSettingsBootstrapCheck was not applicable as the keystore was being loaded on init, before the Bootstrap checks were checked, so an elasticsearch keystore of version < 3 would cause the node to fail in a FIPS 140 JVM before the bootstrap check kicked in, and as such hasn't been migrated. Resolves: #34772
1 parent aa29567 commit 24e43df

12 files changed

+135
-445
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/license/XPackLicenseState.java

+5
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
import org.elasticsearch.xpack.core.monitoring.MonitoringField;
1717

1818
import java.util.Collections;
19+
import java.util.EnumSet;
1920
import java.util.LinkedHashMap;
2021
import java.util.List;
2122
import java.util.Map;
2223
import java.util.Objects;
24+
import java.util.Set;
2325
import java.util.concurrent.CopyOnWriteArrayList;
2426
import java.util.function.BiFunction;
2527

@@ -28,6 +30,9 @@
2830
*/
2931
public class XPackLicenseState {
3032

33+
public static final Set<OperationMode> FIPS_ALLOWED_LICENSE_OPERATION_MODES =
34+
EnumSet.of(License.OperationMode.PLATINUM, License.OperationMode.TRIAL);
35+
3136
/** Messages for each feature which are printed when the license expires. */
3237
static final Map<String, String[]> EXPIRATION_MESSAGES;
3338
static {

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/SSLConfigurationSettings.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public static String getKeyStoreType(Setting<Optional<String>> setting, Settings
242242
return setting.get(settings).orElseGet(() -> inferKeyStoreType(path));
243243
}
244244

245-
private static String inferKeyStoreType(String path) {
245+
public static String inferKeyStoreType(String path) {
246246
String name = path == null ? "" : path.toLowerCase(Locale.ROOT);
247247
if (name.endsWith(".p12") || name.endsWith(".pfx") || name.endsWith(".pkcs12")) {
248248
return PKCS12_KEYSTORE_TYPE;

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/FIPS140JKSKeystoreBootstrapCheck.java

-49
This file was deleted.

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/FIPS140LicenseBootstrapCheck.java

-35
This file was deleted.

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/FIPS140PasswordHashingAlgorithmBootstrapCheck.java

-34
This file was deleted.

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/FIPS140SecureSettingsBootstrapCheck.java

-53
This file was deleted.

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java

+37-6
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@
263263
import static java.util.Collections.emptyList;
264264
import static java.util.Collections.singletonList;
265265
import static org.elasticsearch.cluster.metadata.IndexMetaData.INDEX_FORMAT_SETTING;
266+
import static org.elasticsearch.license.XPackLicenseState.FIPS_ALLOWED_LICENSE_OPERATION_MODES;
266267
import static org.elasticsearch.xpack.core.XPackSettings.API_KEY_SERVICE_ENABLED_SETTING;
267268
import static org.elasticsearch.xpack.core.XPackSettings.HTTP_SSL_ENABLED;
268269
import static org.elasticsearch.xpack.core.security.index.RestrictedIndicesNames.SECURITY_MAIN_ALIAS;
@@ -313,11 +314,7 @@ public Security(Settings settings, final Path configPath) {
313314
new ApiKeySSLBootstrapCheck(),
314315
new TokenSSLBootstrapCheck(),
315316
new PkiRealmBootstrapCheck(getSslService()),
316-
new TLSLicenseBootstrapCheck(),
317-
new FIPS140SecureSettingsBootstrapCheck(settings, env),
318-
new FIPS140JKSKeystoreBootstrapCheck(),
319-
new FIPS140PasswordHashingAlgorithmBootstrapCheck(),
320-
new FIPS140LicenseBootstrapCheck()));
317+
new TLSLicenseBootstrapCheck()));
321318
checks.addAll(InternalRealms.getBootstrapChecks(settings, env));
322319
this.bootstrapChecks = Collections.unmodifiableList(checks);
323320
Automatons.updateConfiguration(settings);
@@ -330,6 +327,9 @@ public Security(Settings settings, final Path configPath) {
330327

331328
private static void runStartupChecks(Settings settings) {
332329
validateRealmSettings(settings);
330+
if (XPackSettings.FIPS_MODE_ENABLED.get(settings)) {
331+
validateForFips(settings);
332+
}
333333
}
334334

335335
@Override
@@ -882,6 +882,37 @@ static void validateRealmSettings(Settings settings) {
882882
}
883883
}
884884

885+
static void validateForFips(Settings settings) {
886+
final List<String> validationErrors = new ArrayList<>();
887+
Settings keystoreTypeSettings = settings.filter(k -> k.endsWith("keystore.type"))
888+
.filter(k -> settings.get(k).equalsIgnoreCase("jks"));
889+
if (keystoreTypeSettings.isEmpty() == false) {
890+
validationErrors.add("JKS Keystores cannot be used in a FIPS 140 compliant JVM. Please " +
891+
"revisit [" + keystoreTypeSettings.toDelimitedString(',') + "] settings");
892+
}
893+
Settings keystorePathSettings = settings.filter(k -> k.endsWith("keystore.path"))
894+
.filter(k -> settings.hasValue(k.replace(".path", ".type")) == false);
895+
if (keystorePathSettings.isEmpty() == false && SSLConfigurationSettings.inferKeyStoreType(null).equals("jks")) {
896+
validationErrors.add("JKS Keystores cannot be used in a FIPS 140 compliant JVM. Please " +
897+
"revisit [" + keystorePathSettings.toDelimitedString(',') + "] settings");
898+
}
899+
final String selectedAlgorithm = XPackSettings.PASSWORD_HASHING_ALGORITHM.get(settings);
900+
if (selectedAlgorithm.toLowerCase(Locale.ROOT).startsWith("pbkdf2") == false) {
901+
validationErrors.add("Only PBKDF2 is allowed for password hashing in a FIPS 140 JVM. Please set the " +
902+
"appropriate value for [ " + XPackSettings.PASSWORD_HASHING_ALGORITHM.getKey() + " ] setting.");
903+
}
904+
905+
if (validationErrors.isEmpty() == false) {
906+
final StringBuilder sb = new StringBuilder();
907+
sb.append("Validation for FIPS 140 mode failed: \n");
908+
int index = 0;
909+
for (String error : validationErrors) {
910+
sb.append(++index).append(": ").append(error).append(";\n");
911+
}
912+
throw new IllegalArgumentException(sb.toString());
913+
}
914+
}
915+
885916
@Override
886917
public List<TransportInterceptor> getTransportInterceptors(NamedWriteableRegistry namedWriteableRegistry, ThreadContext threadContext) {
887918
if (transportClientMode || enabled == false) { // don't register anything if we are not enabled
@@ -1044,7 +1075,7 @@ public void accept(DiscoveryNode node, ClusterState state) {
10441075
if (inFipsMode) {
10451076
License license = LicenseService.getLicense(state.metaData());
10461077
if (license != null &&
1047-
FIPS140LicenseBootstrapCheck.ALLOWED_LICENSE_OPERATION_MODES.contains(license.operationMode()) == false) {
1078+
FIPS_ALLOWED_LICENSE_OPERATION_MODES.contains(license.operationMode()) == false) {
10481079
throw new IllegalStateException("FIPS mode cannot be used with a [" + license.operationMode() +
10491080
"] license. It is only allowed with a Platinum or Trial license.");
10501081

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/FIPS140JKSKeystoreBootstrapCheckTests.java

-49
This file was deleted.

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/FIPS140LicenseBootstrapCheckTests.java

-45
This file was deleted.

0 commit comments

Comments
 (0)