sculk.network
Nightly Stable docs
sculk.networknightly · 39a95aaView in Stable docs

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) and nightly builds.
  • Disabled by default on stable builds.
  • Force on or off with SCULK_FEATURES=sculkworm or SCULK_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/route and PUT /api/servers/:id/route return 404 {"error":"not_found"} with Cache-Control: no-store.
  • GET /api/servers/:id omits sculkwormAddress.
  • 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"} on PUT /api/servers/:id/route, logged and skipped on background hooks).
  • When a server is disconnected while sculkworm is unreachable, its sculkworm_routes row stays tombstoned (deleted_at set) 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-address or PUT /api/servers/:id/route): assigns the route if needed and pushes PUT /v1/routes/{host} via the sculkworm JS SDK (crates/sculkworm/sdk/js).
  • On server disconnect (POST /api/servers/:id/disconnect): tombstones the row inside the disconnect transaction, then sends DELETE /v1/routes/{host} via the SDK and deletes the local row once confirmed (204 or 404 not_found).
  • Reconcile job (sculkworm.reconcile): runs on boot and every 5 minutes. Lists routes owned by this tenant via GET /v1/routes, creates missing routes, fixes drifted targets, and deletes routes for deleted servers (plus orphaned routes under SCULKWORM_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 printing SCULKWORM_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)#

  1. Build and start sculkworm with a tenants file scoped to play.sculk.test:
sh
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
json
{"status":"ok"}
  1. Bring up a dev lane pointed at the relay with SCULK_FEATURES=sculkworm:
sh
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
  1. Sign in, create a server, and set its game address:
sh
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"}'
json
{"id":"e4lytgrcw6v4fo3v","name":"Survival SMP","createdAt":"2026-11-26T23:57:40.963Z"}
sh
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
json
{"routes":[{"host":"survival-smp.play.sculk.test","target":"127.0.0.1:25565","tenant":"sculk"}]}
  1. Update the backend target and confirm sculkworm reflects the change:
sh
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
json
{"host":"survival-smp.play.sculk.test","target":"127.0.0.1:25566","tenant":"sculk"}
  1. Disconnect the server and confirm the route is deleted:
sh
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
json
{"ok":true}
{"routes":[]}
  1. Restart with SCULK_FEATURES=-sculkworm to confirm flag-off returns 404 with Cache-Control: no-store and leaves sculkworm untouched:
sh
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 4
text
HTTP/1.1 404 Not Found
cache-control: no-store
content-type: application/json