From a8124a803b35a0930b453a0fd5a61a6dfecb5545 Mon Sep 17 00:00:00 2001 From: Semprini Date: Fri, 18 Sep 2026 20:08:36 +1200 Subject: [PATCH] Resolve Synapse's admin API internally, not through Traefik MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit semprini-core now refuses /_synapse/admin/* at the edge (SR-05) — it needed no auth of its own and let anyone on the internet create or deactivate Matrix accounts given the registration shared secret. This script already reads that secret straight out of the user-synapse container; it now resolves the container's semprini_internal address the same way semprini-core's scripts/setup-matrix-alerts.py does, and uses it for every call instead of the public hostname. Verified live against the real maintainer bot account: it found the existing token still valid and re-used the existing room, unchanged. Co-Authored-By: Claude Sonnet 5 --- register-matrix-bot.sh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/register-matrix-bot.sh b/register-matrix-bot.sh index 5f1131e..5b714e1 100755 --- a/register-matrix-bot.sh +++ b/register-matrix-bot.sh @@ -46,7 +46,20 @@ ROOM_ID="$(cfg_get "['matrix'].get('room_id','')" 2>/dev/null || echo "")" # localpart from @maintainer-bot:semprini.me -> maintainer-bot BOT_LOCAL="${BOT_USER_ID#@}"; BOT_LOCAL="${BOT_LOCAL%%:*}" -echo "→ Homeserver : $HOMESERVER" +# Traefik refuses /_synapse/admin/* at the edge (semprini-core SR-05: it was +# reachable from the public internet). Talk to Synapse's own container address +# on semprini_internal instead, the same way scripts/setup-matrix-alerts.py +# does in semprini-core — this script already runs on the host with docker +# access. Only the admin API is guarded, so plain /_matrix/client/* calls +# (whoami, createRoom, profile) would work fine through $HOMESERVER too, but +# using the same base for both keeps this script off Traefik entirely. +SYNAPSE_IP="$(docker inspect -f \ + '{{with index .NetworkSettings.Networks "semprini_internal"}}{{.IPAddress}}{{end}}' \ + "$SYNAPSE_CONTAINER")" +[ -n "$SYNAPSE_IP" ] || { echo "ERROR: $SYNAPSE_CONTAINER has no semprini_internal address"; exit 1; } +API_BASE="http://$SYNAPSE_IP:8008" + +echo "→ Homeserver : $HOMESERVER (admin API via $API_BASE)" echo "→ Bot : $BOT_USER_ID" echo "→ Admin : $ADMIN_USER_ID" @@ -61,7 +74,7 @@ SHARED_SECRET="$(docker exec "$SYNAPSE_CONTAINER" \ # All the Matrix work happens in one Python block (stdlib only): ensure the bot # has a valid standalone access token, ensure the room, and write # access_token + room_id back into config.json. -python3 - "$CONFIG" "$HOMESERVER" "$SHARED_SECRET" "$BOT_LOCAL" "$BOT_USER_ID" "$ADMIN_USER_ID" "$ROOM_ID" <<'PY' +python3 - "$CONFIG" "$API_BASE" "$SHARED_SECRET" "$BOT_LOCAL" "$BOT_USER_ID" "$ADMIN_USER_ID" "$ROOM_ID" <<'PY' import hmac, hashlib, json, secrets, sys, urllib.request, urllib.error config, hs, shared, bot_local, bot_id, admin_id, room_id = sys.argv[1:8]