Skip to content

Commit e9cc37a

Browse files
turt2liveS7evinK
andauthored
Merge commit from fork
* Support configuring allow/deny networks * Make the DNS cache aware of the allow/deny networks * Allow all networks in CI * Update GMSL * Add missed file --------- Co-authored-by: Till Faelligen <[email protected]>
1 parent 4fb8335 commit e9cc37a

File tree

9 files changed

+50
-3
lines changed

9 files changed

+50
-3
lines changed

cmd/dendrite/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ func main() {
9494
dnsCache = fclient.NewDNSCache(
9595
cfg.Global.DNSCache.CacheSize,
9696
cfg.Global.DNSCache.CacheLifetime,
97+
cfg.FederationAPI.AllowNetworkCIDRs,
98+
cfg.FederationAPI.DenyNetworkCIDRs,
9799
)
98100
logrus.Infof(
99101
"DNS cache enabled (size %d, lifetime %s)",

cmd/generate-config/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ func main() {
7171
cfg.ClientAPI.RateLimiting.Enabled = false
7272
cfg.FederationAPI.DisableTLSValidation = false
7373
cfg.FederationAPI.DisableHTTPKeepalives = true
74+
// Allow allow networks when running in CI, as otherwise connections
75+
// to other servers might be blocked when running Complement/Sytest.
76+
cfg.FederationAPI.DenyNetworkCIDRs = []string{}
77+
cfg.FederationAPI.AllowNetworkCIDRs = []string{}
7478
// don't hit matrix.org when running tests!!!
7579
cfg.FederationAPI.KeyPerspectives = config.KeyPerspectives{}
7680
cfg.MediaAPI.BasePath = config.Path(filepath.Join(*dirPath, "media"))

contrib/dendrite-demo-i2p/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ func main() {
7070
dnsCache = fclient.NewDNSCache(
7171
cfg.Global.DNSCache.CacheSize,
7272
cfg.Global.DNSCache.CacheLifetime,
73+
cfg.FederationAPI.AllowNetworkCIDRs,
74+
cfg.FederationAPI.DenyNetworkCIDRs,
7375
)
7476
logrus.Infof(
7577
"DNS cache enabled (size %d, lifetime %s)",

contrib/dendrite-demo-tor/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ func main() {
6565
dnsCache = fclient.NewDNSCache(
6666
cfg.Global.DNSCache.CacheSize,
6767
cfg.Global.DNSCache.CacheLifetime,
68+
cfg.FederationAPI.AllowNetworkCIDRs,
69+
cfg.FederationAPI.DenyNetworkCIDRs,
6870
)
6971
logrus.Infof(
7072
"DNS cache enabled (size %d, lifetime %s)",

dendrite-sample.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,24 @@ federation_api:
254254
# last resort.
255255
prefer_direct_fetch: false
256256

257+
# deny_networks and allow_networks are the CIDR ranges used to prevent requests
258+
# from accessing private IPs. If your system has specific IPs it should never
259+
# contact, add them here with CIDR notation.
260+
#
261+
# The deny list is checked before the allow list.
262+
deny_networks:
263+
- "127.0.0.1/8"
264+
- "10.0.0.0/8"
265+
- "172.16.0.0/12"
266+
- "192.168.0.0/16"
267+
- "100.64.0.0/10"
268+
- "169.254.0.0/16"
269+
- "::1/128"
270+
- "fe80::/64"
271+
- "fc00::/7"
272+
allow_networks:
273+
- "0.0.0.0/0" # "Everything". The deny list will help limit this.
274+
257275
# Configuration for the Media API.
258276
media_api:
259277
# Storage path for uploaded media. May be relative or absolute.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ require (
2525
github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e
2626
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91
2727
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530
28-
github.com/matrix-org/gomatrixserverlib v0.0.0-20241215094829-e86ab16eabe8
28+
github.com/matrix-org/gomatrixserverlib v0.0.0-20250116181547-c4f1e01eab0d
2929
github.com/matrix-org/pinecone v0.11.1-0.20230810010612-ea4c33717fd7
3030
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66
3131
github.com/mattn/go-sqlite3 v1.14.24

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91 h1:s7fexw
232232
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo=
233233
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8r4Fzarl4+Y3K5hjothkVW5z7T1dUM11U=
234234
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
235-
github.com/matrix-org/gomatrixserverlib v0.0.0-20241215094829-e86ab16eabe8 h1:nC998SaawQwbZ16/V70Pil3pY3rSQwTaeLOpHWp7ZTo=
236-
github.com/matrix-org/gomatrixserverlib v0.0.0-20241215094829-e86ab16eabe8/go.mod h1:qil34SWn6VB6gO5312rzziCUcZtgROPjrLE+4ly/0os=
235+
github.com/matrix-org/gomatrixserverlib v0.0.0-20250116181547-c4f1e01eab0d h1:c3Dkci0GDH/6cGGt8zGIiJMP+UOdtX0DPY6dxiJvtZM=
236+
github.com/matrix-org/gomatrixserverlib v0.0.0-20250116181547-c4f1e01eab0d/go.mod h1:qil34SWn6VB6gO5312rzziCUcZtgROPjrLE+4ly/0os=
237237
github.com/matrix-org/pinecone v0.11.1-0.20230810010612-ea4c33717fd7 h1:6t8kJr8i1/1I5nNttw6nn1ryQJgzVlBmSGgPiiaTdw4=
238238
github.com/matrix-org/pinecone v0.11.1-0.20230810010612-ea4c33717fd7/go.mod h1:ReWMS/LoVnOiRAdq9sNUC2NZnd1mZkMNB52QhpTRWjg=
239239
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y=

setup/base/base.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func CreateFederationClient(cfg *config.Dendrite, dnsCache *fclient.DNSCache) fc
8282
fclient.WithSkipVerify(cfg.FederationAPI.DisableTLSValidation),
8383
fclient.WithKeepAlives(!cfg.FederationAPI.DisableHTTPKeepalives),
8484
fclient.WithUserAgent(fmt.Sprintf("Dendrite/%s", internal.VersionString())),
85+
fclient.WithAllowDenyNetworks(cfg.FederationAPI.AllowNetworkCIDRs, cfg.FederationAPI.DenyNetworkCIDRs),
8586
}
8687
if cfg.Global.DNSCache.Enabled {
8788
opts = append(opts, fclient.WithDNSCache(dnsCache))

setup/config/config_federationapi.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,31 @@ type FederationAPI struct {
4646

4747
// Should we prefer direct key fetches over perspective ones?
4848
PreferDirectFetch bool `yaml:"prefer_direct_fetch"`
49+
50+
// Deny/Allow lists used for restricting request scopes.
51+
DenyNetworkCIDRs []string `yaml:"deny_networks"`
52+
AllowNetworkCIDRs []string `yaml:"allow_networks"`
4953
}
5054

5155
func (c *FederationAPI) Defaults(opts DefaultOpts) {
5256
c.FederationMaxRetries = 16
5357
c.P2PFederationRetriesUntilAssumedOffline = 1
5458
c.DisableTLSValidation = false
5559
c.DisableHTTPKeepalives = false
60+
c.DenyNetworkCIDRs = []string{
61+
"127.0.0.1/8",
62+
"10.0.0.0/8",
63+
"172.16.0.0/12",
64+
"192.168.0.0/16",
65+
"100.64.0.0/10",
66+
"169.254.0.0/16",
67+
"::1/128",
68+
"fe80::/64",
69+
"fc00::/7",
70+
}
71+
c.AllowNetworkCIDRs = []string{
72+
"0.0.0.0/0",
73+
}
5674
if opts.Generate {
5775
c.KeyPerspectives = KeyPerspectives{
5876
{

0 commit comments

Comments
 (0)