iFargle / headscale-webui

A simple Headscale web UI for small-scale deployments.
Other
668 stars 65 forks source link

Internal Server Error on "machines" #134

Open felixn-unity opened 10 months ago

felixn-unity commented 10 months ago

Hi

When clock on "machines" I get an "Internal Server Error", logs:

headscale-webui | [2024-01-28 09:45:42,035] INFO in helper: All startup checks passed. headscale-webui | [2024-01-28 09:45:42,036] INFO in helper: Testing API key validity. headscale-webui | [2024-01-28 09:45:42,256] INFO in helper: Key check passed. headscale-webui | [2024-01-28 09:45:42,256] INFO in headscale: Getting API key information headscale-webui | [2024-01-28 09:45:42,498] INFO in headscale: Looking for valid API Key... headscale-webui | [2024-01-28 09:45:42,498] INFO in headscale: Key found. headscale-webui | [2024-01-28 09:45:42,498] INFO in renderer: Rendering machine cards headscale-webui | [2024-01-28 09:45:42,499] INFO in headscale: Getting machine information headscale-webui | [2024-01-28 09:45:42,655] ERROR in app: Exception on /machines [GET] headscale-webui | Traceback (most recent call last): headscale-webui | File "/app/.venv/lib/python3.11/site-packages/flask/app.py", line 2190, in wsgi_app headscale-webui | response = self.full_dispatch_request() headscale-webui | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ headscale-webui | File "/app/.venv/lib/python3.11/site-packages/flask/app.py", line 1486, in full_dispatch_request headscale-webui | rv = self.handle_user_exception(e) headscale-webui | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ headscale-webui | File "/app/.venv/lib/python3.11/site-packages/flask/app.py", line 1484, in full_dispatch_request headscale-webui | rv = self.dispatch_request() headscale-webui | ^^^^^^^^^^^^^^^^^^^^^^^ headscale-webui | File "/app/.venv/lib/python3.11/site-packages/flask/app.py", line 1469, in dispatch_request headscale-webui | return self.ensure_sync(self.view_functions[rule.endpoint])(*view_args) headscale-webui | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ headscale-webui | File "/app/server.py", line 114, in decorated headscale-webui | return view_func(args, **kwargs) headscale-webui | ^^^^^^^^^^^^^^^^^^^^^^^^^^ headscale-webui | File "/app/server.py", line 207, in machines_page headscale-webui | cards = renderer.render_machines_cards() headscale-webui | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ headscale-webui | File "/app/renderer.py", line 490, in render_machines_cards headscale-webui | num_threads = len(machines_list["machines"]) headscale-webui | ~~~~~^^^^^^^^^^^^ headscale-webui | KeyError: 'machines'

felixn-unity commented 10 months ago

I can see headcale server has changed api to "/api/v1/node/" instead of "/api/v1/machine/"

can this will fix it : https://github.com/iFargle/headscale-webui/pull/127

RoFrie commented 8 months ago

