Repository navigation
Conversation
Signed-off-by: Hakan Altindag <hakangoudberg@hotmail.com>
Signed-off-by: Hakan Altindag <hakangoudberg@hotmail.com>
Signed-off-by: Hakan Altindag <hakangoudberg@hotmail.com>
There was a problem hiding this comment.
🟡 Changes recommended
An undefined constant blocks compilation, and TLS initialization and truststore reload defects remain unresolved.
6 open issues
Use the correct SSL reload-period constant · New Check disabled provider before installing trust supplier · New Preserve separate client key-password handling · New Avoid casting custom truststore providers to file providers · New Atomically validate TLS managers before replacement · New Rebuild truststore from original certificate sources · New
What changed in this PR
This PR begins implementing certificate hot reload for #26524, adding reloadable TLS material to Keycloak’s outbound HTTP clients. Server-side support remains outside this work-in-progress change.
Changes:
- Adds Ayza-backed, swappable key and trust managers with scheduled reloads.
- Integrates reloading into the default and Vert.x HTTP clients, using a configurable 12-hour default interval.
- Adds truststore reinitialization support and dependency declarations.
| File | Description |
|---|---|
| services/src/main/java/org/keycloak/truststore/FileTruststoreProviderFactory.java | Retains configuration for truststore reinitialization. |
| services/src/main/java/org/keycloak/tls/SslReloadService.java | Loads, swaps, and schedules TLS material updates. |
| services/src/main/java/org/keycloak/tls/CertificateReloadScheduler.java | Parses reload intervals and runs periodic tasks. |
| services/src/main/java/org/keycloak/connections/httpclient/DefaultHttpClientFactory.java | Integrates reloadable TLS and interval configuration. |
| services/pom.xml | Adds the Ayza dependency. |
| server-spi-private/src/main/java/org/keycloak/truststore/TruststoreProviderFactory.java | Adds a truststore reinitialization method. |
| quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/httpclient/VertxHttpClientFactory.java | Integrates reloadable key and trust managers. |
| quarkus/runtime/pom.xml | Adds the Ayza runtime dependency. |
| pom.xml | Manages the Ayza dependency version. |
Review effort: Balanced
| } catch (Exception e) { | ||
| throw new RuntimeException("Failed to serialize keystore", e); | ||
| } | ||
| String reloadPeriodValue = config.get(DefaultHttpClientFactory.CLIENT_SSL_RELOAD_PERIOD, DefaultHttpClientFactory.DEFAULT_CLIENT_KEYSTORE_RELOAD_PERIOD); |
| } | ||
| return providerFactory.create(session).getTruststore(); | ||
| }; | ||
| sslReloadService.setTrustMaterial(truststoreSupplier); |
| try { | ||
| KeyStore ks = KeystoreUtil.loadKeyStore(clientKeystore, clientKeystorePassword); | ||
| options.setKeyCertOptions(keystoreToOptions(ks, config.get("client-key-password", clientKeystorePassword))); | ||
| sslReloadService.setIdentityMaterial(clientKeystore, clientKeystorePassword, clientKeystorePassword); |
| FileTruststoreProviderFactory factory = (FileTruststoreProviderFactory) session.getKeycloakSessionFactory().getProviderFactory(TruststoreProvider.class); | ||
| factory.reInit(); | ||
| return factory.create(session).getTruststore(); |
| if (baseKeyManager != null) { | ||
| KeyStore keyStore; | ||
| try { | ||
| keyStore = KeystoreUtil.loadKeyStore(keyStorePath, keyStorePassword); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException("Failed to load key store " + keyStorePath, e); | ||
| } | ||
|
|
||
| X509ExtendedKeyManager newKeyManager = KeyManagerUtils.createKeyManager(keyStore, keyPassword != null ? keyPassword.toCharArray() : null); | ||
| KeyManagerUtils.swapKeyManager(baseKeyManager, newKeyManager); | ||
| } | ||
|
|
||
| if (baseTrustManager != null) { | ||
| KeyStore trustStore = truststoreSupplier.get(); | ||
| X509ExtendedTrustManager newTrustManager = TrustManagerUtils.createTrustManager(trustStore); | ||
| TrustManagerUtils.swapTrustManager(baseTrustManager, newTrustManager); | ||
| } |
|
|
||
| @Override | ||
| public void reInit() { | ||
| init(config); |
| </dependency> | ||
| <dependency> | ||
| <groupId>io.github.hakky54</groupId> | ||
| <artifactId>ayza</artifactId> |
There was a problem hiding this comment.
Instead of introducing arbitrary libraries, we should leverage the Quarkus TLS Registry.
There was a problem hiding this comment.
Good catch. I added indeed the ayza library and the main reason is that it provides flexible tls configuration. The quarkus tls registry is powerfull and provides by default ssl reloading for the default configuration. However, as far as I noticed in the source code of the client side the ssl configuration in keycloak is already custom as it is being configured programatically as shown here: https://github.com/keycloak/keycloak/pull/54327/changes#diff-4ea37268beba58c59898db2471806ff05624476d6ef95396357d2e8f4844a54b
In that referenced file different paths are being considered while building the ssl configuration for example trust all option, or configure trustoptions only if it is present and the same goes for the keyoptions. It made sense to extend on that config and therefor I added the ayza library. Next to that, I need to admit, that I am the maintainer of the Ayza library. It provides reloadable ssl configuration and that made it also more convenient to use. But if you don't prefer it, thats ok then I can remove it. Feel free to share your thoughts.
Next to that I also noticed that there was the following PR: #52520 based on the tls registry. This pull request should achieve the same with less and more maintainable code. However I only worked on the client side, the server side still needs to be done. This is more a WIP PR to gather early feedback
|
Related: #52520 |
it is not only related, my PR implements the same thing, using the TLS registry and also takes cares of the integrations relying on the truststore as well as providing better test coverage |
|
it also came first (my PR) |
This is more a WIP to gather early feedback. I have not worked yet on the test to be honest |
Good point, thanks. I'm closing this PR then as we have #52520 already open for it. |


This is an implementation for the following feature request: #26524
The community seeks for a solution to reload the ssl configuration of the client and the server. I added an implementation to the existing default http client to reload the ssl configuration by default every 12 hours. This pull request is still a WIP as the server implementation needs to be added. I opened the pull request to get early feedback. Please share your thoughts or idea's.
The ssl hot reloading logic depends on the Ayza library. It has these specialised keymanager/trustmanager already available in the library itself. So no need to reimplement. The existing key and trust options just needs to be wrapped in a specialised keymanager/trustmanager. Next to that it needs to be configured when to reload and what properties to use for reloading. Please have a look at the implementation.
In the coming days/weeks I will include a working version for the server as well. It is a bit more complicate compared to the client, but hopefully I can provide something soon.