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

[ELY-2496] Add integrity to existing filesystem realms using Elytron Tool #1896

Merged
merged 7 commits into from
May 23, 2023

Conversation

jessicarod7
Copy link
Contributor

@jessicarod7 jessicarod7 commented Apr 19, 2023

https://issues.redhat.com/browse/ELY-2496

Commits:

1. The first two commits come from ELY-2514, since the integrity command uses JDK 11 features. First JDK 11 commit removes Java 8 specific classes
2. Second JDK 11 commit replaces with Java 9 specific classes and updates POMs. (dropped from this PR)

  1. Moves reused parameters into a common class Params within Command
  2. Add hash-charset parameter and test cases to filesystem-realm-encrypt, which was missed in the original PR [ELY-2078] Add encryption support to FileSystemSecurityRealm  #1676
  3. EDIT: Updated warning messages in Command.getSecretKey() to be more consistent, and always warn (vs. sometimes crashing from an uncaught exception)
  4. Adds new filesystem-realm-integrity command, with support for upgraded encrypted realms
  5. Support upgrading realms with integrity enabled in filesystem-realm-encrypt. Also disabled upgrade of empty realms (see below)
  6. Add test cases in both commands for filesystem realms with integrity
  7. Modified to remove methods which require JDK 11 (see [ELY-2514] Update minimum JDK for all modules to 11 #1880)

Summary of changes:

  • Addition of a new command filesystem-realm-integrity to upgrade existing realms to support integrity verification. Requires an non-empty filesystem realm, and a password-protected keystore with a key pair.
  • Update filesystem-realm-encrypt command to support upgrading filesystem realms which already have integrity enabled (Note that encryption command cannot enable integrity, and vice versa)
    • Added missing option hash-charset to encryption command
  • Changes for both commands
    • Move static Elytron password/keystore providers, overrideable warning/error handlers, and methods getSecretKey and getKeyPair to Command class
    • Add new method FileSystemRealmUtil.createRealmWithIntegrityValidation() to build new realm; moved shared code between encryption and integrity commands into a private method
    • Empty filesystem realms cannot upgraded by Elytron Tool (the directory is not copied), so instead provides a warning and instructs user to update within management client (see [WFCORE-6129] Unable to add integrity support to existing filesystem realm wildfly/wildfly-core#5411)
  • Other
    • Move common parameters and strings across Elytron Tool commands (ex. HELP_PARAM, System.getProperty(“line.separator”)) to new class org.wildfly.security.tool.Command$Params

Also, I've manually imported and tested all of the test case realms with the wildfly/wildfly@784cc50 commit. All identities are readable, and the :verify-integrity CLI command works.

SecretKey key;
try {
key = credentialStore.retrieve(alias, SecretKeyCredential.class).getSecretKey();
} catch (NullPointerException e) {
Copy link
Contributor

@fjuma fjuma Apr 25, 2023

Choose a reason for hiding this comment

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

Instead of catching the NullPointerException here, it would be better to check the return value of credentialStore.retrieve prior to calling getSecretKey. If it's null, we can print the error and return null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll update this and the other section to be similar to getKeyPair. This code was unchanged from the original encrypt command, so I'm not as familiar with the functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@OndrejKotek Noting that I made some changes in response to this, in the new 5th commit

@jessicarod7 jessicarod7 force-pushed the ELY-2496 branch 2 times, most recently from bffc0c0 to 782550d Compare April 26, 2023 20:31
tool/src/main/java/org/wildfly/security/tool/Command.java Outdated Show resolved Hide resolved
public static void createEncryptedRealmFromUnencrypted(FileSystemSecurityRealm unencryptedRealm, FileSystemSecurityRealm encryptedRealm) throws RealmUnavailableException {
Assert.checkNotNullParam("unencryptedRealm", unencryptedRealm);
Assert.checkNotNullParam("encryptedRealm", encryptedRealm);
public static void cloneIdentitiesToNewRealm(FileSystemSecurityRealm oldRealm, FileSystemSecurityRealm newRealm) throws RealmUnavailableException {
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI for other reviewers, this is private API.

tool/src/main/java/org/wildfly/security/tool/Command.java Outdated Show resolved Hide resolved
tool/src/main/java/org/wildfly/security/tool/Command.java Outdated Show resolved Hide resolved
@jessicarod7 jessicarod7 force-pushed the ELY-2496 branch 2 times, most recently from 8ed421b to 42fcbee Compare May 19, 2023 13:47
@jessicarod7
Copy link
Contributor Author

Looks like a random failure due to a timeout on the Windows build. Could someone please rerun the CI?

@fjuma
Copy link
Contributor

fjuma commented May 19, 2023

Thanks, re-triggered it.

Copy link
Contributor

@Skyllarr Skyllarr left a comment

Choose a reason for hiding this comment

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

@cam-rod LGTM, thanks!

* @param warning The warning to be shown
*/
protected void warningHandler(String warning) {
System.out.print("WARNING: ");
Copy link
Contributor

Choose a reason for hiding this comment

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

@cam-rod just a minor, we can set status to GENERAL_CONFIGURATION_WARNING here

Copy link
Contributor Author

@jessicarod7 jessicarod7 May 23, 2023

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

turns out this change actually broke a number of tests in FileSystemRealmCommandTest, so I'm reverting it

if (passwordOption == null && passwordEnvOption == null) {
passwordOption = prompt(false, ElytronToolMessages.msg.keyStorePasswordPrompt(), false, null);
if (passwordOption == null) {
setStatus(GENERAL_CONFIGURATION_ERROR);
Copy link
Contributor

Choose a reason for hiding this comment

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

@cam-rod just a total minor, this line is superfluous since we configured the status to be GENERAL_CONFIGURATION_ERROR at the beginning

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in this command and encryption (where I made the same change)

@Skyllarr Skyllarr added the +1 DV label May 23, 2023
@jessicarod7 jessicarod7 force-pushed the ELY-2496 branch 2 times, most recently from c760eea to 108d334 Compare May 23, 2023 19:10
Copy link
Contributor

@fjuma fjuma left a comment

Choose a reason for hiding this comment

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

Thanks @cam-rod!

@fjuma fjuma added the +1 FJ label May 23, 2023
@fjuma
Copy link
Contributor

fjuma commented May 23, 2023

@cam-rod Just noticed, we have some CI failures now.

Due to ELY-2514, this module must be compiled for Java 8. This commit
can be reversed or reverted once this issue is fixed.
@jessicarod7
Copy link
Contributor Author

Thanks for the heads up, added some patches for the rebase.

@fjuma
Copy link
Contributor

fjuma commented May 23, 2023

Thanks @cam-rod!

@fjuma fjuma merged commit f4794df into wildfly-security:2.x May 23, 2023
@jessicarod7 jessicarod7 deleted the ELY-2496 branch May 24, 2023 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants