Skip to content

Support custom trust stores for https#295

Merged
RyanSkraba merged 13 commits intoAiven-Open:mainfrom
madhavvishnubhatta:f-ssl_custom_keystore_support
Oct 7, 2025
Merged

Support custom trust stores for https#295
RyanSkraba merged 13 commits intoAiven-Open:mainfrom
madhavvishnubhatta:f-ssl_custom_keystore_support

Conversation

@madhavvishnubhatta
Copy link
Copy Markdown
Contributor

@madhavvishnubhatta madhavvishnubhatta commented Oct 1, 2025

Added custom trust store support. Can you please review this?

This will fix the issue #293

I tested this with both http and https (with custom trust store) endpoints.

@madhavvishnubhatta madhavvishnubhatta requested a review from a team as a code owner October 1, 2025 10:16
@madhavvishnubhatta madhavvishnubhatta marked this pull request as draft October 1, 2025 10:19
@madhavvishnubhatta madhavvishnubhatta marked this pull request as ready for review October 1, 2025 10:28
@madhavvishnubhatta
Copy link
Copy Markdown
Contributor Author

@muralibasani Just a follow-up to see if you have any other feedback on the pull request.

@muralibasani
Copy link
Copy Markdown

@muralibasani Just a follow-up to see if you have any other feedback on the pull request.

@madhavvishnubhatta ok from me, but pinged other team members for a 2nd review.

Copy link
Copy Markdown

@Claudenw Claudenw left a comment

Choose a reason for hiding this comment

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

Please try with NO_DEFAULT values. It should work as expected. Otherwise I will approve this as it stands.

