Relay service for sg.zone with per-user tokens and admin panel protected by Authelia.
- No SSH access for developers.
- Personal JWT token per user.
- Token creation from any device via
/adminpage. - Admin access protected by Authelia 2FA.
- Relay endpoint is fixed to
sg.zoneonly. - Audit logs for token issuance and relay requests.
- Ready for
pm2(ecosystem.config.cjsincluded).
- Install dependencies:
npm install- Configure env:
cp .env.sample .env- Set required values in
.env:
RELAY_TOKEN_SECRETRELAY_ADMIN_EMAILSTRUSTED_AUTH_SHARED_SECRET
- Start relay locally:
npm run startpm2 start ecosystem.config.cjs
pm2 save
pm2 statusGET /health- health check.GET /admin- admin page (Authelia + trusted proxy headers required).POST /admin/tokens- issue personal token (Authelia + trusted proxy headers required). Response includestokenFingerprint.GET /relay?path=/replays?p=1- relay request (Bearer token required).
By default logs are written to ./logs/ with two targets:
./logs/<YYYY-MM-DD_HH-mm-ss>/info.log- runtime relay logs../logs/<YYYY-MM-DD_HH-mm-ss>/error.log- unhandled errors/exceptions../logs/issued-tokens.log- unified registry of all issued tokens (username,issuedBy,tokenFingerprint,expiresInDays).
If needed, override directory with RELAY_LOGS_DIR.
To map token to user, use tokenFingerprint from /admin/tokens response and match it in issued-tokens.log and relay request logs.
REPLAYS_RELAY_URL=https://relay.your-domain/relay
REPLAYS_RELAY_TOKEN=<user-token>See deploy/authelia-nginx/README.md.
Workflow: .github/workflows/cd.yml.
Trigger:
pushtomainormasterworkflow_dispatch(manual run)
Create repository secrets:
CD_SSH_HOST- server IP or host.CD_SSH_PORT- SSH port (usually22).CD_SSH_USER- deploy user on server.CD_SSH_PRIVATE_KEY- private SSH key for this deploy user.CD_APP_DIR- absolute path to project on server.
Example for CD_APP_DIR:
/home/deploy/sg_stats_relay
# 1) clone repo
mkdir -p /home/deploy
cd /home/deploy
git clone git@github.com:<org>/<repo>.git sg_stats_relay
cd sg_stats_relay
# 2) prepare relay env
cp .env.sample .env
# fill .env manually
# 3) prepare auth stack env
cp deploy/authelia-nginx/.env.example deploy/authelia-nginx/.env
# fill deploy/authelia-nginx/.env manually
# 4) start relay and authelia
npm ci
pm2 startOrReload ecosystem.config.cjs --update-env
pm2 save
cd deploy/authelia-nginx && docker compose up -dAfter that, each push to main/master runs remote script deploy/remote-deploy.sh:
- fetch + checkout target branch
- hard reset to
origin/<branch> npm ci --omit=devpm2 startOrReload ecosystem.config.cjs --update-envdocker compose up -d --remove-orphansindeploy/authelia-nginx
- Keep production
.envfiles only on server (never commit them). - Deploy user should have minimal rights: project directory,
pm2, anddocker compose. - If your default branch has another name, update
cd.ymltrigger.