Skip to content

Commit 32cd2e6

Browse files
beanuwaveiigoninretabennygoerzigKarstenSchnitter
authored
Add FIPS build tooling (#17907)
* Add FIPS build-tooling Signed-off-by: Igonin <[email protected]> Co-authored-by: Benny Goerzig <[email protected]> Co-authored-by: Karsten Schnitter <[email protected]> Co-authored-by: Kai Sternad <[email protected]> # Conflicts: # CHANGELOG.md # Conflicts: # CHANGELOG.md * Update distribution/tools/plugin-cli/src/test/java/org/opensearch/tools/cli/plugin/InstallPluginCommandTests.java Co-authored-by: Andriy Redko <[email protected]> Signed-off-by: Iwan Igonin <[email protected]> * Update server/src/main/java/org/opensearch/bootstrap/SecurityProviderManager.java Co-authored-by: Andriy Redko <[email protected]> Signed-off-by: Iwan Igonin <[email protected]> * add additional '-Ptests.fips.enabled=true' parameter; set KEYSTORE_PASSWORD when running docker tests. Signed-off-by: Igonin <[email protected]> Co-authored-by: Benny Goerzig <[email protected]> Co-authored-by: Karsten Schnitter <[email protected]> Co-authored-by: Kai Sternad <[email protected]> * prevent bc deps propagation outside their modules Signed-off-by: Igonin <[email protected]> Co-authored-by: Benny Goerzig <[email protected]> Co-authored-by: Karsten Schnitter <[email protected]> Co-authored-by: Kai Sternad <[email protected]> * change TestUtilsTests to test for cryptographic equality Signed-off-by: Igonin <[email protected]> Co-authored-by: Benny Goerzig <[email protected]> Co-authored-by: Karsten Schnitter <[email protected]> Co-authored-by: Kai Sternad <[email protected]> * use 'fipsOnly' for all BC declarations Signed-off-by: Igonin <[email protected]> Co-authored-by: Benny Goerzig <[email protected]> Co-authored-by: Karsten Schnitter <[email protected]> Co-authored-by: Kai Sternad <[email protected]> * fix: do not allow other values than 'FIPS-140-3' for 'crypto.standard' Signed-off-by: Igonin <[email protected]> Co-authored-by: Benny Goerzig <[email protected]> Co-authored-by: Karsten Schnitter <[email protected]> Co-authored-by: Kai Sternad <[email protected]> * exclude BC from client & server compile scope Signed-off-by: Igonin <[email protected]> Co-authored-by: Benny Goerzig <[email protected]> Co-authored-by: Karsten Schnitter <[email protected]> Co-authored-by: Kai Sternad <[email protected]> * Refactor BootstrapForTesting & Randomness Signed-off-by: Igonin <[email protected]> Co-authored-by: Benny Goerzig <[email protected]> Co-authored-by: Karsten Schnitter <[email protected]> Co-authored-by: Kai Sternad <[email protected]> * revert Randomness.java Signed-off-by: Igonin <[email protected]> Co-authored-by: Benny Goerzig <[email protected]> Co-authored-by: Karsten Schnitter <[email protected]> Co-authored-by: Kai Sternad <[email protected]> # Conflicts: # server/src/main/java/org/opensearch/common/Randomness.java * rename SecurityProviderManager#excludeSunJCE to SecurityProviderManager#removeNonCompliantFipsProviders Signed-off-by: Igonin <[email protected]> Co-authored-by: Benny Goerzig <[email protected]> Co-authored-by: Karsten Schnitter <[email protected]> Co-authored-by: Kai Sternad <[email protected]> --------- Signed-off-by: Iwan Igonin <[email protected]> Signed-off-by: Igonin <[email protected]> Co-authored-by: Igonin <[email protected]> Co-authored-by: Andriy Redko <[email protected]> Co-authored-by: Benny Goerzig <[email protected]> Co-authored-by: Karsten Schnitter <[email protected]> Co-authored-by: Kai Sternad <[email protected]>
1 parent 130173c commit 32cd2e6

File tree

52 files changed

+798
-693
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+798
-693
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
3535
- Added File Cache Stats - Involves Block level as well as full file level stats ([#17538](https://github.com/opensearch-project/OpenSearch/issues/17479))
3636
- Added File Cache Pinning ([#17617](https://github.com/opensearch-project/OpenSearch/issues/13648))
3737
- Support consumer reset in Resume API for pull-based ingestion. This PR includes a breaking change for the experimental pull-based ingestion feature. ([#18332](https://github.com/opensearch-project/OpenSearch/pull/18332))
38+
- Add FIPS build tooling ([#4254](https://github.com/opensearch-project/security/issues/4254))
3839

3940
### Changed
4041
- Create generic DocRequest to better categorize ActionRequests ([#18269](https://github.com/opensearch-project/OpenSearch/pull/18269)))

build.gradle

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ apply from: 'gradle/ide.gradle'
6666
apply from: 'gradle/forbidden-dependencies.gradle'
6767
apply from: 'gradle/formatting.gradle'
6868
apply from: 'gradle/local-distribution.gradle'
69-
apply from: 'gradle/fips.gradle'
7069
apply from: 'gradle/run.gradle'
7170
apply from: 'gradle/missing-javadoc.gradle'
7271
apply from: 'gradle/code-coverage.gradle'
@@ -427,13 +426,19 @@ gradle.projectsEvaluated {
427426

428427
project.tasks.withType(Test) { task ->
429428
if (task != null) {
430-
task.jvmArgs += ["--add-modules=jdk.incubator.vector"]
429+
task.jvmArgs += [
430+
"--add-modules=jdk.incubator.vector",
431+
"--add-exports=java.base/com.sun.crypto.provider=ALL-UNNAMED"
432+
]
431433

432434
// Add Java Agent for security sandboxing
433435
if (!(project.path in [':build-tools', ":libs:agent-sm:bootstrap", ":libs:agent-sm:agent"])) {
434436
dependsOn(project(':libs:agent-sm:agent').prepareAgent)
435437
jvmArgs += ["-javaagent:" + project(':libs:agent-sm:agent').jar.archiveFile.get()]
436438
}
439+
if (BuildParams.inFipsJvm) {
440+
task.jvmArgs += ["-Dorg.bouncycastle.fips.approved_only=true"]
441+
}
437442
}
438443
}
439444

@@ -703,6 +708,14 @@ allprojects {
703708
plugins.withId('lifecycle-base') {
704709
checkPart1.configure { dependsOn 'check' }
705710
}
711+
712+
plugins.withId('opensearch.testclusters') {
713+
testClusters.configureEach {
714+
if (BuildParams.inFipsJvm) {
715+
keystorePassword 'notarealpasswordphrase'
716+
}
717+
}
718+
}
706719
}
707720

708721
subprojects {

buildSrc/src/main/java/org/opensearch/gradle/OpenSearchTestBasePlugin.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,13 @@ public void execute(Task t) {
161161
test.systemProperty("tests.seed", BuildParams.getTestSeed());
162162
}
163163

164-
var securityFile = "java.security";
165-
test.systemProperty(
166-
"java.security.properties",
167-
project.getRootProject().getLayout().getProjectDirectory() + "/distribution/src/config/" + securityFile
168-
);
164+
if (BuildParams.isInFipsJvm()) {
165+
test.systemProperty(
166+
"java.security.properties",
167+
project.getRootProject().getLayout().getProjectDirectory() + "/distribution/src/config/fips_java.security"
168+
);
169+
}
170+
169171
// don't track these as inputs since they contain absolute paths and break cache relocatability
170172
File gradleHome = project.getGradle().getGradleUserHomeDir();
171173
String gradleVersion = project.getGradle().getGradleVersion();
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.gradle.info;
10+
11+
import java.util.function.Function;
12+
13+
public class FipsBuildParams {
14+
15+
@Deprecated
16+
public static final String FIPS_BUILD_PARAM_FOR_TESTS = "tests.fips.enabled";
17+
public static final String FIPS_BUILD_PARAM = "crypto.standard";
18+
public static final String DEFAULT_FIPS_MODE = "FIPS-140-3";
19+
20+
private static String fipsMode;
21+
22+
public static void init(Function<String, Object> fipsValue) {
23+
var fipsBuildParamForTests = Boolean.parseBoolean((String) fipsValue.apply(FIPS_BUILD_PARAM_FOR_TESTS));
24+
var fipsBuildParam = (String) fipsValue.apply(FIPS_BUILD_PARAM);
25+
26+
if (fipsBuildParamForTests || DEFAULT_FIPS_MODE.equals(fipsBuildParam)) {
27+
fipsMode = DEFAULT_FIPS_MODE;
28+
} else {
29+
fipsMode = "any-supported";
30+
}
31+
}
32+
33+
private FipsBuildParams() {}
34+
35+
public static boolean isInFipsMode() {
36+
return DEFAULT_FIPS_MODE.equals(fipsMode);
37+
}
38+
39+
public static String getFipsMode() {
40+
return fipsMode;
41+
}
42+
43+
}

buildSrc/src/main/java/org/opensearch/gradle/info/GlobalBuildInfoPlugin.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ public void apply(Project project) {
109109
File rootDir = project.getRootDir();
110110
GitInfo gitInfo = gitInfo(rootDir);
111111

112+
FipsBuildParams.init(project::findProperty);
113+
112114
BuildParams.init(params -> {
113115
// Initialize global build parameters
114116
boolean isInternal = GlobalBuildInfoPlugin.class.getResource("/buildSrc.marker") != null;
@@ -129,7 +131,7 @@ public void apply(Project project) {
129131
params.setIsCi(System.getenv("JENKINS_URL") != null);
130132
params.setIsInternal(isInternal);
131133
params.setDefaultParallel(findDefaultParallel(project));
132-
params.setInFipsJvm(Util.getBooleanProperty("tests.fips.enabled", false));
134+
params.setInFipsJvm(FipsBuildParams.isInFipsMode());
133135
params.setIsSnapshotBuild(Util.getBooleanProperty("build.snapshot", true));
134136
if (isInternal) {
135137
params.setBwcVersions(resolveBwcVersions(rootDir));
@@ -179,7 +181,7 @@ private void logGlobalBuildInfo() {
179181
LOGGER.quiet(" JAVA_HOME : " + gradleJvm.getJavaHome());
180182
}
181183
LOGGER.quiet(" Random Testing Seed : " + BuildParams.getTestSeed());
182-
LOGGER.quiet(" In FIPS 140 mode : " + BuildParams.isInFipsJvm());
184+
LOGGER.quiet(" Crypto Standard : " + FipsBuildParams.getFipsMode());
183185
LOGGER.quiet("=======================================");
184186
}
185187

buildSrc/src/main/java/org/opensearch/gradle/testclusters/OpenSearchNode.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.opensearch.gradle.Version;
4747
import org.opensearch.gradle.VersionProperties;
4848
import org.opensearch.gradle.info.BuildParams;
49+
import org.opensearch.gradle.info.FipsBuildParams;
4950
import org.gradle.api.Action;
5051
import org.gradle.api.Named;
5152
import org.gradle.api.NamedDomainObjectContainer;
@@ -546,6 +547,10 @@ public synchronized void start() {
546547
logToProcessStdout("installed plugins");
547548
}
548549

550+
if (FipsBuildParams.isInFipsMode() && keystorePassword.isEmpty()) {
551+
throw new TestClustersException("Can not start " + this + " in FIPS JVM, missing keystore password");
552+
}
553+
549554
logToProcessStdout("Creating opensearch keystore with password set to [" + keystorePassword + "]");
550555
if (keystorePassword.length() > 0) {
551556
runOpenSearchBinScriptWithInput(keystorePassword + "\n" + keystorePassword + "\n", "opensearch-keystore", "create", "-p");
-101 KB
Binary file not shown.

buildSrc/src/main/resources/fips_java_bcjsse_11.policy

Lines changed: 0 additions & 29 deletions
This file was deleted.

buildSrc/src/main/resources/fips_java_bcjsse_11.security

Lines changed: 0 additions & 53 deletions
This file was deleted.

buildSrc/src/main/resources/fips_java_bcjsse_8.policy

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)