You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At the moment, reloading certificates can only be done from the file system, for example, by configuring the property quarkus.tls.https.trust-store.pem.certs=certs/ca_cert.pem. The certificate file must exist, if it does not exist, the application will not be able to start.
Following the documentation 7. Reloading certificates I wrote this piece of code where I used the available tlsConfiguration.getTrustStore().setCertificateEntry API to set the CA certificates coming from an external source (network endpoint, NFS Filesystem, etc.).
@ApplicationScopedpublicclassGovCertificateUpdater {
@ConfigProperty(name = "gov.trust.certs.url")
StringcertsUrl;
@InjectLoggerlog;
@InjectGovCertParsercertParser;
@InjectEvent<CertificateUpdatedEvent> certificateUpdatedEvent;
@InjectTlsConfigurationRegistrytlsConfigurationRegistry;
publicvoidreload() {
TlsConfigurationtlsConfiguration = tlsConfigurationRegistry.get("https").orElseThrow();
try {
// Path to the PEM file containing all CA certificatesStringpathGovBundlePemTrustStore = certParser.getOutputPathPemBundle() + File.separator +
certParser.getOutputPemBundleFileName();
PathcaCertsPath = Path.of(pathGovBundlePemTrustStore);
// Load the CA certificatesCertificateFactorycertFactory = CertificateFactory.getInstance("X.509");
try (varcertStream = Files.newInputStream(caCertsPath)) {
varcerts = certFactory.generateCertificates(certStream);
for (varcert : certs) {
X509CertificatecaCert = (X509Certificate) cert;
tlsConfiguration.getTrustStore()
.setCertificateEntry(caCert.getSubjectX500Principal().getName(), caCert);
log.info("Loaded CA certificate: " + caCert.getSubjectX500Principal().getName());
}
}
// Reload the TLS configuration to apply the changesif (tlsConfiguration.reload()) {
log.info("TLS configuration reloaded to apply new CA certificates");
certificateUpdatedEvent.fire(newCertificateUpdatedEvent("https", tlsConfiguration));
} else {
log.error("Failed to reload TLS configuration");
}
} catch (Exceptione) {
log.error("Failed to load additional CA certificates", e);
}
}
@Scheduled(every = "2h")
publicvoidupdateCertificates() {
// Download bundle PEM certs
....
// reload the certificates via TLS configuration to apply the changesreload();
}
}
In this way I am not forced to configure (on application.properties) the location on the file system of the certificates but I can take them dynamically from external sources.
I hope I was clear in my explanation. Please refer to the issue #43135
Implementation ideas
No response
The text was updated successfully, but these errors were encountered:
First, I don't believe keeping the certificate in memory is a good idea. It would not survive restart and would not work when there are multiple instances of the application (like in Kubernetes). The code is not working because the call to reload erases all the changes and reloads from the file system.
You cannot use the VertxCertificateHolder (implementation of the runtime TLSConfiguration to do this). However, you can implement and register your own TLSConfiguration. While application code can do it, I recommend using an extension to implement such a feature.
Basically, the extension will configure and maintain its certificates, register it in the TLS registry, and do whatever it wants for the reload.
Now, I wonder if using an empty p12 file at startup and adding the entries like you do before calling reload would work. I guess it will (I don't remember checking if a p12 file is empty if you do not set an alias). The advantage of a P12 file is that you can add and remove multiple certs.
Description
At the moment, reloading certificates can only be done from the file system, for example, by configuring the property
quarkus.tls.https.trust-store.pem.certs=certs/ca_cert.pem
. The certificate file must exist, if it does not exist, the application will not be able to start.Following the documentation 7. Reloading certificates I wrote this piece of code where I used the available
tlsConfiguration.getTrustStore().setCertificateEntry
API to set the CA certificates coming from an external source (network endpoint, NFS Filesystem, etc.).In this way I am not forced to configure (on application.properties) the location on the file system of the certificates but I can take them dynamically from external sources.
I hope I was clear in my explanation. Please refer to the issue #43135
Implementation ideas
No response
The text was updated successfully, but these errors were encountered: