-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41501 from cescoffier/tls-reload-certs
Cert-Manager support and TLS periodic reload
- Loading branch information
Showing
13 changed files
with
710 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
extensions/tls-registry/runtime/src/main/java/io/quarkus/tls/CertificateUpdatedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.quarkus.tls; | ||
|
||
/** | ||
* Event fired when a certificate is updated. | ||
* <p> | ||
* IMPORTANT: Consumers of this event should be aware that the event is fired from a blocking context (worker thread), | ||
* and thus can perform blocking operations. | ||
* | ||
* @param name the name of the certificate (as configured in the configuration, {@code <default>} for the default certificate) | ||
* @param tlsConfiguration the updated TLS configuration - the certificate has already been updated | ||
*/ | ||
public record CertificateUpdatedEvent(String name, TlsConfiguration tlsConfiguration) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...ions/tls-registry/runtime/src/main/java/io/quarkus/tls/runtime/TlsCertificateUpdater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.quarkus.tls.runtime; | ||
|
||
import java.time.Duration; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
|
||
import jakarta.enterprise.event.Event; | ||
import jakarta.enterprise.inject.spi.CDI; | ||
|
||
import io.quarkus.tls.CertificateUpdatedEvent; | ||
import io.quarkus.tls.TlsConfiguration; | ||
import io.vertx.core.Handler; | ||
import io.vertx.core.Vertx; | ||
|
||
/** | ||
* A helper class that reload the TLS certificates at a configured interval. | ||
* When the certificate is reloaded, a {@link CertificateUpdatedEvent} is fired. | ||
*/ | ||
public class TlsCertificateUpdater { | ||
|
||
private final Vertx vertx; | ||
private final CopyOnWriteArrayList<Long> tasks; | ||
private final Event<CertificateUpdatedEvent> event; | ||
|
||
public TlsCertificateUpdater(Vertx vertx) { | ||
this.vertx = vertx; | ||
this.tasks = new CopyOnWriteArrayList<>(); | ||
this.event = CDI.current().getBeanManager().getEvent().select(CertificateUpdatedEvent.class); | ||
} | ||
|
||
public void close() { | ||
for (Long task : tasks) { | ||
vertx.cancelTimer(task); | ||
} | ||
tasks.clear(); | ||
} | ||
|
||
public void add(String name, TlsConfiguration tlsConfiguration, Duration period) { | ||
var id = vertx.setPeriodic(period.toMillis(), new Handler<Long>() { | ||
@Override | ||
public void handle(Long id) { | ||
vertx.executeBlocking(new Callable<Void>() { | ||
@Override | ||
public Void call() { | ||
// Reload is most probably a blocking operation as it needs to reload the certificate from the | ||
// file system. Thus, it is executed in a blocking context. | ||
// Then we fire the event. This is also potentially blocking, as the consumer are invoked on the | ||
// same thread. | ||
if (tlsConfiguration.reload()) { | ||
event.fire(new CertificateUpdatedEvent(name, tlsConfiguration)); | ||
} | ||
return null; | ||
} | ||
}, false); | ||
} | ||
}); | ||
|
||
tasks.add(id); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.