Compare commits

..
Author SHA1 Message Date
timedout 298113c0a6 feat: Update MSC4456 implementation, new route 2026-10-14 10:34:52 +01:00
timedout 62de19970e fix: Address review comments 2026-10-14 10:34:51 +01:00
timedout 6b532eb7d0 perf: Yield ssk instead of doing a serialization roundtrip 2026-10-14 10:34:51 +01:00
timedout b541aadc2b feat: Don't double-sign our own keys 2026-10-14 10:34:51 +01:00
timedout c1f6a7c082 fix: Don't do weird wire signing for server keys route 2026-10-14 10:34:51 +01:00
timedout 3508b1a5e3 fix: Don't make origin key requests to ourself
Intercepting the request and serving it locally seems like a pretty good blanket solution
2026-10-14 10:34:51 +01:00
timedout 9867e99bb2 fix: Typo (MSC4456 -> MSC4556) 2026-10-14 10:34:50 +01:00
timedout 7b180667e8 style: Reformat 2026-10-14 10:34:50 +01:00
timedout e001e4a68a fix: Pass correct object for signing 2026-10-14 10:34:50 +01:00
timedout 75383af35c chore: Update trusted_servers docs 2026-10-14 10:34:50 +01:00
timedout c486eeac06 fix: Don't serve expired responses in the criterialess path 2026-10-14 10:34:49 +01:00
timedout 1ded0b4e97 fix: Enforce specific notary limits per MSC4556 2026-10-14 10:34:49 +01:00
timedout cd94a0d3ab fix: Refuse to process >4096 servers and/or >8192 keys
pending msc
2026-10-14 10:34:49 +01:00
timedout 08307970a1 fix: Deduplicate signing key responses if we already satisfied them 2026-10-14 10:34:49 +01:00
timedout ebf7c9920a fix: Don't short circuit if all requested servers have no query criteria
Also adds some traces
2026-10-14 10:34:48 +01:00
timedout a15905e8c9 chore: Rebuild example config 2026-10-14 10:34:47 +01:00
timedout 19bc5d2016 feat: Correctly ask origin for keys before seeding from local cache 2026-10-14 10:32:36 +01:00
timedout 6bbebd8b54 chore: Add newsfrag 2026-10-14 10:32:36 +01:00
timedout 4e1fb09bfb fix: Maybe query origin when fetching latest keys 2026-10-14 10:32:36 +01:00
timedout 39cd151ca3 fix: Don't attempt to contact origins as a notary more than once a minute 2026-10-14 10:32:36 +01:00
timedout a5a7905494 fix: Actually contact origins in notary key fetching 2026-10-14 10:32:35 +01:00
timedout a05d7a8cf3 style: Condense repeated code into a reusable function 2026-10-14 10:32:35 +01:00
timedout af8ca8580e fix: Correctly sum total_queried_keys 2026-10-14 10:32:35 +01:00
timedout 7050ea84e3 feat: Strip extraneous signatures to avoid leaking our own notaries 2026-10-14 10:32:35 +01:00
timedout 441ab78c4e feat: Notary server 2026-10-14 10:32:34 +01:00
151 changed files with 2244 additions and 2650 deletions

No files matched your search

