Labelgate

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. Write 0s for 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

KeyEnv varDefaultMeaning
modeLABELGATE_MODEmainmain, or agent for a remote Docker host.
log_levelLABELGATE_LOG_LEVELinfodebug, info, warn or error.
log_formatLABELGATE_LOG_FORMATtexttext or json.
label_prefixLABELGATE_LABEL_PREFIXlabelgateFirst part of every label key. Lowercase letters, digits, ., _, -.
default_tunnelLABELGATE_DEFAULT_TUNNEL-Tunnel for labels without tunnel. Empty means cloudflare.tunnel_id; otherwise a name from cloudflare.tunnels.
instance_idLABELGATE_INSTANCE_ID-Only to recover after losing the database. 4-32 lowercase letters and digits. See Ownership.
skip_credential_validationLABELGATE_SKIP_CREDENTIAL_VALIDATIONfalseStart without checking the Cloudflare tokens, and without requiring one.
-LABELGATE_CONFIG-Path to the config file.

Cloudflare

KeyEnv varDefaultMeaning
cloudflare.api_tokenLABELGATE_CLOUDFLARE_API_TOKEN-Required unless you use cloudflare.credentials. The main API token.
cloudflare.account_idLABELGATE_CLOUDFLARE_ACCOUNT_ID-Account of the tunnel. Required with tunnel_id.
cloudflare.tunnel_idLABELGATE_CLOUDFLARE_TUNNEL_ID-The default tunnel for tunnel labels. Uses cloudflare.api_token.
cloudflare.credentials.<name>.api_tokenfile only-Required. An extra API token.
cloudflare.credentials.<name>.zonesfile onlyall zonesZones this token is used for, e.g. example.com.
cloudflare.tunnels.<name>.account_idfile only-Required. Account of an extra tunnel.
cloudflare.tunnels.<name>.tunnel_idfile only-Required. ID of an extra tunnel.
cloudflare.tunnels.<name>.credentialfile onlycloudflare.api_tokenWhich 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: company

How Labelgate picks the token for a hostname:

  1. A credential label wins. credential: default means cloudflare.api_token.
  2. Otherwise, the token that can see the hostname's zone. If several can, the longest zone wins; on a tie, cloudflare.api_token wins.
  3. 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

KeyEnv varDefaultMeaning
sync.intervalLABELGATE_SYNC_INTERVAL5mFull check against Cloudflare, on top of Docker events. Minimum 10s.
sync.remove_delayLABELGATE_SYNC_REMOVE_DELAY30mWait this long after a container is gone before deleting its resources (cleanup: true). 0s deletes at once.
sync.orphan_ttlLABELGATE_SYNC_ORPHAN_TTL0sForget kept resources (cleanup: false) after this long. Only the database entry is removed, never the Cloudflare object. 0s = never.
sync.agent_graceLABELGATE_SYNC_AGENT_GRACE24hKeep an offline agent's resources this long. Minimum 5m.

Labelgate only ever deletes resources it created. See Ownership & Conflicts.

Docker

KeyEnv varDefaultMeaning
docker.endpointLABELGATE_DOCKER_ENDPOINTunix:///var/run/docker.sockDocker daemon: unix:///path or tcp://host:port.
docker.poll_intervalLABELGATE_DOCKER_POLL_INTERVAL2mRe-list all containers this often, on top of Docker events. Must be above 0s.
docker.filter_labelLABELGATE_DOCKER_FILTER_LABEL-Only read containers with this label: key or key=value.
docker.tls.caLABELGATE_DOCKER_TLS_CA-CA file to check a tcp:// daemon's certificate.
docker.tls.certLABELGATE_DOCKER_TLS_CERT-Client certificate. Set together with key.
docker.tls.keyLABELGATE_DOCKER_TLS_KEY-Client key.
docker.tls.insecure_skip_verifyLABELGATE_DOCKER_TLS_INSECURE_SKIP_VERIFYfalseDo 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

KeyEnv varDefaultMeaning
db.pathLABELGATE_DB_PATH/app/config/labelgate.dbSQLite file. Keep /app/config on a volume and back it up.

API and dashboard

KeyEnv varDefaultMeaning
api.enabledLABELGATE_API_ENABLEDtrueServe the API and the dashboard.
api.addressLABELGATE_API_ADDRESS:28111Listen address.
api.base_pathLABELGATE_API_BASE_PATH/apiAPI path. Starts with /, no trailing /, not /dashboard.
api.tokenLABELGATE_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.

