Skip to content
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

Fips compliance2 #244

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
128fb79
Draft to allow run in FIPS compliace mode
iigonin Mar 4, 2024
2c6e14b
make tests run without BC (not BCFIPS) libraries.
iigonin Aug 7, 2024
30c0b32
disable approved-only mode for launch configuration of testcluster
iigonin Aug 8, 2024
0ef725d
update all BC libraries to support JAVA 21
iigonin Aug 8, 2024
a33a10f
try to pass bwc staged build by adding expected version
iigonin Aug 8, 2024
54e31be
ensure FIPS-mode can be enabled by fixing existent and creating addit…
iigonin Aug 30, 2024
32586d4
fixing additional tests.
iigonin Sep 23, 2024
24510e7
Configure FIPS mode through global ENV VAR instead of thread-based.
iigonin Oct 18, 2024
5562d1f
write some additional unit tests.
iigonin Oct 24, 2024
71ef8d9
test SystemJvmOptions.java & replace FIPS-140-2 by FIPS-140-3
iigonin Oct 28, 2024
4832553
categorize JKS keystore as untrusted
iigonin Nov 8, 2024
183891d
general exclusion of keystore binaries and certificates from fobidden…
iigonin Nov 14, 2024
5cc787d
Kerberos, forbiddenApis, SecureRandom, SunJCE, AzureTests
iigonin Nov 19, 2024
fe86126
remove BC libs from 'libs:common'; revert SecureRandomHolder
iigonin Jan 9, 2025
945ec7d
loosen some direct BC dependencies
iigonin Jan 16, 2025
cfa5d79
set default testcluster password for all project modules
iigonin Jan 27, 2025
b609772
build with 'crypto.standard' gradle build parameter
iigonin Jan 31, 2025
f88d5a5
run REST-tests with JKS & BCFKS keystores
iigonin Feb 4, 2025
5c97dd6
Explicitly call closeConnectionChannel
cwperks Feb 12, 2025
c583753
Run on fork
cwperks Feb 12, 2025
2ebf326
Remove if
cwperks Feb 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/gradle-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ jobs:

