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

Deploying sculkworm

sculkworm compiles to a static Linux musl binary inside a non-root gcr.io/distroless/static-debian12:nonroot container image. It can run purely from a static routes.json file (stateless) or with the multi-tenant HTTP admin API enabled alongside a JSON state file.

Sharing port 25565 across servers#

Minecraft Java Edition connects to TCP port 25565 by default. Because sculkworm inspects the hostname in the initial Handshake packet before opening a backend socket, one sculkworm instance on port 25565 can front as many Minecraft servers as you configure via routes.json or the admin API. Players connect using only the hostname (survival.play.example, creative.play.example) without entering a port number.

Container image#

Build the image locally from crates/sculkworm.

sh
docker build -t sculkworm crates/sculkworm
text
 => => naming to docker.io/library/sculkworm:latest

The image sets:

  • SCULKWORM_LISTEN=0.0.0.0:25565
  • SCULKWORM_ROUTES_FILE=/etc/sculkworm/routes.json
  • SCULKWORM_API_ADDR=0.0.0.0:8080
  • SCULKWORM_STATE_FILE=/var/lib/sculkworm/state.json

It creates /var/lib/sculkworm owned by nonroot:nonroot, runs as nonroot:nonroot, and exposes ports 25565 (Minecraft relay) and 8080 (admin API when SCULKWORM_TENANTS_FILE is set). When SCULKWORM_TENANTS_FILE is unset, port 8080 is not bound.

Keeping the admin API private#

The HTTP admin API does not terminate TLS and grants full route control over each tenant's domain scope to anyone holding that tenant's bearer key.

  • Never publish port 8080 on a public interface. Bind SCULKWORM_API_ADDR to 127.0.0.1:8080 (the binary default) or publish it only to 127.0.0.1:8080:8080 or a private container/Tailscale/WireGuard network.
  • If callers reach the admin API across a network boundary, terminate TLS and enforce network-level access controls in front of it.
  • To run in API-only mode inside Docker without a routes.json file, clear SCULKWORM_ROUTES_FILE (-e SCULKWORM_ROUTES_FILE=).

Example routes file#

Save a routes.json file on the host with one entry per public hostname.

json
{
	"routes": {
		"survival.play.example": "10.0.0.10:25565",
		"creative.play.example": "10.0.0.11:25565"
	}
}

Docker run#

Mount routes.json read-only at /etc/sculkworm/routes.json and publish port 25565.

sh
docker run -d --name sculkworm \
	--restart unless-stopped \
	-p 25565:25565 \
	-v "$PWD/routes.json:/etc/sculkworm/routes.json:ro" \
	sculkworm
text
<container id>

Inspect stderr logs to confirm startup.

sh
docker logs sculkworm
text
level=info event=listening addr=0.0.0.0:25565 routes=2

Docker run with the admin API and state volume#

Create a tenants.json file and a named Docker volume (or a host directory writable by uid/gid 65532, nonroot:nonroot) for /var/lib/sculkworm. Publish port 8080 on loopback (127.0.0.1:8080:8080) or attach callers to a private Docker network.

sh
docker volume create sculkworm-state
docker run -d --name sculkworm \
	--restart unless-stopped \
	-p 25565:25565 \
	-p 127.0.0.1:8080:8080 \
	-e SCULKWORM_ROUTES_FILE= \
	-e SCULKWORM_TENANTS_FILE=/etc/sculkworm/tenants.json \
	-v "$PWD/tenants.json:/etc/sculkworm/tenants.json:ro" \
	-v sculkworm-state:/var/lib/sculkworm \
	sculkworm
text
level=info event=state_loaded routes=0
level=info event=listening addr=0.0.0.0:25565 routes=0
level=info event=api_listening addr=0.0.0.0:8080

Docker Compose#

Mount the directory containing routes.json and tenants.json rather than a single file when you plan to edit files atomically (for example with mv). A single-file bind mount in Docker stays pinned to the old inode when the host replaces the file, so a SIGHUP reload inside the container would keep reading the old contents.