EndpointReturns
GET /api/health{"status":"ok"}. No token needed.
GET /api/overviewCounts, sync status and agent summary. sync.problems lists the current problems (up to 200), sync.problems_total counts all of them.
GET /api/resources/dnsDNS records.
GET /api/resources/tunnelsTunnel routes.
GET /api/resources/accessAccess applications.
GET /api/agentsAgents.
GET /api/versionVersion.

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 /health answers within 2 seconds.
  • Main with the API off or no api.token: always healthy.
  • Agent: inbound agents check that connect.listen accepts connections; outbound agents are always healthy.

Retry

Applies to Cloudflare calls and agent reconnects.

KeyEnv varDefaultMeaning
retry.attemptsLABELGATE_RETRY_ATTEMPTS3Maximum attempts. At least 1.
retry.delayLABELGATE_RETRY_DELAY1sFirst wait between attempts. Above 0s.
retry.max_delayLABELGATE_RETRY_MAX_DELAY30sLongest wait. At least retry.delay.
retry.backoffLABELGATE_RETRY_BACKOFF2Multiply the wait by this after each attempt. At least 1.

Agents: main instance

Settings on the main instance for accepting agents.

KeyEnv varDefaultMeaning
agent.enabledLABELGATE_AGENT_ENABLEDfalseAccept agents.
agent.listenLABELGATE_AGENT_LISTEN:28112Listen address. Agents connect to wss://<host>:28112/ws.
agent.accept_tokenLABELGATE_AGENT_ACCEPT_TOKEN-One shared token for agents not listed in agent.agents. See Agent tokens.
agent.accept_hostnamesLABELGATE_AGENT_ACCEPT_HOSTNAMESanyHostnames those agents may use, as globs: *.edge.example.com. A wildcard hostname needs an identical entry.
agent.accept_tunnelsLABELGATE_AGENT_ACCEPT_TUNNELSdefault tunnelTunnels those agents may use: default, a name from cloudflare.tunnels, or a tunnel ID.
agent.accept_servicesLABELGATE_AGENT_ACCEPT_SERVICESIP addressesExtra tunnel service hosts those agents may use: hostname globs, IPs or CIDRs.
agent.tls.certLABELGATE_AGENT_TLS_CERT-Server certificate. Turns on wss://. Set together with key.
agent.tls.keyLABELGATE_AGENT_TLS_KEY-Server key.
agent.tls.caLABELGATE_AGENT_TLS_CAsystem CAsCA to check inbound agents' certificates.
agent.tls.insecure_skip_verifyLABELGATE_AGENT_TLS_INSECURE_SKIP_VERIFYfalseDo 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"].

KeyDefaultMeaning
token-Required. This agent's token. See Agent tokens.
name-Display name in the dashboard.
default_tunneldefault_tunnelTunnel for this agent's labels without tunnel.
tunnelsits default tunnelTunnels this agent may use.
hostnamesanyHostnames this agent may use, as globs. A wildcard hostname needs an identical entry.
servicesIP addressesExtra 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 32

Agents: agent instance

Used only with mode: agent. In agent mode, only these, log_*, docker and retry are used.

KeyEnv varDefaultMeaning
connect.modeLABELGATE_CONNECT_MODEoutboundoutbound: the agent dials the main. inbound: the main dials the agent.
connect.endpointLABELGATE_CONNECT_ENDPOINT-Required for outbound. Main URL including /ws: wss://main.example.com:28112/ws.
connect.listenLABELGATE_CONNECT_LISTEN-Required for inbound. Listen address, e.g. :28113.
connect.tokenLABELGATE_CONNECT_TOKEN-Required. Same token as on the main. See Agent tokens.
connect.agent_idLABELGATE_CONNECT_AGENT_IDfrom machine IDAgent 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_intervalLABELGATE_CONNECT_HEARTBEAT_INTERVAL30sHow often the agent sends a full report. Minimum 1s.
connect.tls.caLABELGATE_CONNECT_TLS_CAsystem CAsCA to check the main's certificate.
connect.tls.certLABELGATE_CONNECT_TLS_CERT-Inbound only: server certificate. Set together with key.
connect.tls.keyLABELGATE_CONNECT_TLS_KEY-Inbound only: server key.
connect.tls.insecure_skip_verifyLABELGATE_CONNECT_TLS_INSECURE_SKIP_VERIFYfalseDo 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.*.

On this page