return null;
}
try {
final KeyStore trustStore = KeyStore.getInstance("JKS");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Would it be a good idea to also add a config for the keystore type?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, but jks meets my need. I can think of adding other types later if I have the time, but it would be good to not hold this off until other support is available. Let me know what you think. if you agree, I can update teh documentation to make it clear that only JKS is supported for now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it's probably fine to not add the keystore type immediately -- IIUC, adding the truststore here is just a mechanism to create an allow list of acceptable HTTPS servers (not to verify that the client is acceptable). This is by far the most frequent usage (e.g., when my browser contacts https://github.com, the server never checks who I am).

Copy link
Copy Markdown
Contributor Author

@madhavvishnubhatta madhavvishnubhatta Oct 3, 2025

Choose a reason for hiding this comment

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

Correct. This is only for the client to validate the server. This is not a mechanism for the server to check who is connecting. But makes me think if mTLS might be a future feature request. Anyway, that is out of scope for this PR.

@RyanSkraba RyanSkraba changed the title F ssl custom keystore support Support custom trust stores for https Oct 3, 2025
@RyanSkraba
Copy link
Copy Markdown
Contributor

Hello! I'm going through this and it looks pretty good so far! Thanks.

I'm assuming the use case is that you have a self-signed HTTPS server, or with a private certificate authority, and you want to avoid http.ssl.trust.all.certs in production? This seems like the right way to go.

I guess technically trusting all certs is dubious 🤔 but since the end user is the only one telling the connector where to connect, it's already a pretty explicit "allow list". Is there another use for adding the trust store? It might be worthwhile documenting in the PR!

Copy link
Copy Markdown
Contributor

@RyanSkraba RyanSkraba left a comment

Choose a reason for hiding this comment

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

Hey, this looks good -- do you think it would be possible to generate the truststore.jks programmatically instead of checking in the binary?

If it's possible, it's probably more future proof.

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

final class TruststoreLoader {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
final class TruststoreLoader {
final class TrustStoreLoader {

Haha, the canonical spelling of TrustStore has an internal capital S. It's definitely NOT that important but it's definitely worth getting it right at the start (as someone who has fussed with APIs and documentation around Elasticsearch and OpenSearch).

return getBoolean(HTTP_SSL_TRUST_ALL_CERTIFICATES);
}

public final String sslTruststoreLocation() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
public final String sslTruststoreLocation() {
public final String sslTrustStoreLocation() {

Haha, the Java spelling of TrustStore has an internal capital S.

It's a nit-pick, but I've spent too much time chasing down Elasticsearch vs. OpenSearch inconsistencies 😆 I only care about the public methods and classnames though!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Absolutely. As a pedant myself 😄 , I shouldn't have missed it. And will definitely fix it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed this in the latest commit.


final var config = new HttpSinkConfig(properties);
assertThat(config.sslTruststoreLocation()).isEqualTo("/path/to/truststore.jks");
assertThat(config.sslTruststorePassword()).isEqualTo("password123");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If I understand correctly (especially for TrustStores), the password is only used to check integrity.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct. Password for the trust stores is only for integrity.

@madhavvishnubhatta
Copy link
Copy Markdown
Contributor Author

Hello! I'm going through this and it looks pretty good so far! Thanks.

I'm assuming the use case is that you have a self-signed HTTPS server, or with a private certificate authority, and you want to avoid http.ssl.trust.all.certs in production? This seems like the right way to go.

I guess technically trusting all certs is dubious 🤔 but since the end user is the only one telling the connector where to connect, it's already a pretty explicit "allow list". Is there another use for adding the trust store? It might be worthwhile documenting in the PR!

Your assumption about the usecase is correct.

To your question about whether telling the connector where to connect is already an explicit allow list, and why there is a need for more security, I dont think that is valid. The trust store ensures that the https endpoint being reached is not compromised by some bad actors (or due to some DNS trickery). This is especially true when the https endpoint is managed/controlled by someone external to the org that is running the connector. Let me know if that makes sense.

… done. Also changed 'Truststore' to 'TrustStore' (note the 'S' in caps)
@madhavvishnubhatta
Copy link
Copy Markdown
Contributor Author

I have answered all questions asked so far and also made the suggested changes. Please take a look and let me know if you have more feedback.

Claudenw
Claudenw previously approved these changes Oct 6, 2025
@RyanSkraba
Copy link
Copy Markdown
Contributor

Oh my, this is amazing -- I was just going to log in and say not to bother doing the generated truststore exercise, because it was too difficult 😆 Really nice work, I appreciate you taking the time to educate us on your use cases. I'll merge this as soon as the CI passes!

RyanSkraba
RyanSkraba previously approved these changes Oct 6, 2025
@RyanSkraba
Copy link
Copy Markdown
Contributor

Ooops, looks like it's missing a dependency for the trust store generation! I still think it's a good idea (to not check in a truststore binary), but if you just want to revert that chunk of code, we can make an issue to future-proof that part later! Up to you -- I'm happy with the tests, and the non-test code looks just right!

@madhavvishnubhatta madhavvishnubhatta dismissed stale reviews from RyanSkraba and Claudenw via 0d21144 October 6, 2025 12:03
@madhavvishnubhatta
Copy link
Copy Markdown
Contributor Author

madhavvishnubhatta commented Oct 6, 2025

Ooops, looks like it's missing a dependency for the trust store generation! I still think it's a good idea (to not check in a truststore binary), but if you just want to revert that chunk of code, we can make an issue to future-proof that part later! Up to you -- I'm happy with the tests, and the non-test code looks just right!

I have pushed in another commit with the dependencies. Let me check if the CI passes now.

@madhavvishnubhatta
Copy link
Copy Markdown
Contributor Author

Oh my, this is amazing -- I was just going to log in and say not to bother doing the generated truststore exercise, because it was too difficult 😆 Really nice work, I appreciate you taking the time to educate us on your use cases. I'll merge this as soon as the CI passes!

Just to be transparent, I used Amazon Q Developer to help 🙂

@madhavvishnubhatta
Copy link
Copy Markdown
Contributor Author

Can someone approve this workflow so that I can debug failures (if any)?

@RyanSkraba RyanSkraba merged commit 7247fdf into Aiven-Open:main Oct 7, 2025
6 checks passed
@RyanSkraba
Copy link
Copy Markdown
Contributor

LGTM, thanks again!

@madhavvishnubhatta
Copy link
Copy Markdown
Contributor Author

@RyanSkraba What is the release policy? Any idea when the next release will be, of which this will be a part?

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.

5 participants