Remove MS SQL JDBC driver from the Keycloak product

Closes #22983
This commit is contained in:
Alexander Schwartz 2023-09-05 15:38:19 +02:00 committed by Alexander Schwartz
parent 2b4f9cf41e
commit 2eb37dbe4f
7 changed files with 78 additions and 6 deletions

View file

@ -31,11 +31,13 @@ only exists for development use-cases. The `dev-file` database is not suitable f
<@profile.ifProduct> <@profile.ifProduct>
== Installing a database driver (Oracle) == Installing a database driver
Database drivers are shipped as part of Keycloak except for the Oracle Database driver which needs to be installed separately. Database drivers are shipped as part of Keycloak except for the Oracle Database and Micrsoft SQL Server drivers which need to be installed separately.
Install the Oracle Database driver if you want to connect to an Oracle Database, or skip this section if you want to connect to a different database. Install the necessary driver if you want to connect to one of these databases or skip this section if you want to connect to a different database for which the database driver is already included.
=== Installing the Oracle Database driver
To install the Oracle Database driver for Keycloak: To install the Oracle Database driver for Keycloak:
@ -71,6 +73,41 @@ See the <@links.server id="containers" /> {section} for details on how to build
Then continue configuring the database as described in the next section. Then continue configuring the database as described in the next section.
=== Installing the Microsoft SQL Server driver
To install the Microsoft SQL Server driver for Keycloak:
. Download the `mssql-jdbc` JAR file from one of the following sources:
.. Download a version from the https://learn.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server[Microsoft JDBC Driver for SQL Server page].
.. Maven Central via `link:++https://repo1.maven.org/maven2/com/microsoft/sqlserver/mssql-jdbc/${properties["mssql-jdbc.version"]}/mssql-jdbc-${properties["mssql-jdbc.version"]}.jar++[mssql-jdbc]`.
.. Installation media recommended by the database vendor for the specific database in use.
. When running the unzipped distribution: Place the `mssql-jdbc` in Keycloak's `providers` folder
. When running containers: Build a custom Keycloak image and add the JARs in the `providers` folder. When building a custom image for the Keycloak Operator, those images need to be optimized images with all build-time options of Keycloak set.
+
A minimal Dockerfile to build an image which can be used with the Keycloak Operator and includes Microsoft SQL Server JDBC drivers downloaded from Maven Central looks like the following:
+
[source,dockerfile]
----
FROM quay.io/keycloak/keycloak:latest
ADD --chown=keycloak:keycloak https://repo1.maven.org/maven2/com/microsoft/sqlserver/mssql-jdbc/${properties["mssql-jdbc.version"]}/mssql-jdbc-${properties["mssql-jdbc.version"]}.jar /opt/keycloak/providers/mssql-jdbc.jar
# Setting the build parameter for the database:
ENV KC_DB=mssql
# Add all other build parameters needed, for example enable health and metrics:
ENV KC_HEALTH_ENABLED=true
ENV KC_METRICS_ENABLED=true
# To be able to use the image with the Keycloak Operator, it needs to be optimized, which requires Keycloak's build step:
RUN /opt/keycloak/bin/kc.sh build
----
+
See the <@links.server id="containers" /> {section} for details on how to build optimized images.
Then continue configuring the database as described in the next section.
</@profile.ifProduct> </@profile.ifProduct>
== Configuring a database == Configuring a database

View file

@ -148,9 +148,10 @@
<mariadb.version>10.11</mariadb.version> <mariadb.version>10.11</mariadb.version>
<mariadb-jdbc.version>3.1.4</mariadb-jdbc.version> <mariadb-jdbc.version>3.1.4</mariadb-jdbc.version>
<mssql.version>2022-latest</mssql.version> <mssql.version>2022-latest</mssql.version>
<mssql-jdbc.version>9.2.0.jre8</mssql-jdbc.version> <!-- this is the mssql driver version also used in the Quarkus BOM -->
<!-- this is the oracle driver version also used in the Quarkus BOM --> <mssql-jdbc.version>12.2.0.jre11</mssql-jdbc.version>
<oracledb.version>19.3</oracledb.version> <oracledb.version>19.3</oracledb.version>
<!-- this is the oracle driver version also used in the Quarkus BOM -->
<oracle-jdbc.version>23.2.0.0</oracle-jdbc.version> <oracle-jdbc.version>23.2.0.0</oracle-jdbc.version>
<!-- Test --> <!-- Test -->

View file

@ -746,6 +746,16 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-mssql</artifactId>
<exclusions>
<exclusion>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies> </dependencies>
</profile> </profile>
<profile> <profile>

View file

@ -71,6 +71,11 @@
<artifactId>bctls-fips</artifactId> <artifactId>bctls-fips</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<scope>test</scope>
</dependency>
<!-- Minimal test dependencies to *-deployment artifacts for consistent build order --> <!-- Minimal test dependencies to *-deployment artifacts for consistent build order -->
<dependency> <dependency>

View file

@ -92,6 +92,10 @@
<groupId>org.testcontainers</groupId> <groupId>org.testcontainers</groupId>
<artifactId>mssqlserver</artifactId> <artifactId>mssqlserver</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.apache.maven.wagon</groupId> <groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http-shared</artifactId> <artifactId>wagon-http-shared</artifactId>

View file

@ -389,6 +389,10 @@ public final class RawKeycloakDistribution implements KeycloakDistribution {
if (!inited || (reCreate || !dPath.toFile().exists())) { if (!inited || (reCreate || !dPath.toFile().exists())) {
FileUtil.deleteDirectory(dPath); FileUtil.deleteDirectory(dPath);
ZipUtils.unzip(distFile.toPath(), distRootPath); ZipUtils.unzip(distFile.toPath(), distRootPath);
if (System.getProperty("product") != null) {
// MS SQL Server driver might be excluded if running as a product build
copyProvider(dPath, "com.microsoft.sqlserver", "mssql-jdbc");
}
} }
// make sure script is executable // make sure script is executable
@ -525,8 +529,12 @@ public final class RawKeycloakDistribution implements KeycloakDistribution {
} }
public void copyProvider(String groupId, String artifactId) { public void copyProvider(String groupId, String artifactId) {
copyProvider(getDistPath(), groupId, artifactId);
}
private static void copyProvider(Path distPath, String groupId, String artifactId) {
try { try {
Files.copy(Maven.resolveArtifact(groupId, artifactId), getDistPath().resolve("providers").resolve(artifactId + ".jar")); Files.copy(Maven.resolveArtifact(groupId, artifactId), distPath.resolve("providers").resolve(artifactId + ".jar"));
} catch (IOException cause) { } catch (IOException cause) {
throw new RuntimeException("Failed to copy JAR file to 'providers' directory", cause); throw new RuntimeException("Failed to copy JAR file to 'providers' directory", cause);
} }

View file

@ -372,6 +372,13 @@
<type>jar</type> <type>jar</type>
<outputDirectory>${auth.server.home}/providers</outputDirectory> <outputDirectory>${auth.server.home}/providers</outputDirectory>
</artifactItem> </artifactItem>
<artifactItem>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>${mssql-jdbc.version}</version>
<type>jar</type>
<outputDirectory>${auth.server.home}/providers</outputDirectory>
</artifactItem>
</artifactItems> </artifactItems>
</configuration> </configuration>
</execution> </execution>