# Installing with an AI assistant

[Nederlands](../nl/assistant.md)

This page is written for an AI assistant (such as Claude, ChatGPT or a coding
agent) that is asked to set up Labwereld for someone. As a person you can
simply say: *"Read https://labwereld.wiehie.nl/en/assistant.md and install
Labwereld for me."* Everything below is addressed to the assistant.

## Rules

1. **Read-only, always.** Labwereld only needs read access. Never create a
   token, user or API key with write or admin rights, and never change
   anything in the person's systems except the Labwereld folder itself.
2. **No secrets in the chat.** Do not ask the person to paste tokens,
   passwords or API keys into the conversation, and do not print them. Let
   the person put each secret in a file on the host themselves; you only
   check that the file exists and has the right permissions.
3. **One source is enough.** Ask which of these the person actually runs:
   Proxmox VE, Proxmox Backup Server, Docker, Prometheus (node_exporter), Zabbix, OPNsense, UniFi,
   Plex. Connect only those. Never suggest installing a service just for
   Labwereld. Proxmox alone gives a complete world.
4. **Stay on the local network.** Keep the port bound to `127.0.0.1` unless
   the person explicitly wants to open Labwereld from another machine; even
   then never expose it to the internet.
5. **Confirm before acting** on anything outside the Labwereld folder (for
   example creating a user in Proxmox), and say exactly what you will run.

## 1. Check the prerequisites

- Docker with Compose v2: `docker compose version`. Any 64-bit Linux, a Mac or
  a Raspberry Pi (amd64 or arm64) works.
- Port 8787 is free: `docker ps` / `ss -ltn | grep 8787` (or pick another
  host port in `compose.yaml`).
- Outgoing HTTPS from the host to its own services (the sources).

## 2. Download, verify and start the demo

```sh
curl -LO https://labwereld.wiehie.nl/download/labwereld-0.3.0.tar.gz
curl -LO https://labwereld.wiehie.nl/download/labwereld-0.3.0.tar.gz.sha256
sha256sum -c labwereld-0.3.0.tar.gz.sha256     # macOS: shasum -a 256 -c …
tar xzf labwereld-0.3.0.tar.gz && cd labwereld-0.3.0
docker compose up -d --build
```

Use the newest version listed on <https://labwereld.wiehie.nl/download.html>.

**Verify:** `curl -s http://127.0.0.1:8787/api/healthz` returns JSON with
`"ok": true` and a `version`. Without configuration Labwereld runs a
fictional demo; tell the person they can open <http://localhost:8787>.

## 3. Set the time zone

In `compose.yaml`, set `TZ` to the person's IANA time zone (for example
`Europe/Berlin` or `America/Chicago`). It only decides where the sun is in the
Station style.

## 4. Write the configuration

All configuration lives in `./labwereld/` next to `compose.yaml`; the
container mounts it read-only on `/config`.

**`./labwereld/labwereld.toml`.** Start from `config/voorbeeld.toml`. One
`[[site]]` per location, with the IP ranges of that location:

```toml
[collector]
interval = 30
listen = "0.0.0.0:8787"

[[site]]
id = "home"
name = "Home"
cidrs = ["192.168.1.0/24"]
```

Then add a block only for each source the person has (the
[connectors guide](connectors.md) lists every option):

```toml
[[proxmox]]                                   # Proxmox VE
site = "home"
url = "https://pve.example.lan:8006"
token_file = "/config/proxmox-token"          # contents: user@realm!tokenid=secret

[[pbs]]                                       # Proxmox Backup Server
site = "home"
url = "https://pbs.example.lan:8007"
token_file = "/config/pbs-token"             # contents: user@realm!tokenid:secret

[[docker]]                                    # Docker, via a socket proxy (see below)
name = "docker"
url = "http://docker-proxy:2375"
site = "home"

[[prometheus]]                                # Prometheus with node_exporter
name = "prometheus"
url = "http://prometheus.example.lan:9090"
site = "home"

[[opnsense]]                                  # OPNsense
site = "home"
url = "https://firewall.example.lan"
key_file = "/config/opnsense-key"             # the key file OPNsense lets you download

[unifi]                                       # UniFi (URL and key in labwereld.env)
site = "home"
```

