Skip to content

Hub API and tokens ​

Everything the hub's web interface does goes through its JSON API. For automation (n8n, CI, your own scripts) there are API tokens: access without a password or a browser session, with a role, a host and group scope, an address list and an expiry. With the same token the hub is an MCP server for AI agents.

Tokens ​

API tokens

"About" → "API tokens" → "New token" (admins only):

  • Role. Read: the host list, state, findings, vulnerabilities, services and containers, alerts, pipelines and job logs, scripts, moves, the Traffic Fly map, clusters. Admin: also actions, such as deploying and rolling back a pipeline, dry runs, IP bans and unbans on the hosts, service and container actions, vulnerability scans, running saved scripts, stack moves, Traffic Fly (saving and applying the map), and manifests into clusters. By permission: read plus only the chosen actions, with resource limits (below, “Token by permission”).
  • Hosts and groups limit the token. Both empty means all hosts. A host is in scope if it is named itself or belongs to one of the groups (a machine belongs to its host's group). Renaming a group does not break the token.
  • Addresses: the addresses or subnets the token is accepted from (empty means any). The hub trusts proxy headers (X-Forwarded-For) only when the connection comes from loopback, that is from your own reverse proxy; a header cannot fake the address of a direct connection.
  • Expiry: 30, 90 or 365 days, or never.
  • Through nkt-edge: the token is also accepted through an edge with the API role (see below).

The secret is shown once, right after creation. If it is lost, use "New secret": the old one stops working at once. "Revoke" deletes the token. Editing (name, role, scope, addresses, expiry) happens in a window with a "what will change" diff. Creating, editing, issuing a new secret and revoking are written to the audit log, and the token's calls are logged as token:<name>. The list shows when and from which address the token was last used.

No role gives a token: hub management (accounts, tokens themselves, export and import, hub updates, edge, AI settings, adding and deleting hosts), creating and editing scripts, creating, deleting and upgrading clusters, the kubeconfig and Helm, Kubernetes on a host directly, the terminal and console, files and backups, config contents, or websockets. Such a call gets 403.

Token by permission ​

For an agent, CI or contractor that needs one job, not the whole hub: “deploy pipeline shop”, “keep a compose stack in group staging within 2 CPU”, “an own namespace in a cluster with a quota”, “up to three machines of 2 vCPU”.

  • Presets fill in the fields: read only; CI — deploy a pipeline; agent — compose with limits; k8s — own namespace with a quota; machines — up to three.
  • Actions — what else is allowed besides reading: deploy (and roll back, dry run), “Start” / “Stop”, create pipelines (its own: compose only on the token's hosts, edit and remove only those it created; no need to add them to the pipeline list), run saved scripts, k8s manifests, machines, containers, services, Traffic Fly, moves, fail2ban, vulnerability scans. Anything else is a 403 naming the action.
  • Objects — pipelines, scripts and clusters by name (empty — all within the token's hosts); k8s namespaces — required for manifests (kube-* and default are not allowed).
  • Limits (empty — no limit):
    • total — CPU, memory, disk: the sum of everything the token deployed and created that still exists;
    • per host — CPU and memory of the token's stacks and machines on one host;
    • compose service — CPU and memory: a service without its own limits gets this limit (in the copy of the compose file that goes to the host), a service with higher limits is refused; free on the host — space before a deployment;
    • machines — how many in total and the limits of one (vCPU, memory, disk);
    • k8s namespace quota — CPU, memory, storage, pods;
    • actions per hour — deployments, starts, applies, machines.

How the sum works. The hub keeps a ledger per token: a compose stack on each host (the sum of the services' limits times replicas), a machine (vCPU, memory, disk), a k8s namespace (its quota). A new action passes if “in use without this same entry + new” is within the limit: a repeated deployment of the same stack replaces its entry instead of adding up. Stopped things keep their place — “Start” won't be refused. A stack or machine removed outside nkt — the hub drops the entry on a check (every 10 minutes and when the token window opens); the token window shows “In use … of …” and a manual “Release”. A deleted token takes its ledger with it.

What a token with limits can't have in compose: privileged, host network, pid and ipc, cap_add, devices, security_opt: …unconfined, host path and docker socket mounts (./… inside the stack directory and named volumes are fine). Docker has no volume quota, so for compose the disk limit is a free-space check before a deployment.

k8s. A manifest goes only into the token's namespaces, without kinds that change the whole cluster (ClusterRole, CRD, PersistentVolume, ResourceQuota…), and without node access (privileged, hostNetwork, hostPID, hostIPC, hostPath). Before the first apply the hub puts a ResourceQuota (the namespace limits) and a LimitRange (the service limit — default and maximum per container) into the namespace: the cluster itself holds the quota, even for pods created from inside.

Machines — create (create_vm in MCP, “New machine” over the API, vm create in a script), start, stop and delete only its own: created by this token. A token's machines are isolated:

  • a machine can be created only on a host within the token's limits (hosts and groups), otherwise 403;
  • a token's machine lives in the token's own NAT network on the host (nkt-t<number>): it can reach the internet, but the host only for DNS and DHCP, and not the LAN, other tokens' networks or the metadata address (Token networks); the token cannot set a network or a bridge — 403;
  • a token by permission does not see other machines (of other tokens and of the administrator) in lists, monitoring or scripts;
  • its own machines stay visible and reachable for a token limited by hosts, even when the machine itself is not in the token's host list.

What else a token can do with its machine (the “machines” action): reboot; snapshots — take, revert, delete (up to the “snapshots per machine” limit; empty — no snapshots); vCPU, memory and disk within the token's limits (the disk only grows, vCPU and memory apply after shutdown and start); reinstall from a catalog image (disk and data anew, name, network and size kept); own user_data — a #cloud-config with packages, files and commands (up to 64 KB; nkt sets the account, keys and login); delete the machine entirely — with its disks, record and usage. An image from the host's disk directory (host:…) is not allowed for a token: other machines' disks live there too.

LXD instances — like KVM machines: a container or an LXD machine (POST /api/hub/hosts/{id}/lxd {"name":"c1","image":"ubuntu:24.04","vm":false, "cpu":1,"mem_mb":1024,"disk_gb":10} — a job), start, stop, restart, snapshots, vCPU and memory (live) and disk (grows only), deletion. A token gets only its own: they count as machines (a shared count and limits with KVM; with limits set, sizes are required), live in the token's LXD network nkt-t<number> under the same nftables rules, unprivileged and without nesting. Pool ports and Fly routes are for KVM machines so far.

Bandwidth, disk, mail and snapshots of a token machine.

  • Network (Mbit/s, in and out), IOPS and disk MB/s per machine are token limits; empty — the hub's defaults (“About” → API tokens → “Machine limits by default”, initially 100 Mbit/s, 1000 IOPS, 100 MB/s). They are set when the machine is created (KVM — in the domain definition, LXD — on eth0 and the root disk, without IOPS); new values do not apply to existing machines. GET/PUT /api/hub/vm/limit-defaults — for an administrator.
  • Outbound port 25 from the token's network is closed; “allow mail” in the token's permissions opens it on all hosts of its machines at once.
  • Each snapshot reserves the machine's disk size in the token's disk total (a snapshot can grow that much); a snapshot over the disk limit is refused, the reserve goes with the snapshot, the machine or a reinstall.

Ports and names for an own machine.

  • An administrator sets the host's port pool: “Hosts” → the host row → “Port pool” (no pool by default; 1024–65535, up to 10,000 ports, clear of the Traffic Fly service ports 40000–41999).
  • With the “ports” action a token takes a free pool port to its machine (POST /api/hub/hosts/{id}/vm/ports {"vm_port":22,"proto":"tcp"}, TCP or UDP) — within its “pool ports” limit (empty — none). The machine's address is pinned with a DHCP reservation, the rule is DNAT on the host; other tokens' networks cannot reach the machine through that port.
  • With the “own Traffic Fly routes” action a token publishes its machine by name: HTTPS with a certificate on the gateway (POST /api/hub/own/fly {"name":"app.client.example.com","host_id":…,"port":8080}). The name is only the token's assigned domain or a name under it, a taken name is refused; the gateway is the one set in the permissions or the only one; a “routes” limit (empty — none). The token neither sees nor edits the whole Fly map and can remove only its own route. With a DNS plugin for the domain the record is set automatically.
  • When a machine is deleted, its ports and token routes go with it.

Own cluster (the “own Kubernetes cluster” action, an “own clusters” limit; empty — none): POST /api/hub/k8s/clusters/own {"name":"lab","topology":"cp1","workers":2,"image_id":"ubuntu-24.04", "cp_vcpus":2,"cp_memory_mb":4096,"cp_disk_gb":20,"w_vcpus":1,"w_memory_mb":2048, "w_disk_gb":20} — a job.

  • k3s on the token's machines: single (one machine) or cp1 (a control plane and workers), all on one host (host_id 0 — the hub picks), in the token's network under the nftables rules; each node is a token machine (shared count and limits), the image comes from the catalog.
  • The cluster API opens on a port of the host's pool (no pool — refused); the answer has api_port and address.
  • The kubeconfig (cluster-admin of the own cluster) — POST /api/hub/k8s/clusters/own/{id}/kubeconfig, once, when ready; it is not issued again.
  • DELETE /api/hub/k8s/clusters/own/{id} — the cluster with its machines, usage and port. The same rules apply to k8s … create in a script run by a token.

Own namespace in a shared cluster (the “own namespaces” action):

sh
curl -sS -X POST -H "Authorization: Bearer $NKT_TOKEN" -H 'Content-Type: application/json' \
  -d '{"cluster":"shared","namespace":"shop"}' https://hub.example.com/api/hub/k8s/own \
  | jq -r .kubeconfig > shop.kubeconfig
kubectl --kubeconfig shop.kubeconfig get pods
  • Outside by name — a Traffic Fly route to the own namespace: POST /api/hub/own/fly {"name":"shop.client.example.com","cluster":"shared", "namespace":"shop"} (or fly own … cluster … namespace … in a script) goes to the cluster's ingress set by the administrator (“Client ingress”); the namespace needs an Ingress with the same name.
  • The cluster must run Cilium (it enforces network policies) and Kubernetes 1.30+ (admission policies); protection details — Security.
  • Outside access — only Ingress, HTTPRoute and GRPCRoute with names in the token's domain (fly_domain), Service — only ClusterIP; NodePort, LoadBalancer, externalIPs, Gateway and own network policies are refused both through the hub and with the own kubeconfig. Outbound port 25 is closed unless “allow mail” is checked in the token's permissions.
  • The cluster comes from the token's cluster list (empty — any within its scope); the name is new (an existing namespace is never taken over), not kube-*, default or nkt-*; up to the “own namespaces” limit (empty — none).
  • The hub labels the namespace with Pod Security restricted, sets the quota and LimitRange from the token's limits, a NetworkPolicy “ingress only from this namespace” and the service account nkt-client with the edit role in it only.
  • That account's kubeconfig is returned once (via the API, not MCP); POST /api/hub/k8s/own/{cluster}/{ns}/kubeconfig reissues it and the old token stops working.
  • Own namespaces are open to the token's manifests (k8s.apply), pod logs (GET …/{cluster}/{ns}/logs?pod=…) and helm (POST …/{cluster}/{ns}/helm): the chart is rendered on the cluster (helm template, no host repositories), passes the same checks as a token manifest and is applied; dry_run only renders and checks. DELETE …/{cluster}/{ns} deletes the namespace with everything in it.

Own k8s cluster in a script — k8s CLUSTER create and destroy in a script — only with the “own Kubernetes cluster” action.

A script run by a token is checked the same way as the API: each line needs its action (vm … — “machines”, k8s … apply — “k8s manifests”, k8s … create — “own cluster”), machines — limits and usage, manifests — the token's namespaces, quota and restrictions. Hub-wide commands (host, group, Traffic Fly) are not allowed for a limited token. If the token is deleted or expires, its job stops at the next step.

Own limits — GET /api/hub/tokens/self/usage (and the MCP tool my_usage): the token's limits and usage of CPU, memory, disk, machines, pool ports, own Fly routes, namespaces and clusters, the usage rows and the allowed actions — the same answer the administrator sees in the token window.

MCP shows the agent only the allowed tools. Connection examples are in the token window (“MCP examples”), with the issued secret — right after creation.

Permissions, limits and the ledger travel in the hub export with the token.

Presenting the token ​

Bearer is simple. The secret travels with every request, so use it inside your own network or over HTTPS:

sh
curl -H "Authorization: Bearer nkt_<key>_<secret>" https://hub.example.com/api/hub/hosts

A signed request never sends the secret; a signature lives for 5 minutes and cannot be replayed. This lets the token go through an intermediate node as well. Headers:

HeaderValue
X-NKT-API-Keythe token key (16 characters)
X-NKT-API-Timestampthe time in unix seconds; up to 5 minutes off the hub's clock
X-NKT-API-Noncea random string of 16–128 A-Za-z0-9_- characters, new for every request
X-NKT-API-Signaturehex HMAC-SHA256 with the secret over the string below

The signed string is six lines joined with \n:

text
NKT-API-1
<timestamp>
<nonce>
<METHOD>
<path?query>           e.g. /api/hub/events?after=120
<hex sha256 of body>   an empty body is the sha256 of an empty string

Bash:

sh
KEY=abcdefghijklmnop SECRET='...'
TS=$(date +%s) NONCE=$(openssl rand -hex 16)
BODY='{"action":"ban","ips":["198.51.100.7"]}'
URI=/api/hub/fail2ban/fleet
HASH=$(printf %s "$BODY" | sha256sum | cut -d' ' -f1)
SIG=$(printf 'NKT-API-1\n%s\n%s\nPOST\n%s\n%s' "$TS" "$NONCE" "$URI" "$HASH" \
  | openssl dgst -sha256 -hmac "$SECRET" | sed 's/.* //')
curl -X POST -H 'Content-Type: application/json' \
  -H "X-NKT-API-Key: $KEY" -H "X-NKT-API-Timestamp: $TS" \
  -H "X-NKT-API-Nonce: $NONCE" -H "X-NKT-API-Signature: $SIG" \
  -d "$BODY" "https://hub.example.com$URI"

JavaScript (Node, or the Code node in n8n):

js
const crypto = require('crypto')
function sign(secret, method, uri, body = '') {
  const ts = String(Math.floor(Date.now() / 1000))
  const nonce = crypto.randomBytes(16).toString('hex')
  const hash = crypto.createHash('sha256').update(body).digest('hex')
  const sig = crypto.createHmac('sha256', secret)
    .update(['NKT-API-1', ts, nonce, method.toUpperCase(), uri, hash].join('\n')).digest('hex')
  return { 'X-NKT-API-Timestamp': ts, 'X-NKT-API-Nonce': nonce, 'X-NKT-API-Signature': sig }
}

A signed request body is limited to 1 MB. The signature covers the body exactly as it is sent.

From outside through nkt-edge ​

If the hub is behind NAT, the API can be reached from outside (n8n in the cloud, CI) through an nkt-edge with the API role: the request goes to https://api.example.com/api/… and the edge passes it to the hub through the tunnel. Conditions:

  • the token has the "through nkt-edge" box ticked;
  • signed requests only: the edge passes neither Bearer nor cookies, so the token secret never reaches the VPS;
  • the token's address list is checked against the client address the edge passed on;
  • the signed path is the one the hub sees: /api/hub/hosts, without the edge name.

What a token can call ​

CallRoleWhat
GET /api/auth/mereadwho am I: the token's name, role and scope
GET /api/hub/hostsreadhosts in the token's scope: status, version, findings
GET /api/hub/events?after=Nreadalerts newer than number N (polling)
GET /api/hub/fail2ban/bannedreadbanned addresses per host
GET /api/hub/sitesreadsites
GET /api/hub/pipelines, /{id}, /{id}/deploymentsreadpipelines and deployment history
GET /api/hub/jobs/{id}, /{id}/log?after=Nreada hub job and its log
GET /api/hosts/{id}/<section>readoverview, findings, vulnerabilities, services, containers, certificates, monitor, jobs, fail2ban, firewall, updates and other host sections
POST /api/hub/pipelines/{id}/deployadmindeploy ({"ref":"","tag":""}) → job_id
POST /api/hub/pipelines/{id}/rollbackadminroll back to a deployment
GET /api/hub/pipelines/{id}/powerreadwhat “Start” / “Stop” affect: hosts, Traffic Fly routes, the “stopped” tag
POST /api/hub/pipelines/{id}/stop, /startadminstop a deployment (containers and data stay) or bring up the same version → job_id
POST /api/hub/pipelines/dryrunadmindry run ({"pipeline_id":1,"skip":[]} or {"content":"…"} — a description not saved yet) → job_id
GET /api/hub/pipelines/examples, ?key=…readexample descriptions from examples/ (the list; with key — the text)
POST /api/hub/pipelinesadmincreate a pipeline ({"name":"…","content":"…"}): env: values go to the pipeline's .env, generate: — the hub creates them; by permission — the “create pipelines” action
PUT /api/hub/pipelines/{id}adminreplace the description ({"content":"…","note":"…"}): a new version, diff in the answer; a .env value already set — 409 env_conflict, to replace — "replace_env":true
POST /api/hub/pipelines/{id}/removeadminremove a compose pipeline with its stack as a job ({"all":true,"volumes":false,"images":false,"cert":false}) → job_id
POST /api/hub/vm/provisionadmina new machine ({"host_id":1,"spec":{"name":"app1","image_id":"ubuntu-24.04","vcpus":2,"memory_mb":2048,"disk_gb":20,"user":"deploy","ssh_key":"ssh-ed25519 …","user_data":"#cloud-config\n…"}}) → job_id; host_id 0 or absent — the hub picks the host itself (online, KVM and libvirtd, free memory and disk space with a margin, within the token's scope and limits; of those — the most free memory); by permission — “machines”, within limits, in the token's network
POST /api/hub/hosts/{id}/vm/{action}adminstart, shutdown, destroy, reboot; {id} is the machine's own record
GET, POST /api/hub/hosts/{id}/vm/snapshotsadminmachine snapshots: list; take ({"name":"before"}) — a token up to its snapshot limit
POST …/vm/snapshots/{snap}/revert, DELETE …/vm/snapshots/{snap}adminrevert to a snapshot, delete a snapshot
POST /api/hub/hosts/{id}/vm/resizeadmin{"vcpus":4,"memory_mb":4096,"disk_gb":40} (0 — keep; the disk only grows) → restart_needed
POST /api/hub/hosts/{id}/vm/reinstalladminreinstall from an image ({"image_id":"…","ssh_key":"…","user_data":"…","install_nkt":false}) → job_id
GET, POST /api/hub/hosts/{id}/lxdadmina host's LXD instances (a token — its own); create ({"name","image","vm","cpu","mem_mb","disk_gb"}) → job_id
POST /api/hub/hosts/{id}/lxd/{name}/{action}, …/resize, DELETE /api/hub/hosts/{id}/lxd/{name}adminstart, stop, restart; vCPU, memory, disk; delete
GET, POST …/lxd/{name}/snapshots, POST …/snapshots/{snap}/restore, DELETE …/snapshots/{snap}admininstance snapshots (a token — within its limit)
GET, PUT /api/hub/vm/limit-defaultsadmindefault bandwidth and disk of token machines ({"net_mbit":100,"iops":1000,"disk_mbps":100})
GET /api/hub/tokens/self/usageany tokenits own limits and usage (totals, machines, ports, Fly routes, namespaces, clusters), usage rows, allowed actions
GET, POST /api/hub/k8s/clusters/ownby permissionown clusters; create (single or cp1 on the token's machines) → id, job_id, api_port, address
POST /api/hub/k8s/clusters/own/{id}/kubeconfig, DELETE /api/hub/k8s/clusters/own/{id}by permissionthe kubeconfig once; delete the cluster with its machines → job_id
GET, POST /api/hub/k8s/ownby permissionown namespaces; create ({"cluster","namespace"}) → kubeconfig once
POST /api/hub/k8s/own/{cluster}/{ns}/kubeconfig, DELETE /api/hub/k8s/own/{cluster}/{ns}by permissionreissue the kubeconfig; delete the namespace
GET …/{cluster}/{ns}/logs?pod=&container=&tail=, POST …/{cluster}/{ns}/helmby permissionpod log; helm via render and checks ({"repo_url","chart","version","release","values","dry_run"})
GET, PUT /api/hub/hosts/{id}/port-pooladminthe host's port pool ({"from":20000,"to":20999}; from 0 — off)
GET, POST /api/hub/hosts/{id}/vm/ports, DELETE …/vm/ports/{port}adminpool ports to a machine ({"vm_port":22,"proto":"tcp"}) → port, address; by permission — “ports”, within the limit
GET, POST /api/hub/own/fly, DELETE /api/hub/own/fly/{route}by permissionown Traffic Fly routes ({"name":"…","host_id":…,"port":8080}) → the apply job_id
GET /api/hub/k8s-addon-versions?addon=longhornreadadd-on chart versions (default, versions[] with kube_version) — from index.yaml, cached for an hour
GET, POST /api/hub/clusters/{id}/addonsadmincluster add-ons: what is installed (installed) and what the description says; {"name":"longhorn","version":"1.12.1"} — install or upgrade as a job → job_id
GET, PUT /api/hub/clusters/{id}/client-crdsadminoperator resources for client namespaces ({"resources":["registries.registry.rgstr.io"]}): the ClusterRole nkt-client-crds aggregated into edit
DELETE /api/hub/hosts/{id}/vmadmindelete the machine entirely: domain, disks, record, usage → job_id
POST /api/hub/fail2ban/fleetadminban or unban ({"action":"ban","ips":[…],"host_ids":[…]})
POST /api/hosts/{id}/vulnerabilities/scanadminvulnerability scan
POST/PUT/DELETE /api/hosts/{id}/<section>/…adminhost actions: services, containers, package updates and so on, except what is closed above and file uploads (image archives, machine images, file browser files, backups — they have routes of their own, closed to tokens)
POST /api/hosts/{id}/images/archives/fetchadmindownload an image archive to the host by URL and load it into Docker or Podman → job_id (see below)
GET /api/hub/scripts, /{id}readsaved scripts and their text
POST /api/hub/scripts/checkadminparse and check a text ({"content":"…"}): steps, errors, what it asks (asks) — changes nothing
POST /api/hub/scripts/{id}/runadminrun a saved script ({"dry_run":false,"values":{"param:FROM":"web1"}}) → job_id; a token cannot create or edit scripts
GET /api/hub/migrations, /api/hub/migrate/livereadthe moves record, moves in progress
POST /api/hub/migrate/previewadmina move plan ({"from":1,"to":2,"container":"…"}): what travels, obstacles, routes, pipeline
POST /api/hub/migrateadminmove a stack (… "switch_fly":true,"switch_pipeline":true,"clean_leftovers":false) → job_id
POST /api/hub/migrations/{id}/rollback, /remove, /stopnewadminroll back, "remove old" ({"data":true} — with volumes), stop the second copy → job_id
GET /api/hub/fly, /fly/status, /fly/versionsreadthe Traffic Fly map (and its YAML text), target and tunnel health, version history
PUT /api/hub/flyadminsave the whole map (a new version; reaches the gateways when applied)
POST /api/hub/fly/opsadminpoint changes: add or remove a target, make active, reserve, drain → job_id
POST /api/hub/fly/routes/{id}/switchadminswitch a route's active target
POST /api/hub/fly/applyadminapply ({"dry_run":false}) → job_id
POST /api/hub/fly/clusteradminreconcile the targets of routes bound to a cluster ({"cluster":"lab"}; no name — every cluster that has bound routes) → job_id
GET /api/hub/clusters, /{id}/nodesreadclusters and nodes; a cluster carries fly_routes — how many Traffic Fly routes lead into it
GET /api/hub/k8s/manifests, /{id}adminsaved manifests
POST /api/hub/k8s/manifests/diffadminkubectl diff per cluster ({"name":"…","content":"…","clusters":[1,2]})
POST /api/hub/k8s/manifests/apply?job=1adminkubectl apply per cluster as a job (body as for diff, plus note) → job_id
POST /api/hub/scripts/{id}/run with "dry_first": trueadmina dry run, then the run if it passes, as one job → job_id
POST /api/mcpreadMCP for AI agents: JSON-RPC; tools by the token's role and scope
GET /api/hub/pluginsreadconnected plugins with their manifests
POST /api/hub/plugins/{name}/callread / by permissiona plugin operation ({"op":"…","args":{…}}): changes — for an administrator or with the “plugin NAME” action

Still closed to any token: creating, editing and deleting scripts; creating, deleting and upgrading clusters, adding workers, the kubeconfig, Helm; restoring an old Traffic Fly map version; hosts, groups, profiles, service descriptions, the assistant, "About", users, export; on hosts — the service descriptions section (/api/hosts/{id}/svcdesc*: the sample reads the host's files and commands).

The hub machine is /api/hosts/local/…; in a token's scope its number is -1. A scoped token sees only its hosts, their alerts and sites; only compose pipelines whose hosts are all in its scope; and it can dry-run only a saved pipeline (a description text — with the “create pipelines” action and only compose on its own hosts). A scoped token sees only the hub jobs it started itself.

Also for a scoped token:

  • a script runs only if all its hosts are in scope — checked by parsing before the run (on, install, wait, migrate — both hosts, the k8s create placement hosts, the pipeline block hosts); host, group, fly route, fly apply, a pipeline by group are refused;
  • a move and its plan — only between hosts in scope; the moves record shows only such entries;
  • clusters — only those with all nodes in scope; a manifest goes only to such clusters;
  • Traffic Fly is unavailable: the map is shared by all hosts.

Examples ​

sh
H='Authorization: Bearer nkt_…'
# Run a saved script (dry run) and wait for the outcome
curl -s -H "$H" -H 'Content-Type: application/json' https://hub.example.com/api/hub/scripts/4/run \
  -d '{"dry_run":true,"values":{"param:FROM":"web1","param:TO":"web2","param:DOMAIN":"git.example.com"}}'
curl -s -H "$H" https://hub.example.com/api/hub/jobs/123          # status: succeeded | failed
curl -s -H "$H" 'https://hub.example.com/api/hub/jobs/123/log?after=0'

# Move a stack switching the routes and the pipeline
curl -s -H "$H" -H 'Content-Type: application/json' https://hub.example.com/api/hub/migrate \
  -d '{"from":1,"to":2,"container":"forgejo-forgejo-1","switch_fly":true,"switch_pipeline":true}'

# Apply Traffic Fly
curl -s -H "$H" -H 'Content-Type: application/json' https://hub.example.com/api/hub/fly/apply -d '{}'

# A manifest into two clusters
jq -Rs '{name: "hello", content: ., clusters: [1, 2]}' hello.yaml |
  curl -s -H "$H" -H 'Content-Type: application/json' --data @- 'https://hub.example.com/api/hub/k8s/manifests/apply?job=1'

Deployments and dry runs are jobs: the response is job_id, the outcome is in GET /api/hub/jobs/{id} (status: queued, running, succeeded, failed), and the log is in /log?after=<last line number>.

Uploading Docker and Podman images ​

An image built on your machine goes to hosts one of two ways.

From your computer — signed in as an administrator (file uploads are closed to tokens). The archive goes to the host through the hub over an SSH connection of its own; up to 10 GB, the transfer through the hub may take up to 6 hours. load=1 — as soon as the whole file is in, the host starts docker load (or podman load) itself as a job:

sh
HUB=https://hub.example.com HOST=3          # host number: GET /api/hub/hosts; the hub's machine — local
curl -s -c jar -H 'Content-Type: application/json' \
  -d '{"username":"admin","password":"…"}' $HUB/api/auth/login
docker save app:1.2 | gzip > app.tar.gz
curl -s -b jar -T app.tar.gz \
  "$HUB/api/hosts/$HOST/images/archives/upload?name=docker__app-1.2.tar.gz&load=1"
# {"name":"docker__app-1.2.tar.gz","size":…,"job_id":42}
# &remove=1 — delete the archive from the host after a successful docker load
curl -s -b jar $HUB/api/hosts/$HOST/jobs/42     # status: queued, running, succeeded, failed
curl -s -b jar "$HUB/api/hosts/$HOST/jobs/42/log?after=0"

The archive name is docker__<name> or podman__<name> (which engine to load into) with a .tar, .tar.gz, .tgz, .tar.xz or .tar.zst extension; an archive with the same name is replaced. Without load=1 the archive only lands in the host's "Image archives". For several hosts — the same curl -T in a loop over their numbers.

By URL — with a token. The host downloads the archive itself (your HTTP server, a CI artifact store, S3 with a signed URL) and loads it into the engine; the URL must be reachable from the host:

sh
curl -s -H "Authorization: Bearer nkt_<key>_<secret>" -H 'Content-Type: application/json' \
  -d '{"engine":"docker","url":"https://files.example.com/app-1.2.tar.gz","checksum":"<sha256, optional>","load":true}' \
  $HUB/api/hosts/3/images/archives/fetch
# {"job_id":43} — progress and result: GET /api/hosts/3/jobs/43

"remove": true deletes the archive after a successful load; name is optional, otherwise taken from the URL; checksum is the archive's sha256 — a wrong sum fails the job and leaves no archive behind. The token needs the administrator role, and the host must be within its limits.

Error responses ​

CodeWhen
401wrong token or signature, a stale or reused signature, an expired token
403address not allowed, call closed to tokens, a read-only role for an action, host out of scope
413a signed request body over 1 MB
429too many invalid tokens from the address; wait a few minutes

The response body is {"error": "…"} in the Accept-Language language.

Outgoing webhooks ​

The other direction: the hub sends events out by itself, to n8n, a chat bot or your own system. "Alerts" → "Settings" → "Outgoing webhooks" → "New recipient": a name, a URL (http:// or https://), which events, hosts and groups, and the text language. The hub reaches out by itself, so nothing needs to be exposed.

Outgoing webhooks

Events: the same kinds as the "Alerts" journal: unreachable, recovered, new findings, findings resolved, job failed, rebooted, new bans, forecast, UPS, Traffic Fly, old stack after a move, deployment succeeded and failed, nkt-edge offline and back online, site certificate expiring. Webhooks do not depend on the journal: a kind the journal does not record still reaches the recipient. A host and group scope limits it to its hosts' events; a deployment passes if all its hosts are in scope.

The request: POST, Content-Type: application/json, headers:

HeaderValue
X-NKT-Eventthe event kind (unreachable, deploy-failed, test…)
X-NKT-Deliverythe delivery number (a retry of a delivery keeps it)
X-NKT-Timestampthe time in unix seconds
X-NKT-Signaturehex HMAC-SHA256 with the secret over <timestamp>.<body>

The signature is the same as on nkt's incoming webhooks. The body:

json
{
  "id": "4f1c…", "kind": "unreachable", "ts": "2026-10-01T12:00:00Z",
  "hub": "nkt 1.11.72", "text": "unreachable: …", "severity": "warning",
  "event_id": 120,
  "host": {"id": 3, "name": "web1", "addr": "root@203.0.113.10:22"}
}

A deployment has pipeline (id, name), job_id, commit, tag, trigger and, on failure, error instead of host.

Delivery happens in the background. A non-2xx response or no connection is retried after 10 s, 1 and 5 minutes. Redirects are not followed. The recipient shows the outcome of the last delivery; "Test" sends a test event at once and shows the response. The signing secret is shown once; "New secret" replaces it at once. Edits happen in a window with a diff, and everything goes to the audit log.

Checking it in n8n (Webhook node → Code):

js
const crypto = require('crypto')
const ts = $json.headers['x-nkt-timestamp']
const sig = crypto.createHmac('sha256', '<secret>')
  .update(ts + '.' + JSON.stringify($json.body)).digest('hex')
if (sig !== $json.headers['x-nkt-signature']) throw new Error('bad signature')

The hub sends the body without escaping <, > or &, so JSON.stringify of the parsed body gives the same bytes. The raw body is the most reliable (the n8n Webhook node's "Raw Body" option).