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

Support for FIPS compliance mode #14912

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

beanuwave
Copy link

Description

  • FIPS gradle build script is removed.
  • All BC dependencies are replaces by BCFIPS.
  • Password matcher inside Identity-Shiro that replies on BC to check if hashed passwords matches with OpenBSDBCrypt, is replaced by password4j implementation.
  • Adds support for BCFKS format (*.bks) for Key & Truststores.
  • Refactor parsing private keys with formats EC, PKCS8, PKCS1, DSA, w/wo encryption, w/wo parameters.
  • FIPS approved-only mode can be configured over opensearch.yml file.
  • java security file is added to the build.
  • java policy file is altered to grant neccessary security permissions.

This PR provides FIPS 140-2 support by replacing all BC dependencies with BCFIPS dependencies and making FIPS approved-only mode configurable at launch. Running application in approved-only mode restricts BCFIPS provoder to rely solely on FIPS certified cyphers. Due to replacement of BC libraries, BCrypt password matching and private-key loading from file were replaced by alternative implementations.

Reasons for refactoring PemUtils.java that is used by Reindex API, in case of migrating data from a remote cluster that is TLS protected:

  • PKCS#8 implementation was not supported by BCFIPS library.
  • java type security.
  • Password Based Key Derivation Functions such as PKCS#12 and OpenSSL are not supported in BCFIPS approved-only mode, because only PBKDF2 standard is approved for use in FIPS.
  • generally good idea to let ASN1 annotation parsing be done by external security libraries.

Related Issues

opensearch-project/security#3420

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link
Contributor

❌ Gradle check result for 6016d5d: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@beanuwave beanuwave changed the title Draft to allow run in FIPS compliace mode Draft to allow run in FIPS compliance mode Jul 24, 2024
Copy link
Contributor

❌ Gradle check result for 8e8ed47: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

❌ Gradle check result for 6016d5d: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use case of the identity-shiro plugin inside OpenSearch? Is it used as an alternative to the security plugin for authentication or does it have a different use?

As far as I understand we will need to add support for PBKDF2 to this plugin as BCrypt itself is not FIPS validated.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is also mine understanding what identity-shiro plugin/adapter is used for. As we do not really rely on BCrypt algo implementation here, it can be replaced by PBKDF2WithHmacSHA256 or similar.
Sidenote: most of the code is just copy&paste from OS security module, as it has password4j BCrypt hashing and matching for password, related to FIPS compliance.

Copy link
Member

@cwperks cwperks Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dancristiancecoi IMO identity-shiro should be placed sanbox/plugins or sandbox/modules. Its an example implementation of an experimental IdentityPlugin.

Relevant issue: #5834

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification @cwperks !!

@dblock
Copy link
Member

dblock commented Jul 24, 2024

Could use some help maybe from @cwperks or @peternied reviewing this, please.

