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 CDI providers of key/trust stores in TLS registry #45937

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

emattheis
Copy link
Contributor

@emattheis emattheis commented Jan 29, 2025

Per discussion #41024, this PR provides a mechanism for application code to supply keystores or truststores to the TLS registry.

Copy link

quarkus-bot bot commented Jan 29, 2025

Thanks for your pull request!

Your pull request does not follow our editorial rules. Could you have a look?

  • description should not be empty, describe your intent or provide links to the issues this PR is fixing (using Fixes #NNNNN) or changelogs

This message is automatically generated by a bot.

@quarkus-bot quarkus-bot bot added the area/arc Issue related to ARC (dependency injection) label Jan 29, 2025
Copy link
Member

@cescoffier cescoffier left a comment

Choose a reason for hiding this comment

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

Very nice!

I made a few comment and I added a question for @mkouba


public interface KeyStoreProvider {

KeyStoreAndKeyCertOptions getKeyStore(Vertx vertx);
Copy link
Member

Choose a reason for hiding this comment

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

A bit of javadoc would be nice


public interface TrustStoreProvider {

TrustStoreAndTrustOptions getTrustStore(Vertx vertx);
Copy link
Member

Choose a reason for hiding this comment

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

A bit of javadoc would be nice

@cescoffier
Copy link
Member

I forgot to mention that this deserves a small section in the TLS registry documentation.

This comment has been minimized.

Copy link

🎊 PR Preview 83338cf has been successfully built and deployed to https://quarkus-pr-main-45937-preview.surge.sh/version/main/guides/

  • Images of blog posts older than 3 months are not available.
  • Newsletters older than 3 months are not available.

This comment has been minimized.

@@ -188,4 +209,29 @@ public TlsConfigurationRegistry get() {
public void register(String name, Supplier<TlsConfiguration> supplier) {
register(name, supplier.get());
}

static void addNamedConfigForForProvidersIfNecessary(Class<?> type, Map<String, TlsBucketConfig> namedConfigs) {
Copy link
Member

@michalvavrik michalvavrik Jan 30, 2025

Choose a reason for hiding this comment

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

I think this method (that is called twice) can be completely replaced with. Also this way, you can drop changes in TlsBucketConfig.

// alpn == true by default, but we need to set some property to let SR Config that we need a bucket with such name, maybe Roberto knows a better way
`new RunTimeConfigurationDefaultBuildItem("quarkus.tls.collected-identifier.alpn", "true")`

I didn't try it, I just think that's how this should work. Just tell config "I need these keys if user didn't configure them". Of course, there is even better way, I think you can use https://smallrye.io/smallrye-config/Main/config/mappings/, you collect all the identifiers during the build-time and then you create var namedConfigs = new HashMap<>(config.namedCertificateConfig()); as you already do and iterate over identifiers collected at the build-time and do config.namedCertificateConfig().get("identifier-abz") and you don't care whether it is user config or defaults, because it will always return config for your identifiers.

But then maybe, @cescoffier don't want this in config 🤷 , I don't really know what is preferable for this extension.

Copy link
Member

Choose a reason for hiding this comment

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

I mean @WithDefaults of the config mapping if it wasn't clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@michalvavrik I think I understand what you mean, but I'm a bit unclear how to proceed. It would definitely be better to simply merge the @Identifier values into the config at build time.

I think I would need a build step that can take the bean discovery and config state as input. Then I can find all the providers with annotations and collect the values. Then I need to put any missing names into the namedCertificateConfig map with default values.

If you can give me a bit more guidance, I'll be happy to do it 🙏

Copy link
Member

Choose a reason for hiding this comment

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

I can't really decide if this should be done in this extension. Nevertheless, I can give you guidance, this is just a metacode, you will need to figure details like everyone else. What I usually do is to simply look for usage of a class/method and "get inspired".

  1. in initializeCertificate inject CombinedIndexBuildItem, get Identifier annotation instances from index, filter them by annotation target where it implements KeyStoreProvider or TrustStoreProvider and collect identifier annotation instance values. I suppose you can stick to Set<String>
  2. pass it down to the io.quarkus.tls.runtime.CertificateRecorder#validateCertificates
  3. add @WithDefaults top Map<String, TlsBucketConfig> namedCertificateConfig()
  4. create your final named configs like:
Set<String> identifiers; // method param
        var namedConfigs = new HashMap<>(config.namedCertificateConfig());
        for (String identifier : identifiers) {
            if (!namedConfigs.containsKey(identifier)) {
                namedConfigs.put(identifier, config.namedCertificateConfig().get(identifier));
            }
        }

Shout if you get stuck.

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 mean @WithDefaults of the config mapping if it wasn't clear.

So if I add @WithDefaults to TlsConfig::namedCertificateConfig I should be able to get a default for any unconfigured key?

Copy link
Member

Choose a reason for hiding this comment

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

I mean @WithDefaults of the config mapping if it wasn't clear.

So if I add @WithDefaults to TlsConfig::namedCertificateConfig I should be able to get a default for any unconfigured key?

yep; I supposed unasked question is what about unavailable beans, because this would create default config for these, no idea if that is an issue, I'd rather say no...

@emattheis emattheis force-pushed the tls-config-providers branch from 46074e3 to 1f63c0a Compare January 30, 2025 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/arc Issue related to ARC (dependency injection) triage/flaky-test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants