configure-trust.sh 45 lignes · 1647 octets
#!/usr/bin/env bash
# Configure cross-instance trust by writing directly into each instance's
# fediverse_trusted_domains table via psql.
#
# Rationale: the admin trust list UI is a CSRF-protected form POST that
# would require a full login + token-extraction dance for automation.
# Direct SQL insertion is simpler, safer (no auth bypass), and only
# reasonable in this testbed context where we own the database.

set -euo pipefail

cd "$(dirname "$0")/.."

# Bidirectional trust: each instance trusts the two others.
declare -A TRUSTS=(
  [alpha]="beta.local gamma.local"
  [beta]="alpha.local gamma.local"
  [gamma]="alpha.local beta.local"
)

# Flip the fediverse_enabled app setting to true, so admin UI shows the
# fediverse pages. Protocol endpoints (inbox/webfinger) do not depend on
# this flag, but the admin UX does.
ENABLE_SQL="
UPDATE app_settings SET value = 'true' WHERE key = 'fediverse_enabled';
"

for instance in alpha beta gamma; do
  echo "==> Configuring trust list on $instance"
  for peer in ${TRUSTS[$instance]}; do
    SQL="
      INSERT INTO fediverse_trusted_domains (id, domain, note, added_by_user_id, created_at)
      VALUES (gen_random_uuid(), '$peer', 'testbed bootstrap', NULL, NOW())
      ON CONFLICT (domain) DO NOTHING;
    "
    docker compose exec -T "postgres-$instance" psql -U rustwarden -d "rustwarden_$instance" \
      -c "$SQL" >/dev/null
    echo "    trusts $peer"
  done
  docker compose exec -T "postgres-$instance" psql -U rustwarden -d "rustwarden_$instance" \
    -c "$ENABLE_SQL" >/dev/null
  echo "    fediverse_enabled=true"
done

echo "==> Trust list configured for all three instances."