You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using withRealmImportFile the realm file is copied into the container and then on startup imported by keycloak.
However, the copying uses default file attributes.
As it turns out this works for local development defaults but fails in our CI with this error:
INFO [org.keycloak.exportimport.singlefile.SingleFileImportProvider] (main) Full importing from file /opt/keycloak/bin/../data/import/realm.json
ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Failed to start server in (development) mode
ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: java.nio.file.AccessDeniedException: /opt/keycloak/bin/../data/import/realm.json
ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: /opt/keycloak/bin/../data/import/realm.json
It took me a long time to be able to debug into the container inside the CI server what is really tricky but I figured that the file permissions are wrong:
keycloak container itself is following some anti-pattern running as a dedicated keycloak user but the default user for copying files in root. A lot of suck problems could be prevented, if keycloak would run as root.
IMHO the umask of the OS is applied here and on CI this is more restrictive so there are no read permissions for the keycloak user.
Solution suggestion:
So in your code where you create the MountableFile
you should provide the file permissions as 0777 to the MountableFile static factory method (be aware of the leading zero that in Java is used for octal notation causing a lot of confusion as 0777 != 777).
Version
3.3.0
Expected behavior
Keycloak will startup and not raise AccessDeniedException
Actual behavior
Keycloak causes this error and then immediately exists without starting up:
INFO [org.keycloak.exportimport.singlefile.SingleFileImportProvider] (main) Full importing from file /opt/keycloak/bin/../data/import/realm.json
ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Failed to start server in (development) mode
ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: java.nio.file.AccessDeniedException: /opt/keycloak/bin/../data/import/realm.json
ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: /opt/keycloak/bin/../data/import/realm.json
How to Reproduce?
Good question. Probably test on a linux OS and change your system default umask to something like 077 (umask 077).
Relevant log output
INFO [org.keycloak.exportimport.singlefile.SingleFileImportProvider] (main) Full importing from file /opt/keycloak/bin/../data/import/realm.json
ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Failed to start server in (development) mode
ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: java.nio.file.AccessDeniedException: /opt/keycloak/bin/../data/import/realm.json
ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: /opt/keycloak/bin/../data/import/realm.json
Anything else?
No response
The text was updated successfully, but these errors were encountered:
Describe the bug
When using
withRealmImportFile
the realm file is copied into the container and then on startup imported by keycloak.However, the copying uses default file attributes.
As it turns out this works for local development defaults but fails in our CI with this error:
It took me a long time to be able to debug into the container inside the CI server what is really tricky but I figured that the file permissions are wrong:
IMHO there are several problems:
keycloak
user but the default user for copying files inroot
. A lot of suck problems could be prevented, if keycloak would run asroot
.keycloak
user.Solution suggestion:
So in your code where you create the
MountableFile
testcontainers-keycloak/src/main/java/dasniko/testcontainers/keycloak/ExtendableKeycloakContainer.java
Line 194 in 3bf421a
you should provide the file permissions as
0777
to theMountableFile
static factory method (be aware of the leading zero that in Java is used for octal notation causing a lot of confusion as0777 != 777
).Version
3.3.0
Expected behavior
Keycloak will startup and not raise AccessDeniedException
Actual behavior
Keycloak causes this error and then immediately exists without starting up:
How to Reproduce?
Good question. Probably test on a linux OS and change your system default umask to something like 077 (
umask 077
).Relevant log output
INFO [org.keycloak.exportimport.singlefile.SingleFileImportProvider] (main) Full importing from file /opt/keycloak/bin/../data/import/realm.json ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Failed to start server in (development) mode ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: java.nio.file.AccessDeniedException: /opt/keycloak/bin/../data/import/realm.json ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: /opt/keycloak/bin/../data/import/realm.json
Anything else?
No response
The text was updated successfully, but these errors were encountered: