dasniko / testcontainers-keycloak

A Testcontainer implementation for Keycloak IAM & SSO.
Apache License 2.0
328 stars 51 forks source link

Custom commands are overwritten by keycloak container #42

Closed ps-rseidl closed 2 years ago

ps-rseidl commented 2 years ago

hello!

could it be, that a custom command for the KeycloakContainer like this:

... keycloakContainer = new KeycloakContainer("quay.io/keycloak/keycloak:15.0.2"). withCopyFileToContainer().withCommand( "-c standalone.xml", "-b 0.0.0.0", "-Dkeycloak.profile.feature.upload_scripts=enabled", "-Dkeycloak.migration.action=import", "-Dkeycloak.migration.strategy=OVERWRITE_EXISTING", "-Dkeycloak.migration.provider=singleFile", "-Dkeycloak.migration.file=/tmp/keycloak.json" ) ...

is overwritten in the configure() method of the KeycloakContainer class?

@Override protected void configure() { withCommand( "-c standalone.xml", // don't start infinispan cluster "-b 0.0.0.0", // ensure proper binding "-Dkeycloak.profile.feature.upload_scripts=enabled" // enable script uploads );

I debugged a little bit and my custom command is set correctly until the configure method is called. Maybe it's the same issue as it was for the PostgreSQLContainer mentioned here? --> https://github.com/testcontainers/testcontainers-java/pull/938/files# and here --> https://github.com/testcontainers/testcontainers-java/issues/937

dasniko commented 2 years ago

Thanks for reporting. Without digging into the code, yes, this might be possible.

While this would be easy to fix for the current v1.x branch, it will be a bit more work for v2/keycloak-x, as we have to set some commands depending on other things (e.g. if there are custom extensions available or not).

Additionally, this may break things if users configure some strange things if they don't know exactly what they are doing. Keycloak might not be able to startup because of their misconfiguration and they are then blaming the lib...

Have to think about it a bit.

dasniko commented 2 years ago

Currently I won't allow to set custom commands, as, as already mentioned, Keycloak needs some complex configuration when starting the container and custom commands may destroy the default and needed configuration. This might yield in container not working and thus support issues in this project, where there is no cause in the project itself but in the wrong usage of custom commands. This would even become a bigger issue with the new Quarkus-based distro, which is now default and covered with v2 of this library.