Skip to content

Conversation

@Galsza
Copy link
Contributor

@Galsza Galsza commented Jul 14, 2024

What changes were proposed in this pull request?

It's possible to use KeyManagers and TrustManagers directly for mTLS communication instead of creating Key/TrustStoresFactory objects.

Please describe your PR in detail:
Typical usage of the Key/TrustManager before this pull request was that the PemFilesBasedKeyStoresFactory created factory methods to get instances of the key and trust managers and use those instances to establish mTLS communication. This is more complicated than it needs to be as for the mTLS only the KeyManager and the TrustManager is needed. By refactoring the CertificateClient can return these.

HDDS-11167

How was this patch tested?

This patch has no functional change, ci coverage should be enough:
https://github.com/Galsza/ozone/actions/runs/9913347327

@Galsza
Copy link
Contributor Author

Galsza commented Jul 14, 2024

@fapifta, @dombizita please take a look

Copy link
Contributor

@fapifta fapifta left a comment

Choose a reason for hiding this comment

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

Thank you for simplifying this code @Galsza, the change looks good to me, I have one suggestion that helps to avoid some casts, and a really small nuanced nitpick comment. Please take a look, I am +1 overall after these are implemented.

* Return the store factory for key manager and trust manager for server.
*/
KeyStoresFactory getServerKeyStoresFactory() throws CertificateException;
KeyManager getKeyManager() throws CertificateException;
Copy link
Contributor

Choose a reason for hiding this comment

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

If you define the return value of this method to be ReloadingX509KeyManager, then you can spare a cast in the methods implementing these and in some tests also, while that way the returned object still remains a KeyManager also, so it can be set to TLSConfig, and SSLContext and other places as is. This same is true for the getTrustManager method where you can use ReloadingX509TrustManager instead of TrustManager.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank for that, that was a great observation. Fixed it

this.type = type;
keyManagerRef = new AtomicReference<>();
keyManagerRef.set(loadKeyManager(caClient));
this.alias = componentName + "_key";
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can we move this up by one line before the instantiation of keyManagerRef?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing

Change the return type of getTrust/KeyManagers.
remove some linebreaks only needed for 80 characters/line
@Galsza
Copy link
Contributor Author

Galsza commented Jul 19, 2024

There is a related test failure on my fork, converting this to draft until I can fix it.

@Galsza Galsza marked this pull request as draft July 19, 2024 08:01
@Galsza Galsza marked this pull request as ready for review July 19, 2024 19:13
@Galsza
Copy link
Contributor Author

Galsza commented Jul 19, 2024

@fapifta please take another look when you get the chance

Copy link
Contributor

@fapifta fapifta left a comment

Choose a reason for hiding this comment

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

Thank you @Galsza for taking this on and get us to a more simple structure here. LGTM. Pending CI.

@fapifta fapifta merged commit 9ba4a73 into apache:master Jul 26, 2024
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.

2 participants