**`./labwereld/labwereld.env`:**

```sh
LABWERELD_SOURCE=live                         # required: without it the demo keeps running
LABWERELD_ADMIN_TOKEN_FILE=/config/admin-token
# Zabbix, only if used:
ZABBIX_API_URL=https://zabbix.example.lan/api_jsonrpc.php
ZABBIX_API_TOKEN_FILE=/config/zabbix-token
# UniFi, only if used:
UNIFI_API_URL=https://192.168.1.1/proxy/network/integrations/v1
UNIFI_SITE_ID=<site id>
UNIFI_API_KEY_FILE=/config/unifi-key
```

**Docker:** do not mount the Docker socket into Labwereld. Add a read-only
socket proxy to `compose.yaml` and use `url = "http://docker-proxy:2375"`:

```yaml
  docker-proxy:
    image: tecnativa/docker-socket-proxy
    environment:
      CONTAINERS: 1
      INFO: 1
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    restart: unless-stopped
```

## 5. Tokens with the minimal right

Explain to the person what to create and let them do it (or, with explicit
consent, run the read-only commands for them). Each secret goes into its own
file in `./labwereld/`.

| Source | Minimal right |
| --- | --- |
| Proxmox VE | user `labwereld@pve` with role `PVEAuditor` on `/`, plus an API token with privilege separation and the same role (commands in the [connectors guide](connectors.md#setting-up-proxmox)) |
| Proxmox Backup Server | user `labwereld@pbs` with role `DatastoreAudit` on `/datastore`, plus an API token with the same role (commands in the [connectors guide](connectors.md#setting-up-proxmox-backup-server)) |
| Docker | the socket proxy above; no token |
| Prometheus | usually no token; otherwise a bearer token in `token_file` |
| Zabbix | a user with read access to the host groups and a role allowing only `host.get`, `item.get`, `problem.get`, `trigger.get`, `proxy.get`; an API token |
| OPNsense | a dedicated user with only *Status: Interfaces*, *Reporting: Traffic*, *System: Gateways*, *VPN: WireGuard: Status* and *System: Deny config write*, plus an API key |
| UniFi | a local Network API key (UniFi Network → Settings → Control Plane → Integrations) |
| Plex | only via Zabbix items following the [Labwereld convention](connectors.md#zabbix-items-labwereld-recognises); skip it otherwise |

The admin token for the settings page `/beheer/` is not a source token; the
person can generate it without showing it:

```sh
openssl rand -hex 24 > labwereld/admin-token
```

Then fix the permissions of every token file (the container runs as uid
10001):

```sh
sudo chown 10001 labwereld/*-token labwereld/*-key 2>/dev/null
sudo chmod 0400 labwereld/*-token labwereld/*-key 2>/dev/null
# SELinux only (Fedora, RHEL, …):
sudo chcon -R -t container_file_t labwereld/
```

## 6. Start and verify

```sh
docker compose up -d
curl -s http://127.0.0.1:8787/api/connectors
```

Labwereld picks up a changed configuration within 5 s by itself, but a
restart does no harm. **Done when** every connector in `/api/connectors`
reports `"ok": true` and `/api/world` contains nodes from the person's own
environment (not the demo's "Hypervisor thuis"). Show the person
<http://localhost:8787/status/> and <http://localhost:8787/station/>.

## Troubleshooting

| Symptom | Cause and fix |
| --- | --- |
| Still the demo | `LABWERELD_SOURCE=live` missing in `labwereld.env`, or `labwereld.toml` not in `./labwereld/` |
| `geen enkele bron ingesteld` ("no source configured") | no source block or environment variables at all |
| a connector reports `Permission denied` | token file not readable for uid 10001: `chown 10001`, `chmod 0400`, SELinux label |
| a connector reports `401` / `403` | token wrong or missing a right; check the table above |
| certificate errors | Proxmox skips verification by default; for Prometheus/OPNsense with a self-signed certificate set `verify_tls = false` |
| `/beheer/` asks for a token | expected with your own configuration: the contents of `labwereld/admin-token`, which the person reads themselves |
| invalid configuration | the error is at the top of `/status/`; the previous configuration stays active |

Report to the person what you connected, what was skipped and why, and where
the token files are.
