Quick and easy way to toggle dashboard at runtime

The dashboard is very useful, but:

  • once my server is running properly, I want to disable it
  • if I run into problems, I want to enable it for debugging / troubleshooting purposes

However it is configured in the static config, so I must restart traefik (which impacts dependent services).

I wanted a quick way to do this, maybe in a script. What I tried:

  • I put all my static config in docker-compose.yml
  • I created a traefik.yml file and put only the api config in there, nothing else
  • I created a toggle-dashboard.sh bash script that edits traefik.yml by toggling dashboard: true between true/false, and then runs docker compose restart traefik
  • This minimises bugs by editing a simple static file, instead of a large complex compose file

What I discovered is that traefik doesn't work properly when some static config is in docker-compose.yml and some in traefik.yml. So this approach failed.

What other options are there, if any? What do other people do? (Maybe others just leave the dashboard, with basic auth, running all the time?)

Update: I added a feature request to the repo (for toggling the api/dashboard at runtime via dynamic config).

You should be able to add and remove the dashboard router in a dynamic config file, loaded via provider.file.

1 Like

Thanks bluepuma, I didn't think of that.

This is my dynamic config file:

http:
  routers:
    dashboard:
      entrypoints: websecure
      rule: Host(`dashboard.example.com`) && PathPrefix(`/api`, `/dashboard`, `/debug`)
      middlewares: dashboard-auth
      service: api@internal
  middlewares:
    dashboard-auth:
      basicAuth:
        usersFile: /foo/bar/users

So if I understand you correctly, at runtime, I can simply delete those lines. Then traefik will delete the associated router, which means that even though the api/dashboard is enabled in the static config (--api=true), any requests to https://dashboard.example.com/dashboard/ will not have a matching router, so it will respond with 404.

If that is correct, then there maybe is an even more elegant solution, which is to have multiple dynamic config files (file watcher in a directory). Then instead of editing the file (potential for errors), script can run:

  • to enable cp dashboard.yml /path/on/host/to/traefik/dynamic-config/dashboard.yml
  • to disable rm /path/on/host/to/traefik/dynamic-config/dashboard.yml

What do you think... good/bad idea?

Yes, that should work, just enable watch on provider.file.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.