@@ -44,7 +44,7 @@ runs:
- name: Login to builtin registry
if: ${{ env.BUILTIN_REGISTRY_ENABLED == 'true' }}
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4
with:
registry: ${{ env.BUILTIN_REGISTRY }}
username: ${{ inputs.registry_user }}
@@ -79,7 +79,7 @@ runs:
- name: Login to builtin registry
if: ${{ env.BUILTIN_REGISTRY_ENABLED == 'true' }}
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4
with:
registry: ${{ env.BUILTIN_REGISTRY }}
username: ${{ inputs.registry_user }}
+1 -1
View File
@@ -7,7 +7,7 @@ runs:
using: composite
steps:
- name: Install sccache
uses: https://forgejo.ellis.link/continuwuation/sccache-action@v1
uses: https://git.tomfos.tr/tom/sccache-action@v1
- name: Configure sccache
uses: https://github.com/actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
with:
@@ -29,7 +29,7 @@ runs:
steps:
- name: Detect runner OS
id: runner-os
uses: https://forgejo.ellis.link/continuwuation/detect-versions@v1
uses: https://git.tomfos.tr/actions/detect-versions@v1
- name: Configure cross-compilation architecture
if: inputs.dpkg-arch != ''
+2 -2
View File
@@ -39,7 +39,7 @@ runs:
steps:
- name: Detect runner OS
id: runner-os
uses: https://forgejo.ellis.link/continuwuation/detect-versions@v1
uses: https://git.tomfos.tr/actions/detect-versions@v1
- name: Configure Cargo environment
shell: bash
@@ -147,7 +147,7 @@ runs:
run: echo "::group::📦 Restoring build cache"
- name: Setup sccache
uses: https://forgejo.ellis.link/continuwuation/sccache-action@v1
uses: https://git.tomfos.tr/tom/sccache-action@v1
- name: End build cache restore group
shell: bash
+1 -1
View File
@@ -71,7 +71,7 @@ runs:
- name: Install timelord-cli and git-warp-time
if: steps.check-binaries.outputs.need-install == 'true'
uses: https://github.com/taiki-e/install-action@682ce6c3c696a4cd5168a05f98e51aa02b877941 # v2
uses: https://github.com/taiki-e/install-action@1168f6810a3cb30a3514bf5756a3b7f0422c6df8 # v2
with:
tool: git-warp-time,timelord-cli@3.0.1
+1 -1
View File
@@ -60,7 +60,7 @@ jobs:
cargo-debian-${{ steps.debian-version.outputs.distribution }}-${{ matrix.arch }}-
- name: Setup sccache
uses: https://forgejo.ellis.link/continuwuation/sccache-action@v1
uses: https://git.tomfos.tr/tom/sccache-action@v1
- name: Configure sccache environment
run: |
+2 -2
View File
@@ -28,13 +28,13 @@ jobs:
- name: Detect runner environment
id: runner-env
uses: https://forgejo.ellis.link/continuwuation/detect-versions@v1
uses: https://git.tomfos.tr/actions/detect-versions@v1
- name: Setup Node.js
if: steps.runner-env.outputs.node_major == '' || steps.runner-env.outputs.node_major < '20'
uses: https://github.com/actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7
with:
node-version: 26
node-version: 24
- name: Cache npm dependencies
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
+1 -1
View File
@@ -43,7 +43,7 @@ jobs:
name: Renovate
runs-on: ubuntu-latest
container:
image: ghcr.io/renovatebot/renovate:44.210.1@sha256:45cc73346c44a9afe037f2d19766f2b545b59b2ed31b937b5b09017d2958e45f
image: ghcr.io/renovatebot/renovate:44.151.2@sha256:29b3bf193f855c6f4b7027395a9c66c3417ad8bb6f30458090e1c2363d04eef7
options: --tmpfs /tmp:exec
steps:
- name: Checkout
+1 -2
View File
@@ -7,7 +7,6 @@ f419c64aca300a338096b4e0db4c73ace54f23d0
5998a0d883d31b866f7c8c46433a8857eae51a89
# trailing whitespace and newlines
46c193e74b2ce86c48ce802333a0aabce37fd6e9
# rustfmt updates that rewrapped tons of comments
# rustfmt update that rewrapped tons of comments
9fbabe221051e6956a05d8824142092ede68971e
b0c0905472b882ff0cc79232e73d307fd0b5035b
9c27441acf2e65f85c106ccff5c6b6c37030ddca
-1
View File
@@ -1,4 +1,3 @@
open_collective: continuwuity
github: [JadedBlueEyes, timedoutuk, gingershaped]
custom:
- https://timedout.uk/donate.html
Generated
+211 -192
View File
File diff suppressed because it is too large. Load diff
+6 -8
View File
@@ -104,7 +104,6 @@ version = "0.8.8"
default-features = false
features = [
"form",
"query",
"http1",
"http2",
"json",
@@ -331,7 +330,7 @@ version = "2.1.1"
# used for MPSC channels
[workspace.dependencies.loole]
version = "0.6.0"
version = "0.4.0"
# used for MPMC channels
[workspace.dependencies.async-channel]
@@ -349,7 +348,7 @@ version = "1.1.1"
# Used for matrix spec type definitions and helpers
[workspace.dependencies.ruma]
git = "https://github.com/ruma/ruma.git"
rev = "0ed7fba34213f18a628a56f527c6cc795cd7eef5"
rev = "f5e5e1c885f598036fd4326c566e9d1928027d5d"
features = [
"appservice-api-c",
"client-api",
@@ -389,7 +388,6 @@ features = [
"unstable-msc4494",
"unstable-msc4484",
"unstable-msc4540",
"unstable-msc4560",
"unstable-extensible-events",
]
@@ -454,7 +452,7 @@ features = ["http", "grpc-tonic", "trace", "logs", "metrics"]
# optional sentry metrics for crash/panic reporting
[workspace.dependencies.sentry]
version = "0.49.0"
version = "0.48.0"
default-features = false
features = [
"backtrace",
@@ -469,9 +467,9 @@ features = [
]
[workspace.dependencies.sentry-tracing]
version = "0.49.0"
version = "0.48.0"
[workspace.dependencies.sentry-tower]
version = "0.49.0"
version = "0.48.0"
# jemalloc usage
[workspace.dependencies.tikv-jemalloc-sys]
@@ -545,7 +543,7 @@ features = ["hardware-lock-elision", "deadlock_detection"] # TODO: Check if dead
# Use this when extending with_lock::WithLock to parking_lot
[workspace.dependencies.lock_api]
version = "0.5.0"
version = "0.4.13"
[workspace.dependencies.bytesize]
version = "2.0"
-3
View File
@@ -1,3 +0,0 @@
Implemented unstable support for [MSC4560] (Stripped state requests over federation). Contributed by @ginger.
[MSC4560]: https://github.com/matrix-org/matrix-spec-proposals/pull/4560
-1
View File
@@ -1 +0,0 @@
The first-run version of the web UI now includes a link to the registration page. Contributed by @ginger
-1
View File
@@ -1 +0,0 @@
Continuwuity now supports the OAuth 2.0 client credentials grant type, allowing secure automated access to the Matrix homeserver admin API, as well as future administrative functionality. Contributed by @ginger.
-1
View File
@@ -1 +0,0 @@
Room summary visibility checks are no longer incorrectly applied for remote rooms. Contributed by @ginger.
@@ -1 +0,0 @@
Fix new devices sometimes never reaching other users' device lists. Contributed by @eleboucher.
@@ -1 +0,0 @@
Fix gap filling skipping outlier events that are missing their previous events. Contributed by @eleboucher.
@@ -1 +0,0 @@
Fix state resolution applying events out of order, which could undo room joins. Contributed by @eleboucher.
@@ -1 +0,0 @@
Fix to-device messages, including room keys, sometimes being lost before delivery. Contributed by @eleboucher.
+1
View File
@@ -0,0 +1 @@
Added support for acting as a trusted server, meaning the `trusted_servers` list can consist of servers that are either Synapse OR continuwuity.
-1
View File
@@ -1 +0,0 @@
Add a section on [troubleshooting Docker issues](https://continuwuity.org/troubleshooting#docker-issues). Contributed by @stratself.
-1
View File
@@ -1 +0,0 @@
Instructions for Authelia added to the [OIDC guide](https://continuwuity.org/authentication/oidc.html). Contributed by @fhoekstra
-1
View File
@@ -1 +0,0 @@
Fix some possible deadlocks/freezes and reduce lock contention (improving performance). Contributed by @Jade
-1
View File
@@ -1 +0,0 @@
Docker compose examples now use bind mounts by default, instead of Docker volumes, as they are easier to work with esp. for backup/restore. Contributed by @stratself.
-1
View File
@@ -1 +0,0 @@
Once again fixed how room extremities are handled, fixing a problem that made continuwuity gradually make rooms needlessly complex, which also caused more frequent state resets.
-1
View File
@@ -1 +0,0 @@
The OAuth identity reset page is no longer linked from the account management UI to reduce confusion. Contributed by @ginger.
-1
View File
@@ -1 +0,0 @@
Fixed a worker panic when knocking on a room over federation. Contributed by @eleboucher.
-1
View File
@@ -1 +0,0 @@
Perform more validation on events received during atomic gapfill from remote servers, fixing a panic if bad data was persisted by another server and later lazily fetched by us.
-1
View File
@@ -1 +0,0 @@
Redirect URIs in OAuth clients' metadata are now properly validated to be on a subdomain of the OAuth issuer URL domain. Contributed by @ginger.
-1
View File
@@ -1 +0,0 @@
Updated internal Sentry integration setup to the new pattern required by the SDK.
-1
View File
@@ -1 +0,0 @@
Fix v12 rooms created by the same user in the same millisecond ending up as the same room. Contributed by @eleboucher.
-1
View File
@@ -1 +0,0 @@
Setting a profile key longer than 255 bytes now returns 400 `M_KEY_TOO_LARGE` as required by the spec, instead of 413 `M_TOO_LARGE`.
-1
View File
@@ -1 +0,0 @@
Setting profile data that would make the profile exceed 64 KiB now returns 400 `M_PROFILE_TOO_LARGE` as required by the spec, instead of a 500 error.
-1
View File
@@ -1 +0,0 @@
Appservices masquerading as a device that does not exist now receive 400 `M_UNKNOWN_DEVICE` as required by the spec, instead of 403 `M_FORBIDDEN`.
-1
View File
@@ -1 +0,0 @@
Setting `m.fully_read` via the account data endpoints now returns 405 `M_BAD_JSON` as required by the spec, instead of 400.
-1
View File
@@ -1 +0,0 @@
The `m.forget_forced_upon_leave` capability now reflects the `forget_forced_upon_leave` config option instead of always being advertised as enabled.
-1
View File
@@ -1 +0,0 @@
Fixed push notifications for membership events setting `user_is_target` based on the sender rather than the user being notified.
+2 -47
View File
@@ -1018,10 +1018,7 @@
# (trusted key notary servers), as well as serve as trusted servers for
# other operations like backfill and event fetching.
#
# Currently, continuwuity doesn't support inbound key requests, so
# this list should only contain other Synapse servers.
#
# example: ["matrix.org", "starstruck.systems"]
# example: ["continuwuity.org", "matrix.org"]
#
# It is possible to restrict which signing keys trusted servers are
# allowed to sign responses with. Without configuring this, all responses
@@ -1059,7 +1056,7 @@
# is discouraged for performance and reliability reasons.
#
# env: CONTINUWUITY_TRUSTED_SERVERS
#trusted_servers = ["matrix.org"]
#trusted_servers = ["continuwuity.org", "continuwuity.rocks", "matrix.org"]
# Whether to prioritise trusted server lookups over origin server lookups.
#
@@ -2680,45 +2677,3 @@
#
# env: CONTINUWUITY_OAUTH__OIDC__PROFILE_KEY_IMPORT_MODE
#profile_key_import_mode = "on_registration"
#[global.oauth.clients."$id"]
# Use this section to add static OAuth clients for bots and automation.
# Clients added here may use the client credentials OAuth grant to authorize
# themselves with Continuwuity.
#
# Make sure to replace `$id` in the header with your client ID of choice! You can
# add more copies of this section with different IDs to add multiple clients.
#
# Because the client credentials grant authorizes the client as itself, without
# an attached user, clients that use it will not be able to access most of the Matrix
# client-server API. Administrative functionality that does not require a user
# will still be available.
# The client's client secret.
#
# This must be supplied as the `client_secret` parameter when requesting
# an access token with the OAuth 2.0 token endpoint. Continuwuity does
# not check the `Authorization` header for requests to this endpoint.
#
#client_secret =
# A list of scopes that the client may request. Continuwuity allows static
# clients to request the following scopes:
#
# - "urn:matrix:client:cc.c10y.msc4484.server_administration" (MSC4484):
# This scope grants access to the Matrix server administration APIs, as
# well as Continuwuity's internal admin API (currently a work in
# progress).
# - "urn:matrix:client:api:*": This scope grants access to the Matrix
# client-server API. Most endpoints require an authenticated Matrix user
# and thus will not be usable by static clients.
#
# The `urn:matrix:client:device:<id>` scope may not be requested by static
# clients.
#
# Scopes listed here are not granted by default. The client must
# explicitly include them in the `scope` parameter of its access token
# request.
#
#scopes = []
+1 -1
View File
@@ -50,7 +50,7 @@ EOF
# Developer tool versions
# renovate: datasource=github-releases depName=cargo-bins/cargo-binstall
ENV BINSTALL_VERSION=1.26.1
ENV BINSTALL_VERSION=1.25.3
# renovate: datasource=github-releases depName=psastras/sbom-rs
ENV CARGO_SBOM_VERSION=0.9.1
# renovate: datasource=crate depName=lddtree
+1 -1
View File
@@ -18,7 +18,7 @@ RUN --mount=type=cache,target=/etc/apk/cache apk add \
# Developer tool versions
# renovate: datasource=github-releases depName=cargo-bins/cargo-binstall
ENV BINSTALL_VERSION=1.26.1
ENV BINSTALL_VERSION=1.25.3
# renovate: datasource=github-releases depName=psastras/sbom-rs
ENV CARGO_SBOM_VERSION=0.9.1
# renovate: datasource=crate depName=lddtree
+18 -74
View File
@@ -1,5 +1,3 @@
import { Tab, Tabs } from '@rspress/core/theme';
# Delegated authentication with OIDC
Continuwuity supports delegating user authentication to an external identity provider that implements the OpenID Connect (OIDC) specification, such as Authentik, Kanidm, or Keycloak.
@@ -14,110 +12,56 @@ An account on the homeserver can only be associated with one OIDC subject claim
A simple OIDC configuration is as easy as creating a new OIDC application in your identity provider's settings and supplying Continuwuity with the client ID and client secret.
The instructions below make the following assumptions:
- Continuwuity's base URL: `https://matrix.example.com`. Note that if you employ [well-known delegation](../guides/delegation), this must match the client well-known domain rather than your server name.
- OIDC provider's base URL: `https://idm.example.com`
### Configuring the OIDC provider
This guide will cover [**Kanidm**][kanidm] and [**Authelia**][authelia], but the basic concepts apply to most identity providers. Contributions for them are welcome.
This guide will use [**Kanidm**][kanidm] as an example, but the described steps are broadly applicable to other identity providers. Contributions for them are welcome.
<Tabs groupId="idp">
<Tab label="KanIDM">
Create a new application for continuwuity in kanidm. We will use `c10y` as the client ID.
First, create a new application for Continuwuity in your identity provider.
```sh
kanidm system oauth2 create c10y Continuwuity https://matrix.example.com
# Here, `c10y` is the client ID that Kanidm will use, and `Continuwuity` is the display name.
# Other identity providers may generate a client ID for you.
# Use the domain that clients can reach Continuwuity at, which may not be the same as your server name
# if you have configured well-known delegation.
kanidm system oauth2 create c10y Continuwuity https://matrix.yourdomain.com
```
Configure the redirect URL that Continuwuity uses.
```sh
kanidm system oauth2 add-redirect-url c10y https://matrix.example.com/_continuwuity/oidc/complete
kanidm system oauth2 add-redirect-url c10y https://matrix.yourdomain.com/_continuwuity/oidc/complete
```
Allow Continuwuity to request the `openid` scope.
Allow Continuwuity to request the `openid` scope. Other identity providers may not require this step.
```sh
kanidm system oauth2 update-scope-map c10y idm_all_persons openid
```
Find the client secret that was generated.
Find the client secret that was generated. Other identity providers may show this information in their web UI.
```sh
kanidm system oauth2 show-basic-secret c10y
d1qgx352kkuvs1j70b6w293d65x68jve1f7b27fyk90gjhpr
```
Now the discovery URL for KanIDM is: `https://idm.example.com/oauth2/openid/c10y`
</Tab>
<Tab label="Authelia">
To create a new client in Authelia, it is [recommended][authelia-faq-client-secret] to randomly generate both the client id and client secret. The commands below should get you those:
<Tabs groupId="authelia-generate-client-details">
<Tab label="Bare Binary">
```sh
# Generate random value for Client ID
authelia crypto rand --length 72 --charset rfc3986
# Generate Client Secret (labeled Random Password) and its Digest
authelia crypto hash generate pbkdf2 --variant sha512 --random --random.length 72 --random.charset rfc3986
```
</Tab>
<Tab label="Docker">
```sh
# Generate random value for Client ID
docker run --rm authelia/authelia:latest authelia crypto rand --length 72 --charset rfc3986
# Generate Client Secret (labeled Random Password) and its Digest
docker run --rm authelia/authelia:latest authelia crypto hash generate pbkdf2 --variant sha512 --random --random.length 72 --random.charset rfc3986
```
</Tab>
</Tabs>
Authelia only needs to know the digest of the secret, whereas Continuwuity requires the secret itself.
Go to your Authelia configuration file, find the `identity_provers` block, and add a block for Continuwuity to the `clients` list:
```yaml
identity_providers:
oidc:
jwks:
# This part has the JWKs and is what you configured previously
# ...
clients:
# Add this block below to the clients list
- client_name: continuwuity
client_id: "client-id-goes-here"
# Use the client secret's DIGEST, not the client secret itself
client_secret: "client-secret-DIGEST-goes-here"
redirect_uris: ["https://matrix.example.com/_continuwuity/oidc/complete"]
scopes: [openid]
```
Then restart Authelia to load the new configuration.
The discovery URL is simply the root domain of your Authelia, where it can be reached by clients, i.e. `https://idm.example.com`.
</Tab>
</Tabs>
[kanidm]: https://kanidm.com
[authelia]: https://www.authelia.com
[authelia-faq-client-secret]: https://www.authelia.com/integration/openid-connect/frequently-asked-questions/#how-do-i-generate-a-client-identifier-or-client-secret
### Configuring Continuwuity
Configure Continuwuity with the client ID, client secret, and discovery URL provided from the steps above.
Configure Continuwuity with the client ID, client secret, and discovery URL provided from the steps above. Kanidm has a different discovery URL for each client, but other identity providers may have a single discovery URL at the root of their domain.
```toml
[global.oauth.oidc]
# `/.well-known/openid-configuration` will be appended automatically
discovery_url = "https://your-discovery-url"
discovery_url = "https://idm.example.com/oauth2/openid/c10y"
client_id = "your-client-id"
client_secret = "your-client-secret"
# This may be randomly generated by your identity provider. Kanidm requires
# you to set it manually when you create the application.
client_id = "c10y"
# From the previous step
client_secret = "d1qgx352kkuvs1j70b6w293d65x68jve1f7b27fyk90gjhpr"
```
### Testing that it works
+21 -2
View File
@@ -303,14 +303,33 @@ For browser-based clients, you can also inspect connections using DevTools' Netw
### Docker loopback networking issues
Some distros do not allow Docker containers to connect to the host's public IP, and this breaks connections from `lk-jwt-service` towards `livekit` and `continuwuity` if they're on the same host. This can be tested by the following command:
Some distros do not allow Docker containers in bridge networks to connect to their host's public IP by default. This makes `lk-jwt-service` fail connecting to `livekit` or `continuwuity` on the same host, causing refused and timed out connections to appear in the log entries of the JWT service, even when `LIVEKIT_URL` has been configured correctly.
You can also test that this is the case by cURLing from a sidecar container:
```bash
docker run --rm --net container:lk-jwt-service docker.io/curlimages/curl https://livekit.example.com
# --- some errors ---
```
To resolve this, follow the steps in [Docker loopback networking issues](../troubleshooting.mdx#docker-loopback-networking-issues) of the Troubleshooting page.
To resolve this, configure an `extra_hosts` file mapping LiveKit's and Continuwuity's domain names to Docker's custom host loopback address, represented here by `host-gateway`:
```diff
# in docker-compose.yaml
services:
lk-jwt-service:
...
+ extra_hosts:
+ - "livekit.example.com:host-gateway"
+ - "matrix.example.com:host-gateway"
```
After implementing the changes and restarting your compose, `lk-jwt-service` should now connect to your other services. The sidecar container test above should now return an `OK` from LiveKit.
For more information about the `host-gateway` parameter, kindly refer to the `--add-host` documentation for [Docker][docker-add-host] and [Podman][podman-add-host]. Should you have further difficulties, feel free to enquire in the support rooms.
[docker-add-host]: https://docs.docker.com/reference/cli/docker/container/run/#add-host
[podman-add-host]: https://docs.podman.io/en/latest/markdown/podman-run.1.html#add-host-hostname-hostname-ip
### Incorrect IP address for LiveKit
+17 -58
View File
@@ -53,7 +53,7 @@ For more setups with `.well-known` delegation and split-domain deployments, cons
Docker Compose is the recommended deployment method for Continuwuity containers. The following environment variables will be set:
- `CONTINUWUITY_SERVER_NAME` - Your Matrix server's domain name. **This CANNOT be changed later without a data wipe.**
- `CONTINUWUITY_DATABASE_PATH` - Where to store your database. This must match the docker bind mount.
- `CONTINUWUITY_DATABASE_PATH` - Where to store your database. This must match the docker volume mount.
- `CONTINUWUITY_ADDRESS` - Bind address (for Docker, use `0.0.0.0` to listen on all interfaces).
Alternatively, you can specify a path to mount the configuration file using the `CONTINUWUITY_CONFIG` environment variable.
@@ -89,9 +89,7 @@ Consult the [**DNS tuning guide (recommended)**](../guides/dns.mdx) for full sol
<summary>docker-compose.with-caddy.yml ([view raw](/deploying/docker-compose.with-caddy.yml))</summary>
Create a directory called `caddy-data`, which will store TLS certs obtained by Caddy.
Then, create a Caddyfile with the following content:
Create a Caddyfile with the following content:
```
https://example.com:443, https://example.com:8448 {
@@ -99,7 +97,7 @@ https://example.com:443, https://example.com:8448 {
}
```
Then, for the docker compose file:
Then, for the docker-compose:
```yaml file="../public/deploying/docker-compose.with-caddy.yml"
@@ -112,10 +110,6 @@ Then, for the docker compose file:
<details>
<summary>docker-compose.with-caddy-labels.yml ([view raw](/deploying/docker-compose.with-caddy-labels.yml))</summary>
Create a directory called `caddy-data`, which will store TLS certs obtained by Caddy.
Then, for the docker compose file:
```yaml file="../public/deploying/docker-compose.with-caddy-labels.yml"
```
@@ -138,10 +132,6 @@ Then, for the docker compose file:
<details>
<summary>docker-compose.with-traefik.yml ([view raw](/deploying/docker-compose.with-traefik.yml))</summary>
Create a directory called `traefik-acme-data`, which will store TLS certs obtained by Caddy.
Then, for the docker compose file:
```yaml file="../public/deploying/docker-compose.with-traefik.yml"
```
@@ -174,15 +164,10 @@ See the [Other reverse proxies](generic.mdx#setting-up-the-reverse-proxy) sectio
### Starting Your Server
1. Create a directory named `continuwuity-data`. This will be where your server's database lives.
2. Choose your compose file from the above, and rename it to `docker-compose.yml`. Replace `example.com` with your homeserver's domain name, and edit other values as you see fit.
- Follow all extra instructions as needed.
- If using the override file, rename it to `docker-compose.override.yml` and edit your values.
3. Start the server with the following command:
1. Choose your compose file from the above, and rename it to `docker-compose.yml`. Replace `example.com` with your homeserver's domain name, and edit other values as you see fit.
2. If using the override file, rename it to `docker-compose.override.yml` and
edit your values.
3. Start the server:
```bash
docker compose up -d
@@ -204,7 +189,9 @@ See the [Other reverse proxies](generic.mdx#setting-up-the-reverse-proxy) sectio
Pick your own username and password!
```
5. Log in to your server with any Matrix client, and register for an account with the registration token from the previous step. You'll automatically be invited to the admin room where you can [manage your server](../reference/admin).
5. Log in to your server with any Matrix client, and register for an account with the registration token from step 4. You'll automatically be invited to the admin room where you can [manage your server](../reference/admin).
See the [generic deployment guide](generic.mdx) for more deployment options.
## Testing
@@ -212,9 +199,7 @@ Test that your setup works by following these [instructions](./generic.mdx#how-d
Check your container logs using `docker-compose logs --follow` to debug any issues. See the [Troubleshooting](../troubleshooting.mdx) page for common errors and how to fix them.
## Maintenance
### Updating
## Updating
To update to a new version of Continuwuity, use the following commands:
@@ -227,10 +212,6 @@ docker compose pull
docker compose up -d
```
### Backups
The database in `./continuwuity-data` is present on the host system as a regular directory, and therefore can be backed up using normal mechanisms. See the [Backup](../maintenance.mdx#backups) section of the Maintenance page for more details.
## What's next?
Navigate to [Post-installation](../deploying.mdx#post-installation) for next steps.
@@ -289,6 +270,12 @@ Get a working Continuwuity server with an admin user in four steps:
Once configured, log in to your server with any Matrix client, and register for an account with the registration token from step 3. If you did not configure step 4., log in via the `http://<your_server_ip>:8008` address. You will be automatically invited to the admin room where you can [manage your server](../reference/admin).
### (Optional) Building Custom Images
For information on building your own Continuwuity Docker images, see the
[Building Docker Images](../development/index.mdx#building-docker-images)
section in the development documentation.
### Accessing the Server's Console
Before you can access the server's console and [send admin commands](../reference/admin/index.md) from the CLI, you will need to make the container interactive and allocate a pseudo-tty. Make sure you set `admin_console_automatic` to `true` in [the config](../reference/config.mdx) as well for Continuwuity to activate the CLI on startup.
@@ -310,31 +297,3 @@ From there you can access the server's console by running `docker attach <contai
Note that using `CTRL+c` within `docker attach`'s context will forward the signal to the server, stopping it. See [Docker's reference][docker-attach-reference] for more information.
[docker-attach-reference]: https://docs.docker.com/reference/cli/docker/container/attach/
### Using Docker volumes
The example compose files above utilizes [bind mounts][docker-bind-mounts]. If you want to use [Docker volumes][docker-volumes] instead, apply these changes to your compose file:
```diff
services:
continuwuity:
# ...
volumes:
- - ./continuwuity-data:/var/lib/continuwuity
+ - continuwuity-data:/var/lib/continuwuity
+volumes:
+ continuwuity-data:
```
Consult the [Docker docs][docker-volumes-backup-restore] for details on backing up and restoring Docker volumes
[docker-bind-mounts]: https://docs.docker.com/engine/storage/bind-mounts/
[docker-volumes]: https://docs.docker.com/engine/storage/volumes/
[docker-volumes-backup-restore]: https://docs.docker.com/engine/storage/volumes/#back-up-restore-or-migrate-data-volumes
### Building Custom Images
For information on building your own Continuwuity Docker images, see the
[Building Docker Images](../development/index.mdx#building-docker-images)
section in the development documentation.
-5
View File
@@ -199,11 +199,6 @@ header, making federation non-functional. If you find a workaround, please share
Furthermore, Nginx users need to increase the `client_max_body_size` setting (default is 1M) to match the `max_request_size` defined in conduwuit.toml.
- For HAProxy, ensure that the ACL for the `Host` header matches both the domain and the domain with the port, as federation requests are often sent with the port included. This can be done by using the `host_only` directive:
```
acl matrix-host hdr(host),host_only -i example.com
```
## Starting Your Server
Now you can start Continuwuity with:
+2 -2
View File
@@ -113,7 +113,7 @@ https://matrix.example.com {
### Tuning your trusted servers
:::important Important: Vet your trusted servers!
:::info Vet your trusted servers!
Trusted servers are your first point of contact when obtaining public keys from other servers, and they could theoretically impersonate other servers and cause significant harm to your deployment. Please thoroughly verify your trusted servers' credibility before adding them to your configuration.
If you need suggestions for trusted servers, ask in the Continuwuity main room.
@@ -128,7 +128,7 @@ trusted_servers = ["codestorm.net","starstruck.systems","unredacted.org","matrix
Avoid prioritising `matrix.org` as your primary trusted server, as it tends to be quite slow.
Some users have also reported that increasing `trusted_server_batch_size` helps with faster joins for huge rooms. Start with doubling the default to `2048` until you find a suitable value.
Some users have also reported that increasing `trusted_server_batch_size` has helped with faster joins for huge rooms. Start with doubling the default to `2048` until you find a suitable value.
### Enable HTTP/3 on your reverse proxy
@@ -6,7 +6,7 @@ services:
restart: unless-stopped
command: /sbin/conduwuit
volumes:
- ./continuwuity-data:/var/lib/continuwuity
- db:/var/lib/continuwuity
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
#- ./continuwuity.toml:/etc/continuwuity.toml
networks:
@@ -12,7 +12,7 @@ services:
- proxy
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./caddy-data:/data
- ./data:/data
restart: unless-stopped
labels:
caddy: example.com
@@ -23,7 +23,7 @@ services:
restart: unless-stopped
command: /sbin/conduwuit
volumes:
- ./continuwuity-data:/var/lib/continuwuity
- db:/var/lib/continuwuity
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
# - ./continuwuity.toml:/etc/continuwuity.toml
environment:
@@ -46,5 +46,8 @@ services:
caddy: matrix.example.com
caddy.reverse_proxy: "{{upstreams 8008}}"
volumes:
db:
networks:
proxy:
@@ -9,7 +9,7 @@ services:
networks:
- caddy
volumes:
- ./caddy-data:/data
- ./data:/data
# mount your created Caddyfile into the container
- ./Caddyfile:/etc/caddy/Caddyfile
restart: unless-stopped
@@ -19,7 +19,7 @@ services:
restart: unless-stopped
command: /sbin/conduwuit
volumes:
- ./continuwuity-data:/var/lib/continuwuity
- db:/var/lib/continuwuity
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
# - ./continuwuity.toml:/etc/continuwuity.toml
environment:
@@ -41,3 +41,6 @@ services:
networks:
proxy:
volumes:
db:
@@ -6,7 +6,7 @@ services:
restart: unless-stopped
command: /sbin/conduwuit
volumes:
- ./continuwuity-data:/var/lib/continuwuity
- db:/var/lib/continuwuity
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
#- ./continuwuity.toml:/etc/continuwuity.toml
networks:
@@ -40,7 +40,7 @@ services:
- "443:443"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./traefik-acme-data:/etc/traefik/acme"
- "acme:/etc/traefik/acme"
labels:
- "traefik.enable=true"
@@ -77,5 +77,9 @@ services:
TRAEFIK_PROVIDERS_DOCKER_ENDPOINT: "unix:///var/run/docker.sock"
TRAEFIK_PROVIDERS_DOCKER_EXPOSEDBYDEFAULT: false
volumes:
db:
acme:
networks:
proxy:
@@ -6,7 +6,7 @@ services:
restart: unless-stopped
command: /sbin/conduwuit
volumes:
- ./continuwuity-data:/var/lib/continuwuity
- db:/var/lib/continuwuity
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
#- ./continuwuity.toml:/etc/continuwuity.toml
networks:
@@ -18,7 +18,7 @@ services:
- "traefik.http.routers.continuwuity.tls=true"
- "traefik.http.routers.continuwuity.service=continuwuity"
- "traefik.http.services.continuwuity.loadbalancer.server.port=8008"
# enable tls with the `letsencrypt` certificate resolver (actual name dependant on your static config)
# possibly, depending on your config:
# - "traefik.http.routers.continuwuity.tls.certresolver=letsencrypt"
environment:
CONTINUWUITY_SERVER_NAME: example.com
@@ -34,6 +34,9 @@ services:
server=example.com:443
}
volumes:
db:
networks:
# This must match the network name that Traefik listens on
proxy:
@@ -12,7 +12,7 @@ services:
- proxy
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./caddy-data:/data
- ./data:/data
restart: unless-stopped
homeserver:
@@ -20,7 +20,7 @@ services:
restart: unless-stopped
command: /sbin/conduwuit
volumes:
- ./continuwuity-data:/var/lib/continuwuity
- db:/var/lib/continuwuity
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
# - ./continuwuity.toml:/etc/continuwuity.toml
environment:
@@ -10,7 +10,7 @@ services:
networks:
- proxy
volumes:
- ./caddy-data:/data
- ./data:/data
# mount your created Caddyfile into the container
- ./Caddyfile:/etc/caddy/Caddyfile
restart: unless-stopped
@@ -20,7 +20,7 @@ services:
restart: unless-stopped
command: /sbin/conduwuit
volumes:
- ./continuwuity-data:/var/lib/continuwuity
- db:/var/lib/continuwuity
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
# - ./continuwuity.toml:/etc/continuwuity.toml
environment:
@@ -43,3 +43,6 @@ services:
networks:
proxy:
volumes:
db:
@@ -6,7 +6,7 @@ services:
restart: unless-stopped
command: /sbin/conduwuit
volumes:
- ./continuwuity-data:/var/lib/continuwuity
- db:/var/lib/continuwuity
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
#- ./continuwuity.toml:/etc/continuwuity.toml
networks:
@@ -40,7 +40,7 @@ services:
- "443:443"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./traefik-acme-data:/etc/traefik/acme"
- "acme:/etc/traefik/acme"
labels:
- "traefik.enable=true"
@@ -77,5 +77,9 @@ services:
TRAEFIK_PROVIDERS_DOCKER_ENDPOINT: "unix:///var/run/docker.sock"
TRAEFIK_PROVIDERS_DOCKER_EXPOSEDBYDEFAULT: false
volumes:
db:
acme:
networks:
proxy:
+33 -30
View File
@@ -1,38 +1,41 @@
# Continuwuity - Bare Configuration (for other reverse proxies)
services:
homeserver:
image: "forgejo.ellis.link/continuwuation/continuwuity:latest"
restart: unless-stopped
command: /sbin/conduwuit
ports:
homeserver:
image: "forgejo.ellis.link/continuwuation/continuwuity:latest"
restart: unless-stopped
command: /sbin/conduwuit
ports:
# If your reverse proxy is on the host, use this
# and configure it to connect to `127.0.0.1:8008`
- 127.0.0.1:8008:8008
# If your reverse proxy is on the host, use this
# and configure it to connect to `127.0.0.1:8008`
- 127.0.0.1:8008:8008
# If your reverse proxy is on another machine, use this
# and configure it to connect to <this-machine-ip>:8008
# - 8008:8008
# If your reverse proxy is on another machine, use this
# and configure it to connect to <this-machine-ip>:8008
# - 8008:8008
# If your reverse proxy is a docker container on the same network,
# comment out the entire `ports` section, and configure it to connect to `continuwuity:8008`
# If your reverse proxy is a docker container on the same network,
# comment out the entire `ports` section, and configure it to connect to `continuwuity:8008`
volumes:
- ./continuwuity-data:/var/lib/continuwuity
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
#- ./continuwuity.toml:/etc/continuwuity.toml
environment:
CONTINUWUITY_SERVER_NAME: example.com # EDIT THIS
CONTINUWUITY_DATABASE_PATH: /var/lib/continuwuity
CONTINUWUITY_ADDRESS: 0.0.0.0
CONTINUWUITY_PORT: 8008
#CONTINUWUITY_CONFIG: '/etc/continuwuity.toml' # Uncomment if you mapped config toml above
volumes:
- db:/var/lib/continuwuity
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
#- ./continuwuity.toml:/etc/continuwuity.toml
environment:
CONTINUWUITY_SERVER_NAME: example.com # EDIT THIS
CONTINUWUITY_DATABASE_PATH: /var/lib/continuwuity
CONTINUWUITY_ADDRESS: 0.0.0.0
CONTINUWUITY_PORT: 8008
#CONTINUWUITY_CONFIG: '/etc/continuwuity.toml' # Uncomment if you mapped config toml above
## (Optional) Serve .well-known files to tell others to reach Continuwuity on port :443
## If you do this, remove all routes to port :8448 on your reverse proxy
# CONTINUWUITY_WELL_KNOWN: |
# {
# client=https://example.com,
# server=example.com:443
# }
## (Optional) Serve .well-known files to tell others to reach Continuwuity on port :443
## If you do this, remove all routes to port :8448 on your reverse proxy
# CONTINUWUITY_WELL_KNOWN: |
# {
# client=https://example.com,
# server=example.com:443
# }
volumes:
db:
+17 -87
View File
@@ -1,9 +1,9 @@
# Troubleshooting Continuwuity
:::warning{title="For Docker users"}
It's common for Docker misconfigurations to cause issues, particularly with networking and
permissions. Before continuing, please first check that your issues are notdue Docker
problems. See the dedicated [**Docker issues**](#docker-issues) section for more details.
:::warning{title="Docker users:"}
Docker can be difficult to use and debug. It's common for Docker
misconfigurations to cause issues, particularly with networking and permissions.
Please check that your issues are not due to problems with your Docker setup.
:::
## Continuwuity issues
@@ -13,9 +13,9 @@ problems. See the dedicated [**Docker issues**](#docker-issues) section for more
Some slowness is to be expected if you're the first person on your homeserver to join a room (which will
always be the case for single-user homeservers). In this situation, your homeserver has to verify the signatures of
all of the state events sent by other servers before your join. To make this process as fast as possible, make sure you have
multiple fast, trusted servers listed in `trusted_servers` in your configuration, and ensure
`query_trusted_key_servers_first_on_join` is set to true (the default). Read the
[Tuning your trusted servers](./guides/performance.mdx#tuning-your-trusted-servers) section for more details on doing so.
[multiple fast, trusted servers](./guides/performance.mdx#tuning-your-trusted-servers) listed in `trusted_servers` in your configuration, and ensure
`query_trusted_key_servers_first_on_join` is set to true (the default).
If you need suggestions for trusted servers, ask in the Continuwuity main room.
However, _very_ slow joins, especially to rooms with only a few users in them or rooms created by another user
on your homeserver, may be caused by [issue !779](https://forgejo.ellis.link/continuwuation/continuwuity/issues/779),
@@ -119,63 +119,11 @@ much possible corruption is restored
- If all goes will, you should be able to restore back to using
`TolerateCorruptedTailRecords` and you have successfully recovered your database
## Docker issues
### Debugging Docker networking
The Continuwuity image does not ship with any shell or internal debugging utilities. To debug network conditions for Continuwuity, run another sidecar container that is attached to its network namespace. For example, using the `curl` container:
```bash
docker run --rm -it \
--network container:continuwuity \
docker.io/curlimages/curl \
curl https://continuwuity.org/.well-known/matrix/server
```
### Docker loopback networking issues
Some distros disallow Docker containers in bridge networks to reach out to their host's public IP by default. This can cause connectivity issues between Continuwuity and other services that are on the same host machine, such as LiveKit or a push server.
One can test if this is the case by cURLing those services with a sidecar container:
```bash
docker run --rm -it --network container:continuwuity docker.io/curlimages/curl curl https://push.example.com
# --- some timeout or refused connection errors ---
```
To fix this, use the `extra_hosts` parameter to map local service domains to `host-gateway` - a special Docker value that resolves to the internal IP address of the host.
```diff title="docker-compose.yaml"
services:
continuwuity:
...
# allow Continuwuity to reach out to the push server and livekit
# via the host gateway loopback address
+ extra_hosts:
+ - "push.example.com:host-gateway"
+ - "livekit.example.com:host-gateway"
lk-jwt-service:
...
# allow jwt service to reach out to Continuwuity and livekit
# via the host gateway loopback address
+ extra_hosts:
+ - "livekit.example.com:host-gateway"
+ - "matrix.example.com:host-gateway"
```
Reload the compose file, and connections between these services (as well as the sidecar container test above) should now work.
For more information about the `host-gateway` parameter, kindly consult the Docker docs on [custom DNS with `extra_hosts`][docker-custom-dns] and the [`--add-host` option][docker-add-host].
[docker-custom-dns]: https://docs.docker.com/compose/how-tos/networking/#custom-dns-with-extra_hosts
[docker-add-host]: https://docs.docker.com/reference/cli/docker/container/run/#add-host
## Debugging
Note that users should not really need to debug things. If you find yourself
debugging and find the issue, please let us know and/or how we can fix it.
Various debug commands can be found in [`!admin debug`](./reference/admin/debug).
Various debug commands can be [found in `!admin debug`](./reference/admin/debug).
### Debug/Trace log level
@@ -188,34 +136,23 @@ you need to access debug/trace log levels, you will need to build without the
Continuwuity supports changing the tracing log environment filter on-the-fly using
the admin command `!admin debug change-log-level <log env filter>`. This accepts
a string **without quotes** in the same format as the `log` config option. Complex
filters are also supported as well.
a string **without quotes** the same format as the `log` config option.
```bash
# set log level to debug
!admin debug change-log-level debug
Example: `!admin debug change-log-level debug`
# trace logs for all outgoing federation to `example.com`
!admin debug change-log-level info,conduwuit_service::federation[{dest="example.com"}]=trace
This can also accept complex filters such as:
`!admin debug change-log-level info,conduit_service[{dest="example.com"}]=trace,ruma_state_res=trace`
`!admin debug change-log-level info,conduit_service[{dest="example.com"}]=trace,conduit_service[send{dest="example.org"}]=trace`
# trace logs for client syncs
!admin debug change-log-level info,conduwuit_api::client=trace
And to reset the log level to the one that was set at startup / last config
load, simply pass the `--reset` flag.
# debug logs for everything except h2 and presence
!admin debug change-log-level trace,h2=off,conduwuit_service::presence=off
```
To reset the log level to the one that was set at last config
load, simply do:
```bash
!admin debug change-log-level --reset
```
`!admin debug change-log-level --reset`
### Pinging servers
Continuwuity can ping other servers using `!admin debug ping <server>`. This takes
a server name, goes through the server discovery process, and queries
a server name and goes through the server discovery process and queries
`/_matrix/federation/v1/version`. Errors are outputted.
While it does measure the latency of the request, it is not indicative of
@@ -261,10 +198,3 @@ and is not easy for non-developers to understand.
[unbound-tuning]: https://unbound.docs.nlnetlabs.nl/en/latest/topics/core/performance.html
[unbound-arch]: https://wiki.archlinux.org/title/Unbound
## Other troubleshooting topics
- [LiveKit troubleshooting](./calls/livekit.mdx#troubleshooting)
- [TURN server troubleshooting](./calls/turn.mdx#troubleshooting)
- [Delegation/split-domain troubleshooting](./guides/delegation.mdx#troubleshooting)
- [Push notifications troubleshooting](./guides/push.mdx#troubleshooting)
+1 -1
View File
@@ -12,7 +12,7 @@
target:
target.fromToolchainName {
name = (lib.importTOML "${inputs.self}/rust-toolchain.toml").toolchain.channel;
sha256 = "sha256-+xUr6Al1wZSqX8aEsq7DpuFOK4Ve/i+qTl+K5uWQ9GM=";
sha256 = "sha256-zm3dyIY2T414ZRR3EhLOvptzG6gta4WZUcawzMUWtqI=";
};
in
{
+1 -1
View File
@@ -10,7 +10,7 @@
[toolchain]
profile = "minimal"
channel = "1.99.1"
channel = "1.99.0"
components = [
# For rust-analyzer
"rust-src",
+8 -6
View File
@@ -1,4 +1,4 @@
use conduwuit::{Err, Result, checked, utils::ReadyExt};
use conduwuit::{Err, Result, checked};
use futures::{FutureExt, StreamExt, TryFutureExt};
impl crate::Context<'_> {
@@ -49,6 +49,7 @@ impl crate::Context<'_> {
.services
.appservice
.get_registration(&appservice_identifier)
.await
{
| None => return Err!("Appservice does not exist."),
| Some(config) => {
@@ -77,11 +78,12 @@ impl crate::Context<'_> {
self.services
.users
.stream_local_users()
.ready_filter_map(|user_id| {
self.services
.appservice
.is_user_id(&user_id)
.then_some(user_id)
.filter_map(async |user_id| {
if self.services.appservice.is_user_id(&user_id).await {
Some(user_id)
} else {
None
}
})
.for_each(async |user_id| {
self.services
+1 -41
View File
@@ -14,7 +14,7 @@ use conduwuit::{
state_res::EventTypeExt,
trace, utils,
utils::{
stream::{BroadbandExt, IterStream, ReadyExt},
stream::{IterStream, ReadyExt},
string::EMPTY,
to_canonical_object,
},
@@ -1207,46 +1207,6 @@ impl crate::Context<'_> {
.await
}
pub(super) async fn room_extremities(&self, room_id: OwnedRoomId) -> Result {
let mut extremities = self
.services
.rooms
.state
.get_forward_extremities(&room_id)
.broad_filter_map(|event_id| async move {
self.services.rooms.timeline.get_pdu(&event_id).await.ok()
})
.collect::<Vec<_>>()
.await;
extremities.sort_by_key(|pdu| (pdu.depth, pdu.origin_server_ts));
if extremities.is_empty() {
return Err!("No room extremities.");
}
self.write_str("| Event ID | Kind | Sender | Timestamp | Depth |\n")
.await?;
self.write_str("| -------- | ---- | ------ | --------- | ----- |\n")
.await?;
for pdu in extremities {
let url = format!(
"https://matrix.to/#/{}/{}?via={}",
room_id,
pdu.event_id(),
self.services.server.name
);
self.write_str(&format!(
"| [`{}`]({url}) | `{}` | `{}` | `{}` | `{}` |\n",
pdu.event_id(),
pdu.kind(),
pdu.sender(),
pdu.origin_server_ts,
pdu.depth
))
.await?;
}
Ok(())
}
pub(super) async fn servers_in_backoff(
&self,
room_id: Option<OwnedRoomId>,
-4
View File
@@ -234,10 +234,6 @@ pub enum DebugCommand {
page: Option<usize>,
},
RoomExtremities {
room_id: OwnedRoomId,
},
/// Lists remote servers that are currently in a "backoff" state.
///
/// Servers in this list will not be contacted until the retry time elapses,
+8 -4
View File
@@ -39,13 +39,17 @@ conduwuit::mod_dtor! {}
pub use crate::admin::AdminCommand;
/// Install the admin command processor
pub fn init(admin_service: &service::admin::Service) {
pub async fn init(admin_service: &service::admin::Service) {
_ = admin_service.complete.write().insert(processor::complete);
_ = admin_service.handle.write().insert(processor::dispatch);
_ = admin_service
.handle
.write()
.await
.insert(processor::dispatch);
}
/// Uninstall the admin command handler
pub fn fini(admin_service: &service::admin::Service) {
_ = admin_service.handle.write().take();
pub async fn fini(admin_service: &service::admin::Service) {
_ = admin_service.handle.write().await.take();
_ = admin_service.complete.write().take();
}
+1 -1
View File
@@ -24,7 +24,7 @@ pub(super) async fn process(subcommand: AppserviceCommand, context: &Context<'_>
match subcommand {
| AppserviceCommand::GetRegistration { appservice_id } => {
let timer = tokio::time::Instant::now();
let results = services.appservice.get_registration(&appservice_id);
let results = services.appservice.get_registration(&appservice_id).await;
let query_time = timer.elapsed();
+1
View File
@@ -135,6 +135,7 @@ pub(crate) async fn add_3pid_route(
let email = services
.threepid
.get_valid_session(&body.sid, &body.client_secret)
.await
.map_err(|message| err!(Request(ThreepidAuthFailed("{message}"))))?
.consume();
+4 -7
View File
@@ -117,13 +117,10 @@ async fn set_account_data(
data: &RawJsonValue,
) -> Result {
if event_type_s == "m.fully_read" {
return Err!(Request(
BadJson(
"This endpoint cannot be used for marking a room as fully read (setting \
m.fully_read)"
),
METHOD_NOT_ALLOWED
));
return Err!(Request(BadJson(
"This endpoint cannot be used for marking a room as fully read (setting \
m.fully_read)"
)));
}
let data: serde_json::Value = serde_json::from_str(data.get())
+4 -2
View File
@@ -20,7 +20,8 @@ pub(crate) async fn create_alias_route(
services
.rooms
.alias
.appservice_checks(&body.room_alias, body.identity.appservice_info())?;
.appservice_checks(&body.room_alias, body.identity.appservice_info())
.await?;
// this isn't apart of alias_checks or delete alias route because we should
// allow removing forbidden room aliases
@@ -68,7 +69,8 @@ pub(crate) async fn delete_alias_route(
services
.rooms
.alias
.appservice_checks(&body.room_alias, body.identity.appservice_info())?;
.appservice_checks(&body.room_alias, body.identity.appservice_info())
.await?;
services
.rooms
+1 -2
View File
@@ -46,8 +46,7 @@ pub(crate) async fn get_capabilities_route(
capabilities.get_login_token =
GetLoginTokenCapability::new(services.server.config.login_via_existing_session);
capabilities.forget_forced_upon_leave.enabled =
services.server.config.forget_forced_upon_leave;
capabilities.forget_forced_upon_leave.enabled = true;
if services.users.is_admin(sender_user).await {
capabilities.account_moderation.lock = true;
+16 -15
View File
@@ -1,4 +1,4 @@
use std::{borrow::Borrow, collections::HashMap, sync::Arc};
use std::{borrow::Borrow, collections::HashMap, iter::once, sync::Arc};
use axum::extract::State;
use conduwuit::{
@@ -461,13 +461,14 @@ async fn knock_room_helper_local(
services
.rooms
.timeline
.progress_extremities(&parsed_knock_pdu)
.append_pdu(
&parsed_knock_pdu,
knock_event,
once(parsed_knock_pdu.event_id.borrow()),
&state_lock,
room_id,
)
.await?;
services
.rooms
.timeline
.append_pdu(&parsed_knock_pdu, knock_event, room_id)
.await;
Ok(())
}
@@ -586,7 +587,7 @@ async fn knock_room_helper_remote(
let mut state_map: HashMap<u64, OwnedEventId> = HashMap::new();
for mut event in state {
for event in state {
let Some(state_key) = event.get("state_key") else {
debug_warn!("send_knock stripped state event missing state_key: {event:?}");
continue;
@@ -613,7 +614,6 @@ async fn knock_room_helper_remote(
.get_or_create_shortstatekey(&event_type, &state_key)
.await;
event.insert("event_id".into(), CanonicalJsonValue::String(event_id.to_string()));
services.rooms.outlier.add_pdu_outlier(&event_id, &event);
state_map.insert(shortstatekey, event_id.clone());
}
@@ -662,13 +662,14 @@ async fn knock_room_helper_remote(
services
.rooms
.timeline
.progress_extremities(&parsed_knock_pdu)
.append_pdu(
&parsed_knock_pdu,
knock_event,
once(parsed_knock_pdu.event_id.borrow()),
&state_lock,
room_id,
)
.await?;
services
.rooms
.timeline
.append_pdu(&parsed_knock_pdu, knock_event, room_id)
.await;
info!("Setting final room state for new room");
// We set the room state after inserting the pdu, so that we never have a
+1 -1
View File
@@ -61,7 +61,7 @@ pub(crate) async fn authorization_server_metadata(services: &Services) -> Value
"authorization_endpoint": endpoint_base.join(AUTH_CODE_PATH).unwrap(),
"code_challenge_methods_supported": ["S256"],
"device_authorization_endpoint": endpoint_base.join(DEVICE_AUTHORIZATION_PATH).unwrap(),
"grant_types_supported": ["authorization_code", "refresh_token", "urn:ietf:params:oauth:grant-type:device_code", "client_credentials"],
"grant_types_supported": ["authorization_code", "refresh_token", "urn:ietf:params:oauth:grant-type:device_code"],
"issuer": services.config.get_client_domain(),
"jwks_uri": endpoint_base.join(JWKS_URI_PATH).unwrap(),
"prompt_values_supported": prompt_values_supported,
+9 -21
View File
@@ -1,21 +1,18 @@
use std::{
collections::{BTreeMap, BTreeSet, HashSet},
sync::atomic::{AtomicU64, Ordering::SeqCst},
};
use std::collections::{BTreeMap, BTreeSet, HashSet};
use axum::extract::State;
use conduwuit::{
Err, Error, Result, debug, debug_info, err, info,
matrix::{StateKey, pdu::PartialPdu},
trace,
utils::{self, to_canonical_object},
utils::to_canonical_object,
warn,
};
use conduwuit_service::{Services, appservice::RegistrationInfo};
use futures::FutureExt;
use ruma::{
CanonicalJsonObject, CanonicalJsonValue, Int, MilliSecondsSinceUnixEpoch, OwnedRoomAliasId,
OwnedUserId, RoomAliasId, RoomId, UInt,
OwnedUserId, RoomAliasId, RoomId,
api::{
client::room::{
self,
@@ -49,8 +46,6 @@ use serde_json::value::to_raw_value;
use crate::{Ruma, client::invite_helper};
static LAST_CREATE_TS: AtomicU64 = AtomicU64::new(0);
// We use this to keep around extra data in the `creation_content`
// while still parsing and validating keys that we care about.
#[derive(Deserialize, Default)]
@@ -312,17 +307,6 @@ pub(crate) async fn create_room_route(
.map(MilliSecondsSinceUnixEpoch)
};
// v12+ room IDs are the create event's hash, so give each create event a
// unique timestamp to avoid collisions.
let create_timestamp = custom_origin_server_ts.or_else(|| {
room_id.is_none().then(|| {
let now = utils::millis_since_unix_epoch();
let next = |last: u64| now.max(last.saturating_add(1));
let prev = LAST_CREATE_TS.update(SeqCst, SeqCst, next);
MilliSecondsSinceUnixEpoch(UInt::new_saturating(next(prev)))
})
});
let mut create_event_content = to_canonical_object(create_event_content)
.expect("should be able to serialize create event content");
@@ -338,7 +322,7 @@ pub(crate) async fn create_room_route(
event_type: TimelineEventType::RoomCreate,
content: to_raw_value(&create_event_content)?,
state_key: Some(StateKey::new()),
timestamp: create_timestamp,
timestamp: custom_origin_server_ts,
..Default::default()
},
sender_user,
@@ -774,7 +758,11 @@ async fn room_alias_check(
if !info.aliases.is_match(full_room_alias.as_str()) {
return Err!(Request(Exclusive("Room alias is not in namespace.")));
}
} else if services.appservice.is_exclusive_alias(&full_room_alias) {
} else if services
.appservice
.is_exclusive_alias(&full_room_alias)
.await
{
return Err!(Request(Exclusive("Room alias reserved by appservice.",)));
}
+2 -3
View File
@@ -2,12 +2,11 @@ mod aliases;
mod create;
mod event;
mod initial_sync;
mod stripped_state;
mod summary;
mod upgrade;
pub(crate) use self::{
aliases::get_room_aliases_route, create::create_room_route, event::get_room_event_route,
initial_sync::room_initial_sync_route, stripped_state::get_stripped_state_route,
summary::get_room_summary, upgrade::upgrade_room_route,
initial_sync::room_initial_sync_route, summary::get_room_summary,
upgrade::upgrade_room_route,
};
-71
View File
@@ -1,71 +0,0 @@
use axum::extract::State;
use conduwuit::{Err, Result};
use ruma::{
api::client::state::get_stripped_state, assign, events::ALLOWED_STRIPPED_STATE_EVENTS,
};
use service::rooms::summary::{Accessibility, RoomStrippedState};
use crate::{Ruma, router::ClientIdentity};
/// # `POST /_matrix/client/unstable/org.continuwuity.msc4560.stripped_state/{room_id_or_alias}` ([MSC4560])
///
/// Returns a room's stripped state.
///
/// [MSC4560]: https://github.com/matrix-org/matrix-spec-proposals/pull/4560
#[tracing::instrument(skip_all, name = "stripped_state", level = "info")]
pub(crate) async fn get_stripped_state_route(
State(services): State<crate::State>,
body: Ruma<get_stripped_state::unstable::Request>,
) -> Result<get_stripped_state::unstable::Response> {
let user_id = body.identity.as_ref().and_then(ClientIdentity::sender_user);
if body.via.len() > get_stripped_state::unstable::MAX_VIAS {
return Err!(Request(TooLarge("Too many vias, please be less indecisive.")));
}
if let Some(forbidden_type) = body
.state
.iter()
.find(|event_type| !ALLOWED_STRIPPED_STATE_EVENTS.contains(event_type))
{
return Err!(Request(InvalidParam(
"Event type {forbidden_type} may not be requested as stripped state."
)));
}
let (room_id, _) = services
.rooms
.alias
.resolve_with_servers(&body.room_id_or_alias, Some(body.via.clone()))
.await?;
if services.rooms.metadata.is_banned(&room_id).await {
return Err!(Request(Forbidden("This room is banned on this homeserver.")));
}
match services
.rooms
.summary
.get_stripped_state_for_user(
user_id,
&room_id,
&body.via,
&body.state,
body.num_joined_members,
)
.await
{
| Accessibility::Accessible((
via,
RoomStrippedState { state, num_joined_members, .. },
)) => Ok(
assign!(get_stripped_state::unstable::Response::new(via), { state, num_joined_members }),
),
| Accessibility::Inaccessible => {
Err!(Request(Forbidden("You may not request this room's stripped state.")))
},
| Accessibility::NotFound => {
Err!(Request(NotFound("This room does not exist.")))
},
}
}
+6 -3
View File
@@ -13,7 +13,7 @@ pub(crate) async fn get_room_summary(
State(services): State<crate::State>,
body: Ruma<get_summary::v1::Request>,
) -> Result<get_summary::v1::Response> {
let (room_id, _) = services
let (room_id, servers) = services
.rooms
.alias
.resolve_with_servers(&body.room_id_or_alias, Some(body.via.clone()))
@@ -27,9 +27,12 @@ pub(crate) async fn get_room_summary(
.rooms
.summary
.get_room_summary_for_user(
body.identity.as_ref().and_then(ClientIdentity::sender_user),
body.identity
.as_ref()
.map(ClientIdentity::expect_sender_user)
.transpose()?,
&room_id,
&body.via,
&servers,
)
.await?;
+1 -1
View File
@@ -201,7 +201,7 @@ pub(crate) async fn sync_events_route(
.update_device_last_seen(sender_user, Some(sender_device), client_ip)
.await;
let mut wake_receiver = services.sync.subscribe_to_wake(sender_user);
let mut wake_receiver = services.sync.subscribe_to_wake(sender_user).await;
let response = build_sync_events(&services, &body).await?;
if body.body.full_state
|| !(response.rooms.is_empty()
+1 -1
View File
@@ -147,7 +147,7 @@ pub(crate) async fn sync_events_v5_route(
.sync
.update_snake_sync_request_with_cache(&snake_key, globalsince, &mut body);
let mut wake_receiver = services.sync.subscribe_to_wake(sender_user);
let mut wake_receiver = services.sync.subscribe_to_wake(sender_user).await;
let mut collection = collect_sync_response(
services,
sender_user,
+1 -1
View File
@@ -64,7 +64,7 @@ pub(crate) async fn continuwuity_local_user_count(
.stream_local_users()
.filter_map(async |user_id| {
if !services.users.status(&user_id).await.is_active()
|| services.appservice.is_exclusive_user_id(&user_id)
|| services.appservice.is_exclusive_user_id(&user_id).await
{
None
} else {
+4 -3
View File
@@ -184,7 +184,6 @@ pub fn build(router: Router<State>, state: State) -> Router<State> {
.ruma_route(&client::get_mutual_rooms_unstable_route)
.ruma_route(&client::get_mutual_rooms_route)
.ruma_route(&client::get_room_summary)
.ruma_route(&client::get_stripped_state_route)
.ruma_route(&client::get_suspended_status)
.ruma_route(&client::put_suspended_status)
.ruma_route(&client::get_lock_status)
@@ -207,7 +206,10 @@ pub fn build(router: Router<State>, state: State) -> Router<State> {
if config.allow_federation {
router = router
.ruma_route(&server::get_server_version_route)
.route("/_matrix/key/v2/server", get(server::get_server_keys_route))
.ruma_route(&server::get_server_keys_route)
.ruma_route(&server::get_remote_server_keys_batch_route)
.ruma_route(&server::get_remote_server_keys_batch_v3_unstable_route)
.ruma_route(&server::get_remote_server_keys_route)
.ruma_route(&server::get_public_rooms_route)
.ruma_route(&server::get_public_rooms_filtered_route)
.ruma_route(&server::send_transaction_message_route)
@@ -230,7 +232,6 @@ pub fn build(router: Router<State>, state: State) -> Router<State> {
.ruma_route(&server::get_keys_route)
.ruma_route(&server::claim_keys_route)
.ruma_route(&server::get_hierarchy_route)
.ruma_route(&server::get_stripped_state_route)
.ruma_route(&server::well_known_server)
.ruma_route(&server::get_content_route)
.ruma_route(&server::get_content_thumbnail_route)
+7 -28
View File
@@ -41,7 +41,6 @@ pub(crate) enum ClientIdentity {
sender_device: Option<OwnedDeviceId>,
appservice_info: Box<RegistrationInfo>,
},
StaticClient,
}
impl ClientIdentity {
@@ -49,7 +48,6 @@ impl ClientIdentity {
match self {
| Self::User { sender_user, .. } | Self::Appservice { sender_user, .. } =>
Some(sender_user),
| Self::StaticClient => None,
}
}
@@ -57,8 +55,6 @@ impl ClientIdentity {
match self {
| Self::User { sender_user, .. } | Self::Appservice { sender_user, .. } =>
Ok(sender_user),
| Self::StaticClient =>
Err!(Request(Forbidden("Static clients cannot use this endpoint."))),
}
}
@@ -66,7 +62,6 @@ impl ClientIdentity {
match self {
| Self::User { sender_device, .. } => Some(sender_device),
| Self::Appservice { sender_device, .. } => sender_device.as_deref(),
| Self::StaticClient => None,
}
}
@@ -76,14 +71,12 @@ impl ClientIdentity {
| Self::Appservice { sender_device: Some(sender_device), .. } => Ok(sender_device),
| Self::Appservice { sender_device: None, .. } =>
Err!(Request(Forbidden("Appservices must masquerade to use this endpoint."))),
| Self::StaticClient =>
Err!(Request(Forbidden("Static clients cannot use this endpoint."))),
}
}
pub(crate) fn appservice_info(&self) -> Option<&RegistrationInfo> {
match self {
| Self::User { .. } | Self::StaticClient => None,
| Self::User { .. } => None,
| Self::Appservice { appservice_info, .. } => Some(appservice_info),
}
}
@@ -353,7 +346,7 @@ async fn check_access_token(
}
Ok(ClientIdentity::User { sender_user, sender_device })
} else if let Ok(appservice_info) = services.appservice.find_from_token(token) {
} else if let Ok(appservice_info) = services.appservice.find_from_token(token).await {
let Ok(sender_user) = query.user_id.clone().map_or_else(
|| {
UserId::parse_with_server_name(
@@ -386,7 +379,10 @@ async fn check_access_token(
.await
.is_err()
{
return Err!(Request(UnknownDevice("Device does not exist for this user.")));
return Err!(Request(Forbidden(
"Device does not exist for user or appservice cannot masquerade as this \
device."
)));
}
Some(device_id.to_owned())
@@ -399,23 +395,6 @@ async fn check_access_token(
sender_device,
appservice_info: Box::new(appservice_info),
})
} else if let Some(session) = services.oauth.get_client_credentials_session(token).await {
if !required_scopes
.iter()
.any(|scope| session.scopes.contains(scope))
{
return Err(Error::Request(
ErrorKind::InsufficientUserAuthentication(Box::new(
assign!(InsufficientUserAuthenticationErrorData::new(), {
scope: required_scopes.iter().cloned().collect()
}),
)),
"You do not have permission to access this endpoint.".into(),
StatusCode::UNAUTHORIZED,
));
}
Ok(ClientIdentity::StaticClient)
} else {
Err(Error::Request(
ErrorKind::UnknownToken(UnknownTokenErrorData::new()),
@@ -426,7 +405,7 @@ async fn check_access_token(
}
async fn check_appservice_token(services: &Services, token: &str) -> Result<RegistrationInfo> {
let Ok(appservice_info) = services.appservice.find_from_token(token) else {
let Ok(appservice_info) = services.appservice.find_from_token(token).await else {
return Err!(Request(Unauthorized("Invalid appservice token.")));
};
+2 -7
View File
@@ -1,10 +1,7 @@
use std::{borrow::Borrow, iter::once};
use axum::extract::State;
use conduwuit::{
Err, Event, Result, info,
utils::stream::{BroadbandExt, ReadyExt},
};
use conduwuit::{Err, Event, Result, info, utils::stream::ReadyExt};
use futures::StreamExt;
use ruma::api::federation::authorization::get_event_authorization;
@@ -67,9 +64,7 @@ pub(crate) async fn get_event_authorization_route(
.auth_chain
.event_ids_iter(&body.room_id, once(body.event_id.borrow()))
.ready_filter_map(Result::ok)
.broad_filter_map(
|id| async move { services.rooms.timeline.get_pdu_json(&id).await.ok() },
)
.filter_map(|id| async move { services.rooms.timeline.get_pdu_json(&id).await.ok() })
.then(|pdu| services.sending.convert_to_outgoing_federation_event(pdu))
.collect()
.await;
+2 -15
View File
@@ -1,7 +1,7 @@
use std::collections::{HashSet, VecDeque};
use axum::extract::State;
use conduwuit::{Err, Event, Result, debug, debug_warn, info, trace, utils::to_canonical_object};
use conduwuit::{Err, Event, Result, debug, info, trace, utils::to_canonical_object, warn};
use ruma::{OwnedEventId, api::federation::event::get_missing_events};
use serde_json::value::RawValue;
use service::rooms::event_handler::GET_MISSING_EVENTS_MAX_BATCH_SIZE;
@@ -44,13 +44,6 @@ pub(crate) async fn get_missing_events_route(
.unwrap_or(10)
.min(GET_MISSING_EVENTS_MAX_BATCH_SIZE);
if body.latest_events.len() > limit {
return Err!(Request(InvalidParam("Too many latest_events")));
}
if body.earliest_events.len() > limit {
return Err!(Request(InvalidParam("Too many earliest_events")));
}
let room_version = services.rooms.state.get_room_version(&body.room_id).await?;
let mut queue: VecDeque<OwnedEventId> = VecDeque::from(body.latest_events.clone());
@@ -71,9 +64,7 @@ pub(crate) async fn get_missing_events_route(
let mut pdu = match services.rooms.timeline.get_pdu(&next_event_id).await {
| Ok(pdu) => pdu,
| Err(e) => {
debug_warn!(
"could not find event {next_event_id} while walking missing events: {e}"
);
warn!("could not find event {next_event_id} while walking missing events: {e}");
continue;
},
};
@@ -83,10 +74,6 @@ pub(crate) async fn get_missing_events_route(
body.room_id
)));
}
if pdu.depth < body.min_depth {
debug!(%next_event_id, %pdu.depth, %body.min_depth, "event is below minimum depth, not traversing");
continue;
}
if services
.rooms
.pdu_metadata
+23 -27
View File
@@ -209,35 +209,31 @@ async fn create_invite(
services.sync.wake(&recipient_user).await;
let matching_appservices: Vec<_> = services
.appservice
.read()
.values()
.filter(|appservice| appservice.is_user_match(&recipient_user))
.cloned()
.collect();
for appservice in services.appservice.read().await.values() {
if appservice.is_user_match(&recipient_user) {
let transaction_id = general_purpose::URL_SAFE_NO_PAD
.encode(sha256::hash(pdu.event_id.as_bytes()))
.into();
for appservice in matching_appservices {
let transaction_id = general_purpose::URL_SAFE_NO_PAD
.encode(sha256::hash(pdu.event_id.as_bytes()))
.into();
let request = ruma::api::appservice::event::push_events::v1::Request::new(
transaction_id,
vec![pdu.to_format()],
);
let request = ruma::api::appservice::event::push_events::v1::Request::new(
transaction_id,
vec![pdu.to_format()],
);
services
.sending
.send_appservice_request(appservice.registration.clone(), request)
.await
.map_err(|e| {
error!(
"failed to notify appservice {} about incoming invite: {e}",
appservice.registration.id
);
err!(BadServerResponse("Failed to notify appservice about incoming invite."))
})?;
services
.sending
.send_appservice_request(appservice.registration.clone(), request)
.await
.map_err(|e| {
error!(
"failed to notify appservice {} about incoming invite: {e}",
appservice.registration.id
);
err!(BadServerResponse(
"Failed to notify appservice about incoming invite."
))
})?;
}
}
}
+360 -69
View File
@@ -1,89 +1,380 @@
use std::{collections::BTreeMap, mem::take, time::Duration};
use axum::{Json, extract::State, response::IntoResponse};
use conduwuit::{Result, utils::timepoint_from_now};
use futures::StreamExt;
use ruma::{
MilliSecondsSinceUnixEpoch,
api::{
OutgoingResponseExt,
federation::discovery::{OldVerifyKey, ServerSigningKeys, get_server_keys},
},
assign,
serde::Raw,
use std::{
collections::{BTreeMap, HashMap, HashSet},
ops::Index,
sync::Arc,
time::Instant,
};
use axum::extract::State;
use conduwuit::{
Err, Result, debug, debug_info, error,
utils::{
ReadyExt,
stream::{BroadbandExt, automatic_width},
to_canonical_object,
},
};
use futures::{StreamExt, stream::FuturesUnordered};
use ruma::{
MilliSecondsSinceUnixEpoch, OwnedServerName, OwnedServerSigningKeyId, ServerName,
api::federation::discovery::{
ServerSigningKeys, get_remote_server_keys, get_remote_server_keys_batch,
get_remote_server_keys_batch::v2::QueryCriteria, get_server_keys,
},
serde::Raw,
uint,
};
use serde_json::value::to_raw_value;
use service::{server_keys, server_keys::in_one_week};
use crate::router::Ruma;
/// # `GET /_matrix/key/v2/server`
///
/// Gets the public signing keys of this server.
pub(crate) async fn get_server_keys_route(
State(services): State<crate::State>,
) -> Result<impl IntoResponse> {
let server_name = services.globals.server_name();
let verify_keys = BTreeMap::from([services.server_keys.active_verify_key()]);
_body: Ruma<get_server_keys::v2::Request>,
) -> Result<get_server_keys::v2::Response> {
services
.server_keys
.build_server_keys_response()
.await
.map(get_server_keys::v2::Response::new)
}
let old_verify_keys = if let Some(k) = &services.config.old_verify_keys {
k.to_owned()
const MAX_KEYS_PER_QUERY: usize = 16384;
const MAX_SERVERS_PER_QUERY: usize = 4096;
/// # `POST /_matrix/key/v2/query`
///
/// Fetches remote server signing keys in bulk, seeding from the local server's
/// database.
///
/// This route applies a semaphore to slow down requests that query more signing
/// keys than is allowed by [MSC4556].
///
/// [MSC4556]: https://github.com/matrix-org/matrix-spec-proposals/pull/4556
pub(crate) async fn get_remote_server_keys_batch_route(
State(services): State<crate::State>,
body: Ruma<get_remote_server_keys_batch::v2::Request>,
) -> Result<get_remote_server_keys_batch::v2::Response> {
query_inner(&services, &body.server_keys, false)
.await
.map(get_remote_server_keys_batch::v2::Response::new)
}
/// # `POST /_matrix/key/unstable/org.continuwuity.msc4556/query`
/// ## `POST /_matrix/key/v3/query`
///
/// Fetches remote server signing keys in bulk, seeding from the local server's
/// database.
///
/// MSC4556: https://github.com/matrix-org/matrix-spec-proposals/pull/4556
pub(crate) async fn get_remote_server_keys_batch_v3_unstable_route(
State(services): State<crate::State>,
body: Ruma<ruminuwuity::federation::notary::unstable::Request>,
) -> Result<ruminuwuity::federation::notary::unstable::Response> {
query_inner(&services, &body.server_keys, false)
.await
.map(ruminuwuity::federation::notary::unstable::Response::new)
}
/// Handles querying the server keys for `/_matrix/key/*/query`.
///
/// `v2` should be `true` if the request path is `/_matrix/key/v2/query` - this
/// will potentially apply a rate-limit to the request.
async fn query_inner(
services: &crate::State,
body: &BTreeMap<OwnedServerName, BTreeMap<OwnedServerSigningKeyId, QueryCriteria>>,
v2: bool,
) -> Result<Vec<Raw<ServerSigningKeys>>> {
let start = (Instant::now(), MilliSecondsSinceUnixEpoch::now());
// If the remote server isn't asking for any keys, we can return an empty
// array immediately.
if body.is_empty() {
return Ok(Vec::new());
}
// Count how many keys are being requested.
// Each server incurs a cost of at least one, and then the count of each key
// being queried per-server.
let total_queried_servers = body.len();
let total_queried_keys = body
.values()
.fold(body.len(), |acc, q| acc.saturating_add(q.len()));
if !v2 {
// If we're on the v3 endpoint, we can apply these limits explicitly.
if total_queried_servers > MAX_SERVERS_PER_QUERY {
return Err!(Request(TooLarge(
"Too many server keys requested ({total_queried_servers} > \
{MAX_SERVERS_PER_QUERY}",
)));
}
if total_queried_keys > MAX_KEYS_PER_QUERY {
return Err!(Request(TooLarge(
"Too many keys requested ({total_queried_keys} > {MAX_KEYS_PER_QUERY})"
)));
}
}
let penalise =
total_queried_servers > MAX_SERVERS_PER_QUERY || total_queried_keys > MAX_KEYS_PER_QUERY;
debug_info!("Fetching {total_queried_keys} keys across {} servers", body.len());
let mut futs: FuturesUnordered<_> = FuturesUnordered::new();
// If we're on the v2 endpoint, we aren't allowed to reject the request.
// To avoid overloading the server, we'll apply a semaphore to limit how
// many futures can be active at a time.
let width = automatic_width();
let sem = if v2 && penalise {
Some(Arc::new(tokio::sync::Semaphore::new(width)))
} else {
// We need to figure out any old signing keys we've acquired from
// notaries.
let mut keys = services.server_keys.signing_keys_for(server_name);
let mut old_keys = BTreeMap::new();
while let Some(resp) = keys.next().await {
// We need to verify that this response is still trusted based on
// the current configuration. It's possible we got this response
// from a notary who we no longer trust.
if resp.valid_until_ts > in_one_week() {
continue;
}
let trusted = services.config.trusted_servers.iter().any(|notary| {
server_keys::Service::verify_server_keys_response(
&resp,
Some((notary.server_name(), notary.verify_keys())),
)
.is_ok()
});
if !trusted {
continue;
}
for (old_key_id, old_key) in resp.old_verify_keys {
if old_key.expired_ts > resp.valid_until_ts {
// This key expired in the future which is probably illegal
continue;
None
};
for (server_name, queries) in body.clone() {
futs.push(acquire_keys_as_notary(
services.server_keys.clone(),
services.globals.server_name().to_owned(),
server_name,
queries,
start.1,
sem.clone(),
));
}
let mut response = Vec::with_capacity(total_queried_keys);
while let Some(v) = futs.next().await {
response.extend(v);
}
debug_info!(
elapsed=?start.0.elapsed(),
%total_queried_servers,
%total_queried_keys,
"Fetched {} key responses",
response.len()
);
Ok(response)
}
async fn sign_ssk(
server_keys: &server_keys::Service,
ssk: ServerSigningKeys,
server_name: &ServerName,
our_name: &ServerName,
) -> Result<Raw<ServerSigningKeys>> {
if server_name == our_name {
// Should already be signed by us if we got this far.
debug_info!(
object=?ssk,
%server_name,
%our_name,
"Refusing to sign our own signing keys response (should already be signed)"
);
return to_raw_value(&ssk)
.map(Raw::<ServerSigningKeys>::from_json)
.map_err(Into::into);
}
let mut canonical = to_canonical_object(&ssk)?;
server_keys.sign_json(&mut canonical)?;
server_keys::strip_extraneous_signatures(&mut canonical, server_name, &[our_name]);
to_raw_value(&canonical)
.map(Raw::<ServerSigningKeys>::from_json)
.map_err(Into::into)
}
#[tracing::instrument(skip(server_keys, my_name, queries, start, semaphore))]
async fn acquire_keys_as_notary(
server_keys: Arc<server_keys::Service>,
my_name: OwnedServerName,
remote: OwnedServerName,
mut queries: BTreeMap<OwnedServerSigningKeyId, QueryCriteria>,
start: MilliSecondsSinceUnixEpoch,
semaphore: Option<Arc<tokio::sync::Semaphore>>,
) -> Vec<Raw<ServerSigningKeys>> {
let cost = queries
.len()
.saturating_add(1)
.min(automatic_width())
.try_into()
.unwrap_or(u32::MAX);
let _permit = if let Some(sem) = semaphore {
sem.acquire_many_owned(cost).await.ok()
} else {
None
};
let fetch_all = queries.is_empty();
let mut results = Vec::with_capacity(queries.len().max(1));
let mut keymap = HashMap::with_capacity(queries.len().max(1));
// First contact the origin (if we're allowed to)
if server_keys.notary_may_contact_origin(&remote) {
debug_info!("Asking remote directly for verify keys");
if let Ok(res) = server_keys.origin_request(remote.clone(), start).await
&& let Ok(ssk) = sign_ssk(&server_keys, res.clone(), &remote, &my_name).await
{
let index = results.len();
results.push(ssk);
for key_id in res.verify_keys.keys().chain(res.old_verify_keys.keys()) {
if fetch_all
|| queries.get(key_id).is_some_and(|c| {
c.minimum_valid_until_ts
.is_none_or(|m| res.valid_until_ts >= m)
}) {
queries.remove(key_id);
keymap.insert(key_id.to_owned(), index);
}
old_keys
.entry(old_key_id)
.and_modify(|current_old_key: &mut OldVerifyKey| {
// Use the lowest expiry timestamp
if current_old_key.expired_ts > old_key.expired_ts {
*current_old_key = old_key.clone();
}
})
.or_insert(old_key);
}
}
old_keys
};
} else {
debug!("Not asking remote for keys (already asked recently)");
}
debug!(keys=?keymap.keys(), "Live verify keys");
if fetch_all && keymap.is_empty() {
// If the server asked for all keys, AND we didn't get anything from the
// origin, just fetch any fresh responses we have.
server_keys
.signing_keys_for(&remote)
.broad_filter_map(|ssk| {
let server_name = &remote;
let my_name = &my_name;
let server_keys = &server_keys;
async move {
if ssk.valid_until_ts > in_one_week() || ssk.valid_until_ts < start {
return None;
}
let server_key = assign!(ServerSigningKeys::new(server_name.to_owned(), valid_until_ts()), {
verify_keys,
old_verify_keys,
});
sign_ssk(server_keys, ssk.clone(), server_name, my_name)
.await
.map(|signed_ssk| (ssk, signed_ssk))
.ok()
}
})
.ready_for_each(|(ssk, signed_ssk)| {
let idx = results.len();
results.push(signed_ssk);
for key_id in ssk.verify_keys.keys().chain(ssk.old_verify_keys.keys()) {
keymap.insert(key_id.to_owned(), idx);
}
})
.await;
}
let server_key = Raw::new(&server_key)?;
let mut response = get_server_keys::v2::Response::new(server_key)
.try_into_http_response::<Vec<u8>>()
.map(|mut response| take(response.body_mut()))
.and_then(|body| serde_json::from_slice(&body).map_err(Into::into))?;
// If we're still missing some keys, fetch them from the local cache
for (key_id, criteria) in queries {
debug!(%key_id, "Fetching verify key from local repository");
services.server_keys.sign_json(&mut response)?;
if keymap.contains_key(&key_id) {
debug!(%key_id, "Already found key");
continue;
}
Ok(Json(response))
let minimum_valid_until_ts = criteria
.clone()
.minimum_valid_until_ts
.unwrap_or_else(|| MilliSecondsSinceUnixEpoch(uint!(0)));
let Some(ssk) = server_keys.get_signing_key(&remote, &key_id).await else {
debug!(%remote, %key_id, "Could not find a matching signing key locally.");
continue;
};
if ssk.valid_until_ts < minimum_valid_until_ts || ssk.valid_until_ts > in_one_week() {
debug!(
%key_id,
valid_until_ts=?ssk.valid_until_ts,
?minimum_valid_until_ts,
"Stored verify key does not satisfy query criteria"
);
continue;
}
if let Some(old_verify_key) = ssk.old_verify_keys.get(&key_id) {
if old_verify_key.expired_ts < minimum_valid_until_ts {
debug!(
%key_id,
expired_ts=?old_verify_key.expired_ts,
?minimum_valid_until_ts,
"Stored old verify key does not satisfy query criteria"
);
continue;
}
}
debug!(%key_id, ?ssk, "Found key locally");
let rep_key_ids = ssk.verify_keys.keys().cloned().collect::<Vec<_>>();
let Ok(signed_ssk) = sign_ssk(&server_keys, ssk.clone(), &remote, &my_name)
.await
.inspect_err(
|e| error!(%key_id, %remote, "Failed to sign signing keys chunk: {e:?}"),
)
else {
continue;
};
let idx = results.len();
results.push(signed_ssk);
keymap.insert(key_id, idx);
for key_id in rep_key_ids {
keymap.insert(key_id, idx);
}
}
keymap
.into_values()
.collect::<HashSet<_>>()
.into_iter()
.map(|idx| results.index(idx).to_owned())
.collect()
}
fn valid_until_ts() -> MilliSecondsSinceUnixEpoch {
let dur = Duration::from_hours(12);
let timepoint = timepoint_from_now(dur).expect("SystemTime should not overflow");
MilliSecondsSinceUnixEpoch::from_system_time(timepoint).expect("UInt should not overflow")
/// `GET /_matrix/key/v2/query/{serverName}`
///
/// Fetches the latest keys for a specific server name.
pub(crate) async fn get_remote_server_keys_route(
State(services): State<crate::State>,
body: Ruma<get_remote_server_keys::v2::Request>,
) -> Result<get_remote_server_keys::v2::Response> {
let min_valid_ts = body.minimum_valid_until_ts;
if services
.server_keys
.notary_may_contact_origin(&body.server_name)
&& let Ok(response) = services
.server_keys
.origin_request(body.server_name.clone(), min_valid_ts)
.await
{
return sign_ssk(
&services.server_keys,
response,
&body.server_name,
services.globals.server_name(),
)
.await
.map(|r| Ok(get_remote_server_keys::v2::Response::new(vec![r])))?;
}
let response = services
.server_keys
.signing_keys_for(&body.server_name)
.broad_filter_map(|ssk| {
let server_name = body.server_name.clone();
async move {
if ssk.valid_until_ts > in_one_week() || ssk.valid_until_ts < min_valid_ts {
return None;
}
sign_ssk(
&services.server_keys,
ssk,
server_name.as_ref(),
services.globals.server_name(),
)
.await
.ok()
}
})
.collect::<Vec<_>>()
.await;
Ok(get_remote_server_keys::v2::Response::new(response))
}
+185 -67
View File
@@ -1,19 +1,29 @@
use std::{borrow::ToOwned, pin::pin};
use axum::extract::State;
use conduwuit::{Err, Error, Result, info, matrix::pdu::PartialPdu, utils};
use conduwuit::{
Err, Error, Result, debug, debug_info, info, matrix::pdu::PartialPdu, utils, warn,
};
use conduwuit_service::Services;
use futures::StreamExt;
use ruma::{
OwnedUserId,
OwnedUserId, RoomId, UserId,
api::{
error::{ErrorKind, IncompatibleRoomVersionErrorData},
federation::membership::prepare_join_event,
},
assign,
events::room::{
join_rules::JoinRule,
member::{MembershipState, RoomMemberEventContent},
events::{
StateEventType,
room::{
join_rules::{AllowRule, JoinRule, RoomJoinRulesEventContent},
member::{MembershipState, RoomMemberEventContent},
},
},
};
use serde_json::value::to_raw_value;
use service::rooms::membership::{JoinConditionEntity, JoinConditionResult};
use service::rooms::state::RoomMutexGuard;
use tokio::join;
use crate::Ruma;
@@ -25,6 +35,9 @@ pub(crate) async fn create_join_event_template_route(
State(services): State<crate::State>,
body: Ruma<prepare_join_event::v1::Request>,
) -> Result<prepare_join_event::v1::Response> {
if !services.rooms.metadata.exists(&body.room_id).await {
return Err!(Request(NotFound("Room is unknown to this server.")));
}
if !services
.rooms
.state_cache
@@ -50,6 +63,18 @@ pub(crate) async fn create_join_event_template_route(
.acl_check(&body.identity, &body.room_id)
.await?;
if services
.moderation
.is_remote_server_forbidden(&body.identity)
{
warn!(
"Server {} for remote user {} tried joining room ID {} which has a server name that \
is globally forbidden. Rejecting.",
body.identity, &body.user_id, &body.room_id,
);
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
}
let room_version = services.rooms.state.get_room_version(&body.room_id).await?;
let room_version_rules = room_version.rules().unwrap();
if !body.ver.contains(&room_version) {
@@ -62,78 +87,41 @@ pub(crate) async fn create_join_event_template_route(
}
let state_lock = services.rooms.state.mutex.lock(body.room_id.as_str()).await;
let current_membership = services
.rooms
.state_accessor
.get_member(&body.room_id, &body.user_id)
.await
.ok()
.map_or_else(|| MembershipState::Leave, |content| content.membership);
let (is_invited, is_joined) = join!(
services
.rooms
.state_cache
.is_invited(&body.user_id, &body.room_id),
services
.rooms
.state_cache
.is_joined(&body.user_id, &body.room_id)
);
let join_authorized_via_users_server: Option<OwnedUserId> = {
if matches!(
current_membership,
MembershipState::Join | MembershipState::Invite | MembershipState::Knock
) {
// User is already joined, invited, or knocked, and consequently
// does not need an authorising user
if is_joined || is_invited {
// User is already joined or invited and consequently does not need
// an authorising user
None
} else if !room_version_rules.authorization.restricted_join_rule {
// Room version does not support restricted join rules
// room version does not support restricted join rules
None
} else if user_can_perform_restricted_join(&services, &body.user_id, &body.room_id)
.await?
{
Some(
select_authorising_user(&services, &body.room_id, &body.user_id, &state_lock)
.await?,
)
} else {
let join_rules = services
.rooms
.state_accessor
.get_join_rules(&body.room_id)
.await;
if let JoinRule::Restricted(conditions) | JoinRule::KnockRestricted(conditions) =
join_rules
{
match services
.rooms
.membership
.evaluate_join_conditions(
&body.room_id,
JoinConditionEntity::User(&body.user_id),
&conditions,
)
.await
{
| JoinConditionResult::Satisfied => {
// Try to find an authorizing user
services
.rooms
.membership
.select_authorizing_user(&body.room_id, &body.user_id, &state_lock)
.await
.map(Some)?
},
| JoinConditionResult::Unsatisfied => {
return Err!(Request(Forbidden(
"You do not satisfy this room's join conditions."
)));
},
| JoinConditionResult::UnableToAuthorizeJoin => {
return Err!(Request(UnableToAuthorizeJoin(
"This server cannot check this room's join conditions."
)));
},
}
} else {
None
}
None
}
};
if services.antispam.check_all_joins() {
if services.antispam.check_all_joins() && join_authorized_via_users_server.is_none() {
if services
.antispam
.meowlnir_accept_make_join(body.room_id.clone(), body.user_id.clone())
.await
!= JoinConditionResult::Satisfied
.is_err()
{
return Err!(Request(Forbidden("Antispam rejected join request.")));
}
@@ -165,3 +153,133 @@ pub(crate) async fn create_join_event_template_route(
}),
)
}
/// Attempts to find a user who is able to issue an invite in the target room.
pub(crate) async fn select_authorising_user<'a>(
services: &Services,
room_id: &'a RoomId,
user_id: &'a UserId,
state_lock: &'a RoomMutexGuard,
) -> Result<OwnedUserId> {
let candidates = services.rooms.state_cache.local_users_in_room(room_id);
let mut candidates = pin!(candidates);
while let Some(candidate) = candidates.next().await {
if services
.rooms
.state_accessor
.user_can_invite(room_id, &candidate, user_id, state_lock)
.await
{
return Ok(candidate);
}
}
Err!(Request(UnableToGrantJoin(
"No user on this server is able to assist in joining."
)))
}
/// Checks whether the given user can join the given room via a restricted join.
pub(crate) async fn user_can_perform_restricted_join(
services: &Services,
user_id: &UserId,
room_id: &RoomId,
) -> Result<bool> {
let Ok(join_rules_event_content) = services
.rooms
.state_accessor
.room_state_get_content::<RoomJoinRulesEventContent>(
room_id,
&StateEventType::RoomJoinRules,
"",
)
.await
else {
// No join rules means there's nothing to authorise (defaults to invite)
return Ok(false);
};
let (JoinRule::Restricted(r) | JoinRule::KnockRestricted(r)) =
join_rules_event_content.join_rule
else {
// This is not a restricted room
return Ok(false);
};
if r.allow.is_empty() {
// This will never be authorisable, return forbidden.
return Err!(Request(Forbidden("You are not invited to this room.")));
}
let mut could_satisfy = true;
for allow_rule in &r.allow {
match allow_rule {
| AllowRule::RoomMembership(membership) => {
if !services
.rooms
.state_cache
.server_in_room(services.globals.server_name(), &membership.room_id)
.await
{
// Since we can't check this room, mark could_satisfy as
// false so that we can return
// M_UNABLE_TO_AUTHORIZE_JOIN later.
could_satisfy = false;
continue;
}
if services
.rooms
.state_cache
.is_joined(user_id, &membership.room_id)
.await
{
debug!(
"User {} is allowed to join room {} via membership in room {}",
user_id, room_id, membership.room_id
);
return Ok(true);
}
},
| other if other.rule_type() == "fi.mau.spam_checker" =>
return match services
.antispam
.meowlnir_accept_make_join(room_id.to_owned(), user_id.to_owned())
.await
{
| Ok(()) => Ok(true),
| Err(_) => Err!(Request(Forbidden("Antispam rejected join request."))),
},
| _ => {
// We don't recognise this join rule, so we cannot satisfy the
// request.
could_satisfy = false;
debug_info!(
"Unsupported allow rule in restricted join for room {}: {:?}",
room_id,
allow_rule
);
},
}
}
if could_satisfy {
// We were able to check all the restrictions and can be certain that
// the prospective member is not permitted to join.
Err!(Request(Forbidden(
"You do not belong to any of the rooms or spaces required to join this room."
)))
} else {
// We were unable to check all the restrictions. This usually means we
// aren't in one of the rooms this one is restricted to, ergo can't
// check its state for the user's membership, and consequently the
// user *might* be able to join if they ask another server.
Err!(Request(UnableToAuthorizeJoin(
"You do not belong to any of the recognised rooms or spaces required to join this \
room, but this server is unable to verify every requirement. You may be able to \
join via another server."
)))
}
}
-2
View File
@@ -18,7 +18,6 @@ pub(super) mod send_knock;
pub(super) mod send_leave;
pub(super) mod state;
pub(super) mod state_ids;
pub(super) mod stripped_state;
pub(super) mod user;
pub(super) mod version;
pub(super) mod well_known;
@@ -43,7 +42,6 @@ pub(super) use send_knock::*;
pub(super) use send_leave::*;
pub(super) use state::*;
pub(super) use state_ids::*;
pub(super) use stripped_state::*;
pub(super) use user::*;
pub(super) use version::*;
pub(super) use well_known::*;
+10 -50
View File
@@ -16,11 +16,9 @@ use ruma::{
TimelineEventType,
room::member::{MembershipState, RoomMemberEventContent},
},
room::JoinRule,
room_version_rules::RoomVersionRules,
};
use serde_json::value::to_raw_value;
use service::rooms::membership::{JoinConditionEntity, JoinConditionResult};
use crate::{Ruma, server::utils::validate_any_membership_event};
@@ -110,56 +108,18 @@ async fn create_join_event(
they cannot authorise your join."
)));
}
// If the user is invited or joined we don't need to check the join
// conditions, but in that case the requesting server shouldn't
// have set `join_authorized_via_users_server` in the first place.
let join_rules = services.rooms.state_accessor.get_join_rules(room_id).await;
if let JoinRule::Restricted(conditions) | JoinRule::KnockRestricted(conditions) =
join_rules
{
match services
.rooms
.membership
.evaluate_join_conditions(
room_id,
JoinConditionEntity::User(&sender),
&conditions,
)
.await
{
| JoinConditionResult::Satisfied => {
// Sign the join to prove that we checked the conditions.
services
.server_keys
.hash_and_sign_event(&mut pdu, room_version_rules)
.map_err(|e| {
err!(Request(InvalidParam(warn!(
"Failed to sign send_join event: {e}"
))))
})?;
},
| JoinConditionResult::Unsatisfied => {
return Err!(Request(Forbidden(
"You do not satisfy this room's join conditions."
)));
},
| JoinConditionResult::UnableToAuthorizeJoin => {
return Err!(Request(UnableToAuthorizeJoin(
"This server cannot check this room's join conditions."
)));
},
}
} else {
// We can't sign this, and if we don't sign it our event will fail
// the auth check, so we have to bail out here.
return Err!(Request(InvalidParam(
"join_authorized_via_users_server was supplied for a room that is not restricted"
if !super::user_can_perform_restricted_join(services, &sender, room_id).await? {
return Err!(Request(UnableToAuthorizeJoin(
"Joining user did not pass restricted room's rules."
)));
}
services
.server_keys
.hash_and_sign_event(&mut pdu, room_version_rules)
.map_err(|e| {
err!(Request(InvalidParam(warn!("Failed to sign send_join event: {e}"))))
})?;
}
let mutex_lock = services
-54
View File
@@ -1,54 +0,0 @@
use axum::extract::State;
use conduwuit::{Err, Result};
use ruma::{
api::federation::event::get_stripped_state, assign, events::ALLOWED_STRIPPED_STATE_EVENTS,
};
use service::rooms::summary::{Accessibility, RoomStrippedState};
use crate::Ruma;
/// # `POST /_matrix/federation/unstable/org.continuwuity.msc4560.stripped_state/{room_id}` ([MSC4560])
///
/// Returns a room's stripped state.
///
/// [MSC4560]: https://github.com/matrix-org/matrix-spec-proposals/pull/4560
pub(crate) async fn get_stripped_state_route(
State(services): State<crate::State>,
body: Ruma<get_stripped_state::unstable::Request>,
) -> Result<get_stripped_state::unstable::Response> {
if let Some(forbidden_type) = body
.state
.iter()
.find(|event_type| !ALLOWED_STRIPPED_STATE_EVENTS.contains(event_type))
{
return Err!(Request(InvalidParam(
"Event type {forbidden_type} may not be requested as stripped state."
)));
}
if services.rooms.metadata.is_banned(&body.room_id).await {
return Err!(Request(Forbidden("This room is banned on this homeserver.")));
}
match services
.rooms
.summary
.get_local_stripped_state_for_server(
&body.identity,
&body.room_id,
&body.state,
body.num_joined_members,
)
.await
{
| Accessibility::Accessible(RoomStrippedState { state, num_joined_members, .. }) => Ok(
assign!(get_stripped_state::unstable::Response::default(), { state, num_joined_members }),
),
| Accessibility::Inaccessible => {
Err!(Request(Forbidden("You may not access this room's stripped state.")))
},
| Accessibility::NotFound => {
Err!(Request(NotFound("This room is not known to this server.")))
},
}
}
+8 -63
View File
@@ -1,10 +1,5 @@
use std::{
collections::BTreeMap,
env,
fmt::Write as FmtWrite,
fs,
io::Write,
path::{Path, PathBuf},
collections::BTreeMap, env, fmt::Write as FmtWrite, fs, io::Write, path::Path,
process::Command,
};
@@ -135,68 +130,18 @@ fn main() {
}
// --- Rerun Triggers ---
let resolve_git_path = |path_str: &str| -> PathBuf {
let p = Path::new(path_str);
if p.is_absolute() {
p.to_path_buf()
} else {
Path::new(&manifest_dir).join(p)
}
};
// If workspace root has a .git file (e.g., git worktree or submodule),
// watch it
let workspace_git = metadata.workspace_root.as_std_path().join(".git");
if workspace_git.is_file() {
println!("cargo:rerun-if-changed={}", workspace_git.display());
}
// Rerun if the git HEAD changes
if let Some(git_head) = run_git_command(&["rev-parse", "--git-path", "HEAD"]) {
let head_path = resolve_git_path(&git_head);
if head_path.exists() {
println!("cargo:rerun-if-changed={}", head_path.display());
}
}
// Rerun if the ref pointed to by HEAD changes (e.g., new commit on branch)
if let Some(ref_name) = run_git_command(&["symbolic-ref", "--quiet", "HEAD"]) {
if let Some(git_ref) = run_git_command(&["rev-parse", "--git-path", &ref_name]) {
let ref_path = resolve_git_path(&git_ref);
if ref_path.exists() {
println!("cargo:rerun-if-changed={}", ref_path.display());
} else {
// If the loose ref file does not exist (e.g. refs are packed),
// watch the nearest existing ancestor directory
// so newly created refs trigger rerun.
let mut dir = ref_path.parent();
while let Some(d) = dir {
if d.exists() {
println!("cargo:rerun-if-changed={}", d.display());
break;
}
dir = d.parent();
}
}
}
}
// If packed-refs exists, watch it so git pack-refs or updates to packed
// refs trigger rerun
if let Some(git_packed) = run_git_command(&["rev-parse", "--git-path", "packed-refs"]) {
let packed_path = resolve_git_path(&git_packed);
if packed_path.exists() {
println!("cargo:rerun-if-changed={}", packed_path.display());
}
}
// TODO: The git rerun triggers seem to always run
// // Rerun if the git HEAD changes
// println!("cargo:rerun-if-changed=.git/HEAD");
// // Rerun if the ref pointed to by HEAD changes (e.g., new commit on
// branch) if let Some(ref_path) = run_git_command(&["symbolic-ref",
// "--quiet", "HEAD"]) { println!("cargo:rerun-if-changed=.git/{ref_path}"
// ); }
println!("cargo:rerun-if-env-changed=GIT_COMMIT_HASH");
println!("cargo:rerun-if-env-changed=GIT_COMMIT_HASH_SHORT");
println!("cargo:rerun-if-env-changed=GIT_REMOTE_URL");
println!("cargo:rerun-if-env-changed=GIT_REMOTE_COMMIT_URL");
println!("cargo:rerun-if-env-changed=CONTINUWUITY_VERSION_EXTRA");
println!("cargo:rerun-if-env-changed=CONDUWUIT_VERSION_EXTRA");
println!("cargo:rerun-if-env-changed=CONDUIT_VERSION_EXTRA");
}
fn generate_features_code(features: &BTreeMap<String, Vec<String>>) -> String {
-9
View File
@@ -353,15 +353,6 @@ pub fn check(config: &Config) -> Result {
}
})?;
for (id, client) in &config.oauth.clients {
if client.scopes.is_empty() {
warn!(
"The static OAuth client `{id}` has no scopes configured. It will not be able \
to access any API endpoints."
);
}
}
Ok(())
}
+9 -67
View File
@@ -24,7 +24,6 @@ use ruma::{
OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, OwnedServerSigningKeyId, OwnedUserId,
RoomVersionId, ServerName,
api::{
OAuthClientScope,
client::{discovery::discover_support::ContactRole, rtc::RtcTransport},
federation::discovery::OldVerifyKey,
},
@@ -66,8 +65,8 @@ use crate::{Result, err, error::Error, utils::sys};
ignore = "config_paths catchall"
)]
pub struct Config {
// Paths to config file(s). Not supposed to be set manually in the config
// file, only updated dynamically from the --config option given at runtime.
// Paths to config file(s). Not supposed to be set manually in the config file,
// only updated dynamically from the --config option given at runtime.
pub config_paths: Option<Vec<PathBuf>>,
/// The server_name is the pretty name of this server. It is used as a
@@ -1121,10 +1120,7 @@ pub struct Config {
/// (trusted key notary servers), as well as serve as trusted servers for
/// other operations like backfill and event fetching.
///
/// Currently, continuwuity doesn't support inbound key requests, so
/// this list should only contain other Synapse servers.
///
/// example: ["matrix.org", "starstruck.systems"]
/// example: ["continuwuity.org", "matrix.org"]
///
/// It is possible to restrict which signing keys trusted servers are
/// allowed to sign responses with. Without configuring this, all responses
@@ -1161,7 +1157,7 @@ pub struct Config {
/// empty list (`[]`) to operate without trusted server assistance, but this
/// is discouraged for performance and reliability reasons.
///
/// default: ["matrix.org"]
/// default: ["continuwuity.org", "continuwuity.rocks", "matrix.org"]
#[serde(default = "default_trusted_servers")]
pub trusted_servers: Vec<TrustedServer>,
@@ -2747,12 +2743,7 @@ pub struct OauthConfig {
compatibility_mode: OAuthMode,
/// display: hidden
#[serde(default)]
pub oidc: Option<OidcConfig>,
/// display: hidden
#[serde(default)]
pub clients: HashMap<String, OAuthClient>,
}
impl OauthConfig {
@@ -2966,54 +2957,6 @@ impl TrustedServerConfig {
}
}
#[derive(Clone, Debug, Deserialize)]
#[config_example_generator(
filename = "conduwuit-example.toml",
section = "global.oauth.clients.\"$id\"",
optional = "true",
subheader = "\
# Use this section to add static OAuth clients for bots and automation.
# Clients added here may use the client credentials OAuth grant to authorize
# themselves with Continuwuity.
#
# Make sure to replace `$id` in the header with your client ID of choice! You can
# add more copies of this section with different IDs to add multiple clients.
#
# Because the client credentials grant authorizes the client as itself, without
# an attached user, clients that use it will not be able to access most of the Matrix
# client-server API. Administrative functionality that does not require a user
# will still be available."
)]
pub struct OAuthClient {
/// The client's client secret.
///
/// This must be supplied as the `client_secret` parameter when requesting
/// an access token with the OAuth 2.0 token endpoint. Continuwuity does
/// not check the `Authorization` header for requests to this endpoint.
pub client_secret: String,
/// A list of scopes that the client may request. Continuwuity allows static
/// clients to request the following scopes:
///
/// - "urn:matrix:client:cc.c10y.msc4484.server_administration" (MSC4484):
/// This scope grants access to the Matrix server administration APIs, as
/// well as Continuwuity's internal admin API (currently a work in
/// progress).
/// - "urn:matrix:client:api:*": This scope grants access to the Matrix
/// client-server API. Most endpoints require an authenticated Matrix user
/// and thus will not be usable by static clients.
///
/// The `urn:matrix:client:device:<id>` scope may not be requested by static
/// clients.
///
/// Scopes listed here are not granted by default. The client must
/// explicitly include them in the `scope` parameter of its access token
/// request.
///
/// default: []
pub scopes: BTreeSet<OAuthClientScope>,
}
const DEPRECATED_KEYS: &[&str] = &[
"cache_capacity",
"conduit_cache_capacity_modifier",
@@ -3278,12 +3221,11 @@ fn default_otlp_filter() -> String {
fn default_tracing_flame_output_path() -> String { "./tracing.folded".to_owned() }
fn default_trusted_servers() -> Vec<TrustedServer> {
// TODO(nex): Once we can be a notary, add maintainer(?) homeservers here.
// Rationale: Users are already running our code, arguably that's a higher
// level of trust than is assigned to notaries in the first place.
// We should still remind everyone that notaries are evil and out to get you
// and to replace this list with servers they actually trust.
let trusted_servers = vec![ruma::owned_server_name!("matrix.org")];
let trusted_servers = vec![
ruma::owned_server_name!("continuwuity.org"),
ruma::owned_server_name!("continuwuity.rocks"),
ruma::owned_server_name!("matrix.org"),
];
trusted_servers
.into_iter()
.map(TrustedServer::Name)
+4 -66
View File
@@ -39,7 +39,7 @@ use crate::{
debug, debug_error, err,
matrix::{Event, StateKey},
trace,
utils::stream::{BroadbandExt, IterStream, ReadyExt, TryWidebandExt, WidebandExt},
utils::stream::{BroadbandExt, IterStream, ReadyExt, TryBroadbandExt, WidebandExt},
warn,
};
@@ -590,8 +590,8 @@ where
.find(|aev| is_type_and_key(*aev, &TimelineEventType::RoomPowerLevels, ""));
let content: PowerLevelsContentFields = match pl {
// With no m.room.power_levels in scope the create event's defaults
// apply, under which the room creator holds 100 and everyone else 0.
// With no m.room.power_levels in scope the create event's defaults apply,
// under which the room creator holds 100 and everyone else 0.
| None => return Ok(if sender_is_creator { int!(100) } else { int!(0) }),
| Some(ev) => from_json_str(ev.content().get())?,
};
@@ -706,7 +706,7 @@ where
let events_to_check: Vec<_> = events_to_check
.map(Result::Ok)
.wide_and_then(async |event_id| {
.broad_and_then(async |event_id| {
fetch_event(event_id.to_owned())
.await
.ok_or_else(|| Error::NotFound(format!("Failed to find {event_id}")))
@@ -1123,68 +1123,6 @@ mod tests {
utils::stream::IterStream,
};
#[tokio::test]
async fn iterative_auth_check_keeps_event_order() {
let mut events = INITIAL_EVENTS();
let initial_state = ["CREATE", "IPOWER", "IJR", "IMB"]
.into_iter()
.map(|id| {
let event = &events[&event_id(id)];
(
event
.event_type()
.with_state_key(event.state_key().unwrap()),
event.event_id.clone(),
)
})
.collect();
let leave = to_pdu_event(
"LEAVE",
bob(),
TimelineEventType::RoomMember,
Some(bob().as_str()),
to_raw_json_value(&json!({ "membership": "leave" })).unwrap(),
&["CREATE", "IPOWER", "IMB"],
&["IMB"],
);
let rejoin = to_pdu_event(
"REJOIN",
bob(),
TimelineEventType::RoomMember,
Some(bob().as_str()),
member_content_join(),
&["CREATE", "IPOWER", "IJR", "LEAVE"],
&["LEAVE"],
);
let ordered_events = [leave.event_id.clone(), rejoin.event_id.clone()];
for event in [leave, rejoin] {
events.insert(event.event_id.clone(), event);
}
let fetcher = |id: OwnedEventId| {
let events = &events;
async move {
// Let the rejoin fetch finish before the leave.
if id == event_id("LEAVE") {
tokio::task::yield_now().await;
}
events.get(&id).cloned()
}
};
let resolved = super::iterative_auth_check(
&RoomVersionRules::V6,
ordered_events.iter().map(AsRef::as_ref).stream(),
initial_state,
&fetcher,
)
.await
.unwrap();
assert_eq!(
resolved[&StateEventType::RoomMember.with_state_key(bob().as_str())],
event_id("REJOIN"),
);
}
/// Events at the start of a room have no `m.room.power_levels` in their
/// auth events, so the sender's power for sort ordering comes from the
/// create event instead.
-2
View File
@@ -50,7 +50,5 @@ pub fn unstable_features() -> BTreeMap<String, bool> {
("uk.timedout.msc4494".to_owned(), true),
// server administration OAuth scope (https://github.com/matrix-org/matrix-spec-proposals/pull/4484)
("org.continuwuity.msc4484.unstable".to_owned(), true),
// stripped state over federation (https://github.com/matrix-org/matrix-spec-proposals/pull/4560)
("org.continuwuity.msc4560".to_owned(), true),
])
}
+3 -4
View File
@@ -14,8 +14,6 @@ use tokio_metrics::TaskMonitor;
use tokio_metrics::{RuntimeIntervals, RuntimeMonitor};
pub use self::instruments::{Instruments, duration_buckets};
#[cfg(tokio_unstable)]
use crate::SyncMutex;
use crate::{Err, Result};
pub struct Metrics {
@@ -29,7 +27,7 @@ pub struct Metrics {
_runtime_monitor: Option<RuntimeMonitor>,
#[cfg(tokio_unstable)]
runtime_intervals: SyncMutex<Option<RuntimeIntervals>>,
runtime_intervals: std::sync::Mutex<Option<RuntimeIntervals>>,
// TODO: move stats
pub requests_handle_active: AtomicU32,
@@ -71,7 +69,7 @@ impl Metrics {
_runtime_monitor: runtime_monitor,
#[cfg(tokio_unstable)]
runtime_intervals: SyncMutex::new(runtime_intervals),
runtime_intervals: std::sync::Mutex::new(runtime_intervals),
requests_handle_active: AtomicU32::new(0),
requests_handle_finished: AtomicU32::new(0),
@@ -83,6 +81,7 @@ impl Metrics {
pub fn runtime_interval(&self) -> Option<tokio_metrics::RuntimeMetrics> {
self.runtime_intervals
.lock()
.expect("locked")
.as_mut()
.map(Iterator::next)
.expect("next interval")
+1 -4
View File
@@ -36,10 +36,7 @@ pub use config::Config;
pub use error::Error;
pub use info::version::*;
pub use matrix::{Event, EventTypeExt, Pdu, PduCount, PduEvent, PduId, pdu, state_res};
pub use parking_lot::{
Mutex as SyncMutex, RwLock as SyncRwLock, RwLockReadGuard as SyncRwLockReadGuard,
RwLockWriteGuard as SyncRwLockWriteGuard,
};
pub use parking_lot::{Mutex as SyncMutex, RwLock as SyncRwLock};
pub use server::Server;
pub use utils::{result, result::Result};
+1 -1
View File
@@ -171,7 +171,7 @@ pub(super) static MAPS: &[Descriptor] = &[
},
Descriptor {
name: "referencedevents",
..descriptor::DROPPED
..descriptor::RANDOM
},
Descriptor {
name: "refreshtoken_refreshtokeninfo",
+2 -5
View File
@@ -69,7 +69,7 @@ pub(crate) async fn run(server: &Arc<Server>, starts: bool) -> Result<(bool, boo
let reloads = server.server.reloading.swap(false, Ordering::AcqRel);
let stops = !reloads || stale_from_mods(&main_lock)? <= restart_thresh();
let stops = !reloads || stale(server).await? <= restart_thresh();
let starts = reloads && stops;
if stops {
let stop = main_mod.get::<StopFuncProto>("stop")?;
@@ -140,10 +140,7 @@ async fn stale_count(server: &Arc<Server>) -> usize {
async fn stale(server: &Arc<Server>) -> Result<usize, Error> {
let mods_lock = server.mods.read().await;
stale_from_mods(&mods_lock)
}
fn stale_from_mods(mods: &[mods::Module]) -> Result<usize, Error> {
let mods: &Vec<mods::Module> = &mods_lock;
for (i, module) in mods.iter().enumerate() {
if module.deleted()? {
return Ok(i);
+24 -16
View File
@@ -1,12 +1,19 @@
#![cfg(feature = "sentry_telemetry")]
use std::{borrow::Cow, sync::OnceLock};
use std::{
borrow::Cow,
str::FromStr,
sync::{Arc, OnceLock},
};
use conduwuit_build_metadata as build;
use conduwuit_core::{config::Config, debug, trace};
use sentry::{
Breadcrumb, ClientOptions, Level,
types::protocol::v7::{Context, Event},
types::{
Dsn,
protocol::v7::{Context, Event},
},
};
static SEND_PANIC: OnceLock<bool> = OnceLock::new();
@@ -30,21 +37,22 @@ fn options(config: &Config) -> ClientOptions {
.expect("init_sentry should only be called if sentry is enabled and this is not None")
.as_str();
let options = ClientOptions::new()
.dsn(dsn)
.traces_sample_rate(config.sentry_traces_sample_rate)
.debug(cfg!(debug_assertions))
.maybe_release(release_name())
.user_agent(conduwuit_core::user_agent())
.attach_stacktrace(config.sentry_attach_stacktrace)
.before_send(before_send)
.before_breadcrumb(before_breadcrumb);
config
let server_name = config
.sentry_send_server_name
.then(|| config.server_name.to_string())
.into_iter()
.fold(options, ClientOptions::server_name)
.then(|| config.server_name.to_string().into());
ClientOptions {
dsn: Some(Dsn::from_str(dsn).expect("sentry_endpoint must be a valid URL")),
server_name,
traces_sample_rate: config.sentry_traces_sample_rate,
debug: cfg!(debug_assertions),
release: release_name(),
user_agent: conduwuit_core::user_agent().into(),
attach_stacktrace: config.sentry_attach_stacktrace,
before_send: Some(Arc::new(before_send)),
before_breadcrumb: Some(Arc::new(before_breadcrumb)),
..Default::default()
}
}
fn before_send(event: Event<'static>) -> Option<Event<'static>> {
+2 -2
View File
@@ -25,7 +25,7 @@ pub(crate) async fn run(services: Arc<Services>) -> Result<()> {
debug!("Start");
// Install the admin room callback here for now
admin::init(&services.admin);
admin::init(&services.admin).await;
// Setup shutdown/signal handling
let handle = ServerHandle::new();
@@ -60,7 +60,7 @@ pub(crate) async fn run(services: Arc<Services>) -> Result<()> {
_ = sigs.await;
// Remove the admin room callback
admin::fini(&services.admin);
admin::fini(&services.admin).await;
debug_info!("Finish");
res
+1
View File
@@ -0,0 +1 @@
pub mod notary;
+58
View File
@@ -0,0 +1,58 @@
//! `POST /_matrix/key/*/query`
//!
//! Endpoint to query signing keys through other (notary) servers.
pub mod unstable {
use std::collections::BTreeMap;
use ruma::{
OwnedServerName, OwnedServerSigningKeyId,
api::{
federation::{
authentication::ServerSignatures,
discovery::{ServerSigningKeys, get_remote_server_keys_batch::v2::QueryCriteria},
},
request, response,
},
metadata,
serde::Raw,
};
metadata! {
method: POST,
rate_limited: true,
authentication: ServerSignatures,
history: {
unstable("org.continuwuity.msc4553") => "/_matrix/key/unstable/org.continuwuity.msc4556/query",
}
}
#[request]
pub struct Request {
pub server_keys:
BTreeMap<OwnedServerName, BTreeMap<OwnedServerSigningKeyId, QueryCriteria>>,
}
#[response]
pub struct Response {
pub server_keys: Vec<Raw<ServerSigningKeys>>,
}
impl Request {
#[must_use]
pub fn new(
server_keys: BTreeMap<
OwnedServerName,
BTreeMap<OwnedServerSigningKeyId, QueryCriteria>,
>,
) -> Self {
Self { server_keys }
}
}
impl Response {
/// Creates a new `Response` with the given keys.
#[must_use]
pub fn new(server_keys: Vec<Raw<ServerSigningKeys>>) -> Self { Self { server_keys } }
}
}
Loaded 100 of 151 files, more files were not shown because too many files have changed in this diff. Show more