-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add licensing enforcement for FIPS mode (#32437)
This commit adds licensing enforcement for FIPS mode through the use of a bootstrap check, a node join validator, and a check in the license service. The work done here is based on the current implementation of the TLS enforcement with a production license. The bootstrap check is always enforced since we need to enforce the licensing and this is the best option to do so at the present time.
- Loading branch information
Showing
11 changed files
with
245 additions
and
37 deletions.
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
40 changes: 40 additions & 0 deletions
40
...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,40 @@ | ||
/* | ||
* 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(); | ||
} | ||
} |
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
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.