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

feat(fips): Use nop keystore implementation #279

Closed

Conversation

michel-laterman
Copy link
Contributor

@michel-laterman michel-laterman commented Feb 12, 2025

What does this PR do?

Keystore.Factory and other constuctor functions will return a NopKeystore if the requirefips build tag is set. The NopKeystore will will return ErrKeyDoesntExists for any retrievals, and ErrKeystoreUnsupported for create/save/store operations. The NopKeystore uses the same existing constructor name as the regular file keystore so it can be used in-place by callers.

Minor refactoring to move unchanged constructors, and the Factory method to keystore.go, renamed file_keystore.go to file_keystore_nofips.go to give an addition indicator to developers.

Why is it important?

Current keystore implementation is not FIPS compliant.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works

Keystore.Factory and other constuctor functions will return a
NopKeystore if the requirefips build tag is set. The NopKeystore will
will return ErrNotWritable for any retrievals, and
ErrKeystoreUnsupported for create/save/store operations. The NopKeystore
uses the same existing constructor name as the regular file keystore so
it can be used in-place by callers.
@michel-laterman michel-laterman added enhancement New feature or request Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team labels Feb 12, 2025
@michel-laterman michel-laterman requested a review from a team as a code owner February 12, 2025 22:18
@michel-laterman michel-laterman requested review from rdner and mauri870 and removed request for a team February 12, 2025 22:18
@@ -37,8 +39,24 @@ var (

// ErrNotWritable is returned when the keystore is not writable
ErrNotListing = errors.New("the configured keystore is not listing")

// ErrKeystoreDisabled is returned on create, save, and store operations if built with the requirefips flag
ErrKeystoreDisabled = fmt.Errorf("keystore disabled in FIPS mode: %w", errors.ErrUnsupported)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could also use ErrNotWritable in place of this error

@jlind23 jlind23 requested review from a team, michalpristas, pkoutsovasilis and pchila and removed request for a team, rdner, mauri870 and michalpristas February 17, 2025 14:31
Copy link
Member

@mauri870 mauri870 left a comment

Choose a reason for hiding this comment

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

Tentatively approved. Please wait for at least one more review before merging.

@michel-laterman
Copy link
Contributor Author

Tests will only succeed once #281 is merged

Copy link

@pkoutsovasilis pkoutsovasilis left a comment

Choose a reason for hiding this comment

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

@michel-laterman please tell me if I am missing something, but as far as I can tell, the current keystore implementation should be FIPS compliant:

  • pbkdf2 with SHA512 is approved
  • AES with GCM is approved

I can see all the crypto related calls that we use in the code here.

With all that said, is the keystore implementation not FIPS compliant? 🤔

Copy link

@pkoutsovasilis pkoutsovasilis left a comment

Choose a reason for hiding this comment

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

@michel-laterman can this unit-test failure happen because FIPS enabled code is not decrypting correctly the blocks of both PKCS1 and PKCS8 keys? 🤔

@michel-laterman
Copy link
Contributor Author

The TLS tests have been restricted for now, #281 fixes the issues with tests.
Once I have a second approval, and #281 has been merged I'll merge this PR

Copy link

@pkoutsovasilis pkoutsovasilis left a comment

Choose a reason for hiding this comment

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

I would love this change to be as simple as returning always an error from NewFileKeystoreWithPasswordAndStrictPerms when it is compiled for FIPS. However I understand that due to external dependencies that do not handle appropriately an error there an alternative approach, such as the one of this PR is needed. Thus LGTM

Copy link
Contributor

@simitt simitt left a comment

Choose a reason for hiding this comment

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

@michel-laterman instead of implementing a noop keystore, have you thought of removing the command from the fips compliant binaries?
Something similar to what was done for the APM Server elastic/apm-server#15545?

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

Copy link
Member

@kruskall kruskall left a comment

Choose a reason for hiding this comment

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

I don't think we should add a noop keystore. The implementation itself is ok, the issue is that we're passing an empty password.
Downstream clients should not create a keystore with an empty password in fips mode (e.g. by disabling the keystore)

EDIT: sorry, I missed @simitt comment above, fully agree with what was said about leaving the keystore impl (it would return an error anyway with an empty password in fips mode).

@michel-laterman
Copy link
Contributor Author

I have an alternate approach (as @kruskall suggested) that needs reviews: elastic/beats#42846

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants