thomasdarimont / keycloak-avatar-minio-extension

Simple example for managing avatar images with Keycloak

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NoRouteToHostException

jvinolas opened this issue · comments

I'm using keycloak in a container. Did the steps to include this extension (maven build and then I added provider and spi to standalone-ha.xml as stated in this issue: #2).
Also I started the minio container using docker-compose:

version: '3.7'

services:
  keycloak-avatars:
    image: minio/minio
    container_name: keycloak-avatars
    volumes:
      - ${DATA_FOLDER}/keycloak/avatars:/data
      - ${SRC_FOLDER}/keycloak/avatars:/root/.minio
    environment:
      - MINIO_ACCESS_KEY=AKIAIOSFODNN7EXAMPLE
      - MINIO_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
    command: "server /data"
    networks:
      - my_net

From keycloak container I'm able to ping minio container and minio start logs seem correct. I'm able to see the account-avatar theme but problems arise:

  • Loading user profile: The default image does not show and a java exception es thrown:
07:11:55,048 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (default task-6) Uncaught server error: java.lang.RuntimeException: java.net.NoRouteToHostException: No route to host (Host unreachable)
	at deployment.avatar-minio-extension-bundle-1.0.1.0-SNAPSHOT.ear.com.github.thomasdarimont.keycloak-avatar-minio-extension-module-1.0.1.0-SNAPSHOT.jar//com.github.thomasdarimont.keycloak.avatar.storage.minio.MinioTemplate.execute(MinioTemplate.java:33)
  • Then I try to upload file and when click on save also an error:
07:22:37,064 ERROR [org.keycloak.headers.DefaultSecurityHeadersProvider] (default task-4) MediaType not set on path /auth/realms/master/avatar-provider/, with response status 500
07:22:37,065 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (default task-4) Uncaught server error: javax.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error
	at org.keycloak.keycloak-services@12.0.4//org.keycloak.headers.DefaultSecurityHeadersProvider.addHeaders(DefaultSecurityHeadersProvider.java:75)
	at org.keycloak.keycloak-services@12.0.4//org.keycloak.services.filters.KeycloakSecurityHeadersFilter.filter(KeycloakSecurityHeadersFilter.java:39)
	at org.jboss.resteasy.resteasy-jaxrs@3.13.2.Final//org.jboss.resteasy.core.interception.ContainerResponseContextImpl.filter(ContainerResponseContextImpl.java:357)

What I'm missing here? I assumed that the minio host will use the docker name (keycloak-avatars) but It seems that the extension is looking for another host maybe? If this is the case, how can I set the minio host in this extension?

Ok, I found the minio host server var at:

private static final String DEFAULT_SERVER_URL = "http://172.17.0.2:9000";
private static final String DEFAULT_ACCESS_KEY = "AKIAIOSFODNN7EXAMPLE";
private static final String DEFAULT_SECRET_KEY = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY";
private MinioConfig minioConfig;
@Override
public AvatarStorageProvider create(KeycloakSession session) {
return new MinioAvatarStorageProvider(minioConfig);
}
@Override
public void init(Config.Scope config) {
String serverUrl = config.get("server-url", DEFAULT_SERVER_URL);
String accessKey = config.get("access-key", DEFAULT_ACCESS_KEY);
String secretKey = config.get("secret-key", DEFAULT_SECRET_KEY);

I'm not a java developer and I don't know if this envvar can be set anywhere instead of overwriting the variable in that file (is what I did and worked). I see at line 28 that it gets from config, but I can't find that config.

I'm just trying to get this going myself and I have the same errors you are getting.
The first error is actually fine. It is just telling you there is no image file there yet, and it carries on happily after reporting the error in a scary stack trace.
The second error is a real problem (and I get it too). So far I think it is telling us that it wants a Content Type header added to the POST request that results from submitting an HTML form. I've not found a way to actually do that on an HTML form. Doing it through other HTTP requests is fairly simple but what we have in this case is an HTML form. But maybe I've missed a vital piece of info in that, my HTML knowledge is rusty.
For configuring it I think you need to specify the three env vars you found in the code (ie DEFAULT_SERVER_URL, DEFAULT_ACCESS_KEY, DEFAULT_SECRET_KEY) in your docker-compose file on your keycloak service. Similar to what you did for the Minio env vars.