-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add licensing enforcement for FIPS mode #32437
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b8a9c58
Add licensing enforcement for FIPS mode
jaymode 164af53
Merge branch 'master' into fips_licensing
jaymode d3fe48b
address feedback
jaymode f7e67e1
Merge branch 'master' into fips_licensing
jaymode 2ab9451
simplify alwaysenforce
jaymode 3e9d0fa
only warn in dev mode
jaymode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseFIPSTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.license; | ||
|
||
import org.elasticsearch.action.support.PlainActionFuture; | ||
import org.elasticsearch.cluster.ClusterStateUpdateTask; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.unit.TimeValue; | ||
import org.elasticsearch.protocol.xpack.license.PutLicenseResponse; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Mockito.verify; | ||
|
||
public class LicenseFIPSTests extends AbstractLicenseServiceTestCase { | ||
|
||
public void testFIPSCheckWithAllowedLicense() throws Exception { | ||
License newLicense = TestUtils.generateSignedLicense(randomFrom("trial", "platinum"), TimeValue.timeValueHours(24L)); | ||
PutLicenseRequest request = new PutLicenseRequest(); | ||
request.acknowledge(true); | ||
request.license(newLicense); | ||
Settings settings = Settings.builder() | ||
.put("xpack.security.enabled", true) | ||
.put("xpack.security.transport.ssl.enabled", true) | ||
.put("xpack.security.fips_mode.enabled", randomBoolean()) | ||
.build(); | ||
XPackLicenseState licenseState = new XPackLicenseState(settings); | ||
|
||
setInitialState(null, licenseState, settings); | ||
licenseService.start(); | ||
PlainActionFuture<PutLicenseResponse> responseFuture = new PlainActionFuture<>(); | ||
licenseService.registerLicense(request, responseFuture); | ||
verify(clusterService).submitStateUpdateTask(any(String.class), any(ClusterStateUpdateTask.class)); | ||
} | ||
|
||
public void testFIPSCheckWithoutAllowedLicense() throws Exception { | ||
License newLicense = TestUtils.generateSignedLicense(randomFrom("gold", "standard"), TimeValue.timeValueHours(24L)); | ||
PutLicenseRequest request = new PutLicenseRequest(); | ||
request.acknowledge(true); | ||
request.license(newLicense); | ||
Settings settings = Settings.builder() | ||
.put("xpack.security.enabled", true) | ||
.put("xpack.security.transport.ssl.enabled", true) | ||
.put("xpack.security.fips_mode.enabled", true) | ||
.build(); | ||
XPackLicenseState licenseState = new XPackLicenseState(settings); | ||
|
||
setInitialState(null, licenseState, settings); | ||
licenseService.start(); | ||
PlainActionFuture<PutLicenseResponse> responseFuture = new PlainActionFuture<>(); | ||
IllegalStateException e = expectThrows(IllegalStateException.class, () -> licenseService.registerLicense(request, responseFuture)); | ||
assertThat(e.getMessage(), | ||
containsString("Cannot install a [" + newLicense.operationMode() + "] license unless FIPS mode is disabled")); | ||
licenseService.stop(); | ||
|
||
settings = Settings.builder() | ||
.put("xpack.security.enabled", true) | ||
.put("xpack.security.transport.ssl.enabled", true) | ||
.put("xpack.security.fips_mode.enabled", false) | ||
.build(); | ||
licenseState = new XPackLicenseState(settings); | ||
|
||
setInitialState(null, licenseState, settings); | ||
licenseService.start(); | ||
licenseService.registerLicense(request, responseFuture); | ||
verify(clusterService).submitStateUpdateTask(any(String.class), any(ClusterStateUpdateTask.class)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...security/src/main/java/org/elasticsearch/xpack/security/FIPS140LicenseBootstrapCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.security; | ||
|
||
import org.elasticsearch.bootstrap.BootstrapCheck; | ||
import org.elasticsearch.bootstrap.BootstrapContext; | ||
import org.elasticsearch.license.License; | ||
import org.elasticsearch.license.LicenseService; | ||
|
||
import java.util.EnumSet; | ||
|
||
/** | ||
* A bootstrap check which enforces the licensing of FIPS | ||
*/ | ||
final class FIPS140LicenseBootstrapCheck implements BootstrapCheck { | ||
|
||
static final EnumSet<License.OperationMode> ALLOWED_LICENSE_OPERATION_MODES = | ||
EnumSet.of(License.OperationMode.PLATINUM, License.OperationMode.TRIAL); | ||
|
||
private final boolean isInFipsMode; | ||
|
||
FIPS140LicenseBootstrapCheck(boolean isInFipsMode) { | ||
this.isInFipsMode = isInFipsMode; | ||
} | ||
|
||
@Override | ||
public BootstrapCheckResult check(BootstrapContext context) { | ||
if (isInFipsMode) { | ||
License license = LicenseService.getLicense(context.metaData); | ||
if (license != null && ALLOWED_LICENSE_OPERATION_MODES.contains(license.operationMode()) == false) { | ||
return BootstrapCheckResult.failure("FIPS mode is only allowed with a Platinum or Trial license"); | ||
} | ||
} | ||
return BootstrapCheckResult.success(); | ||
} | ||
|
||
@Override | ||
public boolean alwaysEnforce() { | ||
return isInFipsMode; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -256,8 +256,6 @@ public class Security extends Plugin implements ActionPlugin, IngestPlugin, Netw | |
DiscoveryPlugin, MapperPlugin, ExtensiblePlugin { | ||
|
||
private static final Logger logger = Loggers.getLogger(Security.class); | ||
static final Setting<Boolean> FIPS_MODE_ENABLED = | ||
Setting.boolSetting("xpack.security.fips_mode.enabled", false, Property.NodeScope); | ||
|
||
static final Setting<List<String>> AUDIT_OUTPUTS_SETTING = | ||
Setting.listSetting(SecurityField.setting("audit.outputs"), | ||
|
@@ -595,7 +593,7 @@ public static List<Setting<?>> getSettings(boolean transportClientMode, List<Sec | |
} | ||
|
||
// The following just apply in node mode | ||
settingsList.add(FIPS_MODE_ENABLED); | ||
settingsList.add(XPackSettings.FIPS_MODE_ENABLED); | ||
|
||
// IP Filter settings | ||
IPFilter.addSettings(settingsList); | ||
|
@@ -1002,7 +1000,8 @@ public BiConsumer<DiscoveryNode, ClusterState> getJoinValidator() { | |
return new ValidateTLSOnJoin(XPackSettings.TRANSPORT_SSL_ENABLED.get(settings), | ||
DiscoveryModule.DISCOVERY_TYPE_SETTING.get(settings)) | ||
.andThen(new ValidateUpgradedSecurityIndex()) | ||
.andThen(new ValidateLicenseCanBeDeserialized()); | ||
.andThen(new ValidateLicenseCanBeDeserialized()) | ||
.andThen(new ValidateLicenseForFIPS(XPackSettings.FIPS_MODE_ENABLED.get(settings))); | ||
} | ||
return null; | ||
} | ||
|
@@ -1050,6 +1049,25 @@ public void accept(DiscoveryNode node, ClusterState state) { | |
} | ||
} | ||
|
||
static final class ValidateLicenseForFIPS implements BiConsumer<DiscoveryNode, ClusterState> { | ||
private final boolean inFipsMode; | ||
|
||
ValidateLicenseForFIPS(boolean inFipsMode) { | ||
this.inFipsMode = inFipsMode; | ||
} | ||
|
||
@Override | ||
public void accept(DiscoveryNode node, ClusterState state) { | ||
if (inFipsMode) { | ||
License license = LicenseService.getLicense(state.metaData()); | ||
if (license != null && | ||
FIPS140LicenseBootstrapCheck.ALLOWED_LICENSE_OPERATION_MODES.contains(license.operationMode()) == false) { | ||
throw new IllegalStateException("License operation mode [" + license.operationMode() + "] is not valid for FIPS"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a clearer message indicating that the problem is with
|
||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void reloadSPI(ClassLoader loader) { | ||
securityExtensions.addAll(SecurityExtension.loadExtensions(loader)); | ||
|
44 changes: 44 additions & 0 deletions
44
...ity/src/test/java/org/elasticsearch/xpack/security/FIPS140LicenseBootstrapCheckTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.security; | ||
|
||
import org.elasticsearch.bootstrap.BootstrapContext; | ||
import org.elasticsearch.cluster.metadata.MetaData; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.unit.TimeValue; | ||
import org.elasticsearch.license.License; | ||
import org.elasticsearch.license.TestUtils; | ||
import org.elasticsearch.test.ESTestCase; | ||
|
||
public class FIPS140LicenseBootstrapCheckTests extends ESTestCase { | ||
|
||
public void testBootstrapCheck() throws Exception { | ||
assertTrue(new FIPS140LicenseBootstrapCheck(false) | ||
.check(new BootstrapContext(Settings.EMPTY, MetaData.EMPTY_META_DATA)).isSuccess()); | ||
assertTrue(new FIPS140LicenseBootstrapCheck(randomBoolean()) | ||
.check(new BootstrapContext(Settings.EMPTY, MetaData.EMPTY_META_DATA)).isSuccess()); | ||
|
||
License license = TestUtils.generateSignedLicense(TimeValue.timeValueHours(24)); | ||
MetaData.Builder builder = MetaData.builder(); | ||
TestUtils.putLicense(builder, license); | ||
MetaData metaData = builder.build(); | ||
if (FIPS140LicenseBootstrapCheck.ALLOWED_LICENSE_OPERATION_MODES.contains(license.operationMode())) { | ||
assertTrue(new FIPS140LicenseBootstrapCheck(true).check(new BootstrapContext( | ||
Settings.builder().put("xpack.security.fips_mode.enabled", true).build(), metaData)).isSuccess()); | ||
assertTrue(new FIPS140LicenseBootstrapCheck(false).check(new BootstrapContext( | ||
Settings.builder().put("xpack.security.fips_mode.enabled", false).build(), metaData)).isSuccess()); | ||
} else { | ||
assertTrue(new FIPS140LicenseBootstrapCheck(false).check(new BootstrapContext( | ||
Settings.builder().put("xpack.security.fips_mode.enabled", false).build(), metaData)).isSuccess()); | ||
assertTrue(new FIPS140LicenseBootstrapCheck(true).check(new BootstrapContext( | ||
Settings.builder().put("xpack.security.fips_mode.enabled", true).build(), metaData)).isFailure()); | ||
assertEquals("FIPS mode is only allowed with a Platinum or Trial license", | ||
new FIPS140LicenseBootstrapCheck(true).check(new BootstrapContext( | ||
Settings.builder().put("xpack.security.fips_mode.enabled", true).build(), metaData)).getMessage()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be
true
since the check is itself guarded byisInFipsMode
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed 2ab9451