Skip to content

Commit 3bfbe71

Browse files
committed
remove JDBC properties from docs & add TLS docs to tests-db.md
Signed-off-by: Pedro Ruivo <1492066+pruivo@users.noreply.github.com>
1 parent 9c7b257 commit 3bfbe71

File tree

2 files changed

+59
-211
lines changed

2 files changed

+59
-211
lines changed

docs/guides/server/db.adoc

Lines changed: 0 additions & 210 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,6 @@ This section provides guidance on how to enable these settings in {project_name}
510510
Configuring the database server with the private keys and certificates is outside the scope of this section.
511511
Consult your vendor documentation on how to do it.
512512

513-
=== Using {project_name} CLI options
514-
515513
{project_name} provides unified CLI options to configure database TLS settings across different database vendors.
516514
These options simplify the configuration by abstracting vendor-specific JDBC properties and providing a consistent interface.
517515

@@ -545,214 +543,6 @@ Alternatively, you can use `--truststore-paths` instead of the `db-tls-trust-sto
545543

546544
<@kc.start parameters="--db=postgres --db-tls-mode=verify-server --truststore-paths=/path/to/certificate.pem"/>
547545

548-
=== Using the Java truststore
549-
550-
{project_name} allows adding certificates to the Java truststore using the CLI option `--truststore-paths`, which is supported by most drivers.
551-
The recommended settings for each database are provided below.
552-
553-
==== PostgreSQL
554-
// https://jdbc.postgresql.org/documentation/ssl/
555-
PostgreSQL requires the following JDBC properties to be configured.
556-
557-
[%autowidth]
558-
|===
559-
|JDBC Property |Value | Description
560-
561-
m|sslmode
562-
m|verify-full
563-
|Encrypts the network traffic and validates the server identity.
564-
565-
m|sslfactory
566-
m|org.postgresql.ssl.DefaultJavaSSLFactory
567-
|By default, the driver uses `LibPQFactory` which does not support the Java truststore.
568-
569-
|===
570-
571-
<@kc.start parameters="--truststore-paths=/path/to/database_cert.pem --db-url-properties=?sslmode=verify-full&sslfactory=org.postgresql.ssl.DefaultJavaSSLFactory"/>
572-
573-
==== MySQL
574-
// https://dev.mysql.com/doc/connector-j/en/connector-j-reference-using-ssl.html
575-
MySQL requires the following JDBC property to be configured.
576-
577-
[%autowidth]
578-
|===
579-
|JDBC Property |Value | Description
580-
581-
m|sslMode
582-
m|VERIFY_IDENTITY
583-
|Encrypts the network traffic and validates the server identity.
584-
585-
|===
586-
587-
<@kc.start parameters="--truststore-paths=/path/to/database_cert.pem --db-url-properties=?sslMode=VERIFY_IDENTITY"/>
588-
589-
[%autowidth]
590-
==== MariaDB
591-
// https://mariadb.com/docs/connectors/mariadb-connector-j/using-tls-ssl-with-mariadb-java-connector
592-
MariaDB requires the following JDBC property to be configured.
593-
594-
|===
595-
|JDBC Property |Value | Description
596-
597-
m|sslMode
598-
m|verify-full
599-
|Encrypts the network traffic and validates the server identity.
600-
601-
|===
602-
603-
<@kc.start parameters="--truststore-paths=/path/to/database_cert.pem --db-url-properties=?sslMode=verify-full"/>
604-
605-
[%autowidth]
606-
==== Microsoft SQL Server
607-
// https://learn.microsoft.com/en-us/sql/connect/jdbc/connecting-with-ssl-encryption?view=sql-server-ver17#configuring-the-connection
608-
Microsoft SQL Server requires the following JDBC properties to be configured.
609-
610-
|===
611-
|JDBC Property |Value | Description
612-
613-
m|encrypt
614-
m|true
615-
|Encrypts the network traffic.
616-
617-
m|trustServerCertificate
618-
m|false
619-
|Validates the server identity.
620-
621-
|===
622-
623-
<@kc.start parameters="--truststore-paths=/path/to/database_cert.pem --db-url-properties=;encrypt=true;trustServerCertificate=false"/>
624-
625-
[%autowidth]
626-
==== Oracle
627-
// https://docs.oracle.com/en/database/oracle/oracle-database/21/jajdb/oracle/jdbc/OracleDriver.html
628-
Oracle by default verifies the server identity when the protocol `tcps` is used.
629-
630-
<@kc.start parameters="--truststore-paths=/path/to/database_cert.pem --db-url=jdbc:oracle:thin:@tcps://host:port/database"/>
631-
632-
=== Using database-specific certificate paths
633-
634-
Alternatively, instead of using the Java truststore with `--truststore-paths`, you can configure each database driver to use its own certificate file or truststore directly through JDBC properties.
635-
This approach is useful when you want to keep database certificates separate from the Java truststore.
636-
637-
==== PostgreSQL
638-
639-
PostgreSQL supports specifying the certificate file directly using the `sslrootcert` property.
640-
641-
[%autowidth]
642-
|===
643-
|JDBC Property |Value | Description
644-
645-
m|sslmode
646-
m|verify-full
647-
|Encrypts the network traffic and validates the server identity.
648-
649-
m|sslrootcert
650-
m|/path/to/cert.pem
651-
|The path to the server's certificate file on the client machine.
652-
653-
|===
654-
655-
<@kc.start parameters="--db-url-properties=?sslmode=verify-full&sslrootcert=/path/to/cert.pem"/>
656-
657-
==== MySQL
658-
659-
MySQL supports specifying the certificate file or truststore through dedicated SSL properties.
660-
661-
[%autowidth]
662-
|===
663-
|JDBC Property |Value | Description
664-
665-
m|sslMode
666-
m|VERIFY_IDENTITY
667-
|Encrypts the network traffic and validates the server identity.
668-
669-
m|trustCertificateKeyStoreUrl
670-
m|file:/path/to/truststore.jks
671-
|The URL to a custom truststore file containing the server certificate.
672-
673-
m|trustCertificateKeyStorePassword
674-
m|password
675-
|The password for the custom truststore (if required).
676-
677-
|===
678-
679-
<@kc.start parameters="--db-url-properties=?sslMode=VERIFY_IDENTITY&trustCertificateKeyStoreUrl=file:/path/to/truststore.jks&trustCertificateKeyStorePassword=password"/>
680-
681-
==== MariaDB
682-
683-
MariaDB supports specifying the certificate file directly using the `serverSslCert` property.
684-
685-
[%autowidth]
686-
|===
687-
|JDBC Property |Value | Description
688-
689-
m|sslMode
690-
m|verify-full
691-
|Encrypts the network traffic and validates the server identity.
692-
693-
m|serverSslCert
694-
m|/path/to/cert.pem
695-
|The path to the server's certificate file on the client machine.
696-
697-
|===
698-
699-
<@kc.start parameters="--db-url-properties=?sslMode=verify-full&serverSslCert=/path/to/cert.pem"/>
700-
701-
==== Microsoft SQL Server
702-
703-
Microsoft SQL Server supports specifying a custom truststore using the `trustStore` and `trustStorePassword` properties.
704-
705-
[%autowidth]
706-
|===
707-
|JDBC Property |Value | Description
708-
709-
m|encrypt
710-
m|true
711-
|Encrypts the network traffic.
712-
713-
m|trustServerCertificate
714-
m|false
715-
|Validates the server identity.
716-
717-
m|trustStore
718-
m|/path/to/truststore.jks
719-
|The path to a custom truststore file containing the server certificate.
720-
721-
m|trustStorePassword
722-
m|password
723-
|The password for the custom truststore.
724-
725-
|===
726-
727-
<@kc.start parameters="--db-url-properties=;encrypt=true;trustServerCertificate=false;trustStore=/path/to/truststore.jks;trustStorePassword=password"/>
728-
729-
==== Oracle
730-
731-
Oracle supports using Oracle Wallet or Java keystores for certificate management.
732-
When using `tcps` protocol, you can specify a custom keystore location.
733-
734-
[%autowidth]
735-
|===
736-
|JDBC Property |Value | Description
737-
738-
m|javax.net.ssl.trustStore
739-
m|/path/to/truststore.jks
740-
|The path to a custom truststore file containing the server certificate.
741-
742-
m|javax.net.ssl.trustStorePassword
743-
m|password
744-
|The password for the custom truststore.
745-
746-
m|javax.net.ssl.trustStoreType
747-
m|JKS
748-
|The type of truststore (JKS, PKCS12, etc.).
749-
750-
|===
751-
752-
<@kc.start parameters="--db-url=jdbc:oracle:thin:@tcps://host:port/database --db-url-properties=?javax.net.ssl.trustStore=/path/to/truststore.jks&javax.net.ssl.trustStorePassword=password&javax.net.ssl.trustStoreType=JKS"/>
753-
754-
Alternatively, you can use Oracle Wallet by configuring the wallet location in the JDBC URL or through Oracle-specific properties.
755-
756546
== Setting JPA provider configuration option for migrationStrategy
757547

758548
To setup the JPA migrationStrategy (manual/update/validate) you should setup JPA provider as follows:

docs/tests-db.md

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,67 @@ Stop TiDB:
7070

7171
docker rm -f tidb
7272

73-
Using built-in profiles to run database tests using docker containers
73+
74+
Enabling SSL
75+
============
76+
77+
Generate certificate
78+
-------
79+
80+
To enable TLS connection, a private key and certificate to be provided to the database.
81+
Let's create a directory named `certs` to store the files we need.
82+
83+
```bash
84+
mkdir certs ; cd certs
85+
```
86+
87+
```bash
88+
openssl req -x509 -newkey rsa:4096 -keyout database-key.pem -out database-cert.pem -sha256 -days 3650 -nodes -subj "/CN=localhost
89+
```
90+
91+
Private key permissions
92+
-------
93+
94+
The primary key must belong to the user running in the container and only that user should be able to access.
95+
PostgreSQL, MariaDB, and MySQL both use user with id 999 (at the time of writing).
96+
97+
```bash
98+
chmod 0600 database-key.pem
99+
chown 999:999 database-key.pem
100+
```
101+
102+
Starting the database container
74103
-------
75104
105+
Mount the `certs` directory in the container and configure the database as shown below.
106+
The file `database-cert.pem` can be added to Keycloak truststore to perform the hostname verification.
107+
By default, the JDBC drivers do not perform the hostname verification.
108+
109+
**PostgreSQL**
110+
111+
```bash
112+
docker run -d --name postgres --network host --volume '${PWD}:/mnt/certs:ro' -e POSTGRES_USER=keycloak -e POSTGRES_PASSWORD=keycloak -e POSTGRES_DB=keycloak postgres:17 postgres -c ssl=on -c ssl_cert_file=/mnt/certs/database-cert.pem -c ssl_key_file=/mnt/certs/database-key.pem
113+
```
114+
115+
**MariaDB**
116+
117+
```bash
118+
docker run -d --name maridb --network host --volume '${PWD}:/mnt/certs:ro' -e MARIADB_ROOT_PASSWORD=keycloak -e MARIADB_USER=keycloak -e MARIADB_PASSWORD=keycloak -e MARIADB_DATABASE=keycloak mariadb:11 --ssl-cert=/mnt/certs/database-cert.pem --ssl-key=/mnt/certs/database-key.pem --require-secure-transport
119+
```
120+
121+
The option `--require-secure-transport` ensures only TLS connections are accepted by the server.
122+
123+
**MySQL**
124+
125+
```bash
126+
docker run -d --name mysql --network host --volume '${PWD}:/mnt/certs:ro' -e MYSQL_ROOT_PASSWORD=keycloak -e MYSQL_USER=keycloak -e MYSQL_PASSWORD=keycloak -e MYSQL_DATABASE=keycloak mysql:9 --ssl-cert=/mnt/certs/database-cert.pem --ssl-key=/mnt/certs/database-key.pem --require-secure-transport
127+
```
128+
129+
The option `--require-secure-transport` ensures only TLS connections are accepted by the server.
130+
131+
Using built-in profiles to run database tests using docker containers
132+
============
133+
76134
The project provides specific profiles to run database tests using containers. Below is a just a sample of implemented profiles. In order to get a full list, please invoke (`mvn help:all-profiles -pl testsuite/integration-arquillian | grep -- db-`):
77135
78136
* `db-mysql`

0 commit comments

Comments
 (0)