matrix-org / dendrite

Dendrite is a second-generation Matrix homeserver written in Go!
https://matrix-org.github.io/dendrite/
Apache License 2.0
5.75k stars 676 forks source link

Add .well-known/matrix/server endpoint to dendrite #1985

Closed twentybit closed 3 years ago

twentybit commented 3 years ago

Description:

I'm running dendrite on kubernetes, using an ingress controller. As ingress controllers can't host static content, I've had to spin up an NGINX pod to respond to the .well-known/matrix/server endpoint to enable federation.

This feels like something that should be hosted inside dendrite, as it's a mandatory API to enable federation?

Happy creating a PR if others think the above is sensible!

tulir commented 3 years ago

It's not a mandatory API to enable federation, it's for redirecting federation traffic somewhere else. The only case where serving it from the homeserver is useful is if you're delegating to port 443 on the same IP (because the default federation port is 8448, while the .well-known port is 443).

That special case isn't rare though, so it might still make sense to have a config option for serving it.

kegsay commented 3 years ago

Indeed, whilst .well-known isn't mandated, in practice you need to implement it to allow for flexibility. I'm happy to add an endpoint which serves this content. cc @neilalexander

This will also be useful for Complement - currently it doesn't use .well-known at all and when writing federation tests we always assumes reachability on :8448, but this makes it impossible to parallelise federation tests then (as the processes will attempt to bind to the same port). The current Dendrite image used for Complement doesn't serve .well-known at all.

neilalexander commented 3 years ago

I think it's fine to add HTTP endpoints for these — in particular we'd want to serve .well-known/matrix/server on the federation router (in the federation API routing package) and serve .well-known/matrix/client on the client router (in the client API routing package).

Since Dendrite also has no means of knowing what the correct addresses should be to serve on these endpoints, we should probably also add some optional configuration options for if the URL differs in any way from the configured global server name.

twentybit commented 3 years ago

@neilalexander - Sounds good. The routers currently available to the clientapi and federationapi have PathPrefixes - _matrix/client, _matrix/federation, so I can't just reuse them for the well-known endpoints. Should I just create a new mux.Router, and pass them through like the others, or create a new wellknownapi package?

neilalexander commented 3 years ago

Good point about the path prefixes — I had forgotten about that. Probably best to make a new well-known mux.Router then and pass it through to the client API and federation API as needed. Making a new wellknownapi component will be much heavier than you think.

S7evinK commented 3 years ago

Solved in https://github.com/matrix-org/dendrite/pull/1988 i guess.

kegsay commented 3 years ago

Yep.