yaml
services:
  sculkworm:
    image: sculkworm
    build: ./crates/sculkworm
    restart: unless-stopped
    ports:
      - "25565:25565"
      - "127.0.0.1:8080:8080"
    environment:
      SCULKWORM_LISTEN: "0.0.0.0:25565"
      SCULKWORM_ROUTES_FILE: "/etc/sculkworm/routes.json"
      SCULKWORM_TENANTS_FILE: "/etc/sculkworm/tenants.json"
      SCULKWORM_STATE_FILE: "/var/lib/sculkworm/state.json"
      SCULKWORM_API_ADDR: "0.0.0.0:8080"
      SCULKWORM_MAX_CONNECTIONS: "1024"
    volumes:
      - ./config:/etc/sculkworm:ro
      - sculkworm-state:/var/lib/sculkworm

volumes:
  sculkworm-state:

Start the service and check its startup log.

sh
docker compose up -d sculkworm
docker compose logs sculkworm
text
level=info event=state_loaded routes=0
level=info event=listening addr=0.0.0.0:25565 routes=2
level=info event=api_listening addr=0.0.0.0:8080

Deploying closed mode#

Closed mode adds a single TLS listener (SCULKWORM_TUNNEL_LISTEN) that splits traffic on one port by TLS ALPN:

  • ALPN sculkworm: tunnel sessions from sculkworm-agent and sculkworm-connect.
  • ALPN http/1.1 or no ALPN: public HTTPS login and ticket endpoints (/login/*, /tickets, /logout, /healthz).

Because both protocols share one port and one TLS certificate, publish SCULKWORM_TUNNEL_LISTEN on TCP port 443 (for example bind 0.0.0.0:8443 inside the container and publish -p 443:8443, or bind 0.0.0.0:443 directly with CAP_NET_BIND_SERVICE) so players and agents behind restrictive firewalls can reach it. Do not terminate TLS in an HTTP reverse proxy in front of SCULKWORM_TUNNEL_LISTEN: an HTTP proxy cannot pass through ALPN sculkworm frames. Use either direct port 443 exposure or an L4 TLS passthrough (SNI/TCP) proxy.

State version 2 and downgrade note#

Upgrade and downgrade note: sculkworm reads state versions 1 and 2 and always writes version 2. A version 1 file is loaded as open routes and is only rewritten as version 2 on the next API write. Older sculkworm binaries refuse a version 2 state file (unsupported state version 2). Back up SCULKWORM_STATE_FILE before upgrading if you may need to roll back to a pre-closed-mode release.

1. Prepare certificates, tenants.json, and secrets.json (0600)#

Choose the relay's public hostname (for example relay.example), point its A/AAAA record at the relay host, and obtain a TLS certificate and private key (ACME sidecar such as certbot/lego writing PEM files to a shared volume, or an operator-supplied cert/key). sculkworm reloads both PEM files in place on SIGHUP without dropping existing sessions.

Generate a 32-byte login encryption key:

sh
head -c 32 /dev/urandom | basenc --base64url | tr -d '='
text
brN9rJKkXotCk5p7QxRcalnFpPmOt_cIO8KDB2kic8M

Create tenants.json (with the tenant that owns your closed-route domain) and secrets.json with mode 0600 (or 0400). On Unix, sculkworm refuses to start if group or world permission bits are set on secrets.json. Register ${SCULKWORM_PUBLIC_URL}/login/callback as the redirect URI in each IdP application (for example https://relay.example/login/callback).

sh
mkdir -p config
cat > config/tenants.json <<'EOF'
{
  "tenants": [
    {
      "name": "sculk",
      "key": "replace-with-a-random-key-of-at-least-32-chars",
      "domains": ["play.example"]
    }
  ]
}
EOF
sh
umask 077
cat > config/secrets.json <<'EOF'
{
  "login_keys": {
    "1": "brN9rJKkXotCk5p7QxRcalnFpPmOt_cIO8KDB2kic8M"
  },
  "clients": {
    "discord-main": {
      "tenant": "sculk",
      "kind": "oauth2",
      "preset": "discord",
      "client_id": "1234567890",
      "client_secret_env": "SCULKWORM_DISCORD_SECRET"
    },
    "example-oidc": {
      "tenant": "sculk",
      "kind": "oidc",
      "issuer": "https://accounts.example.com",
      "client_id": "sculkworm",
      "client_secret_env": "SCULKWORM_OIDC_SECRET"
    }
  }
}
EOF
chmod 0600 config/secrets.json

When running the distroless container (USER nonroot:nonroot, uid/gid 65532), ensure the secrets file is owned by 65532:65532 with mode 0400 or 0600 so only the relay process can read it.

2. Run the relay with closed mode enabled#

Every client_secret_env referenced in secrets.json must be set and non-empty when the relay loads the file (SCULKWORM_DISCORD_SECRET and SCULKWORM_OIDC_SECRET for the example above):

sh
SCULKWORM_LISTEN=0.0.0.0:25565 \
SCULKWORM_API_ADDR=127.0.0.1:8080 \
SCULKWORM_TENANTS_FILE=/etc/sculkworm/tenants.json \
SCULKWORM_STATE_FILE=/var/lib/sculkworm/state.json \
SCULKWORM_TUNNEL_LISTEN=0.0.0.0:8443 \
SCULKWORM_TLS_CERT_FILE=/etc/sculkworm/tls/fullchain.pem \
SCULKWORM_TLS_KEY_FILE=/etc/sculkworm/tls/privkey.pem \
SCULKWORM_PUBLIC_URL=https://relay.example \
SCULKWORM_SECRETS_FILE=/etc/sculkworm/secrets.json \
SCULKWORM_DISCORD_SECRET="$DISCORD_SECRET" \
SCULKWORM_OIDC_SECRET="$OIDC_SECRET" \
  /usr/local/bin/sculkworm
text
level=info event=state_loaded routes=0
level=info event=listening addr=0.0.0.0:25565 routes=0
level=info event=api_listening addr=127.0.0.1:8080
level=info event=tunnel_listening addr=0.0.0.0:8443

(In Step 1 the sample files are written to ./config/; copy them to /etc/sculkworm/ or adjust the SCULKWORM_*_FILE paths above to match.)

Example systemd unit for the relay:

ini
[Unit]
Description=sculkworm Minecraft relay (open + closed mode)
After=network-online.target
Wants=network-online.target

[Service]
User=sculkworm
Group=sculkworm
EnvironmentFile=/etc/sculkworm/relay.env
ExecStart=/usr/local/bin/sculkworm
ExecReload=/bin/kill -HUP $MAINPID
AmbientCapabilities=CAP_NET_BIND_SERVICE
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
NoNewPrivileges=true
Restart=on-failure
RestartSec=2s

[Install]
WantedBy=multi-user.target

After renewing TLS certificates (for example from a certbot/lego deploy hook) or editing secrets.json, reload without downtime:

sh
systemctl reload sculkworm

3. Create a closed route and mint an agent token#

Closed routes support oidc (generic allow.claim or sculk.network allow.sculk_server), oauth2 (generic allow.field or the Discord preset with allow.discord_guild), and fixed-list authorizers; see Closed routes: authorizer configuration and Using sculk.network as an authorizer.

Set KEY to the sculk tenant key from tenants.json, then create the closed route referencing the example-oidc client from secrets.json:

sh
KEY="replace-with-a-random-key-of-at-least-32-chars"
curl -sS -X PUT \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -d '{"mode":"closed","authorizer":{"type":"oidc","client":"example-oidc","scopes":["openid","profile"],"allow":{"claim":"groups","any_of":["minecraft"]}}}' \
  http://127.0.0.1:8080/v1/routes/friends.play.example
json
{"active":true,"agent_connected":false,"agent_token":null,"authorizer":{"allow":{"any_of":["minecraft"],"claim":"groups"},"client":"example-oidc","scopes":["openid","profile"],"type":"oidc"},"authorizer_id":"a36e0b5c286c1fd2","host":"friends.play.example","mode":"closed","tenant":"sculk"}

Mint the route's agent token (returned once) and save it on the Minecraft server host with mode 0600:

sh
curl -sS -X POST \
  -H "Authorization: Bearer $KEY" \
  http://127.0.0.1:8080/v1/routes/friends.play.example/agent-token
json
{"token":"swa_0d35c60dc471b165_<base64url-32-random-bytes>","id":"0d35c60dc471b165","created_at":"2026-11-27T09:06:26Z"}

4. Start sculkworm-agent next to the Minecraft server#

Configure the Minecraft server to listen only on 127.0.0.1:25565 (server-ip=127.0.0.1) with no public firewall port opened. Start the agent with the token file (optionally pinning the relay's leaf SPKI with --pin, computed directly in sha256/<base64> form via printf 'sha256/%s\n' "$(openssl x509 -in fullchain.pem -pubkey -noout | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64)"):

sh
sculkworm-agent \
  --relay https://relay.example \
  --route friends.play.example \
  --token-file /etc/sculkworm/agent.token \
  --target 127.0.0.1:25565

Confirm the agent is connected from the relay's admin API:

sh
curl -sS -H "Authorization: Bearer $KEY" http://127.0.0.1:8080/v1/agents
json
{"agents":[{"connected_at":"2026-11-27T09:06:26Z","host":"friends.play.example","peer":"127.0.0.1:41278","session":"e8ddcfbf3c6af4e2","software":"sculkworm-agent/0.1","streams":0,"token_id":"0d35c60dc471b165"}]}

5. Player commands (sculkworm-connect)#

On a desktop with a browser, a player runs play (optionally --add-server to add/update friends.play.example -> 127.0.0.1:25565 in Minecraft's servers.dat):

sh
sculkworm-connect play friends.play.example --add-server

On a headless machine or SSH session, use --device (connect also falls back to the device flow automatically if opening a browser fails):

sh
sculkworm-connect login friends.play.example --relay https://relay.example --device
text
Open https://relay.example/login/device on any device, sign in and type the code KCXB-SMXC.
Logged in to friends.play.example as alex (subject user-alex-42, expires 2026-12-27T09:06:30Z)

Then start the local listener and connect Minecraft to 127.0.0.1:25565:

sh
sculkworm-connect play friends.play.example --add-server
text
level=info event=servers_dat_updated path="/home/alex/.minecraft/servers.dat" name=friends.play.example ip=127.0.0.1:25565
level=info event=connect_listening route=friends.play.example listen=127.0.0.1:25565

To sign out and revoke the stored login on the relay:

sh
sculkworm-connect logout friends.play.example

Reload routes, secrets, and TLS certificates with SIGHUP#

On Unix systems, send SIGHUP to reload SCULKWORM_ROUTES_FILE, SCULKWORM_SECRETS_FILE, and the tunnel TLS certificate/key pair (SCULKWORM_TLS_CERT_FILE / SCULKWORM_TLS_KEY_FILE) without dropping active connections. Existing connections stay spliced to their original backend, existing tunnel sessions stay open, dynamic routes registered via the admin API remain untouched, and new connections or TLS handshakes pick up the reloaded files immediately.

With Docker:

sh
docker kill --signal=HUP sculkworm
text
sculkworm

With a direct process:

sh
kill -HUP <pid>

When the updated file parses cleanly, sculkworm replaces the table and prints:

text
level=info event=reloaded routes=3

When the updated file cannot be read or fails validation, sculkworm keeps the previous route table in memory and prints an error line:

text
level=error event=reload_failed path="/tmp/sculkworm-doc-routes.json" error="invalid routes file: key must be a string at line 1 column 3"

Graceful shutdown#

sculkworm handles SIGTERM and SIGINT (Ctrl-C). When either signal arrives, the process:

  1. Logs level=info event=shutdown.
  2. Closes the listening TCP socket so no new connections are accepted.
  3. Waits up to 5 seconds (DRAIN_TIMEOUT) for active connection tasks to finish and release their permits.
  4. Exits with status 0 once all active tasks finish or the 5-second drain window expires.
sh
kill -TERM <pid>
text
level=info event=shutdown

Running behind another TCP proxy#

sculkworm does not support the HAProxy PROXY protocol (v1 or v2). If an upstream proxy prepends a PROXY protocol header before the Minecraft Handshake packet, sculkworm rejects the connection during Handshake parsing. A PROXY v1 or v2 header followed by enough bytes is logged as reason=unexpected_packet_id. If fewer bytes arrive than the header's first byte claims as a packet length, sculkworm waits for more and logs reason=timeout or reason=eof.

If you run sculkworm behind a plain L4 TCP forwarder that does not add PROXY headers, routing still works because the Minecraft Handshake bytes are unchanged. However, the peer= field in sculkworm logs will record the proxy IP address instead of the player IP address.

Log events#

sculkworm writes structured key=value log lines to stderr. Hostnames written to host= are sanitized before logging. An empty value is logged as <empty>, and any character that is not printable ASCII graphic or is " or \ is replaced with ?.

Lifecycle and reload events#

Level Event Fields When emitted
error config_error error An environment variable is missing or invalid at startup. Process exits 2.
error routes_error error The routes file cannot be read or fails validation at startup. Process exits 2.
error tenants_error error The tenants file cannot be read or fails validation at startup. Process exits 2.
error state_error error The state file cannot be read or fails validation at startup. Process exits 2.
warn state_route_dropped host, reason A persisted route was dropped at startup (unknown_tenant, host_out_of_scope or target_not_allowed).
info state_loaded routes Persisted dynamic routes were loaded from SCULKWORM_STATE_FILE.
error tls_error error SCULKWORM_TLS_CERT_FILE or SCULKWORM_TLS_KEY_FILE cannot be read, fails PEM parsing, or does not match at startup. Process exits 2.
error runtime_error error The Tokio runtime fails to initialize. Process exits 1.
error startup_error error Binding SCULKWORM_LISTEN, SCULKWORM_API_ADDR, or SCULKWORM_TUNNEL_LISTEN fails. Process exits 1.
info listening addr, routes The Minecraft TCP listener is bound and accepting connections.
info api_listening addr The HTTP admin API listener is bound and accepting connections.
info tunnel_listening addr The TLS tunnel listener is bound and accepting connections.
info reloaded routes A SIGHUP reload succeeded and replaced the static routes (dynamic routes stay intact).
info secrets_reloaded (none) A SIGHUP reload succeeded and replaced the secrets config.
info tls_reloaded (none) A SIGHUP reload succeeded and replaced the tunnel TLS certificate and key.
error reload_failed path, error A SIGHUP reload failed. The previous static route table, secrets, or TLS certificate remains active.
info shutdown (none) SIGTERM or SIGINT was received and drain has started on relay, API, and tunnel listeners.

Running sculkworm-agent under systemd#

Run sculkworm-agent (or sculkworm agent) next to a Minecraft server listening on 127.0.0.1:25565. Configure RestartPreventExitStatus=3 so systemd does not restart an agent that exited cleanly with code 3 after being replaced by a newer agent (GOAWAY replaced), and RestartPreventExitStatus=2 3 if you also want configuration/protocol-version errors to stop immediately:

ini
[Unit]
Description=sculkworm tunnel agent
After=network-online.target
Wants=network-online.target

[Service]
User=minecraft
Group=minecraft
ExecStart=/usr/local/bin/sculkworm-agent --relay https://relay.example --route friends.play.example --token-file /etc/sculkworm/agent.token --target 127.0.0.1:25565
NoNewPrivileges=true
Restart=on-failure
RestartSec=2s
RestartPreventExitStatus=2 3

[Install]
WantedBy=multi-user.target

Closed-mode tunnel and login events#

Level Event Fields When emitted
error secrets_error error SCULKWORM_SECRETS_FILE is missing, malformed, or has permissions looser than 0600/0400 at startup. Process exits 2.
warn closed_route_inactive host, reason A closed route loaded from state cannot serve (closed_mode_disabled, unknown_client, or client_tenant_mismatch).
info agent_token_minted tenant, host, token_id A tenant minted an agent token via POST /v1/routes/{host}/agent-token.
info agent_token_revoked tenant, host A tenant deleted an agent token via DELETE /v1/routes/{host}/agent-token.
info logins_revoked tenant/route, host/lid, subject, scope Logins were revoked by admin API (scope=route or subject=...) or player POST /logout (scope=logout).
warn tunnel_connection_rejected reason=ip_limit, peer Source IP exceeded the concurrent tunnel TCP limit (16).
info tunnel_tls_failed peer, error TLS handshake on the tunnel listener failed.
info tunnel_handshake_timeout peer Client did not complete TLS + HELLO within SCULKWORM_HANDSHAKE_TIMEOUT_SECONDS.
warn agent_unauthorized route, peer An agent presented an unknown, revoked, or wrong-route token in HELLO.
info agent_connected route, session, token_id, peer, software An agent session was established.
info agent_replacing route, old_session, new_session A newer agent replaced an existing agent session (GOAWAY replaced sent to old session).
info agent_disconnected route, session, token_id, peer, reason An agent session closed.
info connect_session route, session, lid, subject, name, peer, software A connect session was established with a valid ticket.
info stream_open route, session, stream_id, subject, name, peer A player stream was bridged to the route's agent.
info stream_closed route, session, stream_id, bytes_up, bytes_down, peer A bridged player stream finished.
info login route, lid, subject, name, peer (plus flow=device) A player completed login and was admitted by the route's authorizer.
info login_denied route, reason, peer (plus subject, name when known) A player login failed or was rejected by the authorizer.
info ticket route, lid, subject, name, rotated, peer A short-lived tunnel ticket was minted by POST /tickets.
info ticket_denied route, lid, subject, reason, peer POST /tickets denied a request.
warn idp_unavailable route/client, detail/status, peer An outbound IdP request failed, timed out, or returned 5xx.
warn session_timeout (none) A tunnel session received no frame for 45 seconds and was closed.
error tls_pin_mismatch got / error Agent or connect observed a leaf certificate SPKI that did not match any --pin.

Admin API events#

Level Event Fields When emitted
info api_unauthorized peer A request to /v1/* failed bearer authentication.
info route_put tenant, host, target, created A tenant created (created=true) or updated/confirmed (created=false) a dynamic route.
info route_deleted tenant, host A tenant deleted a dynamic route.
error persist_failed tenant, host, error Writing SCULKWORM_STATE_FILE failed; the in-memory table was not modified.

Per-connection events#

Level Event Fields When emitted
warn accept_error error accept() returned an OS error. The loop backs off for 100 ms before retrying.
warn connection_rejected reason=max_connections, peer SCULKWORM_MAX_CONNECTIONS permits are all in use. The socket closes immediately.
info handshake_rejected reason, peer The client disconnected, timed out, or sent an invalid Handshake packet. See Rejection reasons.
info unknown_host host, peer The parsed route key has no matching open or closed route. The socket closes with zero bytes sent.
info closed_route_answer host, intent, protocol, peer The parsed route key matched a closed route on the public Minecraft port; sculkworm answered directly with status/pong or Login Disconnect without forwarding.
warn backend_unreachable host, target, peer, error DNS lookup failed, TCP connect timed out or was refused, or replaying the buffered Handshake bytes to the backend failed.
warn backend_loop host, target, peer The backend connection reached the relay's own listening port, so a route points back at the relay. The connection closes with zero bytes sent.
info route host, target, intent, protocol, peer The backend accepted the replayed Handshake bytes and bidirectional splicing began.
info closed host, target, bytes_up, bytes_down, peer The spliced connection ended. bytes_up includes the initial buffered Handshake bytes.