gradle-check:
needs: check-files
if: github.repository == 'opensearch-project/OpenSearch' && needs.check-files.outputs.RUN_GRADLE_CHECK == 'true'
permissions:
contents: read # to fetch code (actions/checkout)
pull-requests: write # to create or update comment (peter-evans/create-or-update-comment)
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG-3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Views, simplify data access and manipulation by providing a virtual layer over one or more indices ([#11957](https://github.com/opensearch-project/OpenSearch/pull/11957))
- Added pull-based Ingestion (APIs, for ingestion source, a Kafka plugin, and IngestionEngine that pulls data from the ingestion source) ([#16958](https://github.com/opensearch-project/OpenSearch/pull/16958))
- Added ConfigurationUtils to core for the ease of configuration parsing [#17223](https://github.com/opensearch-project/OpenSearch/pull/17223)
- Support for FIPS-140-3 compliance through environment variable ([#3420](https://github.com/opensearch-project/OpenSearch/pull/14912))

### Dependencies
- Update Apache Lucene to 10.1.0 ([#16366](https://github.com/opensearch-project/OpenSearch/pull/16366))
Expand Down
19 changes: 17 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ apply from: 'gradle/ide.gradle'
apply from: 'gradle/forbidden-dependencies.gradle'
apply from: 'gradle/formatting.gradle'
apply from: 'gradle/local-distribution.gradle'
apply from: 'gradle/fips.gradle'
apply from: 'gradle/run.gradle'
apply from: 'gradle/missing-javadoc.gradle'
apply from: 'gradle/code-coverage.gradle'
Expand Down Expand Up @@ -472,8 +471,8 @@ gradle.projectsEvaluated {
}
}

// test retry configuration
subprojects {
// test retry configuration
tasks.withType(Test).configureEach {
develocity.testRetry {
if (BuildParams.isCi()) {
Expand Down Expand Up @@ -559,6 +558,22 @@ subprojects {
}
}
}

// test with FIPS-140-3 enabled
plugins.withType(JavaPlugin).configureEach {
tasks.withType(Test).configureEach { testTask ->
if (BuildParams.inFipsJvm) {
testTask.jvmArgs += "-Dorg.bouncycastle.fips.approved_only=true"
}
}
}
plugins.withId('opensearch.testclusters') {
testClusters.configureEach {
if (BuildParams.inFipsJvm) {
keystorePassword 'notarealpasswordphrase'
}
}
}
}

// eclipse configuration
Expand Down
4 changes: 0 additions & 4 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,8 @@ if (project != rootProject) {

forbiddenPatterns {
exclude '**/*.wav'
exclude '**/*.p12'
exclude '**/*.jks'
exclude '**/*.crt'
// the file that actually defines nocommit
exclude '**/ForbiddenPatternsTask.java'
exclude '**/*.bcfks'
}

testingConventions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ public void execute(Task t) {
test.systemProperty("tests.seed", BuildParams.getTestSeed());
}

var securityFile = BuildParams.isInFipsJvm() ? "fips_java.security" : "java.security";
test.systemProperty(
"java.security.properties",
project.getRootProject().getLayout().getProjectDirectory() + "/distribution/src/config/" + securityFile
);

// don't track these as inputs since they contain absolute paths and break cache relocatability
File gradleHome = project.getGradle().getGradleUserHomeDir();
String gradleVersion = project.getGradle().getGradleVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

package org.opensearch.gradle.http;

import de.thetaphi.forbiddenapis.SuppressForbidden;

import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;

Expand Down Expand Up @@ -216,15 +218,15 @@ KeyStore buildTrustStore() throws GeneralSecurityException, IOException {
}

private KeyStore buildTrustStoreFromFile() throws GeneralSecurityException, IOException {
KeyStore keyStore = KeyStore.getInstance(trustStoreFile.getName().endsWith(".jks") ? "JKS" : "PKCS12");
var keyStore = getKeyStoreInstance(trustStoreFile.getName().endsWith(".jks") ? "JKS" : "PKCS12");
try (InputStream input = new FileInputStream(trustStoreFile)) {
keyStore.load(input, trustStorePassword == null ? null : trustStorePassword.toCharArray());
}
return keyStore;
}

private KeyStore buildTrustStoreFromCA() throws GeneralSecurityException, IOException {
final KeyStore store = KeyStore.getInstance(KeyStore.getDefaultType());
var store = getKeyStoreInstance(KeyStore.getDefaultType());
store.load(null, null);
final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
int counter = 0;
Expand All @@ -239,6 +241,11 @@ private KeyStore buildTrustStoreFromCA() throws GeneralSecurityException, IOExce
return store;
}

@SuppressForbidden
private KeyStore getKeyStoreInstance(String type) throws KeyStoreException {
return KeyStore.getInstance(type);
}

private SSLContext createSslContext(KeyStore trustStore) throws GeneralSecurityException {
checkForTrustEntry(trustStore);
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.gradle.info;

import java.util.function.Function;

public class FipsBuildParams {

public static final String FIPS_BUILD_PARAM = "crypto.standard";

public static final String FIPS_ENV_VAR = "OPENSEARCH_CRYPTO_STANDARD";

private static String fipsMode;

public static void init(Function<String, Object> fipsValue) {
fipsMode = (String) fipsValue.apply(FIPS_BUILD_PARAM);
}

private FipsBuildParams() {}

public static boolean isInFipsMode() {
return "FIPS-140-3".equals(fipsMode);
}

public static String getFipsMode() {
return fipsMode;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public void apply(Project project) {
File rootDir = project.getRootDir();
GitInfo gitInfo = gitInfo(rootDir);

FipsBuildParams.init(project::findProperty);

BuildParams.init(params -> {
// Initialize global build parameters
boolean isInternal = GlobalBuildInfoPlugin.class.getResource("/buildSrc.marker") != null;
Expand All @@ -129,7 +131,7 @@ public void apply(Project project) {
params.setIsCi(System.getenv("JENKINS_URL") != null);
params.setIsInternal(isInternal);
params.setDefaultParallel(findDefaultParallel(project));
params.setInFipsJvm(Util.getBooleanProperty("tests.fips.enabled", false));
params.setInFipsJvm(FipsBuildParams.isInFipsMode());
params.setIsSnapshotBuild(Util.getBooleanProperty("build.snapshot", true));
if (isInternal) {
params.setBwcVersions(resolveBwcVersions(rootDir));
Expand Down Expand Up @@ -179,7 +181,11 @@ private void logGlobalBuildInfo() {
LOGGER.quiet(" JAVA_HOME : " + gradleJvm.getJavaHome());
}
LOGGER.quiet(" Random Testing Seed : " + BuildParams.getTestSeed());
LOGGER.quiet(" In FIPS 140 mode : " + BuildParams.isInFipsJvm());
if (FipsBuildParams.isInFipsMode()) {
LOGGER.quiet(" Crypto Standard : " + FipsBuildParams.getFipsMode());
} else {
LOGGER.quiet(" Crypto Standard : any-supported");
}
LOGGER.quiet("=======================================");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,13 @@ public class ForbiddenPatternsTask extends DefaultTask {
.exclude("**/*.ico")
.exclude("**/*.jar")
.exclude("**/*.zip")
.exclude("**/*.p12")
.exclude("**/*.jks")
.exclude("**/*.crt")
.exclude("**/*.der")
.exclude("**/*.pem")
.exclude("**/*.key")
.exclude("**/*.bcfks")
.exclude("**/*.keystore")
.exclude("**/*.png");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.FileTree;
import org.gradle.api.plugins.jvm.JvmTestSuite;
Expand Down Expand Up @@ -87,6 +88,7 @@ public class TestingConventionsTasks extends DefaultTask {

private final NamedDomainObjectContainer<TestingConventionRule> naming;
private final Project project;
private final ConfigurableFileCollection extraClassPath = getProject().files();

@Inject
public TestingConventionsTasks(Project project) {
Expand Down Expand Up @@ -398,7 +400,16 @@ private boolean isAnnotated(Method method, Class<?> annotation) {

@Classpath
public FileCollection getTestsClassPath() {
return Util.getJavaTestSourceSet(project).get().getRuntimeClasspath();
return Util.getJavaTestSourceSet(project).get().getRuntimeClasspath().plus(extraClassPath);
}

@Classpath
public ConfigurableFileCollection getExtraClassPath() {
return extraClassPath;
}

public void addExtraClassPath(Object... paths) {
extraClassPath.from(paths);
}

private Map<String, File> walkPathAndLoadClasses(File testRoot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.opensearch.gradle.Version;
import org.opensearch.gradle.VersionProperties;
import org.opensearch.gradle.info.BuildParams;
import org.opensearch.gradle.info.FipsBuildParams;
import org.gradle.api.Action;
import org.gradle.api.Named;
import org.gradle.api.NamedDomainObjectContainer;
Expand Down Expand Up @@ -546,17 +547,21 @@ public synchronized void start() {
logToProcessStdout("installed plugins");
}

if (FipsBuildParams.isInFipsMode() && keystorePassword.isEmpty()) {
throw new TestClustersException("Can not start " + this + " in FIPS JVM, missing keystore password");
}

logToProcessStdout("Creating opensearch keystore with password set to [" + keystorePassword + "]");
if (keystorePassword.length() > 0) {
runOpenSearchBinScriptWithInput(keystorePassword + "\n" + keystorePassword, "opensearch-keystore", "create", "-p");
runOpenSearchBinScriptWithInput(keystorePassword + "\n" + keystorePassword + "\n", "opensearch-keystore", "create", "-p");
} else {
runOpenSearchBinScript("opensearch-keystore", "-v", "create");
}

if (keystoreSettings.isEmpty() == false || keystoreFiles.isEmpty() == false) {
logToProcessStdout("Adding " + keystoreSettings.size() + " keystore settings and " + keystoreFiles.size() + " keystore files");

keystoreSettings.forEach((key, value) -> runKeystoreCommandWithPassword(keystorePassword, value.toString(), "add", "-x", key));
keystoreSettings.forEach((key, value) -> runKeystoreCommandWithPassword(keystorePassword, value.toString(), "add", key));

for (Map.Entry<String, File> entry : keystoreFiles.entrySet()) {
File file = entry.getValue();
Expand Down Expand Up @@ -738,7 +743,12 @@ private void runOpenSearchBinScriptWithInput(String input, String tool, CharSequ
}

private void runKeystoreCommandWithPassword(String keystorePassword, String input, CharSequence... args) {
final String actualInput = keystorePassword.length() > 0 ? keystorePassword + "\n" + input : input;
final String actualInput;
if (keystorePassword.length() > 0) {
actualInput = keystorePassword + "\n" + input + "\n" + input;
} else {
actualInput = input + "\n" + input;
}
runOpenSearchBinScriptWithInput(actualInput, "opensearch-keystore", args);
}

Expand Down Expand Up @@ -786,6 +796,9 @@ private Map<String, String> getOpenSearchEnvironment() {
// Override the system hostname variables for testing
defaultEnv.put("HOSTNAME", HOSTNAME_OVERRIDE);
defaultEnv.put("COMPUTERNAME", COMPUTERNAME_OVERRIDE);
if (FipsBuildParams.isInFipsMode()) {
defaultEnv.put(FipsBuildParams.FIPS_ENV_VAR, FipsBuildParams.getFipsMode());
}

Set<String> commonKeys = new HashSet<>(environment.keySet());
commonKeys.retainAll(defaultEnv.keySet());
Expand Down
Binary file removed buildSrc/src/main/resources/cacerts.bcfks
Binary file not shown.
29 changes: 0 additions & 29 deletions buildSrc/src/main/resources/fips_java_bcjsse_11.policy

This file was deleted.

34 changes: 0 additions & 34 deletions buildSrc/src/main/resources/fips_java_bcjsse_8.policy

This file was deleted.

Loading
Loading