Resolve Synapse's admin API internally, not through Traefik

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 <noreply@anthropic.com>
This commit is contained in:
paulandClaude Sonnet 5 committed 2026-09-18 20:08:36 +12:00
1 parent 4782849ce5
commit a8124a803b
1 file changed
+15 -2
+15 -2
View File
@@ -46,7 +46,20 @@ ROOM_ID="$(cfg_get "['matrix'].get('room_id','')" 2>/dev/null || echo "")"
# localpart from @maintainer-bot:semprini.me -> maintainer-bot # localpart from @maintainer-bot:semprini.me -> maintainer-bot
BOT_LOCAL="${BOT_USER_ID#@}"; BOT_LOCAL="${BOT_LOCAL%%:*}" 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 "→ Bot : $BOT_USER_ID"
echo "→ Admin : $ADMIN_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 # 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 # has a valid standalone access token, ensure the room, and write
# access_token + room_id back into config.json. # 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 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] config, hs, shared, bot_local, bot_id, admin_id, room_id = sys.argv[1:8]