Skip to content

Add federation and database pool configuration support#2

Merged
jevonearth merged 1 commit intomainfrom
add-federation-and-db-pool-support
Feb 25, 2026
Merged

Add federation and database pool configuration support#2
jevonearth merged 1 commit intomainfrom
add-federation-and-db-pool-support

Conversation

@GImbrailo
Copy link
Contributor

Summary

Adds support for Matrix federation behind Cloudflare and configurable database connection pools.

Problem

  1. Federation doesn't work behind Cloudflare: Standard Matrix federation uses port 8448, which Cloudflare doesn't proxy. This breaks cross-operator relay infrastructure.
  2. Database connection pools are hardcoded: Can't tune pool sizes per deployment.

Solution

1. Cloudflare Federation Support

New environment variables:

  • PUBLIC_BASEURL: Public URL for federation (defaults to https://SERVER_NAME)
  • SERVE_WELLKNOWN: Set to "true" to enable .well-known/matrix/server delegation

When SERVE_WELLKNOWN=true:

  • Synapse serves /.well-known/matrix/server with delegation to port 443
  • Other Matrix servers connect on port 443 instead of 8448
  • Works with Cloudflare's supported HTTPS ports

Implementation uses Synapse's built-in serve_server_wellknown setting, automatically added by the entrypoint script.

2. Configurable Database Connection Pools

New environment variables:

  • DB_CP_MIN: Minimum connections (default: 20)
  • DB_CP_MAX: Maximum connections (default: 80)

Previously hardcoded values are now configurable per deployment.

Changes

Files Modified

  • homeserver.yaml: Added public_baseurl, changed cp_min/cp_max to use template variables
  • synctl_entrypoint.sh: Added defaults and variable substitution for new env vars, implemented SERVE_WELLKNOWN logic
  • README.md: Documented new variables and added Cloudflare federation setup guide

Backward Compatibility

Fully backward compatible

  • All new variables have sensible defaults
  • Existing deployments work unchanged without setting new variables
  • No breaking changes to existing functionality

Testing

  • Image builds successfully in CI
  • Local test with docker-compose.example.yml
  • Federation test with SERVE_WELLKNOWN=true
  • Connection pool configuration with custom DB_CP_MIN/MAX values

Use Case

ECAD operates beacon relay servers behind Cloudflare that need to federate with Papers' servers and other operators. This enables the multi-operator relay infrastructure that Beacon/Matrix is designed for.

References

Enables Matrix federation for servers behind Cloudflare and adds
configurable database connection pool sizes.

Changes:

1. Federation for Cloudflare-proxied servers
   - New env var: PUBLIC_BASEURL (defaults to https://SERVER_NAME)
   - New env var: SERVE_WELLKNOWN (set to "true" to enable)
   - When enabled, Synapse serves /.well-known/matrix/server
   - Tells other Matrix servers to connect on port 443 instead of 8448
   - Required for federation when behind Cloudflare (doesn't proxy 8448)

2. Configurable database connection pools
   - New env var: DB_CP_MIN (minimum connections, default: 20)
   - New env var: DB_CP_MAX (maximum connections, default: 80)
   - Previously hardcoded, now tunable per deployment

3. Documentation
   - Added environment variable reference
   - Added Cloudflare federation setup guide
   - Explained reverse proxy requirements

These changes maintain backward compatibility - all new variables have
sensible defaults. Existing deployments work unchanged.

Use case: ECAD's beacon servers are behind Cloudflare and need to
federate with Papers' servers. This enables cross-operator relay
infrastructure as intended by the Beacon/Matrix architecture.
@jevonearth jevonearth self-requested a review February 25, 2026 23:54
@jevonearth jevonearth merged commit a6a1fdc into main Feb 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants