Server step: federate only with listed servers, or never with some

Private and small servers often want to talk to a few others, not the
whole federation; the playbook has the settings, but only as variables.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vvvomitandClaude Opus 5.5 committed 2026-10-29 04:52:24 +03:30
1 parent fe3cceff5c
commit 0181775300
5 files changed
+74

No files matched your search

+3
View File
@@ -85,6 +85,9 @@ or the [Telegram group](https://t.me/+6UwIu9F4gZQxNjM0).
in the presets too. Untick it on Components to keep Synapse's own
logins. Servers that are already installed keep what they have, since
moving existing accounts to MAS is a migration of its own.
- **Who to federate with**, on the Server step: only the servers you
list (Synapse's `federation_domain_whitelist`), and on Continuwuity and
Tuwunel also servers never to federate with.
- **Presets** to start from on the Homeserver step: Minimal chat (Synapse,
MAS, Element and Sable), Friends & family (adds Element Call and
Ketesa), Bridge hub (Telegram, WhatsApp, Signal and Discord with double
+3
View File
@@ -60,6 +60,9 @@ type Config struct {
SSL SSL
IPv6 bool
Federation bool
// FederateOnly, when set, are the only servers federated with;
// FederateNever are never federated with (not on Synapse).
FederateOnly, FederateNever []string
Components map[string]bool
Values map[string]string
+25
View File
@@ -0,0 +1,25 @@
package config
import (
"strings"
"testing"
)
func TestFederationLists(t *testing.T) {
c := Default()
c.Domain, c.Homeserver = "example.org", "synapse"
c.FederateOnly, c.FederateNever = []string{"matrix.org", "friends.example"}, []string{"bad.example"}
y := c.VarsYAML("", "", "")
if !strings.Contains(y, `matrix_synapse_federation_domain_whitelist: ["matrix.org","friends.example"]`) || strings.Contains(y, "bad.example") {
t.Errorf("synapse:\n%s", y)
}
c.Homeserver = "tuwunel"
y = c.VarsYAML("", "", "")
if !strings.Contains(y, `matrix_tuwunel_config_forbidden_remote_server_names: ["^bad\\.example$"]`) {
t.Errorf("tuwunel:\n%s", y)
}
c.Federation = false
if strings.Contains(c.VarsYAML("", "", ""), "remote_server_names") {
t.Errorf("lists written with federation off")
}
}
+33
View File
@@ -1,6 +1,7 @@
package config
import (
"encoding/json"
"fmt"
"maps"
"os"
@@ -189,6 +190,9 @@ func (c *Config) VarsYAML(migrationVersion, certPath, keyPath string) string {
w.raw("devture_systemd_docker_base_ipv6_enabled", fmt.Sprint(c.IPv6))
w.str("postgres_connection_password", c.PostgresPassword)
w.raw("matrix_homeserver_federation_enabled", fmt.Sprint(c.Federation))
if c.Federation {
c.renderFederationLists(w)
}
if c.FederationPort() == "443" {
w.comment("Federation goes through 443 with the client API, so 8448 stays closed.")
w.raw("matrix_federation_public_port", "443")
@@ -389,3 +393,32 @@ func (c *Config) HostsINI() string {
b.WriteString(strings.Join(parts, " ") + "\n")
return b.String()
}
// renderFederationLists writes which servers to federate with: Synapse
// takes an allow list of names, Continuwuity and Tuwunel regexes for both.
func (c *Config) renderFederationLists(w *yamlWriter) {
list := func(names []string, pattern bool) string {
out := []string{}
for _, n := range names {
if pattern {
n = "^" + regexp.QuoteMeta(n) + "$"
}
out = append(out, n)
}
b, _ := json.Marshal(out)
return string(b)
}
switch c.Homeserver {
case "synapse":
if len(c.FederateOnly) > 0 {
w.raw("matrix_synapse_federation_domain_whitelist", list(c.FederateOnly, false))
}
case "continuwuity", "tuwunel":
if len(c.FederateOnly) > 0 {
w.raw("matrix_"+c.Homeserver+"_config_allowed_remote_server_names", list(c.FederateOnly, true))
}
if len(c.FederateNever) > 0 {
w.raw("matrix_"+c.Homeserver+"_config_forbidden_remote_server_names", list(c.FederateNever, true))
}
}
}
+10
View File
@@ -236,8 +236,14 @@ func (s *serverScreen) enter(c *config.Config) tea.Cmd {
toggleField("federation", "Federate with other Matrix servers", c.Federation,
"Turn off for a private server that never talks to the outside world."),
textField("fed.only", "Federate only with", strings.Join(c.FederateOnly, " "), "everyone",
"Server names separated by spaces, e.g. matrix.org friends.example; empty federates with everyone."),
textField("fed.never", "Never federate with", strings.Join(c.FederateNever, " "), "nobody",
"Server names separated by spaces. Synapse can't block single servers; use the list above instead."),
toggleField("ipv6", "Enable IPv6 networking for containers", c.IPv6, "Only if your server has working IPv6."),
)
f.get("fed.only").hidden = func() bool { return !f.get("federation").on }
f.get("fed.never").hidden = func() bool { return !f.get("federation").on || c.Homeserver == "synapse" }
remote := func() bool { return f.value("mode") != "ssh" }
for _, k := range []string{"host", "user", "port", "key"} {
f.get(k).hidden = remote
@@ -326,6 +332,10 @@ func (s *serverScreen) leave(c *config.Config) {
c.SSL = config.SSL{Mode: f.value("ssl"), ACMEEmail: f.value("ssl.email"),
CertPath: f.value("ssl.cert"), KeyPath: f.value("ssl.key")}
c.Federation = f.get("federation").on
names := func(v string) []string {
return strings.FieldsFunc(v, func(r rune) bool { return r == ' ' || r == ',' })
}
c.FederateOnly, c.FederateNever = names(f.value("fed.only")), names(f.value("fed.never"))
c.IPv6 = f.get("ipv6").on
}