Hi It seems ther is no final solution to this. Am I right? Initially I got following logs: [2024-03-25 14:04:15,122] INFO in helper: All startup checks passed. [2024-03-25 14:04:15,131] INFO in helper: Testing API key validity. [2024-03-25 14:04:15,349] INFO in helper: Key check passed. [2024-03-25 14:04:15,351] INFO in headscale: Getting API key information [2024-03-25 14:04:15,585] INFO in headscale: Looking for valid API Key... [2024-03-25 14:04:15,588] INFO in headscale: Key found. [2024-03-25 14:04:15,595] INFO in renderer: Rendering the Overview page [2024-03-25 14:04:15,597] INFO in renderer: Opening /etc/headscale/config.yaml [2024-03-25 14:04:15,624] INFO in headscale: Getting machine information [2024-03-25 14:04:15,845] ERROR in app: Exception on / [GET] Traceback (most recent call last): File "/app/.venv/lib/python3.11/site-packages/flask/app.py", line 2190, in wsgi_app response = self.full_dispatch_request() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/.venv/lib/python3.11/site-packages/flask/app.py", line 1486, in full_dispatch_request rv = self.handle_user_exception(e) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/.venv/lib/python3.11/site-packages/flask/app.py", line 1484, in full_dispatch_request rv = self.dispatch_request() ^^^^^^^^^^^^^^^^^^^^^^^ File "/app/.venv/lib/python3.11/site-packages/flask/app.py", line 1469, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(*view_args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/server.py", line 114, in decorated return view_func(args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/server.py", line 155, in overview_page render_page = renderer.render_overview(), ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/renderer.py", line 45, in render_overview machines_count = len(machines["machines"])


KeyError: 'machines'
[2024-03-25 14:04:16 +0100] [8] [ERROR] Error handling request /favicon.ico
Traceback (most recent call last):
File "/app/.venv/lib/python3.11/site-packages/gunicorn/workers/sync.py", line 136, in handle
self.handle_request(listener, req, client, addr)
File "/app/.venv/lib/python3.11/site-packages/gunicorn/workers/sync.py", line 169, in handle_request
resp, environ = wsgi.create(req, client, addr,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.11/site-packages/gunicorn/http/wsgi.py", line 183, in create
path_info = path_info.split(script_name, 1)[1]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

Then I used the fork l00ps/fix-update-machine-to-node: 
Which made a better a little bit:
[2024-03-25 14:56:29,937] ERROR in app: Exception on /machines [GET]
Traceback (most recent call last):
  File "/app/.venv/lib/python3.11/site-packages/flask/app.py", line 2190, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.11/site-packages/flask/app.py", line 1486, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.11/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.11/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/server.py", line 114, in decorated
    return view_func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/server.py", line 207, in machines_page
    cards = renderer.render_machines_cards()
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/renderer.py", line 521, in render_machines_cards
    content = content+str(sorted_machines[index])
                          ~~~~~~~~~~~~~~~^^^^^^^
KeyError: 0
[2024-03-25 14:56:30 +0100] [8] [ERROR] Error handling request /favicon.ico
Traceback (most recent call last):
  File "/app/.venv/lib/python3.11/site-packages/gunicorn/workers/sync.py", line 136, in handle
    self.handle_request(listener, req, client, addr)
  File "/app/.venv/lib/python3.11/site-packages/gunicorn/workers/sync.py", line 169, in handle_request
    resp, environ = wsgi.create(req, client, addr,
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.11/site-packages/gunicorn/http/wsgi.py", line 183, in create
    path_info = path_info.split(script_name, 1)[1]
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

How can we help to get a final fix for that?
Thanks a lot
yodaphone commented 8 months ago

Not sure if this is related to my issue, but I'm getting the same error but this is my log

I went into the shell of headscale-webui and

  1. ping to headscale:8080 works fine
  2. wget headscale:8080 returns a 404 error (which is fine too)
  3. when i did wget headscale:8080/admin I'm getting a Permission denied error
~ $ ping headscale:8080
PING headscale:8080 (172.31.0.2): 56 data bytes
64 bytes from 172.31.0.2: seq=0 ttl=42 time=0.576 ms
64 bytes from 172.31.0.2: seq=1 ttl=42 time=0.270 ms
64 bytes from 172.31.0.2: seq=2 ttl=42 time=0.442 ms
^C
--- headscale:8080 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.270/0.429/0.576 ms
~ $ wget headscale:8080
Connecting to headscale:8080 (172.31.0.2:8080)
wget: server returned error: HTTP/1.1 404 Not Found
~ $ wget headscale:8080/health
Connecting to headscale:8080 (172.31.0.2:8080)
wget: can't open 'health': Permission denied
~ $

PS: headscale core works fine though. this error only happens when i do headscale.domain.com/admin

My dockercompose file

services:
  headscale:
    container_name: headscale
    image: headscale/headscale:0.23.0-alpha5
    restart: unless-stopped
    ports:
      - 8088:8080
    volumes:
      - ./container-config:/etc/headscale
      - ./container-data:/var/lib/headscale
    entrypoint: headscale serve
    networks:
      headscale-nw:

  headscale-webui:
    image: ghcr.io/ifargle/headscale-webui:latest
    container_name: headscale-webui
    depends_on:
      - headscale
    ports:
      - 5001:5000
    environment:
      - TZ=America/New_York
      - COLOR=red                              # Use the base colors (ie, no darken-3, etc) -
      - HS_SERVER=headscale:8080    # Reachable endpoint for your Headscale server
      - DOMAIN_NAME=https://headscale.<domain>.com
      - SCRIPT_NAME=/admin                     # This is your applications base path (wsgi requires the name "SCRIPT_NAME").  Remove if you are hosing at the root /
      - KEY="Lifesb80eHfByzo+wsWJ8+PhDP7clJS+mkdg/wsMe2A8="             # Generate with "openssl rand -base64 32" - used to encrypt your key on disk.
      - AUTH_TYPE=basic                         # AUTH_TYPE is either Basic or OIDC.  Empty for no authentication
      - LOG_LEVEL=DEBUG                         # Log level.  "DEBUG", "ERROR", "WARNING", or "INFO".  Default "INFO"
      - BASIC_AUTH_USER=admin                   # Used for basic auth
      - BASIC_AUTH_PASS=SomePass                  # Used for basic auth
    volumes:
      - ./volume:/data                         # Headscale-WebUI's storage.  Make sure ./volume is readable by UID 1000 (chown 1000:1000 ./volume)
      - ./container-config:/etc/headscale/:ro # Headscale's config storage location.  Used to read your Headscale config.
    networks:
      headscale-nw:

networks:
  headscale-nw:
    external: true
 ✔ Container headscale        Created                                                                                                                                                                                                   0.1s
 ✔ Container headscale-webui  Created                                                                                                                                                                                                   0.1s
Attaching to headscale, headscale-webui
headscale        | 2024-03-29T12:33:10Z TRC DNS configuration loaded dns_config={"Nameservers":["1.1.1.1","192.168.11.1"],"Proxied":true,"Resolvers":[{"Addr":"1.1.1.1"},{"Addr":"192.168.11.1"}]}
headscale        | 2024-03-29T12:33:10Z INF Opening database database=sqlite3 path=/var/lib/headscale/db.sqlite
headscale        | 2024-03-29T12:33:11Z INF Setting up a DERPMap update worker frequency=86400000
headscale        | 2024-03-29T12:33:11Z INF listening and serving HTTP on: 0.0.0.0:8080
headscale        | 2024-03-29T12:33:11Z INF listening and serving metrics on: 127.0.0.1:9090
headscale-webui  | [2024-03-29 08:33:12 -0400] [1] [INFO] Starting gunicorn 20.1.0
headscale-webui  | [2024-03-29 08:33:12 -0400] [1] [INFO] Listening at: http://0.0.0.0:5000 (1)
headscale-webui  | [2024-03-29 08:33:12 -0400] [1] [INFO] Using worker: sync
headscale-webui  | [2024-03-29 08:33:12 -0400] [8] [INFO] Booting worker with pid: 8
headscale-webui  | [2024-03-29 08:33:14,460] INFO in server: Headscale-WebUI Version:  v0.6.2 / main
headscale-webui  | [2024-03-29 08:33:14,460] INFO in server: LOG LEVEL SET TO DEBUG
headscale-webui  | [2024-03-29 08:33:14,460] INFO in server: DEBUG STATE:  True
headscale-webui  | [2024-03-29 08:33:14,460] INFO in server: Loading basic auth libraries and configuring app...
headscale-webui  | [2024-03-29 08:33:42,742] ERROR in app: Exception on / [GET]
headscale-webui  | Traceback (most recent call last):
headscale-webui  |   File "/app/.venv/lib/python3.11/site-packages/flask/app.py", line 2190, in wsgi_app
headscale-webui  |     response = self.full_dispatch_request()
headscale-webui  |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
headscale-webui  |   File "/app/.venv/lib/python3.11/site-packages/flask/app.py", line 1486, in full_dispatch_request
headscale-webui  |     rv = self.handle_user_exception(e)
headscale-webui  |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
headscale-webui  |   File "/app/.venv/lib/python3.11/site-packages/flask/app.py", line 1484, in full_dispatch_request
headscale-webui  |     rv = self.dispatch_request()
headscale-webui  |          ^^^^^^^^^^^^^^^^^^^^^^^
headscale-webui  |   File "/app/.venv/lib/python3.11/site-packages/flask/app.py", line 1469, in dispatch_request
headscale-webui  |     return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
headscale-webui  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
headscale-webui  |   File "/app/server.py", line 114, in decorated
headscale-webui  |     return view_func(*args, **kwargs)
headscale-webui  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^
headscale-webui  |   File "/app/server.py", line 141, in overview_page
headscale-webui  |     pass_checks = str(helper.load_checks())
headscale-webui  |                       ^^^^^^^^^^^^^^^^^^^^
headscale-webui  |   File "/app/helper.py", line 299, in load_checks
headscale-webui  |     if access_checks() != "Pass": return 'error_page'
headscale-webui  |        ^^^^^^^^^^^^^^^
headscale-webui  |   File "/app/helper.py", line 173, in access_checks
headscale-webui  |     response = requests.get(str(url)+"/health")
headscale-webui  |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
headscale-webui  |   File "/app/.venv/lib/python3.11/site-packages/requests/api.py", line 73, in get
headscale-webui  |     return request("get", url, params=params, **kwargs)
headscale-webui  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
headscale-webui  |   File "/app/.venv/lib/python3.11/site-packages/requests/api.py", line 59, in request
headscale-webui  |     return session.request(method=method, url=url, **kwargs)
headscale-webui  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
headscale-webui  |   File "/app/.venv/lib/python3.11/site-packages/requests/sessions.py", line 587, in request
headscale-webui  |     resp = self.send(prep, **send_kwargs)
headscale-webui  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
headscale-webui  |   File "/app/.venv/lib/python3.11/site-packages/requests/sessions.py", line 695, in send
headscale-webui  |     adapter = self.get_adapter(url=request.url)
headscale-webui  |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
headscale-webui  |   File "/app/.venv/lib/python3.11/site-packages/requests/sessions.py", line 792, in get_adapter
headscale-webui  |     raise InvalidSchema(f"No connection adapters were found for {url!r}")
headscale-webui  | requests.exceptions.InvalidSchema: No connection adapters were found for 'headscale:8080/health'
wenco commented 7 months ago

fix: https://github.com/iFargle/headscale-webui/pull/131