Repository navigation
WFLY-20443 Develop a quickstart which demonstrated the dynamic SSL Cotext capability #1161
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| include::../shared-doc/attributes.adoc[] | ||
|
|
||
| = dynamic-client-ssl-context: Dynamic client SSL Context between Server and Client | ||
| :author: Richard Záň | ||
| :level: Intermediate | ||
| :technologies: Dynamic TLS, Security, Undertow | ||
|
|
||
| [abstract] | ||
| The dynamic-client-ssl-context quickstart shows the option to select different SSL/TLS configurations dynamically based on the host and port of the outbound connection. | ||
|
|
||
| :standalone-server-type: default | ||
| :archiveType: war | ||
|
|
||
| == What is it? | ||
|
|
||
| Elytron client supports dynamic client SSL context. It can be configured everywhere in the subsystem where client-ssl-context attribute can be configured. | ||
|
|
||
| The `dynamic-client-ssl-context` quickstart demonstrates enabled dynamic SSL context for specified URLs and their ports. The only function they represent is to be called via provided REST client and pass a successful call through the SSL/TLS configuration. | ||
|
|
||
| // Link to the quickstart source | ||
| include::../shared-doc/view-the-source.adoc[leveloffset=+1] | ||
| // System Requirements | ||
| include::../shared-doc/system-requirements.adoc[leveloffset=+1] | ||
| // Use of {jbossHomeName} | ||
| include::../shared-doc/use-of-jboss-home-name.adoc[leveloffset=+1] | ||
|
|
||
| // build and run with standard server distribution | ||
| [[start_with_a_clean_server_install]] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| == Start with a Clean Server Install | ||
|
|
||
| It is important to start with a clean version of {productName} before testing this quickstart. Make sure you unzip or install a fresh {productName} instance. | ||
|
|
||
| // Back Up the {productName} Standalone Server Configuration | ||
| include::../shared-doc/back-up-server-standalone-configuration.adoc[leveloffset=+2] | ||
| // Start the {productName} Standalone Server | ||
| include::../shared-doc/start-the-standalone-server.adoc[leveloffset=+2] | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is missing the step to configure the server, ie run the script. You can copy and adapt from https://github.com/wildfly/quickstart/blob/main/ejb-security-context-propagation/README-source.adoc?plain=1#L83 |
||
| [[configure_the_server]] | ||
| == Configure the Server | ||
|
|
||
| You configure the dynamic client SSL context and its dependencies/configuration by running JBoss CLI commands. For your convenience, this quickstart batches the commands into a `configure-dynamic-client-ssl-context.cli` script provided in the root directory of this quickstart. | ||
|
|
||
| . Before you begin, make sure you do the following: | ||
|
|
||
| * xref:back_up_standalone_server_configuration[Back Up the {productName} Standalone Server Configuration] as described above. | ||
| * xref:start_the_eap_standalone_server[Start the {productName} Standalone Server] as described above. | ||
|
|
||
| . Review the `configure-dynamic-client-ssl-context.cli` file in the root of this quickstart directory. This script adds the configuration that enables selecting different SSL/TLS configurations dynamically based on the host and port of the outbound connection for the quickstart deployment. | ||
| Comments in the script describe the purpose of each block of commands. | ||
| . Open a new terminal, navigate to the root directory of this quickstart, and run the following command, replacing `__{jbossHomeName}__` with the path to your server: | ||
| + | ||
| [source,subs="+quotes,attributes+",options="nowrap"] | ||
| ---- | ||
| $ __{jbossHomeName}__/bin/jboss-cli.sh --connect --file=configure-dynamic-client-ssl-context.cli | ||
| ---- | ||
| + | ||
| NOTE: For Windows, use the `__{jbossHomeName}__\bin\jboss-cli.bat` script. | ||
| + | ||
|
|
||
|
|
||
| [[review_the_modified_server_configuration]] | ||
| === Review the Modified Server Configuration | ||
|
|
||
| There are too many additions to the configuration file to list all of them here. | ||
| It is recommended to look into these quickstarts, which have similar SSL setup configuration.: | ||
|
|
||
| . xref:../helloworld-mutual-ssl-secured/README.adoc#review-the-modified-server-configuration[helloworld-mutual-ssl-secured Server configuration] for more information. | ||
| . xref:../helloworld-mutual-ssl/README.adoc#review-the-modified-server-configuration[helloworld-mutual-ssl Server configuration] for more information. | ||
|
|
||
| As another source of information, `configure-dynamic-client-ssl-context.cli` script has detailed description for each step. | ||
|
|
||
| To highlight the most important changes it would be recommended, after the server was stopped, opening the `__{jbossHomeName}__/standalone/configuration/standalone.xml` file to review the changes. | ||
|
|
||
| . Two of the following `key-store` entries was added to the `elytron` subsystem: | ||
| + | ||
| [source,xml,options="nowrap"] | ||
| ---- | ||
| <key-store name="twoWayKS1"> | ||
| <credential-reference clear-text="secret"/> | ||
| <implementation type="PKCS12"/> | ||
| <file path="server1.keystore.P12" relative-to="jboss.server.config.dir"/> | ||
| </key-store> | ||
| <key-store name="twoWayTS1"> | ||
| <credential-reference clear-text="secret"/> | ||
| <implementation type="PKCS12"/> | ||
| <file path="server1.truststore.P12" relative-to="jboss.server.config.dir"/> | ||
| </key-store> | ||
| ---- | ||
|
|
||
| . One of the following `key-manager` entries was added to the `elytron` subsystem: | ||
| + | ||
| [source,xml,options="nowrap"] | ||
| ---- | ||
| <key-manager name="twoWayKM1" key-store="twoWayKS1"> | ||
| <credential-reference clear-text="secret"/> | ||
| </key-manager> | ||
| ---- | ||
|
|
||
| . One of the following `trust-manager` entries was added to the `elytron` subsystem: | ||
| + | ||
| [source,xml,options="nowrap"] | ||
| ---- | ||
| <trust-managers> | ||
| <trust-manager name="twoWayTM1" key-store="twoWayTS1"/> | ||
| </trust-managers> | ||
| ---- | ||
|
|
||
| . The `server-ssl-context` was updated to reference the new `trust-manager` entries to enable two-way TLS: | ||
| + | ||
| [source,xml,options="nowrap"] | ||
| ---- | ||
| <server-ssl-contexts> | ||
| <server-ssl-context name="twoWaySSC1" need-client-auth="true" key-manager="twoWayKM1" trust-manager="twoWayTM1"/> | ||
| </server-ssl-contexts> | ||
| ---- | ||
|
|
||
| . Similarly `client-ssl-context` was updated to reference the new `trust-manager` entries: | ||
| + | ||
| [source,xml,options="nowrap"] | ||
| ---- | ||
| <client-ssl-contexts> | ||
| <client-ssl-context name="client1-ssl-context" key-manager="clientKM1" trust-manager="clientTM1"/> | ||
| </client-ssl-contexts> | ||
| ---- | ||
|
|
||
| . `dynamic-client-ssl-contexts` was enabled: | ||
| + | ||
| [source,xml,options="nowrap"] | ||
| ---- | ||
| <dynamic-client-ssl-contexts> | ||
| <dynamic-client-ssl-context name="dynamicClientSSLContext" authentication-context="ac"/> | ||
| </dynamic-client-ssl-contexts> | ||
| ---- | ||
|
|
||
| // Build and Deploy the Quickstart | ||
| include::../shared-doc/build-and-deploy-the-quickstart.adoc[leveloffset=+2] | ||
|
|
||
| [[access_the_application]] | ||
| === Access the Application | ||
|
|
||
| The application will be running at the following URL: http://localhost:8080/dynamic-client-ssl-context | ||
|
|
||
| A main page displays list of links: | ||
|
|
||
| [source,options="nowrap"] | ||
| ---- | ||
| Click below to send request to different ports: | ||
|
|
||
| Send request to port 9443 | ||
| Send request to port 10443 | ||
| ---- | ||
|
|
||
| Each of links calls specific endpoint on server and the server's endpoint executes https GET request under specified ports. Each port uses a different TLS certificate. Both GET requests use the same dynamic client SSL context. For http://localhost:8080/dynamic-client-ssl-context/rest/port9443request, it will display: | ||
|
|
||
| [source,options="nowrap"] | ||
| ---- | ||
| HTTP status of result is 200 | ||
| ---- | ||
|
|
||
| Similar result is for http://localhost:8080/dynamic-client-ssl-context/rest/port10443request: | ||
|
|
||
| [source,options="nowrap"] | ||
| ---- | ||
| HTTP status of result is 200 | ||
| ---- | ||
|
|
||
| Internally, this quickstart calls the following two URLs, each with enabled dynamic SSL context: | ||
|
|
||
| [cols="100%",options="headers"] | ||
| |=== | ||
| |URL paths with their ports | ||
|
|
||
| |`https://localhost:9443/dynamic-client-ssl-context/` | ||
|
|
||
| |`https://localhost:10443/dynamic-client-ssl-context/` | ||
|
|
||
| |=== | ||
|
|
||
| The server configuration is done using CLI batch scripts located in the root of the quickstart folder. | ||
|
|
||
| // Server Distribution Testing | ||
| include::../shared-doc/run-integration-tests-with-server-distribution.adoc[leveloffset=+1] | ||
|
|
||
| // Undeploy the Quickstart | ||
| include::../shared-doc/undeploy-the-quickstart.adoc[leveloffset=+1] | ||
|
|
||
| // Restore the {productName} Standalone Server Configuration Manually | ||
| include::../shared-doc/restore-standalone-server-configuration-manual.adoc[leveloffset=+1] | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This quickstart includes provisioned-server maven profile, but no instructions related with that, please add the following include to fix this: include::../shared-doc/build-and-run-the-quickstart-with-provisioned-server.adoc[leveloffset=+1] |
||
| // Build and run sections for other environments/builds | ||
| include::../shared-doc/build-and-run-the-quickstart-with-provisioned-server.adoc[leveloffset=+1] | ||
|
|
||
| // Quickstart not compatible with OpenShift | ||
| include::../shared-doc/openshift-incompatibility.adoc[leveloffset=+1] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| # | ||
| # Copyright The WildFly Authors | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
|
|
||
| # Script to configure dynamic SSL context in the application server | ||
|
|
||
| # Create the server's keystores | ||
| /subsystem=elytron/key-store=twoWayKS1:add(path=server1.keystore.P12,relative-to=jboss.server.config.dir,credential-reference={clear-text=secret},type=PKCS12) | ||
| /subsystem=elytron/key-store=twoWayKS2:add(path=server2.keystore.P12,relative-to=jboss.server.config.dir,credential-reference={clear-text=secret},type=PKCS12) | ||
|
|
||
| # Generate new server's key pairs. We'll use an RSA key of size 2048 and we'll use CN=localhost1 and CN=localhost2 | ||
| /subsystem=elytron/key-store=twoWayKS1:generate-key-pair(alias=localhost1 , algorithm=RSA, key-size=2048, validity=365, credential-reference={clear-text=secret}, distinguished-name="cn=localhost") | ||
| /subsystem=elytron/key-store=twoWayKS2:generate-key-pair(alias=localhost2 , algorithm=RSA, key-size=2048, validity=365, credential-reference={clear-text=secret}, distinguished-name="cn=localhost") | ||
|
|
||
| # Export the server's certificates to files called localhost1Cert.crt and path=localhost2Cert.crt | ||
| /subsystem=elytron/key-store=twoWayKS1:export-certificate(alias=localhost1, path=localhost1Cert.crt, relative-to=jboss.server.config.dir, pem=true) | ||
| /subsystem=elytron/key-store=twoWayKS2:export-certificate(alias=localhost2, path=localhost2Cert.crt, relative-to=jboss.server.config.dir, pem=true) | ||
|
|
||
| # Create the server's truststores | ||
| /subsystem=elytron/key-store=twoWayTS1:add(path=server1.truststore.P12,relative-to=jboss.server.config.dir,credential-reference={clear-text=secret},type=PKCS12) | ||
| /subsystem=elytron/key-store=twoWayTS2:add(path=server2.truststore.P12,relative-to=jboss.server.config.dir,credential-reference={clear-text=secret},type=PKCS12) | ||
|
|
||
| # Set up the trust manager and keystore configuration for server's keystores | ||
| /subsystem=elytron/key-manager=twoWayKM1:add(key-store=twoWayKS1,credential-reference={clear-text=secret}) | ||
| /subsystem=elytron/trust-manager=twoWayTM1:add(key-store=twoWayTS1) | ||
| /subsystem=elytron/key-manager=twoWayKM2:add(key-store=twoWayKS2,credential-reference={clear-text=secret}) | ||
| /subsystem=elytron/trust-manager=twoWayTM2:add(key-store=twoWayTS2) | ||
|
|
||
| # Create the server-ssl-context to reference the newly created trust-managers with required client auth option | ||
| /subsystem=elytron/server-ssl-context=twoWaySSC1:add(key-manager=twoWayKM1,trust-manager=twoWayTM1,need-client-auth=true) | ||
| /subsystem=elytron/server-ssl-context=twoWaySSC2:add(key-manager=twoWayKM2,trust-manager=twoWayTM2,need-client-auth=true) | ||
|
|
||
| # Create the client's keystores | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comments at lines 34 and 38 are swapped. "Create the client's keystores" (line 34) is followed by |
||
| /subsystem=elytron/key-store=clientKS1:add(path=client1.keystore.P12,relative-to=jboss.server.config.dir,credential-reference={clear-text=secret},type=PKCS12) | ||
| /subsystem=elytron/key-store=clientKS2:add(path=client2.keystore.P12,relative-to=jboss.server.config.dir,credential-reference={clear-text=secret},type=PKCS12) | ||
|
|
||
| # Create the client's truststores | ||
| /subsystem=elytron/key-store=clientTS1:add(path=client1.truststore.P12,relative-to=jboss.server.config.dir,credential-reference={clear-text=secret},type=PKCS12) | ||
| /subsystem=elytron/key-store=clientTS2:add(path=client2.truststore.P12,relative-to=jboss.server.config.dir,credential-reference={clear-text=secret},type=PKCS12) | ||
|
|
||
| # Generate new client's key pairs. We'll use an RSA key of size 2048 and we'll use CN=client1 and CN=client2 | ||
| /subsystem=elytron/key-store=clientKS1:generate-key-pair(alias=client1 , algorithm=RSA, key-size=2048, validity=365, credential-reference={clear-text=secret}, distinguished-name="cn=client1") | ||
| /subsystem=elytron/key-store=clientKS2:generate-key-pair(alias=client2 , algorithm=RSA, key-size=2048, validity=365, credential-reference={clear-text=secret}, distinguished-name="cn=client2") | ||
|
|
||
| # Export the client's certificates to files called client1Cert.crt and path=client2Cert.crt | ||
| /subsystem=elytron/key-store=clientKS1:export-certificate(alias=client1, path=client1Cert.crt, relative-to=jboss.server.config.dir, pem=true) | ||
| /subsystem=elytron/key-store=clientKS2:export-certificate(alias=client2, path=client2Cert.crt, relative-to=jboss.server.config.dir, pem=true) | ||
|
|
||
| # Import the server's certificates into the client's truststores | ||
| /subsystem=elytron/key-store=clientTS1:import-certificate(alias=localhost1, path=localhost1Cert.crt, relative-to=jboss.server.config.dir, credential-reference={clear-text=secret}, validate=false) | ||
| /subsystem=elytron/key-store=clientTS2:import-certificate(alias=localhost2, path=localhost2Cert.crt, relative-to=jboss.server.config.dir, credential-reference={clear-text=secret}, validate=false) | ||
|
|
||
| # Import the client's certificates into the server's truststores | ||
| /subsystem=elytron/key-store=twoWayTS1:import-certificate(alias=client1, path=client1Cert.crt, relative-to=jboss.server.config.dir, credential-reference={clear-text=secret}, validate=false) | ||
| /subsystem=elytron/key-store=twoWayTS2:import-certificate(alias=client2, path=client2Cert.crt, relative-to=jboss.server.config.dir, credential-reference={clear-text=secret}, validate=false) | ||
|
|
||
| # Persist the changes | ||
| /subsystem=elytron/key-store=twoWayKS1:store() | ||
| /subsystem=elytron/key-store=twoWayKS2:store() | ||
| /subsystem=elytron/key-store=twoWayTS1:store() | ||
| /subsystem=elytron/key-store=twoWayTS2:store() | ||
| /subsystem=elytron/key-store=clientKS1:store() | ||
| /subsystem=elytron/key-store=clientKS2:store() | ||
| /subsystem=elytron/key-store=clientTS1:store() | ||
| /subsystem=elytron/key-store=clientTS2:store() | ||
|
|
||
| # Set up the trust manager and keystore configuration for client's keystores | ||
| /subsystem=elytron/key-manager=clientKM1:add(key-store=clientKS1,credential-reference={clear-text=secret}) | ||
| /subsystem=elytron/trust-manager=clientTM1:add(key-store=clientTS1) | ||
| /subsystem=elytron/key-manager=clientKM2:add(key-store=clientKS2,credential-reference={clear-text=secret}) | ||
| /subsystem=elytron/trust-manager=clientTM2:add(key-store=clientTS2) | ||
|
|
||
| # Create the client-ssl-context to reference the newly created trust-managers with required client auth option | ||
| /subsystem=elytron/client-ssl-context=client1-ssl-context:add(key-manager=clientKM1,trust-manager=clientTM1) | ||
| /subsystem=elytron/client-ssl-context=client2-ssl-context:add(key-manager=clientKM2,trust-manager=clientTM2) | ||
|
|
||
| # Configure the "first" and "second" connections for the main server | ||
| # Add the socket binding to the full-sockets, used by the app-main server | ||
| /socket-binding-group=standard-sockets/socket-binding=first-socket-binding:add(port=9443) | ||
| /socket-binding-group=standard-sockets/socket-binding=second-socket-binding:add(port=10443) | ||
|
|
||
| # Add https listeners | ||
| /subsystem=undertow/server=default-server/https-listener=first-listener:add(socket-binding=first-socket-binding,ssl-context=twoWaySSC1,enable-http2=true) | ||
| /subsystem=undertow/server=default-server/https-listener=second-listener:add(socket-binding=second-socket-binding,ssl-context=twoWaySSC2,enable-http2=true) | ||
|
|
||
| # Add the authentication context | ||
| /subsystem=elytron/authentication-context=ac:add(match-rules=[{match-port=9443,ssl-context=client1-ssl-context},{match-port=10443,ssl-context=client2-ssl-context}]) | ||
|
|
||
| # Set up dynamic client SSL context to be a default SSL Context for the whole server | ||
| /subsystem=elytron/dynamic-client-ssl-context=dynamicClientSSLContext:add(authentication-context=ac) | ||
| /subsystem=elytron:write-attribute(name=default-ssl-context,value=dynamicClientSSLContext) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a comment that we configure the dynamic client SSL context to be a default SSL Context for the whole server. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can mention how to run them here to be consistent with the rest of quickstarts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like this? https://github.com/wildfly/quickstart/blob/main/helloworld-mutual-ssl-secured/README.adoc#building-and-running-the-quickstart-application-with-provisioned-wildfly-server
I have already added parts that cover it:
../shared-doc/start-the-standalone-server.adoc../shared-doc/build-and-deploy-the-quickstart.adoc../shared-doc/run-integration-tests-with-server-distribution.adoc...
I took a massive inspiration from https://github.com/wildfly/quickstart/blob/main/ejb-multi-server/README-source.adoc