@@ -1182,6 +1182,7 @@ private void createConfiguration() {
baseConfig.put("indices.breaker.total.use_real_memory", "false");
// Don't wait for state, just start up quickly. This will also allow new and old nodes in the BWC case to become the master
baseConfig.put("discovery.initial_state_timeout", "0s");
baseConfig.put("fips.approved", "true");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we proposed a similar flag previously we were encouraged not to use boolean flags to control behaviour like this opensearch-project/security#3420 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am of the opinion that this is fine, in this case, I am not sure what greater configuration would make sense. Unless you can provide different approvers or something, there is no reason for this not to be a boolean.

@peternied peternied marked this pull request as draft July 25, 2024 12:31
@peternied peternied changed the title Draft to allow run in FIPS compliance mode Support for FIPS compliance mode Jul 25, 2024
@peternied
Copy link
Member

@beanuwave I've marked this pull request as 'draft' in GitHub, feel free to keep iterating and let us know if there is anything you'd like attention on. I'll keep and eye out, but I'll give it a more detailed look when you've marked this change as Ready for review.

@terryquigleysas
Copy link

@beanuwave @terryquigleysas Thinking about backwards compatibility, would there be an opportunity to pass a flag at build-time to create a distribution that is FIPS-compliant? Would it make sense to have multiple distributions? 1 with bouncycastle (BC) included and 1 without BC?

Looking at the companion PR in the security plugin, I was wondering if it made sense to add logic to check if the BouncyCastleProvider class was on the classpath. If it is on the classpath then can it add the bouncycastle provider? I've written some similar code before in netty: https://github.com/netty/netty/blob/4.1/handler/src/main/java/io/netty/handler/ssl/BouncyCastlePemReader.java#L72-L94

Similar to the provider, is it possible to have different plugin-security.policy files depending on whether bouncycastle is provided or not?

I have replied at opensearch-project/security#4588 (comment)

Copy link
Contributor

github-actions bot commented Aug 7, 2024

❌ Gradle check result for 84e7aa9: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@beanuwave
Copy link
Author

All tests are now successfully running without requiring the BC libraries, by leveraging only the SUN and BCFIPS providers. This demonstrates that including BC libraries in the build process is not essential. The next step is to identify which code cannot operate under FIPS approved-only mode and address these limitations. Notably, the following components have constraints under FIPS compliance (as detailed here):

  • Azure Classic Discovery Plugin: Utilizes JKS keystore for certificates.
  • Ingest Attachment Plugin.
  • KeyStoreWrapper: Handles both v1 and v2 of the internal keystore.
  • General usage of PKCS#12 and PBE standards.
  • SQL CLI Plugin.

Plugin support remains an uncertain area. However, as long as plugins do not interfere with the SecurityManager and permissions, there should be minimal concern.

Copy link
Contributor

github-actions bot commented Aug 8, 2024

❌ Gradle check result for 219e9dc: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@dancristiancecoi
Copy link

Plugin support remains an uncertain area. However, as long as plugins do not interfere with the SecurityManager and permissions, there should be minimal concern.

There can be instances when other plugins interfere with the SecurityManager and permissions as described in this comment.

Copy link
Contributor

github-actions bot commented Aug 8, 2024

❌ Gradle check result for dc753b0: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

github-actions bot commented Aug 8, 2024

❌ Gradle check result for fd825eb: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

github-actions bot commented Aug 8, 2024

❌ Gradle check result for 9bb1591: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

github-actions bot commented Aug 9, 2024

❕ Gradle check result for 5ab8df8: UNSTABLE

Please review all flaky tests that succeeded after retry and create an issue if one does not already exist to track the flaky failure.

Copy link

codecov bot commented Aug 9, 2024

Codecov Report

Attention: Patch coverage is 69.23077% with 24 lines in your changes missing coverage. Please review.

Project coverage is 71.89%. Comparing base (97c1bf0) to head (5ab8df8).
Report is 11 commits behind head on main.

Files Patch % Lines
.../main/java/org/opensearch/bootstrap/Bootstrap.java 0.00% 7 Missing ⚠️
...ch/identity/shiro/realm/BCryptPasswordMatcher.java 54.54% 2 Missing and 3 partials ⚠️
...g/opensearch/tools/launchers/SystemJvmOptions.java 0.00% 3 Missing ⚠️
...rg/opensearch/gradle/OpenSearchTestBasePlugin.java 0.00% 2 Missing ⚠️
...n/java/org/opensearch/common/ssl/KeyStoreUtil.java 0.00% 1 Missing and 1 partial ⚠️
...va/org/opensearch/common/ssl/SslConfiguration.java 33.33% 1 Missing and 1 partial ⚠️
...g/opensearch/tools/launchers/JvmOptionsParser.java 0.00% 1 Missing ⚠️
...n/java/org/opensearch/common/ssl/PemKeyConfig.java 80.00% 1 Missing ⚠️
...a/org/opensearch/common/settings/FipsSettings.java 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #14912      +/-   ##
============================================
+ Coverage     71.74%   71.89%   +0.14%     
+ Complexity    62904    62900       -4     
============================================
  Files          5178     5179       +1     
  Lines        295167   294957     -210     
  Branches      42679    42636      -43     
============================================
+ Hits         211774   212063     +289     
+ Misses        66011    65472     -539     
- Partials      17382    17422      +40     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

❌ Gradle check result for 8e5237f: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Signed-off-by: Iwan Igonin <[email protected]>

# Conflicts:
#	server/build.gradle
Signed-off-by: Iwan Igonin <[email protected]>

# Conflicts:
#	client/rest/build.gradle
#	distribution/tools/plugin-cli/build.gradle
#	server/src/main/resources/org/opensearch/bootstrap/test-framework.policy
Signed-off-by: Iwan Igonin <[email protected]>
Copy link
Contributor

❌ Gradle check result for 7e202a2: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants