Configuration Reference
Every Labelgate setting with its environment variable and default.
Each table lists the config file key, its environment variable, the default and what it does. See Configuration for how to set them.
- Durations need a unit:
30s,5m,24h. Write0sfor zero. - Lists are comma-separated in environment variables:
a.example.com,b.example.com. - Keys shown as
<name>or<id>are map sections. They work only in the config file.
General
| Key | Env var | Default | Meaning |
|---|---|---|---|
mode | LABELGATE_MODE | main | main, or agent for a remote Docker host. |
log_level | LABELGATE_LOG_LEVEL | info | debug, info, warn or error. |
log_format | LABELGATE_LOG_FORMAT | text | text or json. |
label_prefix | LABELGATE_LABEL_PREFIX | labelgate | First part of every label key. Lowercase letters, digits, ., _, -. |
default_tunnel | LABELGATE_DEFAULT_TUNNEL | - | Tunnel for labels without tunnel. Empty means cloudflare.tunnel_id; otherwise a name from cloudflare.tunnels. |
instance_id | LABELGATE_INSTANCE_ID | - | Only to recover after losing the database. 4-32 lowercase letters and digits. See Ownership. |
skip_credential_validation | LABELGATE_SKIP_CREDENTIAL_VALIDATION | false | Start without checking the Cloudflare tokens, and without requiring one. |
| - | LABELGATE_CONFIG | - | Path to the config file. |
Cloudflare
| Key | Env var | Default | Meaning |
|---|---|---|---|
cloudflare.api_token | LABELGATE_CLOUDFLARE_API_TOKEN | - | Required unless you use cloudflare.credentials. The main API token. |
cloudflare.account_id | LABELGATE_CLOUDFLARE_ACCOUNT_ID | - | Account of the tunnel. Required with tunnel_id. |
cloudflare.tunnel_id | LABELGATE_CLOUDFLARE_TUNNEL_ID | - | The default tunnel for tunnel labels. Uses cloudflare.api_token. |
cloudflare.credentials.<name>.api_token | file only | - | Required. An extra API token. |
cloudflare.credentials.<name>.zones | file only | all zones | Zones this token is used for, e.g. example.com. |
cloudflare.tunnels.<name>.account_id | file only | - | Required. Account of an extra tunnel. |
cloudflare.tunnels.<name>.tunnel_id | file only | - | Required. ID of an extra tunnel. |
cloudflare.tunnels.<name>.credential | file only | cloudflare.api_token | Which credentials name manages this tunnel. |
Names under credentials and tunnels use lowercase letters, digits, - and _. default is reserved.
The tunnel's connector token (TUNNEL_TOKEN) is not a Labelgate setting. It belongs to cloudflared; see cloudflared Setup.
Several API tokens
Use this when your zones are in different Cloudflare accounts, or need different tokens.
cloudflare:
api_token: main-token
credentials:
company:
api_token: company-token
zones: [company.io]
tunnels:
secondary:
account_id: company-account-id
tunnel_id: company-tunnel-id
credential: companyHow Labelgate picks the token for a hostname:
- A
credentiallabel wins.credential: defaultmeanscloudflare.api_token. - Otherwise, the token that can see the hostname's zone. If several can, the longest zone wins; on a tie,
cloudflare.api_tokenwins. - If no token fits, the label shows an error.
In zones, example.com means that zone. *.example.com matches zones below it, such as dev.example.com, but not example.com itself.
A tunnel label must name a configured tunnel (or its ID). An unknown tunnel is an error.
Sync and cleanup
| Key | Env var | Default | Meaning |
|---|---|---|---|
sync.interval | LABELGATE_SYNC_INTERVAL | 5m | Full check against Cloudflare, on top of Docker events. Minimum 10s. |
sync.remove_delay | LABELGATE_SYNC_REMOVE_DELAY | 30m | Wait this long after a container is gone before deleting its resources (cleanup: true). 0s deletes at once. |
sync.orphan_ttl | LABELGATE_SYNC_ORPHAN_TTL | 0s | Forget kept resources (cleanup: false) after this long. Only the database entry is removed, never the Cloudflare object. 0s = never. |
sync.agent_grace | LABELGATE_SYNC_AGENT_GRACE | 24h | Keep an offline agent's resources this long. Minimum 5m. |
Labelgate only ever deletes resources it created. See Ownership & Conflicts.
Docker
| Key | Env var | Default | Meaning |
|---|---|---|---|
docker.endpoint | LABELGATE_DOCKER_ENDPOINT | unix:///var/run/docker.sock | Docker daemon: unix:///path or tcp://host:port. |
docker.poll_interval | LABELGATE_DOCKER_POLL_INTERVAL | 2m | Re-list all containers this often, on top of Docker events. Must be above 0s. |
docker.filter_label | LABELGATE_DOCKER_FILTER_LABEL | - | Only read containers with this label: key or key=value. |
docker.tls.ca | LABELGATE_DOCKER_TLS_CA | - | CA file to check a tcp:// daemon's certificate. |
docker.tls.cert | LABELGATE_DOCKER_TLS_CERT | - | Client certificate. Set together with key. |
docker.tls.key | LABELGATE_DOCKER_TLS_KEY | - | Client key. |
docker.tls.insecure_skip_verify | LABELGATE_DOCKER_TLS_INSECURE_SKIP_VERIFY | false | Do not check the daemon's certificate. For testing only. |
A tcp:// endpoint uses TLS only when a docker.tls.* key is set. Without one, the connection is plain and unauthenticated.
Database
| Key | Env var | Default | Meaning |
|---|---|---|---|
db.path | LABELGATE_DB_PATH | /app/config/labelgate.db | SQLite file. Keep /app/config on a volume and back it up. |
API and dashboard
| Key | Env var | Default | Meaning |
|---|---|---|---|
api.enabled | LABELGATE_API_ENABLED | true | Serve the API and the dashboard. |
api.address | LABELGATE_API_ADDRESS | :28111 | Listen address. |
api.base_path | LABELGATE_API_BASE_PATH | /api | API path. Starts with /, no trailing /, not /dashboard. |
api.token | LABELGATE_API_TOKEN | - | Required for the API and the dashboard. At least 16 characters. If empty, both are off. |
Generate the token with openssl rand -hex 32. The dashboard is at /dashboard/. Do not expose the port to the internet; put it behind a VPN, a TLS reverse proxy or Cloudflare Access.
Endpoints
All endpoints except /health need the header Authorization: Bearer <api.token>. Paths below use the default /api.
| Endpoint | Returns |
|---|---|
GET /api/health | {"status":"ok"}. No token needed. |
GET /api/overview | Counts, sync status and agent summary. sync.problems lists the current problems (up to 200), sync.problems_total counts all of them. |
GET /api/resources/dns | DNS records. |
GET /api/resources/tunnels | Tunnel routes. |
GET /api/resources/access | Access applications. |
GET /api/agents | Agents. |
GET /api/version | Version. |
Resource lists accept status, agent_id, hostname, limit (default 500, max 1000) and offset.
Healthcheck
The image runs labelgate healthcheck. It reads the same configuration, so a custom api.address or api.base_path just works.
- Main with the API on and an
api.token: healthy when/healthanswers within 2 seconds. - Main with the API off or no
api.token: always healthy. - Agent: inbound agents check that
connect.listenaccepts connections; outbound agents are always healthy.
Retry
Applies to Cloudflare calls and agent reconnects.
| Key | Env var | Default | Meaning |
|---|---|---|---|
retry.attempts | LABELGATE_RETRY_ATTEMPTS | 3 | Maximum attempts. At least 1. |
retry.delay | LABELGATE_RETRY_DELAY | 1s | First wait between attempts. Above 0s. |
retry.max_delay | LABELGATE_RETRY_MAX_DELAY | 30s | Longest wait. At least retry.delay. |
retry.backoff | LABELGATE_RETRY_BACKOFF | 2 | Multiply the wait by this after each attempt. At least 1. |
Agents: main instance
Settings on the main instance for accepting agents.
| Key | Env var | Default | Meaning |
|---|---|---|---|
agent.enabled | LABELGATE_AGENT_ENABLED | false | Accept agents. |
agent.listen | LABELGATE_AGENT_LISTEN | :28112 | Listen address. Agents connect to wss://<host>:28112/ws. |
agent.accept_token | LABELGATE_AGENT_ACCEPT_TOKEN | - | One shared token for agents not listed in agent.agents. See Agent tokens. |
agent.accept_hostnames | LABELGATE_AGENT_ACCEPT_HOSTNAMES | any | Hostnames those agents may use, as globs: *.edge.example.com. A wildcard hostname needs an identical entry. |
agent.accept_tunnels | LABELGATE_AGENT_ACCEPT_TUNNELS | default tunnel | Tunnels those agents may use: default, a name from cloudflare.tunnels, or a tunnel ID. |
agent.accept_services | LABELGATE_AGENT_ACCEPT_SERVICES | IP addresses | Extra tunnel service hosts those agents may use: hostname globs, IPs or CIDRs. |
agent.tls.cert | LABELGATE_AGENT_TLS_CERT | - | Server certificate. Turns on wss://. Set together with key. |
agent.tls.key | LABELGATE_AGENT_TLS_KEY | - | Server key. |
agent.tls.ca | LABELGATE_AGENT_TLS_CA | system CAs | CA to check inbound agents' certificates. |
agent.tls.insecure_skip_verify | LABELGATE_AGENT_TLS_INSECURE_SKIP_VERIFY | false | Do not check inbound agents' certificates. For testing only. |
Per-agent entries
agent.agents.<id> is file only. <id> is the agent ID: lowercase letters, digits, ., _ and -, up to 63 characters. It must equal the agent's connect.agent_id. Write a dotted ID as one key: YAML nas.lan:, TOML [agent.agents."nas.lan"].
| Key | Default | Meaning |
|---|---|---|
token | - | Required. This agent's token. See Agent tokens. |
name | - | Display name in the dashboard. |
default_tunnel | default_tunnel | Tunnel for this agent's labels without tunnel. |
tunnels | its default tunnel | Tunnels this agent may use. |
hostnames | any | Hostnames this agent may use, as globs. A wildcard hostname needs an identical entry. |
services | IP addresses | Extra tunnel service hosts this agent may use: hostname globs, IPs or CIDRs. |
connect_to | - | ws:// or wss:// URL ending in /ws. The main dials the agent (inbound mode). |
agent:
enabled: true
agents:
edge1:
token: "<openssl rand -hex 32>"
hostnames: ["*.edge1.example.com"]
services: ["web", "172.20.0.0/16"]Agent tokens
agent.agents.<id>.token, agent.accept_token and connect.token must be at least 32 characters with at least 12 different characters. Labelgate does not start otherwise. Generate one with:
openssl rand -hex 32Agents: agent instance
Used only with mode: agent. In agent mode, only these, log_*, docker and retry are used.
| Key | Env var | Default | Meaning |
|---|---|---|---|
connect.mode | LABELGATE_CONNECT_MODE | outbound | outbound: the agent dials the main. inbound: the main dials the agent. |
connect.endpoint | LABELGATE_CONNECT_ENDPOINT | - | Required for outbound. Main URL including /ws: wss://main.example.com:28112/ws. |
connect.listen | LABELGATE_CONNECT_LISTEN | - | Required for inbound. Listen address, e.g. :28113. |
connect.token | LABELGATE_CONNECT_TOKEN | - | Required. Same token as on the main. See Agent tokens. |
connect.agent_id | LABELGATE_CONNECT_AGENT_ID | from machine ID | Agent ID. Takes priority over /etc/machine-id (mount it into the container; the first 12 hex characters are used). With neither, the container hostname is used, which is not stable and logs a warning. A named agent must set it to match the main. |
connect.heartbeat_interval | LABELGATE_CONNECT_HEARTBEAT_INTERVAL | 30s | How often the agent sends a full report. Minimum 1s. |
connect.tls.ca | LABELGATE_CONNECT_TLS_CA | system CAs | CA to check the main's certificate. |
connect.tls.cert | LABELGATE_CONNECT_TLS_CERT | - | Inbound only: server certificate. Set together with key. |
connect.tls.key | LABELGATE_CONNECT_TLS_KEY | - | Inbound only: server key. |
connect.tls.insecure_skip_verify | LABELGATE_CONNECT_TLS_INSECURE_SKIP_VERIFY | false | Do not check the main's certificate. For testing only. |
Removed keys
These v0.2 keys now stop startup. Delete them from your config file and environment.
docker.ssh.host(LABELGATE_DOCKER_SSH_HOST)docker.ssh.key(LABELGATE_DOCKER_SSH_KEY)docker.ssh.key_passphrase(LABELGATE_DOCKER_SSH_KEY_PASSPHRASE)docker.ssh.known_hosts(LABELGATE_DOCKER_SSH_KNOWN_HOSTS)db.retention(LABELGATE_DB_RETENTION)db.vacuum_interval(LABELGATE_DB_VACUUM_INTERVAL)
An ssh:// value in docker.endpoint is also rejected. For a remote Docker host, run a Labelgate agent there, or use tcp:// with docker.tls.*.