Skip to content

[release-v1.16] SRVKE-1720: Setup and initialize HTTPS server correctly when TLS config gets updated #1784

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public class ReceiverVerticle extends AbstractVerticle implements Handler<HttpSe

private final IngressRequestHandler ingressRequestHandler;
private final ReceiverEnv env;
private int oidcDiscoveryCallbackId;

private AuthHandler authHandler;
private final Handler<HttpServerRequest> handler;
private HttpServer httpServer;
private HttpServer httpsServer;
private MessageConsumer<Object> messageConsumer;
Expand Down Expand Up @@ -124,6 +124,9 @@ public ReceiverVerticle(

this.authVerifier = new AuthVerifierImpl(oidcDiscoveryConfigListener);
this.authHandler = new AuthHandler(this.authVerifier);

this.handler = new ProbeHandler(
env.getLivenessProbePath(), env.getReadinessProbePath(), new MethodNotAllowedHandler(this));
}

public HttpServerOptions getHttpsServerOptions() {
Expand Down Expand Up @@ -155,9 +158,6 @@ public void start(final Promise<Void> startPromise) {

authVerifier.start(vertx);

final var handler = new ProbeHandler(
env.getLivenessProbePath(), env.getReadinessProbePath(), new MethodNotAllowedHandler(this));

if (this.httpsServer != null) {
CompositeFuture.all(
this.httpServer
Expand Down Expand Up @@ -252,15 +252,31 @@ public void updateServerConfig() {
.setCertValue(Buffer.buffer(java.nio.file.Files.readString(this.tlsCrtFile.toPath())))
.setKeyValue(Buffer.buffer(java.nio.file.Files.readString(this.tlsKeyFile.toPath())));

httpsServer
.updateSSLOptions(new SSLOptions().setKeyCertOptions(keyCertOptions))
.onSuccess(v -> logger.info("Succeeded to update TLS key pair"))
.onFailure(
e -> logger.error("Failed to update TLS key pair while executing updateSSLOptions", e));

if (httpsServer == null) {
// receiver was started without an initialized HTTPS server --> initialize and start it now
httpsServerOptions.setSsl(true).setPemKeyCertOptions(keyCertOptions);
httpsServer = vertx.createHttpServer(httpsServerOptions);

this.httpsServer
.requestHandler(handler)
.exceptionHandler(e -> logger.error("Socket error in HTTPS server", e))
.listen(this.httpsServerOptions.getPort(), this.httpsServerOptions.getHost());
} else {
httpsServer
.updateSSLOptions(new SSLOptions().setKeyCertOptions(keyCertOptions))
.onSuccess(v -> logger.info("Succeeded to update TLS key pair"))
.onFailure(e ->
logger.error("Failed to update TLS key pair while executing updateSSLOptions", e));
}
} catch (IOException e) {
logger.error("Failed to read file {}", tlsCrtFile.toPath(), e);
}
} else {
if (httpsServer != null) {
// We had a running HTTPS server before and TLS files were removed now --> shutdown HTTPS server again
httpsServer.close();
httpsServer = null;
}
}
}
}