[keycloak-dev] Connect Keycloak to Galera cluster with Docker

Anthony Durot adurot.pro at gmail.com
Thu Apr 11 13:15:31 EDT 2019


Hi everyone,

I need to connect a Keycloak container to a MariaDB Galera cluster for a
project.
Currently, with the Docker image you can set up environment variables such
as DB_VENDOR, DB_ADDR, DB_PORT, and so on..., and these environment
variables will be added to the connection string of mariaDB.

This is done in [1]:

/subsystem=datasources/data-source=KeycloakDS:
add(jndi-name=java:jboss/datasources/KeycloakDS,enabled=true,use-java-context=true,use-ccm=true,
connection-url=jdbc:mariadb://*${env.DB_ADDR:mariadb}*:*${env.DB_PORT:3306}*
/*${env.DB_DATABASE:keycloak}${env.JDBC_PARAMS:*}, driver-name=mariadb)

As you can see, we put environment variables for the address, port,
database, and so on... But what if I want to connect Keycloak to a cluster
for exemple ?
MariaDB provides a JDBC with this connection string :
jdbc:(mysql|mariadb):[replication:|failover:|sequential:|aurora:]//<hostDescription>[,<hostDescription>...]/[database][?<key1>=<value1>[&<key2>=<value2>]

As you can see, we need to put multiple hostDescription, and currently
it's impossible because we only have a single env.DB_ADDR.
Moreover, when you want to be connected to a cluster, you need to
specify *[replication:|failover:|sequential:|aurora:] *and it's also
currently impossible to do it.

I suggest that maybe we can change [1]
... /subsystem=datasources/data-source=KeycloakDS:add(jndi-name=java:jboss/datasources/KeycloakDS,enabled=true,use-java-context=true,use-ccm=true,
    connection-url=jdbc:mariadb://*${env.DB_ADDR:mariadb}*:*${env.DB_PORT:3306}*/*${env.DB_DATABASE:keycloak}${env.JDBC_PARAMS:*},
driver-name=mariadb)

to:

... /subsystem=datasources/data-source=KeycloakDS:add(jndi-name=java:jboss/datasources/KeycloakDS,enabled=true,use-java-context=true,use-ccm=true,
    connection-url=jdbc:mariadb:*${env.DB_CONNECTION_TYPE:}*//${env.DB_ADDR:mariadb}:${env.DB_PORT:3306}/${env.DB_DATABASE:keycloak}${env.JDBC_PARAMS:},
driver-name=mariadb)


As for the list of host connection, I admit that I don't have any
clever ideas, do you have any suggestion ?

Thank you all for your time

Best regards,
Anthony


[1]
https://github.com/jboss-dockerfiles/keycloak/tree/master/server/tools/cli/databases/mariadb


More information about the keycloak-dev mailing list