Compare commits

...
Author SHA1 Message Date
Ginger fe8314bb4d chore: Fix typo 2026-11-05 10:35:18 -05:00
Ginger 4922e5da01 feat: Add support for OAuth client credentials grant 2026-11-05 10:35:17 -05:00
Erwan Leboucher 8c720e5427 fix: Store to-device messages before syncs can read their count 2026-11-05 15:17:36 +00:00
Erwan Leboucher fb389cb6f9 fix: Record device list changes before syncs can read their count
Signed-off-by: Erwan Leboucher <erwanleboucher@gmail.com>
2026-11-05 15:17:23 +00:00
Bardi Harborow db86d42801 fix: Compare push user_is_target against the notified user
`user_is_target` was set by comparing a member event's `state_key` to its
sender, rather than to the user receiving the notification.
2026-11-05 15:27:50 +11:00
Bardi Harborow 223e889459 fix: Return 405 when setting m.fully_read via account data
The spec requires servers to reject client writes to server-managed
account data types with 405 M_BAD_JSON. We returned 400.
2026-11-04 19:32:17 +00:00
Bardi Harborow 219e8d2e1e fix: Return M_UNKNOWN_DEVICE for unknown masqueraded appservice devices
When an appservice masqueraded as a device_id that does not exist for
the user, we returned 403 M_FORBIDDEN. The spec requires 400
M_UNKNOWN_DEVICE.
2026-11-04 19:32:17 +00:00
Bardi Harborow 4d0ccd998f fix: Return M_PROFILE_TOO_LARGE for oversize profiles
Profile updates that would push the profile over 64 KiB were rejected
with an untyped error, producing a 500. The spec requires 400
M_PROFILE_TOO_LARGE, which ruma now provides.
2026-11-04 19:32:17 +00:00
Bardi Harborow 42609eab02 fix: Return M_KEY_TOO_LARGE for oversize profile keys
Profile keys longer than 255 bytes were rejected with 413 M_TOO_LARGE.
The spec requires 400 M_KEY_TOO_LARGE, which ruma now provides.
2026-11-04 19:32:17 +00:00
Bardi Harborow dad9e1426c fix: Advertise m.forget_forced_upon_leave capability according to config 2026-11-04 18:48:40 +00:00
Ginger 34c5787af0 fix: Fix join rule evaluation for servers again
Reviewed-by: timedout <git@nexy7574.co.uk>
Reviewed-by: Jade Ellis <jade@ellis.link>
2026-11-04 12:24:51 -05:00
Renovate Bot d2eeae34a9 chore(deps): update ghcr.io/renovatebot/renovate docker tag to v44.210.1 2026-11-04 05:01:50 +00:00
Ginger 2ee28c1b82 fix: Fix busted axum feature list 2026-11-03 20:48:58 -05:00
Ginger c77bbf6d18 fix: Fix busted url_preview feature gate 2026-11-03 20:41:11 -05:00
Erwan Leboucher 0727d564a2 fix: Avoid v12 room ID collisions when creating rooms concurrently
Fixes #2424. v12 rooms created by the same user in the same millisecond got the same room ID, so they ended up as one room.

Reviewed-on: https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2433
Reviewed-by: nex <me@nexy7574.co.uk>
Reviewed-by: Jade Ellis <jade@ellis.link>
2026-11-03 09:52:43 +00:00
Renovate Bot 0e5baa9399 chore(deps): update https://github.com/taiki-e/install-action digest to 682ce6c 2026-11-03 05:03:31 +00:00
Ginger d8229a7933 fix(ci): Use local versions of workflows hosted on tomfos.tr 2026-11-02 14:03:52 -05:00
Renovate Bot ddbdd1ed0c chore(deps): update ruma digest to 0ed7fba 2026-11-02 05:36:01 +00:00
timedout f3d8e8d688 chore: Reformat 2026-11-02 00:50:41 +00:00
Ginger 5a4f3acae4 chore: Changelog 2026-11-02 00:44:02 +00:00
Ginger dc03f2136a fix: Validate OAuth HTTPS redirect URIs are subdomains of the client domain 2026-11-02 00:44:02 +00:00
Erwan Leboucher abf8f878bc fix: gap fill outliers that are missing prev events
Signed-off-by: Erwan Leboucher <erwanleboucher@gmail.com>
2026-10-31 09:02:27 +01:00
timedout cb27a2082d chore: Add newsfrag 2026-10-30 00:56:10 +00:00
timedout 068ba88378 style: Fix formatting 2026-10-30 00:54:52 +00:00
timedout 60de549cf9 perf: Write empty rows when replacing extremities 2026-10-30 00:51:52 +00:00
timedout 363097b31b fix: Centralise extremity progression 2026-10-30 00:51:52 +00:00
timedout d128207d71 fix: Make the extremity check consistency migration faster 2026-10-30 00:51:51 +00:00
timedout c6832372c2 feat: Add command to enumerate extremities 2026-10-30 00:51:51 +00:00
timedout 14f5f62182 fix: Only consider accepted PDUs in extremity consistency check 2026-10-30 00:51:51 +00:00
timedout 5208efcb5e fix: Make migration handle excessive extremities too 2026-10-30 00:51:51 +00:00
timedout 224cf04936 fix: Never allow unknown/backfilled PDUs to become extremities 2026-10-30 00:51:51 +00:00
timedout ae26d5c239 fix: Add startup migration to re-process existing extremities on-disk 2026-10-30 00:51:51 +00:00
timedout 30f62eef25 style: reformat 2026-10-30 00:51:51 +00:00
timedout b04ffd7e6a fix: Correctly remove extremities after creating a new event 2026-10-30 00:51:51 +00:00
timedout bc15b7b668 fix: Remove dead references to mark_event_referenced 2026-10-30 00:51:50 +00:00
timedout 3eb2788eb9 feat: Only track appended extremities 2026-10-30 00:51:47 +00:00
timedout 3b0fc25cd3 chore: Add newsfrag 2026-10-30 00:43:55 +00:00
timedout b580379a2d fix: Only check that room_id is not present on create events in PDU check 1 2026-10-30 00:43:55 +00:00
timedout 3c19206534 fix: Perform PDU checks 1, 2, and 3 before yielding a gapfilled PDU
Fixes #2386
2026-10-30 00:43:55 +00:00
Renovate Bot 7358712fb9 chore(deps): update rust crate tower-sec-fetch to 0.2.0 2026-10-29 13:40:37 +00:00
Renovate Bot 18bd828b8b chore(deps): update rust crate tokio to v1.53.3 [security] 2026-10-29 09:06:20 +00:00
Julian Anderson 4c62b96821 chore: Bump sentry and update config to required builder pattern 2026-10-29 09:05:13 +00:00
stratself a6b8bfe2c9 chore: Add changelog for 2324 2026-10-28 23:33:22 +00:00
stratself 028ffabebf docs(troubleshooting,perf): Simplify trusted servers wordings 2026-10-28 23:33:22 +00:00
stratself b70131c301 docs(troubleshooting): Improve wordings a little bit 2026-10-28 23:33:22 +00:00
stratself d4bfb38bd5 docs(troubleshooting): Update complex debug log filters 2026-10-28 23:33:22 +00:00
stratself d4ae9f9ac1 docs(troubleshooting): Add redirs to other troubleshooting topics in other pages 2026-10-28 23:33:22 +00:00
stratself 1247cf1c80 docs(livekit): Shorten redundant docker loopback section 2026-10-28 23:33:22 +00:00
stratself 0d9bb6ba7c docs(troubleshooting): Add networking issues for docker 2026-10-28 23:33:22 +00:00
stratself e769ceb147 docs(troubleshooting): Initialize docker troubleshooting section 2026-10-28 23:33:22 +00:00
stratself 206aaf6893 fix: Newline 2026-10-28 23:23:59 +00:00
stratself b07093c7ab chore: Add changelog for #2353 2026-10-28 23:23:59 +00:00
stratself 5c3bc643d2 docs(docker): Add backup/restore instructions 2026-10-28 23:23:59 +00:00
stratself c5f28c8276 docs(docker): Document volumes usage in Appendix section 2026-10-28 23:23:59 +00:00
stratself 17d575c3e3 docs(docker): Use bind mounts instead of docker volumes
Old volumes of `db` are replaced with bind mounts of `continuwuity-data`.
Other volumes are also converted. This is more beginner-friendly.
2026-10-28 23:23:59 +00:00
Erwan Leboucher 2604b13ef6 chore: Add changelog 2026-10-28 23:22:52 +00:00
Erwan Leboucher c5e976f4bc fix: Store event_id on state events received from send_knock 2026-10-28 23:22:52 +00:00
Renovate Bot a825b7db8b chore(deps): update ruma digest to e03080c 2026-10-28 23:20:41 +00:00
Renovate Bot bdb376c8fd chore(deps): update rust crate lock_api to 0.5.0 2026-10-28 23:20:31 +00:00
Freek a96fec4cbc chore: Add changelog 2026-10-28 22:50:03 +00:00
Freek ea5d2f4d4c fix: spelling 2026-10-28 22:50:03 +00:00
stratself f2cf1b2331 docs(oidc): Sweepfixes for PR2341
* Replaces yourdomain.com with example.com (other pages use this)
* Improve initial domain instructions, remove important block there
* Capitalize "Bare Metal/Docker" tabs
2026-10-28 22:50:03 +00:00
Freek 1c82c57d9f docs(oidc): PR feedback 2026-10-28 22:50:03 +00:00
Freek c6d220dc60 docs(oidc): Styling and QoL fixes 2026-10-28 22:50:03 +00:00
Freek 0adfd32b0c docs(oidc): Simplify, deduplicate and improve consistency 2026-10-28 22:50:03 +00:00
Freek 4cd0e737db docs(oidc): PR feedback: Use tabs for different identity providers, make "Configuring Continuwuity" section more idp-independent 2026-10-28 22:50:03 +00:00
Freek e8593eeaca docs(oidc): Add Authelia to OIDC instructions 2026-10-28 22:50:03 +00:00
Jade Ellis 6fae2475b8 style: Format 2026-10-28 21:56:38 +00:00
Jade Ellis 0ceabb4b3e chore: Changelog 2026-10-28 21:49:26 +00:00
Jade Ellis addd1875d3 refactor(uiaa): Defer uiaa_sessions lock until session insert
Do not hold the uiaa_sessions lock across device lookup in OAuth or
during initial validation. Lock the map only when inserting the newly
created session.
2026-10-28 21:48:55 +00:00
Jade Ellis 24b1e2ebe8 refactor(service): Use SyncRwLock and SyncMutex for in-memory services
Convert in-memory data structures in appservice, rooms::typing, and sync
wakers to use SyncRwLock and SyncMutex. Drop appservice locks before
making outbound network requests in room alias queries and federation
invites.
2026-10-28 21:48:22 +00:00
Jade Ellis 5297e01357 refactor(metrics): Replace std::sync::Mutex with SyncMutex
Replace std::sync::Mutex with parking_lot::Mutex (SyncMutex) in
core::metrics::runtime_intervals. Note that info::introspection retains
std::sync::Mutex because parking_lot panics in dtor after thread locals
are destroyed.
2026-10-28 21:47:41 +00:00
Jade Ellis 18f5f4fbfa refactor(threepid): Use SyncMutex and decouple guard from ValidSession
Change threepid sessions and send_attempts to SyncMutex and avoid

