garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /deploy/cartopolis-sim.service

raw

# The public Cartopolis simulator, as it runs on code.garage44.eu.
#
# Installed at /etc/systemd/system/cartopolis-sim.service. A native binary under
# systemd rather than a container in /data/stack/docker-compose.yml, for the same
# reason Forgejo is: the Forgejo *runner* and this host are the same machine, so
# CI publishes the binary with a file copy and there is no registry to push an
# image to and no image to build. Caddy reaches it across the docker0 gateway
# exactly as it reaches Forgejo (`reverse_proxy 172.17.0.1:3000`).
#
# **Nothing here listens on a public interface, and that is the point.** Every
# client — desktop, Android and browser alike — arrives over `wss://` through
# Caddy, so a password and a session token are never on a network in the clear.
#
#   --listen 127.0.0.1:4747    the TCP wire, loopback only. Kept for the local
#                              tools that speak it (`--connect 127.0.0.1:4747`
#                              against a sim on this box) and because solo mode
#                              uses the same code path. Unreachable from off the
#                              machine, so its plaintext costs nothing.
#   --http-listen 172.17.0.1:4748
#                              the WebSocket carrier (/ws) and the account admin
#                              API, on the docker0 gateway: reachable from Caddy
#                              and from nothing else. The TLS in front of it is
#                              Caddy's, which is also what terminates it for the
#                              browser — one certificate, one terminator, one
#                              code path on the server.
#   --calls-listen 51.195.91.181:4749
#                              the call forwarder, UDP, on the public address:
#                              the one exception to the rule above, and the
#                              reason it is not one. What crosses it is WebRTC
#                              — DTLS-SRTP around frames already sealed on the
#                              caller's device with a key only the chat's
#                              members hold (`docs/notes/calls.md`) — so there
#                              is nothing on it in the clear to protect. It is
#                              the host's own address, not a gateway, because
#                              WebRTC advertises the bound address in the SDP
#                              and clients have to be able to send to it;
#                              Caddy carries no UDP.
#
# This used to be `--listen 0.0.0.0:4747`, published so desktop clients could
# reach it, with a comment admitting the credentials crossed the network in the
# clear. The client speaks `wss://` on every target now (`network::resolve_target`
# resolves a bare hostname to TLS), so the plaintext port had no remaining user
# and is closed. The address to hand people is `cartopolis.org` — no port, no
# scheme; the client adds `wss://` and `/ws` itself.
#
# If you ever reopen it: the reason not to is that a bare `--connect host:4747`
# is the *easy* thing to type, so an open port is not an option people weigh, it
# is the one they take by accident.
[Unit]
Description=Cartopolis simulator
Documentation=https://code.garage44.eu/jeroen/cartopolis
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=cartosim
Group=cartosim
WorkingDirectory=/data/cartopolis/sim
ExecStart=/data/cartopolis/sim/simulator \
    --listen 127.0.0.1:4747 \
    --http-listen 172.17.0.1:4748 \
    --calls-listen 51.195.91.181:4749 \
    --database-path /data/cartopolis/sim/data/world.db
Restart=always
RestartSec=3s
Environment=RUST_LOG=info
EnvironmentFile=/etc/cartopolis-sim.env

# The world database is the only thing this service may write. `refinery`
# migrations run on every start, so it needs write access to that directory and
# to nothing else on the box.
ReadWritePaths=/data/cartopolis/sim/data
ProtectSystem=strict
ProtectHome=true
PrivateTmp=true
NoNewPrivileges=true

[Install]
WantedBy=multi-user.target