-
Notifications
You must be signed in to change notification settings - Fork 28
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 #1270 from michalvavrik/feature/openshift-tls-cert…
…ificate-serving Support OpenShift certificate serving used with TLS registry
- Loading branch information
Showing
20 changed files
with
644 additions
and
20 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
62 changes: 62 additions & 0 deletions
62
examples/https/src/test/java/io/quarkus/qe/OpenShiftServingCertificatesIT.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,62 @@ | ||
package io.quarkus.qe; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.qe.hero.Hero; | ||
import io.quarkus.qe.hero.HeroClient; | ||
import io.quarkus.qe.hero.HeroClientResource; | ||
import io.quarkus.qe.hero.HeroResource; | ||
import io.quarkus.test.bootstrap.Protocol; | ||
import io.quarkus.test.bootstrap.RestService; | ||
import io.quarkus.test.scenarios.OpenShiftScenario; | ||
import io.quarkus.test.scenarios.annotations.DisabledOnNative; | ||
import io.quarkus.test.services.Certificate; | ||
import io.quarkus.test.services.QuarkusApplication; | ||
import io.quarkus.test.utils.AwaitilityUtils; | ||
|
||
/** | ||
* Test OpenShift serving certificate support provided by our framework. | ||
*/ | ||
@DisabledOnNative // building 2 apps is costly and point here is to test FW support not Quarkus | ||
@OpenShiftScenario | ||
public class OpenShiftServingCertificatesIT { | ||
|
||
private static final String CLIENT_TLS_CONFIG_NAME = "cert-serving-test-client"; | ||
private static final String SERVER_TLS_CONFIG_NAME = "cert-serving-test-server"; | ||
|
||
@QuarkusApplication(ssl = true, certificates = @Certificate(tlsConfigName = SERVER_TLS_CONFIG_NAME, servingCertificates = @Certificate.ServingCertificates(addServiceCertificate = true)), classes = { | ||
HeroResource.class, Hero.class }) | ||
static final RestService server = new RestService() | ||
.withProperty("quarkus.http.ssl.client-auth", "request") | ||
.withProperty("quarkus.http.insecure-requests", "DISABLED"); | ||
|
||
@QuarkusApplication(certificates = @Certificate(tlsConfigName = CLIENT_TLS_CONFIG_NAME, servingCertificates = @Certificate.ServingCertificates(injectCABundle = true)), classes = { | ||
HeroClient.class, Hero.class, HeroClientResource.class }) | ||
static final RestService client = new RestService() | ||
.withProperty("quarkus.rest-client.hero.tls-configuration-name", CLIENT_TLS_CONFIG_NAME) | ||
.withProperty("quarkus.rest-client.hero.uri", () -> server.getURI(Protocol.HTTPS).getRestAssuredStyleUri()); | ||
|
||
@Test | ||
public void testSecuredCommunicationBetweenClientAndServer() { | ||
// REST client use OpenShift internal CA | ||
// server is configured with OpenShift serving certificates | ||
// ad "untilAsserted": hopefully it's not necessary, but once I experienced unknown SAN, | ||
// so to avoid flakiness I am adding here retry: | ||
AwaitilityUtils.untilAsserted(() -> { | ||
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-")); | ||
assertTrue(hero.otherName().startsWith("Other-")); | ||
}); | ||
} | ||
|
||
} |
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,4 @@ | ||
package io.quarkus.qe.hero; | ||
|
||
public record Hero(Long id, String name, String otherName, int level, String picture, String powers) { | ||
} |
15 changes: 15 additions & 0 deletions
15
examples/https/src/test/java/io/quarkus/qe/hero/HeroClient.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,15 @@ | ||
package io.quarkus.qe.hero; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
@RegisterRestClient(configKey = "hero") | ||
public interface HeroClient { | ||
|
||
@GET | ||
@Path("/api/heroes/random") | ||
Hero getRandomHero(); | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
examples/https/src/test/java/io/quarkus/qe/hero/HeroClientResource.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,19 @@ | ||
package io.quarkus.qe.hero; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
|
||
@Path("hero-client-resource") | ||
public class HeroClientResource { | ||
|
||
@RestClient | ||
HeroClient heroClient; | ||
|
||
@GET | ||
public Hero triggerClientToServerCommunication() { | ||
return heroClient.getRandomHero(); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
examples/https/src/test/java/io/quarkus/qe/hero/HeroResource.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,17 @@ | ||
package io.quarkus.qe.hero; | ||
|
||
import java.util.random.RandomGenerator; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
@Path("/api/heroes/random") | ||
public class HeroResource { | ||
|
||
@GET | ||
public Hero getRandomHero() { | ||
long random = RandomGenerator.getDefault().nextLong(); | ||
return new Hero(random, "Name-" + random, "Other-" + random, 1, "placeholder", "root"); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1 +1,4 @@ | ||
ts.app.log.enable=true | ||
|
||
# serving certs only works for internal DNS | ||
ts.server.openshift.use-internal-service-as-url=true |
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
55 changes: 55 additions & 0 deletions
55
...est-core/src/main/java/io/quarkus/test/security/certificate/ServingCertificateConfig.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,55 @@ | ||
package io.quarkus.test.security.certificate; | ||
|
||
import io.quarkus.test.bootstrap.ServiceContext; | ||
|
||
public record ServingCertificateConfig(boolean injectCABundle, boolean addServiceCertificate, String tlsConfigName) { | ||
|
||
public static final String SERVING_CERTIFICATE_KEY = "serving-certificate-config-key"; | ||
|
||
public static boolean isServingCertificateScenario(ServiceContext serviceContext) { | ||
return get(serviceContext) != null; | ||
} | ||
|
||
public static ServingCertificateConfig get(ServiceContext serviceContext) { | ||
if (serviceContext.get(SERVING_CERTIFICATE_KEY) instanceof ServingCertificateConfig config) { | ||
return config; | ||
} | ||
return null; | ||
} | ||
|
||
static ServingCertificateConfigBuilder builder() { | ||
return new ServingCertificateConfigBuilder(); | ||
} | ||
|
||
static final class ServingCertificateConfigBuilder { | ||
|
||
private boolean injectCABundle = false; | ||
private boolean addServiceCertificate = false; | ||
private String tlsConfigName = null; | ||
|
||
private ServingCertificateConfigBuilder() { | ||
} | ||
|
||
ServingCertificateConfigBuilder withInjectCABundle(boolean injectCABundle) { | ||
this.injectCABundle = injectCABundle; | ||
return this; | ||
} | ||
|
||
ServingCertificateConfigBuilder withAddServiceCertificate(boolean addServiceCertificate) { | ||
this.addServiceCertificate = addServiceCertificate; | ||
return this; | ||
} | ||
|
||
ServingCertificateConfigBuilder withTlsConfigName(String tlsConfigName) { | ||
this.tlsConfigName = tlsConfigName; | ||
return this; | ||
} | ||
|
||
ServingCertificateConfig build() { | ||
if (injectCABundle || addServiceCertificate) { | ||
return new ServingCertificateConfig(injectCABundle, addServiceCertificate, tlsConfigName); | ||
} | ||
return null; | ||
} | ||
} | ||
} |
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.