sculkworm relay integration
When the sculkworm feature flag is enabled and SCULKWORM_URL, SCULKWORM_API_KEY, and SCULKWORM_BASE_DOMAIN are configured, sculk.network registers a <server-slug>.<SCULKWORM_BASE_DOMAIN> route in a shared sculkworm relay (crates/sculkworm) for every managed server that has a backend address, updates the route when the backend address changes, and deletes it when the server is disconnected.
This integration runs in open mode (hostname-based TCP routing without authentication gating).
sculk.network only registers open routes. A relay operator can also run closed routes, where players log in before the tunnel opens; the oidc authorizer's {"sculk_server": "<id>"} rule admits the players of a sculk.network server, using this instance as the identity provider. That setup lives on the relay and is described in crates/sculkworm/docs/sculk-authorizer.md.
Enabling the feature#
sculkworm is at the nightly feature stage:
- Enabled by default on
dev(0.0.0-dev) andnightlybuilds. - Disabled by default on
stablebuilds. - Force on or off with
SCULK_FEATURES=sculkwormorSCULK_FEATURES=-sculkworm.
In addition to the feature flag, all three environment variables must be set. If any variable is unset, relay integration stays disabled:
| Variable | Secret | Example | Purpose |
|---|---|---|---|
SCULKWORM_URL |
no | http://sculkworm:8080 |
Base URL of the sculkworm HTTP admin API. |
SCULKWORM_API_KEY |
yes | <tenant bearer token> |
Bearer key from SCULKWORM_TENANTS_FILE (at least 32 characters). Never logged. |
SCULKWORM_BASE_DOMAIN |
no | play.example.org |
Domain scope owned by this tenant; routes are registered as <slug>.<SCULKWORM_BASE_DOMAIN>. |
When the sculkworm flag is off:
GET /api/servers/:id/routeandPUT /api/servers/:id/routereturn404 {"error":"not_found"}withCache-Control: no-store.GET /api/servers/:idomitssculkwormAddress.- The server header in the web app does not show a relay address chip.
- Setting
gameAddress, disconnecting a server, and booting the server make zero requests to sculkworm.
Address derivation and stability#
- A server's slug is derived from its name when a route is first assigned: NFKD diacritic stripping, lowercasing, collapsing non-alphanumeric runs to
-, trimming leading/trailing-, capped to a 63-character DNS label ([a-z0-9-]). - Slugs are unique per sculk.network instance and stable once assigned (stored in
sculkworm_routes). - Collisions are rejected (
409 {"error":"slug_collision"}onPUT /api/servers/:id/route, logged and skipped on background hooks). - When a server is disconnected while sculkworm is unreachable, its
sculkworm_routesrow stays tombstoned (deleted_atset) until sculkworm confirms deletion, preventing a new server from reusing the slug before the old route is gone.
Route lifecycle and reconciliation#
- On backend address set/change (
PUT /api/servers/:id/status/game-addressorPUT /api/servers/:id/route): assigns the route if needed and pushesPUT /v1/routes/{host}via thesculkwormJS SDK (crates/sculkworm/sdk/js). - On server disconnect (
POST /api/servers/:id/disconnect): tombstones the row inside the disconnect transaction, then sendsDELETE /v1/routes/{host}via the SDK and deletes the local row once confirmed (204or404 not_found). - Reconcile job (
sculkworm.reconcile): runs on boot and every 5 minutes. Lists routes owned by this tenant viaGET /v1/routes, creates missing routes, fixes drifted targets, and deletes routes for deleted servers (plus orphaned routes underSCULKWORM_BASE_DOMAIN). - Outage handling: a relay outage never fails a sculk.network request. Errors from the SDK are handled by
err.code, logged without ever printingSCULKWORM_API_KEY, and retried by the reconcile job with exponential backoff (10 s up to 5 min).
API endpoints#
| Endpoint | Access | Behavior |
|---|---|---|
GET /api/servers/:id |
server.view |
Includes sculkwormAddress when sculkworm is enabled, configured, and an active route has been confirmed on the relay (synced_target is non-null). |
GET /api/servers/:id/route |
server.settings |
Returns {"route":{"host","slug","target","synced"}} or {"route":null}. Returns 404 when the flag is off or the caller lacks server.settings (the backend target is not shown to players). |
PUT /api/servers/:id/route |
server.settings |
Body {"target":"host:port" | null, "slug"?: "..."}. Registers, updates, or clears the server's route. Returns 409 slug_collision on collision, 409 slug_immutable if changing an existing slug, 409 sculkworm_not_configured if env vars are missing, 404 when flag is off. |
Worked flow (against a dev lane and real sculkworm binary)#
- Build and start sculkworm with a tenants file scoped to
play.sculk.test:
cargo build --manifest-path crates/sculkworm/Cargo.toml
SCULKWORM_LISTEN=127.0.0.1:18946 \
SCULKWORM_API_ADDR=0.0.0.0:18945 \
SCULKWORM_TENANTS_FILE=/tmp/tenants.json \
SCULKWORM_STATE_FILE=/tmp/state.json \
./crates/sculkworm/target/debug/sculkworm &
curl -sS http://127.0.0.1:18945/healthz{"status":"ok"}- Bring up a dev lane pointed at the relay with
SCULK_FEATURES=sculkworm:
pnpm lane up \
--env SCULK_FEATURES=sculkworm \
--env SCULKWORM_URL=http://172.30.0.1:18945 \
--env SCULKWORM_API_KEY="$KEY" \
--env SCULKWORM_BASE_DOMAIN=play.sculk.test- Sign in, create a server, and set its game address:
APP=http://127.0.0.1:40010
COOKIE=$(pnpm lane login 1 owner)
curl -sS -X POST "$APP/api/servers" \
-H "Cookie: sculk_session=$COOKIE" \
-H "Content-Type: application/json" \
-d '{"name":"Survival SMP"}'{"id":"e4lytgrcw6v4fo3v","name":"Survival SMP","createdAt":"2026-11-26T23:57:40.963Z"}curl -sS -X PUT "$APP/api/servers/e4lytgrcw6v4fo3v/status/game-address" \
-H "Cookie: sculk_session=$COOKIE" \
-H "Content-Type: application/json" \
-d '{"gameAddress":"127.0.0.1:25565"}'
curl -sS -H "Authorization: Bearer $KEY" http://127.0.0.1:18945/v1/routes{"routes":[{"host":"survival-smp.play.sculk.test","target":"127.0.0.1:25565","tenant":"sculk"}]}- Update the backend target and confirm sculkworm reflects the change:
curl -sS -X PUT "$APP/api/servers/e4lytgrcw6v4fo3v/status/game-address" \
-H "Cookie: sculk_session=$COOKIE" \
-H "Content-Type: application/json" \
-d '{"gameAddress":"127.0.0.1:25566"}'
curl -sS -H "Authorization: Bearer $KEY" http://127.0.0.1:18945/v1/routes/survival-smp.play.sculk.test{"host":"survival-smp.play.sculk.test","target":"127.0.0.1:25566","tenant":"sculk"}- Disconnect the server and confirm the route is deleted:
curl -sS -X POST "$APP/api/servers/e4lytgrcw6v4fo3v/disconnect" \
-H "Cookie: sculk_session=$COOKIE" \
-H "Content-Type: application/json" \
-d '{"confirmName":"Survival SMP"}'
curl -sS -H "Authorization: Bearer $KEY" http://127.0.0.1:18945/v1/routes{"ok":true}
{"routes":[]}- Restart with
SCULK_FEATURES=-sculkwormto confirm flag-off returns404withCache-Control: no-storeand leaves sculkworm untouched:
pnpm lane svc 1 restart app --env SCULK_FEATURES=-sculkworm
curl -sS -i "$APP/api/servers/jfiehjtlr3jvf2af/route" -H "Cookie: sculk_session=$COOKIE" | head -n 4HTTP/1.1 404 Not Found
cache-control: no-store
content-type: application/json