ch-ui: Error: Connection failed (Invalid or missing ClickHouse credentials)

Environment

Docker

How did you encounter the bug?

Hi team,

I am able to access my DB with the clickhouse client without any problems, but I’m running into this error when opening ch-ui: Connection failed. Credentials have been cleared.

In the dev console, I can see this: Invalid or missing ClickHouse credentials:

{
    "customPath": "",
    "password": "",
    "requestTimeout": 30000,
    "url": "",
    "useAdvanced": false,
    "username": ""
}

I double-checked that the VITE_CLICKHOUSE_URL, VITE_CLICKHOUSE_USER, and VITE_CLICKHOUSE_PASS in the docker-compose.yml file are correct.

While researching a solution, I saw that another user had the same problem but never got an answer: https://www.reddit.com/r/Clickhouse/comments/1hrt2z0/update_chui_opensource_clickhouse_query_interface/

Could you please help?

Image

What did you expect?

I was expecting to be able to log in

Actual Result

I cannot log in

Browser

Safari

Browser Version

Version 18.4 (20621.1.15.11.8)

Version

REPOSITORY                                                               TAG       IMAGE ID       CREATED        SIZE
ghcr.io/caioricciuti/ch-ui                                               latest    81f1fb13fdee   6 days ago     193MB

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 26 (2 by maintainers)

Most upvoted comments

Ideally, I’d have wanted some feedback from the participants pinged above to confirm that for Clickhouse Server images 23.8+ (unlike in the case of @Jaeminst) they wrongfully mounted(empty) the config directories.

That said, I’d say that we explored a lot of cases and the issue can be closed; if they come back with feedback later we can reopen the issue or they can refer to this issue when they open a new one. @caioricciuti

Thanks for your reply.

Still same error. Btw I was able to connect with small Vite project and Clickhouse js.

I’ve tested in my local environment, and it appears to be a CORS issue. The clickhouse-server docker image version 23.8 is blocked by CORS, but when using the latest image, no errors occur and everything works as expected. The recommended solution is to upgrade to a clickhouse-server latest version.

Hey all! I’ll take a look on this issue… special thanks to @condrove10 for the participation, this is awesome!

I think this requires a bit more investigation from @caioricciuti; I’m not able to reproduce your error using the latest image of the container, can you tell me if you use a fork of this repo and eventually the commit hash? @iankressin


I was able to trace it back to: https://github.com/caioricciuti/ch-ui/blob/87f54228edaf8e564a0f6c7203e78d47b2435bd4/src/store/index.ts#L96 => https://github.com/caioricciuti/ch-ui/blame/f48c94bb6e2865808f3c69d010dfb1da81a4ace0/src/store/index.ts#L175

If you’re unsure or you don’t have SSL enabled;

  1. open your favorite browser
  2. open the DevTool window
  3. travel to the Network tab
  4. disable cache
  5. refresh the webpage of your CH-UI instance

I replicated what I think it’s your use case; you should see the response status of the API call to the HTTP API endpoint of your Clickhouse instance. @iankressin

Image

In case one container has to connect to another container that exposes a TCP/HTTP endpoint with TLS/SSL you have to add the Root CA to the CA store of the client container image:

# Add in the last stage if multistage docker container
ADD your_ca_root.crt /usr/local/share/ca-certificates/foo.crt
RUN chmod 644 /usr/local/share/ca-certificates/foo.crt && update-ca-certificates

This is how I’ve setup mine:

version: "3.9"
services:
  clickhouse:
    image: clickhouse/clickhouse-server:latest-alpine
    restart: unless-stopped
    volumes:
      - /opt/clickhouse/config.xml:/etc/clickhouse-server/config.xml
      - /var/opt/clickhouse/data:/var/lib/clickhouse
      - /var/opt/clickhouse/logs:/var/log/clickhouse-server
    ulimits:
      nofile:
        hard: 262144
        soft: 262144
    container_name: clickhouse
    environment:
      - CLICKHOUSE_PASSWORD=<password>
      # - CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1
      - CLICKHOUSE_USER=root
      - CLICKHOUSE_DB=clickhouse
    cap_add:
      - SYS_NICE # For adjusting process priorities
      - NET_ADMIN # For advanced network configurations
      - IPC_LOCK # For locking memory pages (mlock)
    networks:
      - traefik
      - clickhouse
    labels:
      - "traefik.enable=true"
      - "traefik.tcp.routers.clickhouse.rule=HostSNI(`clickhouse.msipro.local`)"
      - "traefik.tcp.routers.clickhouse.entrypoints=websecure"
      - "traefik.tcp.routers.clickhouse.service=clickhouse"
      - "traefik.tcp.routers.clickhouse.tls=true"
      - "traefik.tcp.services.clickhouse.loadbalancer.server.port=9000"
      - "traefik.http.routers.clickhouse-http.rule=Host(`clickhouse-http.msipro.local`)"
      - "traefik.http.routers.clickhouse-http.entrypoints=websecure"
      - "traefik.http.routers.clickhouse-http.service=clickhouse-http"
      - "traefik.http.routers.clickhouse-http.tls=true"
      - "traefik.http.services.clickhouse-http.loadbalancer.server.port=8123"
  ch-ui:
    image: ghcr.io/caioricciuti/ch-ui:latest
    dns:
      - "10.220.0.250"
    restart: unless-stopped
    environment:
      VITE_CLICKHOUSE_URL: "https://clickhouse-http.msipro.local"
      VITE_CLICKHOUSE_USER: "root"
      VITE_CLICKHOUSE_PASS: "<password>"
      # Advanced Options
      VITE_CLICKHOUSE_USE_ADVANCED: "true" # Enable advanced features
      # VITE_CLICKHOUSE_CUSTOM_PATH: "/custom/path"  # Optional: Custom HTTP path
      VITE_CLICKHOUSE_REQUEST_TIMEOUT: "30000" # Optional: Request timeout in milliseconds
    labels:
      - traefik.enable=true
      - traefik.http.routers.chu.rule=Host(`chu.msipro.local`)
      - traefik.http.routers.chu.entrypoints=web,websecure
      - traefik.http.routers.chu.service=chu
      - traefik.http.routers.chu.tls=true
      - traefik.http.services.chu.loadbalancer.server.port=5521
      - traefik.http.services.chu.loadbalancer.passhostheader=true
    networks:
      - clickhouse
      - traefik
networks:
  clickhouse: {}
  traefik:
    external: true

And have my Root CA in my client machine CA store:


Image

I suppose you use some reverse proxy with SSL/TLS (like Traefik) ? @iankressin

In that case you have to add your CA to your store. For example on Linux(Ubuntu/Debian):

sudo cp your_ca_root.crt /usr/local/share/ca-certificates/your_ca_root.crt
sudo chmod 644 /usr/local/share/ca-certificates/your_ca_root.crt
sudo update-ca-certificates

this way your browser adds to its store the certificate and you good to go! @mbUSC