8000 Added support for reloadable ssl configuration by Hakky54 · Pull Request #54327 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Added support for reloadable ssl configuration - #54327

Closed
Hakky54 wants to merge 3 commits into
keycloak:mainfrom
Hakky54:main
Closed

Hakky54 wants to merge 3 commits into
keycloak:mainfrom
Hakky54:main

Conversation

@Hakky54
@Hakky54 Hakky54 commented Oct 25, 2026 •
Copy link
Copy Markdown

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.

Signed-off-by: Hakan Altindag <hakangoudberg@hotmail.com>
Signed-off-by: Hakan Altindag <hakangoudberg@hotmail.com>
Signed-off-by: Hakan Altindag <hakangoudberg@hotmail.com>
@Hakky54
Hakky54 requested review from a team as code owners October 25, 2026 20:38
Copilot AI balanced review requested due to automatic review settings October 25, 2026 20:38
Copilot AI left a comment
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.

🟡 Changes recommended

An undefined constant blocks compilation, and TLS initialization and truststore reload defects remain unresolved.

6 open issues
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);
Comment on lines +241 to +243
FileTruststoreProviderFactory factory = (FileTruststoreProviderFactory) session.getKeycloakSessionFactory().getProviderFactory(TruststoreProvider.class);
factory.reInit();
return factory.create(session).getTruststore();
Comment on lines +107 to +123
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);
@vmuzikar vmuzikar left a comment
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.

@Hakky54 Thank you for the contribution!

Comment thread quarkus/runtime/pom.xml
</dependency>
<dependency>
<groupId>io.github.hakky54</groupId>
<artifactId>ayza</artifactId>
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.

Instead of introducing arbitrary libraries, we should leverage the Quarkus TLS Registry.

@Hakky54 Hakky54 Oct 26, 2026 •
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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

@vmuzikar
Copy link
Copy Markdown
Contributor

Related: #52520
CC @michalvavrik

@michalvavrik
Copy link
Copy Markdown
Member

Related: #52520 CC @michalvavrik

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

@michalvavrik
michalvavrik commented Oct 26, 2026 •
Copy link
Copy Markdown
Member

it also came first (my PR)

@Hakky54
Hakky54 commented Oct 26, 2026
Copy link
Copy Markdown
Author

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

This is more a WIP to gather early feedback. I have not worked yet on the test to be honest

@vmuzikar
Copy link
Copy Markdown
Contributor

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

Good point, thanks.

I'm closing this PR then as we have #52520 already open for it.

@vmuzikar vmuzikar closed this Oct 27, 2026
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.

4 participants

0