holding the sessions mutex across callers of get_valid_session.
2026-10-28 21:47:09 +00:00
Jade Ellis 98ae1fcaa1 refactor(oauth): Avoid holding pending grants lock across async calls
Convert pending grants and tickets to SyncMutex and scope locks tightly

before awaiting external calls in grant_info and redeem_token.
2026-10-28 21:46:29 +00:00
Jade Ellis ad0181a3d8 refactor(service): Scope services.manager lock during lifecycle calls
Avoid holding the services.manager lock across manager.start(),

manager.stop(), and manager.poll() async invocations.
2026-10-28 21:45:49 +00:00
Jade Ellis 938b3d2825 refactor(admin): Release handle lock before command execution
Change admin service handle to SyncRwLock and copy the handler

function pointer before awaiting execution to prevent deadlock.
2026-10-28 21:45:18 +00:00
Jade Ellis 35d606eeb7 fix(main): Prevent re-entrant read lock deadlock during reload
Reuse the already-held main_lock when checking module staleness

in run() instead of re-acquiring server.mods.read().
2026-10-28 21:44:35 +00:00
Jade Ellis 9c4f84940e fix(service): Prevent remote join lock inversion
Do not hold state.mutex across join_remote_room to prevent an ABBA

deadlock against mutex_federation.
2026-10-28 21:44:02 +00:00
Renovate Bot 2badf2dfe9 chore(deps): update dependency node to v26 2026-10-28 16:57:00 +00:00
Renovate Bot 2b18fa12bf chore(deps): update ghcr.io/renovatebot/renovate docker tag to v44.190.1 2026-10-28 05:17:21 +00:00
Jade 747a612fd1 docs: Update funding yaml 2026-10-27 11:01:46 +00:00
Renovate Bot be5c94074c chore(deps): update github-actions-digest 2026-10-27 05:19:19 +00:00
Renovate Bot 8fff8f66d3 chore(deps): update ghcr.io/renovatebot/renovate docker tag to v44.181.10 2026-10-26 05:01:31 +00:00
Ginger 81c62c4a35 fix: Silence tower_sessions warning 2026-10-25 13:47:36 -04:00
Ginger b848aed1bb chore: Update git-blame-ignore-revs 2026-10-25 13:33:31 -04:00
Ginger 3295427af6 fix: Don't check room summary access rules on remote rooms 2026-10-25 14:00:28 +00:00
Renovate Bot ffef3911e7 chore(deps): update rust crate loole to 0.6.0 2026-10-25 08:09:43 +00:00
Renovate Bot 263ccd6b0b chore(deps): update rust-zerover-patch-updates 2026-10-25 08:08:31 +00:00
Renovate Bot 0ad4fc1c25 chore(deps): update dependency cargo-bins/cargo-binstall to v1.26.1 2026-10-25 08:00:13 +00:00
Renovate Bot a13a50836b chore(deps): update rust-non-major 2026-10-25 05:19:08 +00:00
Ginger ef1378509e fix: Remove deactivate link from account page 2026-10-24 15:14:01 -04:00
timedout 9c27441acf style: Reformat with nightly 2026-10-23 23:37:51 +02:00
Erwan Leboucher c5b70958cf fix: preserve event order during state resolution
Signed-off-by: Erwan Leboucher <erwanleboucher@gmail.com>
2026-10-23 23:19:45 +02:00
Filip Kszczot 3b2afe03ac docs(deploying/generic): add haproxy host header quirk
Signed-off-by: Filip Kszczot <filip@kszczot.pl>
2026-10-23 18:13:13 +00:00
Ginger 4a20fd62a9 chore: News fragment 2026-10-21 18:29:30 -04:00
Ginger 783a68cc90 fix: Add link to the account management panel to the first run web UI 2026-10-21 18:27:42 -04:00
Renovate Bot 2f93711a09 chore(deps): update https://github.com/taiki-e/install-action digest to 8cca091 2026-10-20 05:17:52 +00:00
Renovate Bot d72a27b249 chore(deps): update ghcr.io/renovatebot/renovate docker tag to v44.167.5 2026-10-19 05:19:59 +00:00
timedout b0a5caf576 perf: Fetch auth chain events in parallel 2026-10-16 18:32:38 +01:00
timedout 17ddd3966d fix: Apply proper limits to get_missing_events 2026-10-16 18:19:22 +01:00
timedout fe02b03d15 style: Stop warning when encountering an unknown event in get_missing_events
This is actually an expected condition, but it's retained as a debug warning as it may be relevant in debugging
2026-10-16 18:11:55 +01:00
129 changed files with 1737 additions and 1169 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@dbcb813823bdd20940b903addbd779551569679f # v4
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # 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@dbcb813823bdd20940b903addbd779551569679f # v4
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # 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://git.tomfos.tr/tom/sccache-action@v1
uses: https://forgejo.ellis.link/continuwuation/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://git.tomfos.tr/actions/detect-versions@v1
uses: https://forgejo.ellis.link/continuwuation/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://git.tomfos.tr/actions/detect-versions@v1
uses: https://forgejo.ellis.link/continuwuation/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://git.tomfos.tr/tom/sccache-action@v1
uses: https://forgejo.ellis.link/continuwuation/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@1168f6810a3cb30a3514bf5756a3b7f0422c6df8 # v2
uses: https://github.com/taiki-e/install-action@682ce6c3c696a4cd5168a05f98e51aa02b877941 # 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://git.tomfos.tr/tom/sccache-action@v1
uses: https://forgejo.ellis.link/continuwuation/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://git.tomfos.tr/actions/detect-versions@v1
uses: https://forgejo.ellis.link/continuwuation/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: 24
node-version: 26
- 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.151.2@sha256:29b3bf193f855c6f4b7027395a9c66c3417ad8bb6f30458090e1c2363d04eef7
image: ghcr.io/renovatebot/renovate:44.210.1@sha256:45cc73346c44a9afe037f2d19766f2b545b59b2ed31b937b5b09017d2958e45f
options: --tmpfs /tmp:exec
steps:
- name: Checkout
+2 -1
View File
@@ -7,6 +7,7 @@ f419c64aca300a338096b4e0db4c73ace54f23d0
5998a0d883d31b866f7c8c46433a8857eae51a89
# trailing whitespace and newlines
46c193e74b2ce86c48ce802333a0aabce37fd6e9
# rustfmt update that rewrapped tons of comments
# rustfmt updates that rewrapped tons of comments
9fbabe221051e6956a05d8824142092ede68971e
b0c0905472b882ff0cc79232e73d307fd0b5035b
9c27441acf2e65f85c106ccff5c6b6c37030ddca
+1
View File
@@ -1,3 +1,4 @@
open_collective: continuwuity
github: [JadedBlueEyes, timedoutuk, gingershaped]
custom:
- https://timedout.uk/donate.html
Generated
+191 -210
View File
File diff suppressed because it is too large. Load diff
+7 -6
View File
@@ -104,6 +104,7 @@ version = "0.8.8"
default-features = false
features = [
"form",
"query",
"http1",
"http2",
"json",
@@ -330,7 +331,7 @@ version = "2.1.1"
# used for MPSC channels
[workspace.dependencies.loole]
version = "0.4.0"
version = "0.6.0"
# used for MPMC channels
[workspace.dependencies.async-channel]
@@ -348,7 +349,7 @@ version = "1.1.1"
# Used for matrix spec type definitions and helpers
[workspace.dependencies.ruma]
git = "https://github.com/ruma/ruma.git"
rev = "62659d64f712adf3cad126df6b8969f785414bd5"
rev = "0ed7fba34213f18a628a56f527c6cc795cd7eef5"
features = [
"appservice-api-c",
"client-api",
@@ -453,7 +454,7 @@ features = ["http", "grpc-tonic", "trace", "logs", "metrics"]
# optional sentry metrics for crash/panic reporting
[workspace.dependencies.sentry]
version = "0.48.0"
version = "0.49.0"
default-features = false
features = [
"backtrace",
@@ -468,9 +469,9 @@ features = [
]
[workspace.dependencies.sentry-tracing]
version = "0.48.0"
version = "0.49.0"
[workspace.dependencies.sentry-tower]
version = "0.48.0"
version = "0.49.0"
# jemalloc usage
[workspace.dependencies.tikv-jemalloc-sys]
@@ -544,7 +545,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.4.13"
version = "0.5.0"
[workspace.dependencies.bytesize]
version = "2.0"
+1
View File
@@ -0,0 +1 @@
The first-run version of the web UI now includes a link to the registration page. Contributed by @ginger
+1
View File
@@ -0,0 +1 @@
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
@@ -0,0 +1 @@
Room summary visibility checks are no longer incorrectly applied for remote rooms. Contributed by @ginger.
@@ -0,0 +1 @@
Fix new devices sometimes never reaching other users' device lists. Contributed by @eleboucher.
@@ -0,0 +1 @@
Fix gap filling skipping outlier events that are missing their previous events. Contributed by @eleboucher.
@@ -0,0 +1 @@
Fix state resolution applying events out of order, which could undo room joins. Contributed by @eleboucher.
@@ -0,0 +1 @@
Fix to-device messages, including room keys, sometimes being lost before delivery. Contributed by @eleboucher.
+1
View File
@@ -0,0 +1 @@
Add a section on [troubleshooting Docker issues](https://continuwuity.org/troubleshooting#docker-issues). Contributed by @stratself.
+1
View File
@@ -0,0 +1 @@
Instructions for Authelia added to the [OIDC guide](https://continuwuity.org/authentication/oidc.html). Contributed by @fhoekstra
+1
View File
@@ -0,0 +1 @@
Fix some possible deadlocks/freezes and reduce lock contention (improving performance). Contributed by @Jade
+1
View File
@@ -0,0 +1 @@
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
@@ -0,0 +1 @@
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
@@ -0,0 +1 @@
The OAuth identity reset page is no longer linked from the account management UI to reduce confusion. Contributed by @ginger.
+1
View File
@@ -0,0 +1 @@
Fixed a worker panic when knocking on a room over federation. Contributed by @eleboucher.
+1
View File
@@ -0,0 +1 @@
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
@@ -0,0 +1 @@
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
@@ -0,0 +1 @@
Updated internal Sentry integration setup to the new pattern required by the SDK.
+1
View File
@@ -0,0 +1 @@
Fix v12 rooms created by the same user in the same millisecond ending up as the same room. Contributed by @eleboucher.
+1
View File
@@ -0,0 +1 @@
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
@@ -0,0 +1 @@
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
@@ -0,0 +1 @@
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
@@ -0,0 +1 @@
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
@@ -0,0 +1 @@
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
@@ -0,0 +1 @@
Fixed push notifications for membership events setting `user_is_target` based on the sender rather than the user being notified.
+42
View File
@@ -2680,3 +2680,45 @@
#
# 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.25.3
ENV BINSTALL_VERSION=1.26.1
# 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.25.3
ENV BINSTALL_VERSION=1.26.1
# renovate: datasource=github-releases depName=psastras/sbom-rs
ENV CARGO_SBOM_VERSION=0.9.1
# renovate: datasource=crate depName=lddtree
+74 -18
View File
@@ -1,3 +1,5 @@
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.
@@ -12,56 +14,110 @@ 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 use [**Kanidm**][kanidm] as an example, but the described steps are broadly applicable to other identity providers. Contributions for them are welcome.
This guide will cover [**Kanidm**][kanidm] and [**Authelia**][authelia], but the basic concepts apply to most identity providers. Contributions for them are welcome.
First, create a new application for Continuwuity in your identity provider.
<Tabs groupId="idp">
<Tab label="KanIDM">
Create a new application for continuwuity in kanidm. We will use `c10y` as the client ID.
```sh
# 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
kanidm system oauth2 create c10y Continuwuity https://matrix.example.com
```
Configure the redirect URL that Continuwuity uses.
```sh
kanidm system oauth2 add-redirect-url c10y https://matrix.yourdomain.com/_continuwuity/oidc/complete
kanidm system oauth2 add-redirect-url c10y https://matrix.example.com/_continuwuity/oidc/complete
```
Allow Continuwuity to request the `openid` scope. Other identity providers may not require this step.
Allow Continuwuity to request the `openid` scope.
```sh
kanidm system oauth2 update-scope-map c10y idm_all_persons openid
```
Find the client secret that was generated. Other identity providers may show this information in their web UI.
Find the client secret that was generated.
```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. 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.
Configure Continuwuity with the client ID, client secret, and discovery URL provided from the steps above.
```toml
[global.oauth.oidc]
# `/.well-known/openid-configuration` will be appended automatically
discovery_url = "https://idm.example.com/oauth2/openid/c10y"
discovery_url = "https://your-discovery-url"
# 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"
client_id = "your-client-id"
client_secret = "your-client-secret"
```
### Testing that it works
+2 -21
View File
@@ -303,33 +303,14 @@ For browser-based clients, you can also inspect connections using DevTools' Netw
### Docker loopback networking issues
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:
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:
```bash
docker run --rm --net container:lk-jwt-service docker.io/curlimages/curl https://livekit.example.com
# --- some errors ---
```
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
To resolve this, follow the steps in [Docker loopback networking issues](../troubleshooting.mdx#docker-loopback-networking-issues) of the Troubleshooting page.
### Incorrect IP address for LiveKit
+58 -17
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 volume mount.
- `CONTINUWUITY_DATABASE_PATH` - Where to store your database. This must match the docker bind 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,7 +89,9 @@ 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 Caddyfile with the following content:
Create a directory called `caddy-data`, which will store TLS certs obtained by Caddy.
Then, create a Caddyfile with the following content:
```
https://example.com:443, https://example.com:8448 {
@@ -97,7 +99,7 @@ https://example.com:443, https://example.com:8448 {
}
```
Then, for the docker-compose:
Then, for the docker compose file:
```yaml file="../public/deploying/docker-compose.with-caddy.yml"
@@ -110,6 +112,10 @@ Then, for the docker-compose:
<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"
```
@@ -132,6 +138,10 @@ Then, for the docker-compose:
<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"
```
@@ -164,10 +174,15 @@ See the [Other reverse proxies](generic.mdx#setting-up-the-reverse-proxy) sectio
### Starting Your Server
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:
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:
```bash
docker compose up -d
@@ -189,9 +204,7 @@ 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 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.
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).
## Testing
@@ -199,7 +212,9 @@ 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.
## Updating
## Maintenance
### Updating
To update to a new version of Continuwuity, use the following commands:
@@ -212,6 +227,10 @@ 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.
@@ -270,12 +289,6 @@ 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.
@@ -297,3 +310,31 @@ 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,6 +199,11 @@ 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
:::info Vet your trusted servers!
:::important Important: 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` has helped 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` helps 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:
- db:/var/lib/continuwuity
- ./continuwuity-data:/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
- ./data:/data
- ./caddy-data:/data
restart: unless-stopped
labels:
caddy: example.com
@@ -23,7 +23,7 @@ services:
restart: unless-stopped
command: /sbin/conduwuit
volumes:
- db:/var/lib/continuwuity
- ./continuwuity-data:/var/lib/continuwuity
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
# - ./continuwuity.toml:/etc/continuwuity.toml
environment:
@@ -46,8 +46,5 @@ services:
caddy: matrix.example.com
caddy.reverse_proxy: "{{upstreams 8008}}"
volumes:
db:
networks:
proxy:
@@ -9,7 +9,7 @@ services:
networks:
- caddy
volumes:
- ./data:/data
- ./caddy-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:
- db:/var/lib/continuwuity
- ./continuwuity-data:/var/lib/continuwuity
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
# - ./continuwuity.toml:/etc/continuwuity.toml
environment:
@@ -41,6 +41,3 @@ services:
networks:
proxy:
volumes:
db:
@@ -6,7 +6,7 @@ services:
restart: unless-stopped
command: /sbin/conduwuit
volumes:
- db:/var/lib/continuwuity
- ./continuwuity-data:/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"
- "acme:/etc/traefik/acme"
- "./traefik-acme-data:/etc/traefik/acme"
labels:
- "traefik.enable=true"
@@ -77,9 +77,5 @@ 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:
- db:/var/lib/continuwuity
- ./continuwuity-data:/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"
# possibly, depending on your config:
# enable tls with the `letsencrypt` certificate resolver (actual name dependant on your static config)
# - "traefik.http.routers.continuwuity.tls.certresolver=letsencrypt"
environment:
CONTINUWUITY_SERVER_NAME: example.com
@@ -34,9 +34,6 @@ 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
- ./data:/data
- ./caddy-data:/data
restart: unless-stopped
homeserver:
@@ -20,7 +20,7 @@ services:
restart: unless-stopped
command: /sbin/conduwuit
volumes:
- db:/var/lib/continuwuity
- ./continuwuity-data:/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:
- ./data:/data
- ./caddy-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:
- db:/var/lib/continuwuity
- ./continuwuity-data:/var/lib/continuwuity
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
# - ./continuwuity.toml:/etc/continuwuity.toml
environment:
@@ -43,6 +43,3 @@ services:
networks:
proxy:
volumes:
db:
@@ -6,7 +6,7 @@ services:
restart: unless-stopped
command: /sbin/conduwuit
volumes:
- db:/var/lib/continuwuity
- ./continuwuity-data:/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"
- "acme:/etc/traefik/acme"
- "./traefik-acme-data:/etc/traefik/acme"
labels:
- "traefik.enable=true"
@@ -77,9 +77,5 @@ services:
TRAEFIK_PROVIDERS_DOCKER_ENDPOINT: "unix:///var/run/docker.sock"
TRAEFIK_PROVIDERS_DOCKER_EXPOSEDBYDEFAULT: false
volumes:
db:
acme:
networks:
proxy:
+30 -33
View File
@@ -1,41 +1,38 @@
# 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:
- 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
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
## (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:
## (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
# }
+87 -17
View File
@@ -1,9 +1,9 @@
# Troubleshooting Continuwuity
:::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.
:::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.
:::
## Continuwuity issues
@@ -13,9 +13,9 @@ Please check that your issues are not due to problems with your Docker setup.
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](./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.
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.
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,11 +119,63 @@ 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
@@ -136,23 +188,34 @@ 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** the same format as the `log` config option.
a string **without quotes** in the same format as the `log` config option. Complex
filters are also supported as well.
Example: `!admin debug change-log-level debug`
```bash
# set log level to debug
!admin debug change-log-level debug
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 all outgoing federation to `example.com`
!admin debug change-log-level info,conduwuit_service::federation[{dest="example.com"}]=trace
And to reset the log level to the one that was set at startup / last config
load, simply pass the `--reset` flag.
# trace logs for client syncs
!admin debug change-log-level info,conduwuit_api::client=trace
`!admin debug change-log-level --reset`
# 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
```
### Pinging servers
Continuwuity can ping other servers using `!admin debug ping <server>`. This takes
a server name and goes through the server discovery process and queries
a server name, 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
@@ -198,3 +261,10 @@ 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)
+6 -8
View File
@@ -1,4 +1,4 @@
use conduwuit::{Err, Result, checked};
use conduwuit::{Err, Result, checked, utils::ReadyExt};
use futures::{FutureExt, StreamExt, TryFutureExt};
impl crate::Context<'_> {
@@ -49,7 +49,6 @@ impl crate::Context<'_> {
.services
.appservice
.get_registration(&appservice_identifier)
.await
{
| None => return Err!("Appservice does not exist."),
| Some(config) => {
@@ -78,12 +77,11 @@ impl crate::Context<'_> {
self.services
.users
.stream_local_users()
.filter_map(async |user_id| {
if self.services.appservice.is_user_id(&user_id).await {
Some(user_id)
} else {
None
}
.ready_filter_map(|user_id| {
self.services
.appservice
.is_user_id(&user_id)
.then_some(user_id)
})
.for_each(async |user_id| {
self.services
+41 -1
View File
@@ -14,7 +14,7 @@ use conduwuit::{
state_res::EventTypeExt,
trace, utils,
utils::{
stream::{IterStream, ReadyExt},
stream::{BroadbandExt, IterStream, ReadyExt},
string::EMPTY,
to_canonical_object,
},
@@ -1207,6 +1207,46 @@ 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,6 +234,10 @@ 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,
+4 -8
View File
@@ -39,17 +39,13 @@ conduwuit::mod_dtor! {}
pub use crate::admin::AdminCommand;
/// Install the admin command processor
pub async fn init(admin_service: &service::admin::Service) {
pub fn init(admin_service: &service::admin::Service) {
_ = admin_service.complete.write().insert(processor::complete);
_ = admin_service
.handle
.write()
.await
.insert(processor::dispatch);
_ = admin_service.handle.write().insert(processor::dispatch);
}
/// Uninstall the admin command handler
pub async fn fini(admin_service: &service::admin::Service) {
_ = admin_service.handle.write().await.take();
pub fn fini(admin_service: &service::admin::Service) {
_ = admin_service.handle.write().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).await;
let results = services.appservice.get_registration(&appservice_id);
let query_time = timer.elapsed();
-1
View File
@@ -135,7 +135,6 @@ 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();
+7 -4
View File
@@ -117,10 +117,13 @@ 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)"
)));
return Err!(Request(
BadJson(
"This endpoint cannot be used for marking a room as fully read (setting \
m.fully_read)"
),
METHOD_NOT_ALLOWED
));
}
let data: serde_json::Value = serde_json::from_str(data.get())
+2 -4
View File
@@ -20,8 +20,7 @@ pub(crate) async fn create_alias_route(
services
.rooms
.alias
.appservice_checks(&body.room_alias, body.identity.appservice_info())
.await?;
.appservice_checks(&body.room_alias, body.identity.appservice_info())?;
// this isn't apart of alias_checks or delete alias route because we should
// allow removing forbidden room aliases
@@ -69,8 +68,7 @@ pub(crate) async fn delete_alias_route(
services
.rooms
.alias
.appservice_checks(&body.room_alias, body.identity.appservice_info())
.await?;
.appservice_checks(&body.room_alias, body.identity.appservice_info())?;
services
.rooms
+2 -1
View File
@@ -46,7 +46,8 @@ 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 = true;
capabilities.forget_forced_upon_leave.enabled =
services.server.config.forget_forced_upon_leave;
if services.users.is_admin(sender_user).await {
capabilities.account_moderation.lock = true;
+15 -16
View File
@@ -1,4 +1,4 @@
use std::{borrow::Borrow, collections::HashMap, iter::once, sync::Arc};
use std::{borrow::Borrow, collections::HashMap, sync::Arc};
use axum::extract::State;
use conduwuit::{
@@ -461,14 +461,13 @@ async fn knock_room_helper_local(
services
.rooms
.timeline
.append_pdu(
&parsed_knock_pdu,
knock_event,
once(parsed_knock_pdu.event_id.borrow()),
&state_lock,
room_id,
)
.progress_extremities(&parsed_knock_pdu)
.await?;
services
.rooms
.timeline
.append_pdu(&parsed_knock_pdu, knock_event, room_id)
.await;
Ok(())
}
@@ -587,7 +586,7 @@ async fn knock_room_helper_remote(
let mut state_map: HashMap<u64, OwnedEventId> = HashMap::new();
for event in state {
for mut event in state {
let Some(state_key) = event.get("state_key") else {
debug_warn!("send_knock stripped state event missing state_key: {event:?}");
continue;
@@ -614,6 +613,7 @@ 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,14 +662,13 @@ async fn knock_room_helper_remote(
services
.rooms
.timeline
.append_pdu(
&parsed_knock_pdu,
knock_event,
once(parsed_knock_pdu.event_id.borrow()),
&state_lock,
room_id,
)
.progress_extremities(&parsed_knock_pdu)
.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"],
"grant_types_supported": ["authorization_code", "refresh_token", "urn:ietf:params:oauth:grant-type:device_code", "client_credentials"],
"issuer": services.config.get_client_domain(),
"jwks_uri": endpoint_base.join(JWKS_URI_PATH).unwrap(),
"prompt_values_supported": prompt_values_supported,
+21 -9
View File
@@ -1,18 +1,21 @@
use std::collections::{BTreeMap, BTreeSet, HashSet};
use std::{
collections::{BTreeMap, BTreeSet, HashSet},
sync::atomic::{AtomicU64, Ordering::SeqCst},
};
use axum::extract::State;
use conduwuit::{
Err, Error, Result, debug, debug_info, err, info,
matrix::{StateKey, pdu::PartialPdu},
trace,
utils::to_canonical_object,
utils::{self, to_canonical_object},
warn,
};
use conduwuit_service::{Services, appservice::RegistrationInfo};
use futures::FutureExt;
use ruma::{
CanonicalJsonObject, CanonicalJsonValue, Int, MilliSecondsSinceUnixEpoch, OwnedRoomAliasId,
OwnedUserId, RoomAliasId, RoomId,
OwnedUserId, RoomAliasId, RoomId, UInt,
api::{
client::room::{
self,
@@ -46,6 +49,8 @@ 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)]
@@ -307,6 +312,17 @@ 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");
@@ -322,7 +338,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: custom_origin_server_ts,
timestamp: create_timestamp,
..Default::default()
},
sender_user,
@@ -758,11 +774,7 @@ 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)
.await
{
} else if services.appservice.is_exclusive_alias(&full_room_alias) {
return Err!(Request(Exclusive("Room alias reserved by appservice.",)));
}
+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).await;
let mut wake_receiver = services.sync.subscribe_to_wake(sender_user);
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).await;
let mut wake_receiver = services.sync.subscribe_to_wake(sender_user);
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).await
|| services.appservice.is_exclusive_user_id(&user_id)
{
None
} else {
+28 -7
View File
@@ -41,6 +41,7 @@ pub(crate) enum ClientIdentity {
sender_device: Option<OwnedDeviceId>,
appservice_info: Box<RegistrationInfo>,
},
StaticClient,
}
impl ClientIdentity {
@@ -48,6 +49,7 @@ impl ClientIdentity {
match self {
| Self::User { sender_user, .. } | Self::Appservice { sender_user, .. } =>
Some(sender_user),
| Self::StaticClient => None,
}
}
@@ -55,6 +57,8 @@ 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."))),
}
}
@@ -62,6 +66,7 @@ impl ClientIdentity {
match self {
| Self::User { sender_device, .. } => Some(sender_device),
| Self::Appservice { sender_device, .. } => sender_device.as_deref(),
| Self::StaticClient => None,
}
}
@@ -71,12 +76,14 @@ 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 { .. } => None,
| Self::User { .. } | Self::StaticClient => None,
| Self::Appservice { appservice_info, .. } => Some(appservice_info),
}
}
@@ -346,7 +353,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).await {
} else if let Ok(appservice_info) = services.appservice.find_from_token(token) {
let Ok(sender_user) = query.user_id.clone().map_or_else(
|| {
UserId::parse_with_server_name(
@@ -379,10 +386,7 @@ async fn check_access_token(
.await
.is_err()
{
return Err!(Request(Forbidden(
"Device does not exist for user or appservice cannot masquerade as this \
device."
)));
return Err!(Request(UnknownDevice("Device does not exist for this user.")));
}
Some(device_id.to_owned())
@@ -395,6 +399,23 @@ 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()),
@@ -405,7 +426,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).await else {
let Ok(appservice_info) = services.appservice.find_from_token(token) else {
return Err!(Request(Unauthorized("Invalid appservice token.")));
};
+7 -2
View File
@@ -1,7 +1,10 @@
use std::{borrow::Borrow, iter::once};
use axum::extract::State;
use conduwuit::{Err, Event, Result, info, utils::stream::ReadyExt};
use conduwuit::{
Err, Event, Result, info,
utils::stream::{BroadbandExt, ReadyExt},
};
use futures::StreamExt;
use ruma::api::federation::authorization::get_event_authorization;
@@ -64,7 +67,9 @@ 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)
.filter_map(|id| async move { services.rooms.timeline.get_pdu_json(&id).await.ok() })
.broad_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;
+15 -2
View File
@@ -1,7 +1,7 @@
use std::collections::{HashSet, VecDeque};
use axum::extract::State;
use conduwuit::{Err, Event, Result, debug, info, trace, utils::to_canonical_object, warn};
use conduwuit::{Err, Event, Result, debug, debug_warn, info, trace, utils::to_canonical_object};
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,6 +44,13 @@ 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());
@@ -64,7 +71,9 @@ 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) => {
warn!("could not find event {next_event_id} while walking missing events: {e}");
debug_warn!(
"could not find event {next_event_id} while walking missing events: {e}"
);
continue;
},
};
@@ -74,6 +83,10 @@ 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
+27 -23
View File
@@ -209,31 +209,35 @@ async fn create_invite(
services.sync.wake(&recipient_user).await;
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();
let matching_appservices: Vec<_> = services
.appservice
.read()
.values()
.filter(|appservice| appservice.is_user_match(&recipient_user))
.cloned()
.collect();
let request = ruma::api::appservice::event::push_events::v1::Request::new(
transaction_id,
vec![pdu.to_format()],
);
for appservice in matching_appservices {
let transaction_id = general_purpose::URL_SAFE_NO_PAD
.encode(sha256::hash(pdu.event_id.as_bytes()))
.into();
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."
))
})?;
}
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."))
})?;
}
}
+9
View File
@@ -353,6 +353,15 @@ 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(())
}
+56 -2
View File
@@ -24,6 +24,7 @@ use ruma::{
OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, OwnedServerSigningKeyId, OwnedUserId,
RoomVersionId, ServerName,
api::{
OAuthClientScope,
client::{discovery::discover_support::ContactRole, rtc::RtcTransport},
federation::discovery::OldVerifyKey,
},
@@ -65,8 +66,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
@@ -2746,7 +2747,12 @@ 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 {
@@ -2960,6 +2966,54 @@ 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",
+66 -4
View File
@@ -39,7 +39,7 @@ use crate::{
debug, debug_error, err,
matrix::{Event, StateKey},
trace,
utils::stream::{BroadbandExt, IterStream, ReadyExt, TryBroadbandExt, WidebandExt},
utils::stream::{BroadbandExt, IterStream, ReadyExt, TryWidebandExt, 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)
.broad_and_then(async |event_id| {
.wide_and_then(async |event_id| {
fetch_event(event_id.to_owned())
.await
.ok_or_else(|| Error::NotFound(format!("Failed to find {event_id}")))
@@ -1123,6 +1123,68 @@ 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.
+4 -3
View File
@@ -14,6 +14,8 @@ 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 {
@@ -27,7 +29,7 @@ pub struct Metrics {
_runtime_monitor: Option<RuntimeMonitor>,
#[cfg(tokio_unstable)]
runtime_intervals: std::sync::Mutex<Option<RuntimeIntervals>>,
runtime_intervals: SyncMutex<Option<RuntimeIntervals>>,
// TODO: move stats
pub requests_handle_active: AtomicU32,
@@ -69,7 +71,7 @@ impl Metrics {
_runtime_monitor: runtime_monitor,
#[cfg(tokio_unstable)]
runtime_intervals: std::sync::Mutex::new(runtime_intervals),
runtime_intervals: SyncMutex::new(runtime_intervals),
requests_handle_active: AtomicU32::new(0),
requests_handle_finished: AtomicU32::new(0),
@@ -81,7 +83,6 @@ 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")
+4 -1
View File
@@ -36,7 +36,10 @@ 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};
pub use parking_lot::{
Mutex as SyncMutex, RwLock as SyncRwLock, RwLockReadGuard as SyncRwLockReadGuard,
RwLockWriteGuard as SyncRwLockWriteGuard,
};
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::RANDOM
..descriptor::DROPPED
},
Descriptor {
name: "refreshtoken_refreshtokeninfo",
+5 -2
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(server).await? <= restart_thresh();
let stops = !reloads || stale_from_mods(&main_lock)? <= restart_thresh();
let starts = reloads && stops;
if stops {
let stop = main_mod.get::<StopFuncProto>("stop")?;
@@ -140,7 +140,10 @@ async fn stale_count(server: &Arc<Server>) -> usize {
async fn stale(server: &Arc<Server>) -> Result<usize, Error> {
let mods_lock = server.mods.read().await;
let mods: &Vec<mods::Module> = &mods_lock;
stale_from_mods(&mods_lock)
}
fn stale_from_mods(mods: &[mods::Module]) -> Result<usize, Error> {
for (i, module) in mods.iter().enumerate() {
if module.deleted()? {
return Ok(i);
+16 -24
View File
@@ -1,19 +1,12 @@
#![cfg(feature = "sentry_telemetry")]
use std::{
borrow::Cow,
str::FromStr,
sync::{Arc, OnceLock},
};
use std::{borrow::Cow, sync::OnceLock};
use conduwuit_build_metadata as build;
use conduwuit_core::{config::Config, debug, trace};
use sentry::{
Breadcrumb, ClientOptions, Level,
types::{
Dsn,
protocol::v7::{Context, Event},
},
types::protocol::v7::{Context, Event},
};
static SEND_PANIC: OnceLock<bool> = OnceLock::new();
@@ -37,22 +30,21 @@ fn options(config: &Config) -> ClientOptions {
.expect("init_sentry should only be called if sentry is enabled and this is not None")
.as_str();
let server_name = config
.sentry_send_server_name
.then(|| config.server_name.to_string().into());
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);
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()
}
config
.sentry_send_server_name
.then(|| config.server_name.to_string())
.into_iter()
.fold(options, ClientOptions::server_name)
}
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).await;
admin::init(&services.admin);
// 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).await;
admin::fini(&services.admin);
debug_info!("Finish");
res
+7 -5
View File
@@ -27,7 +27,6 @@ use ruma::{
},
},
};
use tokio::sync::RwLock;
use crate::{
Dep, account_data, config, globals,
@@ -38,7 +37,7 @@ use crate::{
pub struct Service {
services: Services,
channel: (Sender<CommandInput>, Receiver<CommandInput>),
pub handle: RwLock<Option<Processor>>,
pub handle: SyncRwLock<Option<Processor>>,
pub complete: SyncRwLock<Option<Completer>>,
#[cfg(feature = "console")]
pub console: Arc<console::Console>,
@@ -131,7 +130,7 @@ impl crate::Service for Service {
media: args.depend::<crate::media::Service>("media"),
},
channel: loole::bounded(COMMAND_QUEUE_LIMIT),
handle: RwLock::new(None),
handle: SyncRwLock::new(None),
complete: SyncRwLock::new(None),
#[cfg(feature = "console")]
console: console::Console::new(&args),
@@ -372,8 +371,11 @@ impl Service {
}
async fn process_command(&self, command: CommandInput) -> ProcessorResult {
let handle_guard = self.handle.read().await;
let handle = handle_guard.as_ref().expect("Admin module is not loaded");
let handle = *self
.handle
.read()
.as_ref()
.expect("Admin module is not loaded");
let services = self
.services
+16 -32
View File
@@ -1,20 +1,19 @@
mod namespace_regex;
mod registration_info;
use std::{collections::BTreeMap, iter::IntoIterator, sync::Arc};
use std::{collections::BTreeMap, sync::Arc};
use async_trait::async_trait;
use conduwuit::{Err, Result, err, utils::stream::IterStream};
use conduwuit::{Err, Result, SyncRwLock, SyncRwLockReadGuard, err, utils::stream::IterStream};
use database::Map;
use futures::{Future, FutureExt, Stream, TryStreamExt};
use futures::{Stream, TryStreamExt};
use ruma::{RoomAliasId, RoomId, UserId, api::appservice::Registration};
use tokio::sync::{RwLock, RwLockReadGuard};
pub use self::{namespace_regex::NamespaceRegex, registration_info::RegistrationInfo};
use crate::{Dep, globals, sending, users};
pub struct Service {
registration_info: RwLock<Registrations>,
registration_info: SyncRwLock<Registrations>,
services: Services,
db: Data,
}
@@ -35,7 +34,7 @@ type Registrations = BTreeMap<String, RegistrationInfo>;
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
registration_info: RwLock::new(BTreeMap::new()),
registration_info: SyncRwLock::new(BTreeMap::new()),
services: Services {
globals: args.depend::<globals::Service>("globals"),
sending: args.depend::<sending::Service>("sending"),
@@ -123,7 +122,6 @@ impl Service {
self.registration_info
.write()
.await
.insert(id, registration.try_into()?);
Ok(())
@@ -139,7 +137,7 @@ impl Service {
// Check for token collision with other appservices (allow
// re-registration of same appservice)
if let Ok(existing) = self.find_from_token(&registration.as_token).await {
if let Ok(existing) = self.find_from_token(&registration.as_token) {
if existing.registration.id != registration.id {
return Err(err!(Request(InvalidParam(
"Cannot register appservice: Token is already used by appservice '{}'. \
@@ -182,7 +180,6 @@ impl Service {
// removes the appservice registration info
self.registration_info
.write()
.await
.remove(appservice_id)
.ok_or_else(|| err!("Appservice not found"))?;
@@ -197,19 +194,17 @@ impl Service {
.await
}
pub async fn get_registration(&self, id: &str) -> Option<Registration> {
pub fn get_registration(&self, id: &str) -> Option<Registration> {
self.registration_info
.read()
.await
.get(id)
.cloned()
.map(|info| info.registration)
}
/// Returns Result to match users::find_from_token for select_ok usage
pub async fn find_from_token(&self, token: &str) -> Result<RegistrationInfo> {
pub fn find_from_token(&self, token: &str) -> Result<RegistrationInfo> {
self.read()
.await
.values()
.find(|info| info.registration.as_token == token)
.cloned()
@@ -217,26 +212,21 @@ impl Service {
}
/// Checks if a given user id matches any exclusive appservice regex
pub async fn is_exclusive_user_id(&self, user_id: &UserId) -> bool {
pub fn is_exclusive_user_id(&self, user_id: &UserId) -> bool {
self.read()
.await
.values()
.any(|info| info.is_exclusive_user_match(user_id))
}
/// Checks if a given user id matches any appservice regex, exclusive or
/// otherwise
pub async fn is_user_id(&self, user_id: &UserId) -> bool {
self.read()
.await
.values()
.any(|info| info.is_user_match(user_id))
pub fn is_user_id(&self, user_id: &UserId) -> bool {
self.read().values().any(|info| info.is_user_match(user_id))
}
/// Checks if a given room alias matches any exclusive appservice regex
pub async fn is_exclusive_alias(&self, alias: &RoomAliasId) -> bool {
pub fn is_exclusive_alias(&self, alias: &RoomAliasId) -> bool {
self.read()
.await
.values()
.any(|info| info.aliases.is_exclusive_match(alias.as_str()))
}
@@ -245,19 +235,15 @@ impl Service {
///
/// TODO: use this?
#[allow(dead_code)]
pub async fn is_exclusive_room_id(&self, room_id: &RoomId) -> bool {
pub fn is_exclusive_room_id(&self, room_id: &RoomId) -> bool {
self.read()
.await
.values()
.any(|info| info.rooms.is_exclusive_match(room_id.as_str()))
}
pub fn iter_ids(&self) -> impl Stream<Item = String> + Send {
self.read()
.map(|info| info.keys().cloned().collect::<Vec<_>>())
.map(IntoIterator::into_iter)
.map(IterStream::stream)
.flatten_stream()
let ids: Vec<String> = self.read().keys().cloned().collect();
ids.stream()
}
pub fn iter_db_ids(&self) -> impl Stream<Item = Result<(String, Registration)>> + Send {
@@ -281,7 +267,5 @@ impl Service {
})
}
pub fn read(&self) -> impl Future<Output = RwLockReadGuard<'_, Registrations>> + Send {
self.registration_info.read()
}
pub fn read(&self) -> SyncRwLockReadGuard<'_, Registrations> { self.registration_info.read() }
}
+2 -2
View File
@@ -146,8 +146,8 @@ impl crate::Service for Service {
.redirect(redirect::Policy::limited(2))
.build()?,
// MSC4174 recommends against following redirects, since the destination
// is only checked before the request is sent.
// MSC4174 recommends against following redirects, since the
// destination is only checked before the request is sent.
webpush: base(config)?
.connect_timeout(Duration::from_secs(config.pusher_conn_timeout))
.timeout(Duration::from_secs(config.pusher_timeout))
+6 -2
View File
@@ -21,7 +21,9 @@ impl Data {
}
}
pub fn next_count(&self) -> Result<u64> {
pub fn next_count(&self) -> Result<u64> { self.next_count_with(|_| ()) }
pub fn next_count_with(&self, write: impl FnOnce(u64)) -> Result<u64> {
let _cork = self.db.cork();
let mut lock = self.counter.write();
let counter: &mut u64 = &mut lock;
@@ -30,7 +32,9 @@ impl Data {
"counter mismatch"
);
*counter = counter.checked_add(1).unwrap_or(*counter);
let next = counter.checked_add(1).unwrap_or(*counter);
write(next);
*counter = next;
self.global.insert(COUNTER, counter.to_be_bytes());
+5
View File
@@ -80,6 +80,11 @@ impl Service {
#[inline]
pub fn next_count(&self) -> Result<u64> { self.db.next_count() }
#[inline]
pub fn next_count_with(&self, write: impl FnOnce(u64)) -> Result<u64> {
self.db.next_count_with(write)
}
#[inline]
pub fn current_count(&self) -> Result<u64> { Ok(self.db.current_count()) }
+1 -5
View File
@@ -7,17 +7,13 @@
use std::time::SystemTime;
#[cfg(feature = "url_preview")]
use conduwuit::utils::response::LimitReadExt;
use conduwuit::{Err, Result, debug, err};
use conduwuit::{Err, Result, debug, err, utils::response::LimitReadExt};
use ipaddress::IPAddress;
#[cfg(feature = "url_preview")]
use ruma::OwnedMxcUri;
use serde::Serialize;
use url::Url;
use super::Service;
#[cfg(feature = "url_preview")]
use crate::media::mxc::Mxc;
#[derive(Serialize, Default)]
+172 -27
View File
@@ -8,12 +8,12 @@ use std::{
};
use conduwuit::{
Err, Error, Event, Pdu, Result, debug, debug_info, debug_warn, err, error, info,
Err, Error, Event, Pdu, PduCount, Result, debug, debug_info, debug_warn, err, error, info,
result::NotFound,
trace,
utils::{
IterStream, ReadyExt,
stream::{TryExpect, TryIgnore},
stream::{TryExpect, TryIgnore, WidebandExt, automatic_width},
to_canonical_object,
},
warn,
@@ -109,35 +109,37 @@ migration!(stringify!($name) => $name)
migration!(fix_readreceiptid_readreceipt_duplicates),
// End pre-fork logic.
// v18: `fix_corrupt_msc4133_fields` will change the `us.cloke.msc4175.tz` field
// in a way that old versions don't understand.
// v18: `fix_corrupt_msc4133_fields` will change the
// `us.cloke.msc4175.tz` field in a way that old versions don't
// understand.
VersionBump(18),
migration!(fix_corrupt_msc4133_fields),
// v19: `populate_userroomid_leftstate_table` will put data in the values of
// `userroomid_leftstate` that old versions will fail to deserialize because
// they expect the values to be empty.
// v19: `populate_userroomid_leftstate_table` will put data in the
// values of `userroomid_leftstate` that old versions will fail to
// deserialize because they expect the values to be empty.
VersionBump(19),
migration!(populate_userroomid_leftstate_table),
// This is backwards compatible because it fixes some data that clients care about but we
// don't.
// This is backwards compatible because it fixes some data that clients
// care about but we don't.
migration!(fix_local_invite_state),
// v20: Old versions expect remote users to be tracked in `userid_password`. This
// migration moves them to a different keyspace.
// v20: Old versions expect remote users to be tracked in
// `userid_password`. This migration moves them to a different keyspace.
VersionBump(20),
migration!(split_userid_password),
// This is backwards compatible because old versions will recreate the keyspace if it's
// missing.
// This is backwards compatible because old versions will recreate the
// keyspace if it's missing.
migration!("drop_roomsynctoken_shortstatehash" => obliterate_roomsynctoken_shortstatehash_with_extreme_prejudice),
// v21: `unembed_unsigned_info` will remove `unsigned` data from PDUs that old versions
// expect to be embedded.
// v21: `unembed_unsigned_info` will remove `unsigned` data from PDUs
// that old versions expect to be embedded.
VersionBump(21),
// This migration can take several hours on old databases, so we run it in the background
// to keep the service manager from killing us for taking too long to start.
// Future maintainers: !!! BE VERY CAREFUL !!! if you need to write more migrations like
// this! This one is fine because it deletes data that we don't check anymore,
// but migrations which replace existing data that we do check should NOT run in
// the background. If they do, the server will finish starting up and might
// access data that the migration hasn't gotten to yet.
// This migration can take several hours on old databases, so we run it
// in the background to keep the service manager from killing us for
// taking too long to start. Future maintainers: !!! BE VERY CAREFUL !!!
// if you need to write more migrations like this! This one is fine
// because it deletes data that we don't check anymore, but migrations
// which replace existing data that we do check should NOT run in
// the background. If they do, the server will finish starting up and
// might access data that the migration hasn't gotten to yet.
Migration("unembed_unsigned_info", |services| {
Box::pin(async {
if services.db["global"]
@@ -158,13 +160,19 @@ migration!(stringify!($name) => $name)
Ok(())
})
}),
// This is backwards compatible because old versions will recreate the keyspace if it's
// missing.
// This is backwards compatible because old versions will recreate the
// keyspace if it's missing.
migration!(drop_server_signingkeys),
// v22: Old versions will fail to deserialize the fixed OAuth scope names,
// preventing users from signing in.
// v22: Old versions will fail to deserialize the fixed OAuth scope
// names, preventing users from signing in.
VersionBump(22),
migration!(fix_oauth_scope_names),
// Removes any extremities in roomid_pduleaves that we do not know about
// (and consequently should not reference).
migration!(remove_unknown_extremities),
// Re-calculates extremities for any rooms that actually lack any
// extremities at all.
migration!(consistency_check_extremity_tracker),
]
};
@@ -851,7 +859,7 @@ async fn split_userid_password(services: &Services) -> Result {
userid_password.remove(&user_id);
remote_users = remote_users.saturating_add(1);
} else if hash.is_empty() {
if !(services.appservice.is_user_id(&user_id).await
if !(services.appservice.is_user_id(&user_id)
|| user_id == services.globals.server_user)
{
info!("Marking {user_id} as deactivated");
@@ -977,3 +985,140 @@ async fn fix_oauth_scope_names(services: &Services) -> Result {
Ok(())
}
#[tracing::instrument(skip_all)]
async fn remove_unknown_extremities(services: &Services) -> Result {
services.db["roomid_pduleaves"]
.keys()
.ignore_err()
.for_each_concurrent(
automatic_width(),
|(room_id, event_id): (OwnedRoomId, OwnedEventId)| async move {
if !services.rooms.timeline.pdu_exists(&event_id).await {
info!("Removing unknown extremity in {room_id}: {event_id}");
services
.rooms
.state
.remove_forward_extremity(&room_id, &event_id);
} else if !services
.rooms
.pdu_metadata
.is_event_accepted(&event_id)
.await
{
info!("Removing failed extremity in {room_id}: {event_id}");
services
.rooms
.state
.remove_forward_extremity(&room_id, &event_id);
}
},
)
.await;
Ok(())
}
#[tracing::instrument(skip_all)]
async fn consistency_check_extremity_tracker(services: &Services) -> Result {
let mut rooms = services.rooms.metadata.iter_ids();
// For every room the server is a member of,
while let Some(room_id) = rooms.next().await {
// If this room has no extremities, re-calculate
let extremity_count = services
.rooms
.state
.get_forward_extremities(&room_id)
.count()
.await;
if extremity_count == 0 {
warn!(
"Room {room_id} is missing extremity information, recalculating. This may take \
a long time if this room is old."
);
let epoch_ts = services
.rooms
.timeline
.first_pdu_in_room(&room_id)
.await
.map_or_default(|e| e.origin_server_ts().0);
services
.rooms
.timeline
.pdus(&room_id, Some(PduCount::Normal(0)))
.ignore_err()
.for_each(|(_, pdu)| {
let room_id = &room_id;
async move {
if pdu.origin_server_ts < epoch_ts {
return;
}
if !services
.rooms
.pdu_metadata
.is_event_accepted(pdu.event_id())
.await
{
return;
}
services
.rooms
.timeline
.progress_extremities(&pdu)
.await
.inspect_err(|e| {
error!("Failed to progress extremities in {room_id}: {e:?}");
})
.ok();
}
})
.await;
} else if extremity_count > 20 {
warn!(
%extremity_count,
"Room {room_id} has an abnormal number of forward extremities, retaining latest 20"
);
let mut thinned = services
.rooms
.state
.get_forward_extremities(&room_id)
.wide_filter_map(|event_id| {
let room_id = &room_id;
async move {
let Ok(pdu) =
services.rooms.timeline.get_non_outlier_pdu(&event_id).await
else {
services
.rooms
.state
.remove_forward_extremity(room_id, &event_id);
return None;
};
Some(pdu)
}
})
.collect::<Vec<_>>()
.await;
thinned.sort_by_key(|pdu| {
(
i64::from(pdu.depth).saturating_mul(-1),
i64::from(pdu.origin_server_ts).saturating_mul(-1),
)
});
thinned
.into_iter()
.stream()
.skip(20)
.ready_for_each(move |pdu| {
services
.rooms
.state
.remove_forward_extremity(&room_id, pdu.event_id());
})
.await;
}
}
Ok(())
}
+16
View File
@@ -81,6 +81,15 @@ impl ClientMetadata {
if !uri.username().is_empty() || uri.password().is_some() {
return Err("HTTPS redirect URIs must not contain credentials.");
}
if !uri
.domain()
.is_some_and(|domain| is_subdomain(domain, client_domain))
{
return Err(
"All HTTPS redirect URIs must be subdomains of the client URI."
);
}
},
| "http" if self.application_type == ApplicationType::Native => {
if uri
@@ -116,6 +125,12 @@ impl ClientMetadata {
}
}
if self.grant_types.contains(&GrantType::ClientCredentials) {
return Err(
"Dynamically registered clients may not use the client credentials grant."
);
}
Ok(())
}
}
@@ -135,6 +150,7 @@ pub enum GrantType {
#[serde(rename = "urn:ietf:params:oauth:grant-type:device_code")]
DeviceCode,
RefreshToken,
ClientCredentials,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Deserialize, Serialize)]
+6 -1
View File
@@ -225,6 +225,10 @@ pub enum TokenRequestType {
RefreshToken {
refresh_token: String,
},
ClientCredentials {
client_secret: String,
scope: RawScopes,
},
}
impl TokenRequestType {
@@ -234,6 +238,7 @@ impl TokenRequestType {
| Self::AuthorizationCode { .. } => GrantType::AuthorizationCode,
| Self::DeviceCode { .. } => GrantType::DeviceCode,
| Self::RefreshToken { .. } => GrantType::RefreshToken,
| Self::ClientCredentials { .. } => GrantType::ClientCredentials,
}
}
}
@@ -243,7 +248,7 @@ pub struct TokenResponse {
pub access_token: String,
pub token_type: TokenType,
pub expires_in: u64,
pub refresh_token: String,
pub refresh_token: Option<String>,
pub scope: String,
}
+183 -77
View File
@@ -1,12 +1,12 @@
use std::{
collections::{BTreeSet, HashMap},
sync::{Arc, Mutex},
sync::Arc,
time::{Duration, SystemTime},
};
use base64::Engine;
use conduwuit::{
Result, info,
Result, SyncMutex, info,
utils::{self, hash::sha256},
};
use database::{Deserialized, Json, Map};
@@ -23,8 +23,9 @@ use crate::{
client_metadata::{ApplicationType, ClientMetadata, GrantType, ResponseType},
grant::{
AuthorizationCodeQuery, AuthorizationCodeResponse, CodeChallengeMethod,
DeviceCodeRequest, DeviceCodeResponse, ErrorCode, OAuthError, RequestedScopes,
ResponseMode, TokenRequest, TokenRequestType, TokenResponse, TokenType,
DeviceCodeRequest, DeviceCodeResponse, ErrorCode, OAuthError, RawScopes,
RequestedScopes, ResponseMode, TokenRequest, TokenRequestType, TokenResponse,
TokenType,
},
},
users::{self, DeviceToken},
@@ -36,9 +37,10 @@ pub mod grant;
pub struct Service {
services: Services,
db: Data,
tickets: Mutex<HashMap<String, HashMap<OAuthTicket, SystemTime>>>,
pending_auth_code_grants: tokio::sync::Mutex<LruCache<String, PendingAuthCodeGrant>>,
pending_device_code_grants: tokio::sync::Mutex<LruCache<String, PendingDeviceCodeGrant>>,
tickets: SyncMutex<HashMap<String, HashMap<OAuthTicket, SystemTime>>>,
pending_auth_code_grants: SyncMutex<LruCache<String, PendingAuthCodeGrant>>,
pending_device_code_grants: SyncMutex<LruCache<String, PendingDeviceCodeGrant>>,
client_credential_sessions: tokio::sync::Mutex<HashMap<String, ClientCredentialsSession>>,
}
struct Data {
@@ -78,6 +80,12 @@ struct RefreshTokenInfo {
device_id: OwnedDeviceId,
}
pub struct ClientCredentialsSession {
pub client_id: String,
pub scopes: BTreeSet<OAuthClientScope>,
created_at: SystemTime,
}
struct PendingAuthCodeGrant {
authorizing_user: OwnedUserId,
requested_scopes: RequestedScopes,
@@ -169,13 +177,10 @@ impl crate::Service for Service {
userdeviceid_oauthsessioninfo: args.db["userdeviceid_oauthsessioninfo"].clone(),
refreshtoken_refreshtokeninfo: args.db["refreshtoken_refreshtokeninfo"].clone(),
},
tickets: Mutex::default(),
pending_auth_code_grants: tokio::sync::Mutex::new(LruCache::new(
Self::MAX_PENDING_GRANTS,
)),
pending_device_code_grants: tokio::sync::Mutex::new(LruCache::new(
Self::MAX_PENDING_GRANTS,
)),
tickets: SyncMutex::default(),
pending_auth_code_grants: SyncMutex::new(LruCache::new(Self::MAX_PENDING_GRANTS)),
pending_device_code_grants: SyncMutex::new(LruCache::new(Self::MAX_PENDING_GRANTS)),
client_credential_sessions: tokio::sync::Mutex::default(),
}))
}
@@ -328,7 +333,6 @@ impl Service {
self.pending_auth_code_grants
.lock()
.await
.insert(code, pending_grant);
Ok(redirect_uri)
@@ -383,7 +387,6 @@ impl Service {
self.pending_device_code_grants
.lock()
.await
.insert(device_code.clone(), pending_grant);
Ok(DeviceCodeResponse {
@@ -399,32 +402,36 @@ impl Service {
&self,
supplied_user_code: &str,
) -> Option<DeviceCodeGrantInfo> {
let pending_grants = self.pending_device_code_grants.lock().await;
let (device_code, client_id, requested_scopes) = {
let pending_grants = self.pending_device_code_grants.lock();
let (device_code, grant) = pending_grants
.iter()
.find(|(_, grant)| {
matches!(&grant.state, DeviceCodeGrantState::Unverified { user_code } if user_code == supplied_user_code)
})?;
let (device_code, grant) = pending_grants
.iter()
.find(|(_, grant)| {
matches!(&grant.state, DeviceCodeGrantState::Unverified { user_code } if user_code == supplied_user_code)
})?;
(device_code.clone(), grant.client_id.clone(), grant.requested_scopes.clone())
};
let client_metadata = self
.get_client_metadata(&grant.client_id)
.get_client_metadata(&client_id)
.await
.expect("client should exist");
Some(DeviceCodeGrantInfo {
device_code: device_code.clone(),
device_code,
client_metadata,
requested_scopes: grant.requested_scopes.clone(),
requested_scopes,
})
}
pub async fn validate_device_code(
pub fn validate_device_code(
&self,
authorizing_user: OwnedUserId,
device_code: &str,
) -> Result<(), String> {
let mut pending_grants = self.pending_device_code_grants.lock().await;
let mut pending_grants = self.pending_device_code_grants.lock();
let Some(pending_grant) = pending_grants.get_mut(device_code) else {
return Err("Invalid device code".to_owned());
@@ -450,35 +457,52 @@ impl Service {
pub async fn issue_token(&self, request: TokenRequest) -> Result<TokenResponse, OAuthError> {
let TokenRequest { client_id, request } = request;
let Some(client_metadata) = self.get_client_metadata(&client_id).await else {
return Err(OAuthError::new_static(ErrorCode::InvalidClient, "Invalid client ID"));
};
if !matches!(request, TokenRequestType::ClientCredentials { .. }) {
// The client credentials grant can only be used by statically
// registered clients, and the other grant types can
// only be used by dynamically registered clients, so we
// don't look up the dynamic client metadata if the token request is
// for the client credentials grant.
if !client_metadata.grant_types.contains(&request.grant_type()) {
return Err(OAuthError::unauthorized_client("Client cannot request this grant type"));
let Some(client_metadata) = self.get_client_metadata(&client_id).await else {
return Err(OAuthError::new_static(
ErrorCode::InvalidClient,
"Invalid client ID",
));
};
if !client_metadata.grant_types.contains(&request.grant_type()) {
return Err(OAuthError::unauthorized_client(
"Client cannot request this grant type",
));
}
}
match request {
| TokenRequestType::AuthorizationCode { code, redirect_uri, code_verifier } => {
let mut pending_grants = self.pending_auth_code_grants.lock().await;
let pending_grant = {
let mut pending_grants = self.pending_auth_code_grants.lock();
let Some(pending_grant) = pending_grants
.remove(&code)
.filter(|grant| grant.is_valid_for(&client_id))
else {
return Err(OAuthError::invalid_grant("Invalid authorization code"));
let Some(pending_grant) = pending_grants
.remove(&code)
.filter(|grant| grant.is_valid_for(&client_id))
else {
return Err(OAuthError::invalid_grant("Invalid authorization code"));
};
if redirect_uri != pending_grant.expected_redirect_uri {
return Err(OAuthError::invalid_grant("Invalid redirect URI"));
}
let expected_code_challenge = base64::prelude::BASE64_URL_SAFE_NO_PAD
.encode(sha256::hash(&code_verifier));
if expected_code_challenge != pending_grant.code_challenge {
return Err(OAuthError::invalid_grant("Invalid code challenge"));
}
pending_grant
};
if redirect_uri != pending_grant.expected_redirect_uri {
return Err(OAuthError::invalid_grant("Invalid redirect URI"));
}
let expected_code_challenge =
base64::prelude::BASE64_URL_SAFE_NO_PAD.encode(sha256::hash(&code_verifier));
if expected_code_challenge != pending_grant.code_challenge {
return Err(OAuthError::invalid_grant("Invalid code challenge"));
}
self.create_session(
pending_grant.authorizing_user,
pending_grant.requested_scopes,
@@ -488,39 +512,44 @@ impl Service {
.await
},
| TokenRequestType::DeviceCode { device_code } => {
let mut pending_grants = self.pending_device_code_grants.lock().await;
let (authorizing_user, requested_scopes, client_name) = {
let mut pending_grants = self.pending_device_code_grants.lock();
let Some(pending_grant) = pending_grants
.remove(&device_code)
.filter(|grant| grant.is_valid_for(&client_id))
else {
return Err(OAuthError::new_static(
ErrorCode::ExpiredToken,
"Invalid device code",
));
};
let Some(pending_grant) = pending_grants
.remove(&device_code)
.filter(|grant| grant.is_valid_for(&client_id))
else {
return Err(OAuthError::new_static(
ErrorCode::ExpiredToken,
"Invalid device code",
));
};
match &pending_grant.state {
| DeviceCodeGrantState::Unverified { .. } => {
pending_grants.insert(device_code, pending_grant);
match &pending_grant.state {
| DeviceCodeGrantState::Unverified { .. } => {
pending_grants.insert(device_code, pending_grant);
Err(OAuthError::new_static(
ErrorCode::AuthorizationPending,
"Authorization is pending",
))
},
| DeviceCodeGrantState::Verified { authorizing_user } =>
self.create_session(
return Err(OAuthError::new_static(
ErrorCode::AuthorizationPending,
"Authorization is pending",
));
},
| DeviceCodeGrantState::Verified { authorizing_user } => (
authorizing_user.to_owned(),
pending_grant.requested_scopes,
pending_grant.client_name,
client_id,
)
.await,
}
),
}
};
self.create_session(authorizing_user, requested_scopes, client_name, client_id)
.await
},
| TokenRequestType::RefreshToken { refresh_token } =>
self.refresh_session(client_id, refresh_token).await,
| TokenRequestType::ClientCredentials { client_secret, scope: scopes } =>
self.create_client_credentials_token(&client_id, &client_secret, scopes)
.await,
}
}
@@ -538,7 +567,7 @@ impl Service {
{
(user_id, device_id)
} else {
return Err(OAuthError::invalid_grant("Invalid access or refersh token"));
return Err(OAuthError::invalid_grant("Invalid access or refresh token"));
};
// This will also call [`Self::remove_session`]
@@ -664,7 +693,7 @@ impl Service {
token_type: TokenType::Bearer,
expires_in: Self::ACCESS_TOKEN_MAX_AGE.as_secs(),
scope: response_scope,
refresh_token,
refresh_token: Some(refresh_token),
})
}
@@ -734,10 +763,89 @@ impl Service {
token_type: TokenType::Bearer,
expires_in: Self::ACCESS_TOKEN_MAX_AGE.as_secs(),
scope,
refresh_token: new_refresh_token,
refresh_token: Some(new_refresh_token),
})
}
async fn create_client_credentials_token(
&self,
client_id: &str,
client_secret: &str,
scopes: RawScopes,
) -> Result<TokenResponse, OAuthError> {
let now = SystemTime::now();
let Some(client) = self.services.config.oauth.clients.get(client_id) else {
return Err(OAuthError::new_static(ErrorCode::InvalidClient, "Unknown client ID"));
};
let RequestedScopes { device_id, scopes } = scopes
.to_scopes()
.map_err(|err| OAuthError::new(ErrorCode::InvalidGrant, err))?;
if device_id.is_some() {
return Err(OAuthError::new_static(
ErrorCode::InvalidGrant,
"Static clients may not request a device ID",
));
}
if client_secret != client.client_secret {
return Err(OAuthError::new_static(
ErrorCode::InvalidClient,
"Client secret does not match",
));
}
if !scopes.is_subset(&client.scopes) {
return Err(OAuthError::new_static(
ErrorCode::InvalidScope,
"This client may not request those scopes",
));
}
let mut sessions = self.client_credential_sessions.lock().await;
// Clear expired sessions while we're at it
sessions.retain(|_, session| {
now.duration_since(session.created_at)
.is_ok_and(|age| age <= Self::ACCESS_TOKEN_MAX_AGE)
});
let access_token = Self::generate_token();
let scope = scopes.iter().join(" ");
sessions.insert(access_token.clone(), ClientCredentialsSession {
client_id: client_id.to_owned(),
scopes,
created_at: now,
});
Ok(TokenResponse {
access_token,
token_type: TokenType::Bearer,
expires_in: Self::ACCESS_TOKEN_MAX_AGE.as_secs(),
refresh_token: None,
scope,
})
}
pub async fn get_client_credentials_session(
&self,
token: &str,
) -> Option<tokio::sync::MappedMutexGuard<'_, ClientCredentialsSession>> {
let sessions = self.client_credential_sessions.lock().await;
tokio::sync::MutexGuard::try_map(sessions, |sessions| {
sessions.get_mut(token).filter(|session| {
SystemTime::now()
.duration_since(session.created_at)
.is_ok_and(|age| age <= Self::ACCESS_TOKEN_MAX_AGE)
})
})
.ok()
}
pub async fn remove_session(&self, user_id: &UserId, device_id: &DeviceId) {
let session_info = self.get_session_info_for_device(user_id, device_id).await;
@@ -773,7 +881,6 @@ impl Service {
pub fn issue_ticket(&self, localpart: String, ticket: OAuthTicket) {
self.tickets
.lock()
.unwrap()
.entry(localpart)
.or_default()
.insert(ticket, SystemTime::now());
@@ -785,7 +892,6 @@ impl Service {
self.tickets
.lock()
.unwrap()
.get_mut(localpart)
.and_then(|tickets| tickets.remove(&ticket))
.is_some_and(|issued| {
+5 -1
View File
@@ -532,6 +532,7 @@ impl Service {
let notify = self
.build_notification(
user,
pusher,
&http.data,
http.format.as_ref(),
@@ -549,6 +550,7 @@ impl Service {
| PusherKind::WebPush(data) => {
let notify = self
.build_notification(
user,
pusher,
&data.data,
data.format.as_ref(),
@@ -564,8 +566,10 @@ impl Service {
}
}
#[allow(clippy::too_many_arguments)]
async fn build_notification<E>(
&self,
user: &UserId,
pusher: &Pusher,
data: &JsonObject,
format: Option<&PushFormat>,
@@ -614,7 +618,7 @@ impl Service {
notify.content = serde_json::value::to_raw_value(event.content()).ok();
if *event.kind() == TimelineEventType::RoomMember {
notify.user_is_target = event.state_key() == Some(event.sender().as_str());
notify.user_is_target = event.state_key() == Some(user.as_str());
}
notify.sender_display_name =
+22 -19
View File
@@ -269,18 +269,26 @@ impl Service {
) -> Result<Option<OwnedRoomId>> {
use ruma::api::appservice::query::query_room_alias;
for appservice in self.services.appservice.read().await.values() {
if appservice.aliases.is_match(room_alias.as_str())
&& matches!(
self.services
.sending
.send_appservice_request(
appservice.registration.clone(),
query_room_alias::v1::Request::new(room_alias.to_owned()),
)
.await,
Ok(Some(_opt_result))
) {
let matching_appservices: Vec<_> = self
.services
.appservice
.read()
.values()
.filter(|appservice| appservice.aliases.is_match(room_alias.as_str()))
.cloned()
.collect();
for appservice in matching_appservices {
if matches!(
self.services
.sending
.send_appservice_request(
appservice.registration.clone(),
query_room_alias::v1::Request::new(room_alias.to_owned()),
)
.await,
Ok(Some(_opt_result))
) {
return self
.resolve_local_alias(room_alias)
.await
@@ -292,7 +300,7 @@ impl Service {
Ok(None)
}
pub async fn appservice_checks(
pub fn appservice_checks(
&self,
room_alias: &RoomAliasId,
appservice_info: Option<&RegistrationInfo>,
@@ -309,12 +317,7 @@ impl Service {
if !info.aliases.is_match(room_alias.as_str()) {
return Err!(Request(Exclusive("Room alias is not in namespace.")));
}
} else if self
.services
.appservice
.is_exclusive_alias(room_alias)
.await
{
} else if self.services.appservice.is_exclusive_alias(room_alias) {
return Err!(Request(Exclusive("Room alias reserved by appservice.")));
}
@@ -9,7 +9,7 @@ use assign::assign;
use conduwuit::error;
use conduwuit::{
Err, Event, PduEvent, Result, debug, debug_info, debug_warn, err,
result::FlatOk,
result::{FlatOk, LogErr},
state_res::lexicographical_topological_sort,
trace,
utils::{IterStream, math::Expected, stream::BroadbandExt},
@@ -203,8 +203,8 @@ impl super::Service {
"GET_MISSING_EVENTS_MAX_BATCH_SIZE (usize) should fit in u16 (<=65536)",
))
.max(
// This max call ensures we fetch *at least* all the prev events the
// head has.
// This max call ensures we fetch *at least* all the prev
// events the head has.
u16::try_from(head.prev_events.len())
.expect("cannot have more than 20 prev events, which fits in u16"),
);
@@ -310,9 +310,9 @@ impl super::Service {
.stream()
.fold(0_u8, |i, event_id| async move {
if self.services.timeline.pdu_exists(event_id).await {
i.expected_add(1)
} else {
i
} else {
i.expected_add(1)
}
})
.await;
@@ -387,6 +387,7 @@ impl super::Service {
remote: OwnedServerName,
event_id: OwnedEventId,
room_version_rules: &RoomVersionRules,
create_event_id: &EventId,
) -> Result<(OwnedEventId, CanonicalJsonObject)> {
let res = self
.services
@@ -399,21 +400,28 @@ impl super::Service {
.await?;
if calculated_event_id != event_id {
Err!(Request(BadJson(warn!(
return Err!(Request(BadJson(warn!(
expected=%event_id,
received=%calculated_event_id,
"Server didn't return event id we requested",
))))
} else {
Ok((event_id, value))
))));
}
Self::pdu_format_check_1(&value, room_version_rules, create_event_id)?;
self.signature_hash_check_2_3(value, room_version_rules)
.await
.map(|value| (calculated_event_id, value))
}
/// Fetches an event from multiple candidates in parallel (by calling
/// fetch_event_via on each candidate), returning the first successful
/// result.
async fn fetch_event_vias(
&self,
candidates: impl Iterator<Item = &OwnedServerName>,
event_id: &EventId,
room_version_rules: &RoomVersionRules,
create_event_id: &EventId,
) -> Result<(OwnedEventId, CanonicalJsonObject)> {
if let Ok(pdu_json) = self.services.timeline.get_pdu_json(event_id).await {
return Ok((event_id.to_owned(), pdu_json));
@@ -424,6 +432,7 @@ impl super::Service {
remote.to_owned(),
event_id.to_owned(),
room_version_rules,
create_event_id,
))
})
.collect::<Vec<_>>();
@@ -511,7 +520,12 @@ impl super::Service {
})?;
debug!(elapsed=?start.elapsed(), "Fetching {target_id} over federation");
let value = match self
.fetch_event_vias(candidates.iter(), &target_id, room_version_rules)
.fetch_event_vias(
candidates.iter(),
&target_id,
room_version_rules,
create_event.event_id(),
)
.await
{
| Ok((_, value)) => {
@@ -657,8 +671,13 @@ impl super::Service {
debug_warn!(error=?e, "Not attempting to pull missing prev event");
continue;
}
let pdu = match self
.fetch_event_vias(candidates.iter(), &next_id, room_version_rules)
let pdu_json = match self
.fetch_event_vias(
candidates.iter(),
&next_id,
room_version_rules,
create_event.event_id(),
)
.await
{
| Ok((_, data)) => {
@@ -676,7 +695,7 @@ impl super::Service {
},
};
let prev_events = match expect_event_id_array(&pdu, "prev_events").map_err(|e| {
let prev_events = match expect_event_id_array(&pdu_json, "prev_events").map_err(|e| {
err!(Request(BadJson(warn!(
event_id=%next_id,
"Failed to parse event fetched from remote: {e}"
@@ -698,11 +717,14 @@ impl super::Service {
})
.collect::<Vec<_>>()
.await;
let Ok(pdu) = PduEvent::from_id_val(&next_id, pdu_json.clone())
.map_err(|e| err!("Failed to parse already validated PDU {next_id}: {e:?}"))
.log_err()
else {
continue;
};
todo.extend(missing_prev);
discovered_events.insert(
next_id.clone(),
PduEvent::from_id_val(&next_id, pdu).expect("fetched PDU was already validated"),
);
discovered_events.insert(next_id, pdu);
}
discovered_events
@@ -62,12 +62,6 @@ impl super::Service {
return Err!(Request(TooLarge("PDU is too large")));
}
if event_format.require_room_create_room_id {
if pdu_json.get("room_id").is_none() {
return Err!(Request(BadJson("Missing required PDU field: `room_id`")));
}
}
let auth_events = expect_event_id_array(pdu_json, "auth_events")?;
if auth_events.len() > 10 {
return Err!(Request(BadJson("PDU has too many auth events")));
@@ -90,6 +84,9 @@ impl super::Service {
let is_create_event = event_type == "m.room.create" && state_key == Some("");
if !is_create_event {
if pdu_json.get("room_id").is_none() {
return Err!(Request(BadJson("Missing required PDU field: `room_id`")));
}
let create_event_in_auth_events = auth_events.iter().any(|id| id == create_event_id);
if !event_format.allow_room_create_in_auth_events && create_event_in_auth_events {
return Err!(Request(BadJson("PDU references a create event")));
@@ -98,6 +95,8 @@ impl super::Service {
{
return Err!(Request(BadJson("PDU does not reference the room create event")));
}
} else if !event_format.require_room_create_room_id && pdu_json.get("room_id").is_some() {
return Err!(Request(BadJson("Unexpected PDU field: `room_id`")));
}
let prev_events = expect_event_id_array(pdu_json, "prev_events")?;
+19 -22
View File
@@ -226,9 +226,10 @@ impl Service {
}
}
drop(state_lock);
// If we aren't participating in the room, or failed to join locally,
// try to join over federation.
self.join_remote_room(sender_user, room_id, reason, &servers, &state_lock)
self.join_remote_room(sender_user, room_id, reason, &servers)
.boxed()
.await?;
@@ -305,7 +306,6 @@ impl Service {
room_id: &RoomId,
reason: Option<String>,
servers: &[&OwnedServerName],
state_lock: &RoomMutexGuard,
) -> Result {
// public so the admin command force-join-room-remotely works
info!("Joining {room_id} over federation.");
@@ -540,9 +540,6 @@ impl Service {
}
self.services.outlier.add_pdu_outlier(&event_id, &value);
self.services.pdu_metadata.clear_pdu_markers(&event_id);
self.services
.pdu_metadata
.mark_as_referenced(room_id, once(event_id.as_ref()));
if let Some(state_key) = &pdu.state_key {
let shortstatekey = self
.services
@@ -575,9 +572,6 @@ impl Service {
trace!(%event_id, "Adding PDU as an outlier from send_join auth_chain");
self.services.outlier.add_pdu_outlier(&event_id, &value);
self.services.pdu_metadata.clear_pdu_markers(&event_id);
self.services
.pdu_metadata
.mark_as_referenced(room_id, once(event_id.as_ref()));
let state_key = value
.get("state_key")
.and_then(|s| s.as_str())
@@ -662,9 +656,10 @@ impl Service {
.await?;
debug!("Forcing state for new room");
let state_lock = self.services.state.mutex.lock(room_id).await;
self.services
.state
.force_state(room_id, statehash_before_join, added, removed, state_lock)
.force_state(room_id, statehash_before_join, added, removed, &state_lock)
.await?;
debug!("Updating joined counts for new room");
@@ -673,6 +668,10 @@ impl Service {
// We append to state before appending the pdu, so we don't have a
// moment in time with the pdu without it's state. This is okay
// because append_pdu can't fail.
self.services
.timeline
.progress_extremities(&parsed_join_pdu)
.await?;
let statehash_after_join = self
.services
.state
@@ -682,14 +681,8 @@ impl Service {
info!("Appending new room join event");
self.services
.timeline
.append_pdu(
&parsed_join_pdu,
join_event,
once(parsed_join_pdu.event_id.as_ref()),
state_lock,
room_id,
)
.await?;
.append_pdu(&parsed_join_pdu, join_event, room_id)
.await;
self.services
.metadata
.maybe_set_mindepth(room_id, parsed_join_pdu.depth.into())
@@ -701,7 +694,7 @@ impl Service {
// exist
self.services
.state
.set_room_state(room_id, statehash_after_join, state_lock);
.set_room_state(room_id, statehash_after_join, &state_lock);
if !resident_before {
// NOTE: We replace local extremities for this room if we were not a
// resident before. We might be doing a remote join to satisfy
@@ -711,7 +704,11 @@ impl Service {
info!("Replacing local forward extremities");
self.services
.state
.set_forward_extremities(room_id, once(parsed_join_pdu.event_id()), state_lock)
.replace_forward_extremities(
room_id,
once(parsed_join_pdu.event_id()),
&state_lock,
)
.await;
}
drop(cork);
@@ -904,7 +901,7 @@ impl Service {
.server_in_room(self.services.globals.server_name(), condition_room)
.await
{
let is_joined = match entity {
let is_joined_to_condition_room = match entity {
| JoinConditionEntity::User(user_id) =>
self.services
.state_cache
@@ -913,11 +910,11 @@ impl Service {
| JoinConditionEntity::Server(server) =>
self.services
.state_cache
.server_in_room(server, room_id)
.server_in_room(server, condition_room)
.await,
};
if is_joined {
if is_joined_to_condition_room {
debug!(
?entity,
?room_id,
+1 -19
View File
@@ -12,7 +12,7 @@ use conduwuit::{
};
use database::Map;
use futures::{Stream, StreamExt};
use ruma::{EventId, RoomId, UserId, api::Direction};
use ruma::{EventId, UserId, api::Direction};
use crate::{
Dep,
@@ -25,7 +25,6 @@ use crate::{
pub(super) struct Data {
tofrom_relation: Arc<Map>,
referencedevents: Arc<Map>,
softfailedeventids: Arc<Map>,
rejectedeventids: Arc<Map>,
services: Services,
@@ -40,7 +39,6 @@ impl Data {
let db = &args.db;
Self {
tofrom_relation: db["tofrom_relation"].clone(),
referencedevents: db["referencedevents"].clone(),
softfailedeventids: db["softfailedeventids"].clone(),
rejectedeventids: db["rejectedeventids"].clone(),
services: Services {
@@ -106,22 +104,6 @@ impl Data {
})
}
#[inline]
pub(super) fn mark_as_referenced<'a, I>(&self, room_id: &RoomId, event_ids: I)
where
I: Iterator<Item = &'a EventId>,
{
for prev in event_ids {
let key = (room_id, prev);
self.referencedevents.put_raw(key, []);
}
}
pub(super) async fn is_event_referenced(&self, room_id: &RoomId, event_id: &EventId) -> bool {
let key = (room_id, event_id);
self.referencedevents.qry(&key).await.is_ok()
}
pub(super) fn mark_event_soft_failed(&self, event_id: &EventId) {
self.softfailedeventids.insert(event_id, []);
}
-14
View File
@@ -115,20 +115,6 @@ impl Service {
pdus
}
#[tracing::instrument(skip_all, level = "debug")]
pub fn mark_as_referenced<'a, I>(&self, room_id: &RoomId, event_ids: I)
where
I: Iterator<Item = &'a EventId>,
{
self.db.mark_as_referenced(room_id, event_ids);
}
#[inline]
#[tracing::instrument(skip(self), level = "debug")]
pub async fn is_event_referenced(&self, room_id: &RoomId, event_id: &EventId) -> bool {
self.db.is_event_referenced(room_id, event_id).await
}
#[inline]
#[tracing::instrument(skip(self), level = "debug")]
pub fn mark_event_soft_failed(&self, event_id: &EventId) {
Loaded 100 of 129 files, more files were not shown because too many files have changed in this diff. Show more