Skip to content
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

[DEBUG, DON'T MERGE] OpenShift certificate serving #1990

Closed
Show file tree
Hide file tree
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
@@ -1,10 +1,14 @@
package hero;

import jakarta.enterprise.event.Observes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;

import org.eclipse.microprofile.rest.client.inject.RestClient;

import io.quarkus.runtime.StartupEvent;
import io.quarkus.tls.TlsConfigurationRegistry;

@Path("hero-client-resource")
public class HeroClientResource {

Expand All @@ -16,4 +20,17 @@ public Hero triggerClientToServerCommunication() {
return heroClient.getRandomHero();
}

void observer(@Observes StartupEvent ev, TlsConfigurationRegistry registry) {
try {
var ts = registry.get("hero-client").get().getTrustStore();
if (ts == null) {
System.out.println("ts is null...");
}
ts.aliases().asIterator().forEachRemaining(alias -> {
System.out.println("hero client alias is " + alias);
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
18 changes: 18 additions & 0 deletions http/rest-client-reactive/src/test/java/hero/HeroResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import java.util.random.RandomGenerator;

import jakarta.enterprise.event.Observes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;

import io.quarkus.runtime.StartupEvent;
import io.quarkus.tls.TlsConfigurationRegistry;

@Path("/api/heroes/random")
public class HeroResource {

Expand All @@ -14,4 +18,18 @@ public Hero getRandomHero() {
return new Hero(random, "Name-" + random, "Other-" + random, 1, "placeholder", "root");
}

void observer(@Observes StartupEvent ev, TlsConfigurationRegistry registry) {
try {
var ks = registry.get("cert-serving-test-server").get().getKeyStore();
if (ks == null) {
System.out.println("ks is null .............");
return;
}
ks.aliases().asIterator().forEachRemaining(alias -> {
System.out.println("hero server alias is " + alias);
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.time.Duration;
import java.io.IOException;

import jakarta.inject.Inject;

import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
Expand All @@ -13,11 +15,12 @@

import io.quarkus.test.bootstrap.Protocol;
import io.quarkus.test.bootstrap.RestService;
import io.quarkus.test.bootstrap.inject.OpenShiftClient;
import io.quarkus.test.scenarios.OpenShiftScenario;
import io.quarkus.test.services.Certificate;
import io.quarkus.test.services.Certificate.ServingCertificates;
import io.quarkus.test.services.QuarkusApplication;
import io.quarkus.test.utils.AwaitilityUtils;
import io.quarkus.test.utils.Command;

import hero.Hero;
import hero.HeroClient;
Expand All @@ -39,6 +42,9 @@ public class OpenShiftServingCertificatesIT {
private static final String HERO_CLIENT = "hero-client";
private static final String SERVER_TLS_CONFIG_NAME = "cert-serving-test-server";

@Inject
static OpenShiftClient ocp;

@QuarkusApplication(ssl = true, certificates = @Certificate(tlsConfigName = SERVER_TLS_CONFIG_NAME, servingCertificates = {
@ServingCertificates(addServiceCertificate = true)
}), classes = { HeroResource.class, Hero.class, Villain.class,
Expand All @@ -54,17 +60,27 @@ public class OpenShiftServingCertificatesIT {
@Order(1)
@Test
public void testSecuredCommunicationBetweenClientAndServer() {

// REST client use OpenShift internal CA
// server is configured with OpenShift serving certificates
// ad "untilAsserted": we experienced unknown SAN, so to avoid flakiness I am adding here retry:
AwaitilityUtils.untilAsserted(() -> {
try {
var hero = client.given().get("hero-client-resource").then().statusCode(200).extract().as(Hero.class);
assertNotNull(hero);
assertNotNull(hero.name());
assertTrue(hero.name().startsWith("Name-"));
assertNotNull(hero.otherName());
assertTrue(hero.otherName().startsWith("Other-"));
}, AwaitilityUtils.AwaitilitySettings.usingTimeout(Duration.ofSeconds(50)));
} catch (Throwable t) {
// FIXME: debug only, don't merge this
runOcpCmd("oc", "get", "pod", "-o", "wide");
runOcpCmd("oc", "describe", "secret", "serving-certificates-secret");
runOcpCmd("oc", "get", "secret", "serving-certificates-secret", "-o", "yaml");
runOcpCmd("oc", "describe", "configmap", "ca-bundle-configmap");
ocp.podsInService(server).forEach(pod -> runOcpCmd("oc", "describe", "pod", pod.getMetadata().getName()));
ocp.podsInService(client).forEach(pod -> runOcpCmd("oc", "describe", "pod", pod.getMetadata().getName()));
throw t;
}
}

@Order(2)
Expand All @@ -78,4 +94,12 @@ public void testConfiguredTlsProtocolEnforced() {
client.logs().assertContains("Received fatal alert: protocol_version");
}

private static void runOcpCmd(String... commands) {
try {
new Command(commands).outputToConsole().runAndWait();
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
}

}