Skip to content

Implementation of MSC4195: MatrixRTC Transport using LiveKit Backend - #128

Merged
fkwp merged 27 commits into
mainfrom
fkwp/matrix2
Nov 10, 2025
Merged

Implementation of MSC4195: MatrixRTC Transport using LiveKit Backend#128
fkwp merged 27 commits into
mainfrom
fkwp/matrix2

Conversation

@fkwp

@fkwp fkwp commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

As part of Matrix 2.0 Spec the MatrixRTC Authorization Service implements MSC4195: MatrixRTC Transport using LiveKit Backend

  • According the MSC4195 the JWT request endpoint is now /get_token. For smooth transition we still listen for a transition period to the old endpoint /get/sfu

  • Refactoring of /sfu/get POST request handling to allow different request types

    • Actual processing is carried out by processLegacySFURequest and processSFURequest function and createLivekKitRoom helper function
    • POST request is validated and mapped into LegacySFURequest or SFURequest by mapSFURequest
  • Add new endpoint /get_token using processSFURequest

  • Added tests

    • TestMapSFURequest
    • TestMapSFURequestMemoryLeak
    • TestProcessLegacySFURequest
    • TestProcessSFURequest
    • TestLegacyHandlePost

fkwp added 12 commits October 31, 2025 19:52
…est types:

- split out into two functions
  - processSFURequest: main request handling
  - createLiveKitRoom: utility function which will be used by all different request types
- applying previously added writeMatrixError func
- cache body request for later processing
- add mapSFURequest function to map the request into LegacySFURequest or Matrix2 SFURequest. Including request field validation
@fkwp
fkwp marked this pull request as ready for review November 6, 2025 11:28
@fkwp
fkwp requested a review from a team as a code owner November 6, 2025 11:28
@Half-Shot
Half-Shot requested review from Half-Shot and removed request for BillCarsonFr November 6, 2025 15:27

@Half-Shot Half-Shot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go code looks competent ✨ . My concern is mostly in that we've got and endpoint that takes two different schemas of values, and that puts the overhead on the server to figure out the correct route.

I think we should probably just have a second endpoint, maybe under /v2/ or something that handles the new RTC endpoints. There is a marginal speedup to be had, and we will have an easier time in the client debugging if it's not supported.

Comment thread main.go Outdated
Comment thread main.go Outdated
Comment thread main.go Outdated
Comment thread main.go Outdated
Comment thread main.go Outdated
Comment thread main.go
Comment thread main.go Outdated
Comment thread main.go
Comment thread main.go
Comment thread main_test.go Outdated
@fkwp

fkwp commented Nov 6, 2025

Copy link
Copy Markdown
Contributor Author

Go code looks competent ✨ . My concern is mostly in that we've got and endpoint that takes two different schemas of values, and that puts the overhead on the server to figure out the correct route.

I think we should probably just have a second endpoint, maybe under /v2/ or something that handles the new RTC endpoints. There is a marginal speedup to be had, and we will have an easier time in the client debugging if it's not supported.

My rational was that we will just remove the LegacyRTCRequest at a soon point in time. Otherwise we could also find a better endpoint name for /sfu/get ... what about /sfu/get_token

@Half-Shot

Copy link
Copy Markdown
Member

/sfu/get_token is better, at least it tells me what it does :)

fkwp and others added 3 commits November 7, 2025 12:10
…h transition:

- Allow for a transition period the old endpoint `/get/sfu`
- This old endpoint does auto map according to request type (LegacySFURequest, SFURequest)
- Define related function to 'legacy` and add TODO to remove them in future
- implement the new endpoint `/get_token`
Co-authored-by: Will Hunt <2072976+Half-Shot@users.noreply.github.com>
Co-authored-by: Will Hunt <2072976+Half-Shot@users.noreply.github.com>
fkwp and others added 6 commits November 7, 2025 12:14
Co-authored-by: Will Hunt <2072976+Half-Shot@users.noreply.github.com>
Co-authored-by: Will Hunt <2072976+Half-Shot@users.noreply.github.com>
@fkwp
fkwp requested a review from Half-Shot November 7, 2025 11:58
Half-Shot
Half-Shot previously approved these changes Nov 10, 2025

@Half-Shot Half-Shot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, a few nitpicks here and there.

Comment thread main.go
Comment thread main.go
Comment thread main.go Outdated

@Half-Shot Half-Shot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks beautiful ✔️

@fkwp
fkwp merged commit 6573de0 into main Nov 10, 2025
4 checks passed
@fkwp
fkwp deleted the fkwp/matrix2 branch November 10, 2025 13:50
eleboucher pushed a commit to eleboucher/homelab that referenced this pull request May 15, 2026
…0 → 0.4.4) (#485)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [ghcr.io/element-hq/lk-jwt-service](https://github.com/element-hq/lk-jwt-service) | minor | `0.3.0` → `0.4.4` |

---

### Release Notes

<details>
<summary>element-hq/lk-jwt-service (ghcr.io/element-hq/lk-jwt-service)</summary>

### [`v0.4.4`](https://github.com/element-hq/lk-jwt-service/releases/tag/v0.4.4)

[Compare Source](element-hq/lk-jwt-service@v0.4.3...v0.4.4)

##### Towards Delegation of Delayed Events

This release updates the service to accept the JSON signature required for the delegation of MatrixRTC membership leave events, as specified in [MSC4195](matrix-org/matrix-spec-proposals#4195).

Note: This update specifically addresses the JSON signature for JWT request. Comprehensive parsing and handling of the additional delegation data are currently in development (PR [#&#8203;171](element-hq/lk-jwt-service#171)).

##### Docker image

The service is available as a Docker image from the [GitHub Container Registry](https://github.com/element-hq/lk-jwt-service/pkgs/container/lk-jwt-service).

```
docker pull ghcr.io/element-hq/lk-jwt-service:0.4.4
```

##### Precompiled binaries

The service is available as static precompiled binaries for amd64 and arm64 on linux attached to this release below.

##### What's Changed

- Update Docker image version in installation steps by [@&#8203;her001](https://github.com/her001) in [#&#8203;175](element-hq/lk-jwt-service#175)
- Adapted the lastest JSON signature from MSC4195 for SFURequest by [@&#8203;fkwp](https://github.com/fkwp) in [#&#8203;176](element-hq/lk-jwt-service#176)

##### New Contributors

- [@&#8203;her001](https://github.com/her001) made their first contribution in [#&#8203;175](element-hq/lk-jwt-service#175)

**Full Changelog**: <element-hq/lk-jwt-service@v0.4.3...v0.4.4>

### [`v0.4.3`](https://github.com/element-hq/lk-jwt-service/releases/tag/v0.4.3)

[Compare Source](element-hq/lk-jwt-service@v0.4.2...v0.4.3)

##### Security Update and MSC4195 Identity Alignment

This release introduces important security updates and aligns the LiveKit identity calculation with the latest MSC4195 specification.

##### ⚠️ Breaking Change

The update to the LiveKit Identity hash calculation ([#&#8203;172](element-hq/lk-jwt-service#172)) impacts two experimental modes in Element Call: **Compatibility: state events & multi SFU** and **Matrix 2.0**. Note that by default, these modes are not activated and Element Call will remain working with this release.

For these experimental features to function correctly, the versions of Element Call and the JWT Service must be aligned:

- Compatible: Element Call v0.19.2 or higher AND lk-jwt-service v0.4.3 or higher
- Incompatible:
  - Element Call v0.19.1 or lower AND lk-jwt-service v0.4.3 or higher
  - Element Call v0.19.2 or higher AND lk-jwt-service v0.4.2 or lower

##### Docker image

The service is available as a Docker image from the [GitHub Container Registry](https://github.com/element-hq/lk-jwt-service/pkgs/container/lk-jwt-service).

```
docker pull ghcr.io/element-hq/lk-jwt-service:0.4.3
```

##### Precompiled binaries

The service is available as static precompiled binaries for amd64 and arm64 on linux attached to this release below.

##### What's Changed

- Pin element-hq/setup-ess-cluster-action action to [`aac02ff`](element-hq/lk-jwt-service@aac02ff) by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;169](element-hq/lk-jwt-service#169)
- Update module github.com/go-jose/go-jose/v3 to v3.0.5 \[SECURITY] by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;170](element-hq/lk-jwt-service#170)
- Update all non-major dependencies by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;173](element-hq/lk-jwt-service#173)
- Update softprops/action-gh-release action to v3 by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;174](element-hq/lk-jwt-service#174)
- Adapt LiveKit Identity hash calculation to latest MSC4195 update by [@&#8203;fkwp](https://github.com/fkwp) in [#&#8203;172](element-hq/lk-jwt-service#172)

**Full Changelog**: <element-hq/lk-jwt-service@v0.4.2...v0.4.3>

### [`v0.4.2`](https://github.com/element-hq/lk-jwt-service/releases/tag/v0.4.2)

[Compare Source](element-hq/lk-jwt-service@v0.4.1...v0.4.2)

##### Healthcheck Improvement & Security Updates

This is a minor release focused on maintenance and small improvements.
Highlights:

Added support for the HEAD method on the healthcheck endpoint, improving compatibility with monitoring tools.
Included multiple security-related dependency updates to ensure the service remains up to date and secure.
No breaking changes are introduced in this release.

##### Docker image

The service is available as a Docker image from the [GitHub Container Registry](https://github.com/element-hq/lk-jwt-service/pkgs/container/lk-jwt-service).

```
docker pull ghcr.io/element-hq/lk-jwt-service:0.4.2
```

##### Precompiled binaries

The service is available as static precompiled binaries for amd64 and arm64 on linux attached to this release below.

##### What's Changed

- Consolidate non-major dependency updates into larger batches by [@&#8203;robintown](https://github.com/robintown) in [#&#8203;160](element-hq/lk-jwt-service#160)
- Update module github.com/pion/dtls/v3 to v3.0.11 \[SECURITY] by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;154](element-hq/lk-jwt-service#154)
- Update module google.golang.org/grpc to v1.79.3 \[SECURITY] by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;162](element-hq/lk-jwt-service#162)
- Add tests against ESS by [@&#8203;gaelgatelement](https://github.com/gaelgatelement) in [#&#8203;164](element-hq/lk-jwt-service#164)
- Update all non-major dependencies by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;165](element-hq/lk-jwt-service#165)
- Update github.com/matrix-org/gomatrixserverlib digest to [`20c9de3`](element-hq/lk-jwt-service@20c9de3) by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;134](element-hq/lk-jwt-service#134)
- Allow HEAD method on healthcheck by [@&#8203;VlaDexa](https://github.com/VlaDexa) in [#&#8203;151](element-hq/lk-jwt-service#151)
- Push docker images also to oci.element.io by [@&#8203;fkwp](https://github.com/fkwp) in [#&#8203;166](element-hq/lk-jwt-service#166)
- Update all non-major dependencies by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;167](element-hq/lk-jwt-service#167)
- Update GitHub Actions (major) by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;168](element-hq/lk-jwt-service#168)

##### New Contributors

- [@&#8203;VlaDexa](https://github.com/VlaDexa) made their first contribution in [#&#8203;151](element-hq/lk-jwt-service#151)

**Full Changelog**: <element-hq/lk-jwt-service@v0.4.1...v0.4.2>

### [`v0.4.1`](https://github.com/element-hq/lk-jwt-service/releases/tag/v0.4.1)

[Compare Source](element-hq/lk-jwt-service@v0.4.0...v0.4.1)

##### 🚀 Cont. Towards Matrix 2.0 – MatrixRTC-Authorisation Service

This release is a minor update from 0.4.0 reflecting the lastest changes in **MSC4195: MatrixRTC Transport** which adds unpadded base64 encoding to hashes for room alias and participant ID.

Furthermore, this release ensures compatibility between clients using the old `/sfu/get` endpoint and the new `/get_token` endpoint (details are [here](https://github.com/element-hq/lk-jwt-service/blob/fa226031ac7a9252996f8d038c45fc086d9d960b/main.go#L230)).

##### Docker image

The service is available as a Docker image from the [GitHub Container Registry](https://github.com/element-hq/lk-jwt-service/pkgs/container/lk-jwt-service).

```
docker pull ghcr.io/element-hq/lk-jwt-service:0.4.1
```

##### Precompiled binaries

The service is available as static precompiled binaries for amd64 and arm64 on linux attached to this release below.

##### What's Changed

- README: Use LIVEKIT\_FULL\_ACCESS\_HOMESERVERS consistently by [@&#8203;csett86](https://github.com/csett86) in [#&#8203;140](element-hq/lk-jwt-service#140)
- README: Describe the static binaries by [@&#8203;csett86](https://github.com/csett86) in [#&#8203;141](element-hq/lk-jwt-service#141)
- refactor build.yaml into reusable chunks  by [@&#8203;fkwp](https://github.com/fkwp) in [#&#8203;142](element-hq/lk-jwt-service#142)
- fix build.yaml date determination by [@&#8203;fkwp](https://github.com/fkwp) in [#&#8203;143](element-hq/lk-jwt-service#143)
- Use base64 encoded hashes for room alias and participant ID (minimize identifying metadata sent to SFU) by [@&#8203;robintown](https://github.com/robintown) in [#&#8203;144](element-hq/lk-jwt-service#144)
- Add 'synchronize' and 'opened' types to PR trigger by [@&#8203;fkwp](https://github.com/fkwp) in [#&#8203;146](element-hq/lk-jwt-service#146)
- Update room alias handling in token generation for LegacySfuRequest by [@&#8203;fkwp](https://github.com/fkwp) in [#&#8203;147](element-hq/lk-jwt-service#147)

##### New Contributors

- [@&#8203;robintown](https://github.com/robintown) made their first contribution in [#&#8203;144](element-hq/lk-jwt-service#144)

**Full Changelog**: <element-hq/lk-jwt-service@v0.4.0...v0.4.1>

### [`v0.4.0`](https://github.com/element-hq/lk-jwt-service/releases/tag/v0.4.0)

[Compare Source](element-hq/lk-jwt-service@v0.3.0...v0.4.0)

##### 🚀 Towards Matrix 2.0 – MatrixRTC-Authorisation Service

This release brings major foundational work towards **MSC4195: MatrixRTC Transport**, introduces the new `/get_token` endpoint, improves validation and error-handling, and enhances deployment flexibility with improved bind controls.

##### ✨ What's New

##### **Implementation of MSC4195: MatrixRTC Transport using LiveKit Backend**

This release introduces the new MSC4195-compliant request flow and `/get_token` endpoint, while keeping `/get/sfu` available for a transition period.

Key changes:

- Added unified error handling via `writeMatrixError`.
- Introduced new Matrix 2.0 `SFURequest` type, alongside `LegacySFURequest`.
- Refactored internal functions for better testability and structure.
- Added extensive new tests across request mapping, processing, and JSON handling.
- Updated logging, error codes, and user-identity checks.

##### **🔌 Allow Binding of Arbitrary Addresses**

This release improves deployment flexibility by allowing the service to bind to any or a specific address.

##### Features & Fixes

- **feat:** Introduced support for binding to arbitrary addresses.\
  *Contributed by [@&#8203;matdup](https://github.com/matdup)*
- **fix:** Documentation updated for environment variable changes.
- **feat:** Reintroduced `LIVEKIT_JWT_PORT` for backward compatibility.
  - Now mutually exclusive with `LIVEKIT_JWT_BIND`.
  - Emits a warning when used.
- **feat:** Enforced mutual exclusivity between `LIVEKIT_JWT_BIND` and `LIVEKIT_JWT_PORT`.

##### ⚙️ Configuration

##### Environment Variables

| Variable           | Description                                                                           |
| ------------------ | ------------------------------------------------------------------------------------- |
| `LIVEKIT_JWT_BIND` | Binds the service to a specific host:port (new preferred method). Defaults to `:8080` |
| `LIVEKIT_JWT_PORT` | Deprecated but still supported. Mutually exclusive with `LIVEKIT_JWT_BIND`.           |

##### Endpoint Changes

| Endpoint     | Status                    | Notes                                                         |
| ------------ | ------------------------- | ------------------------------------------------------------- |
| `/get_token` | **New (Primary)**         | Conforms to MSC4195.                                          |
| `/get/sfu`   | **Legacy (Transitional)** | Auto-maps request types; will be removed in a future release. |

##### 🤝 Client Compatibility

- Legacy MatrixRTC clients continue functioning via `/sfu/get`.
- MSC4195-aware clients should migrate to **`/get_token`**.
- Both request formats remain supported during the transition.
- Stricter validation may require client-side updates:
  - Correct request field shapes
  - Accurate user identity claims (`claimed_user_id` vs OpenID `sub`)

##### Docker image

The service is available as a Docker image from the [GitHub Container Registry](https://github.com/element-hq/lk-jwt-service/pkgs/container/lk-jwt-service).

```
docker pull ghcr.io/element-hq/lk-jwt-service:0.4.0
```

##### Precompiled binaries

The service is available as static precompiled binaries for amd64 and arm64 on linux attached to this release below.

##### What's Changed

- ci: add static go releases for linux arm64 and amd64 by [@&#8203;csett86](https://github.com/csett86) in [#&#8203;111](element-hq/lk-jwt-service#111)
- fix(deps): update github.com/matrix-org/gomatrixserverlib digest to [`a234d6d`](element-hq/lk-jwt-service@a234d6d) by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;113](element-hq/lk-jwt-service#113)
- chore(deps): update dependency go to v1.24.5 by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;114](element-hq/lk-jwt-service#114)
- refactor README.md by [@&#8203;fkwp](https://github.com/fkwp) in [#&#8203;115](element-hq/lk-jwt-service#115)
- feat: allow binding of arbitrary addresses by [@&#8203;MatthieuCoder](https://github.com/MatthieuCoder) in [#&#8203;118](element-hq/lk-jwt-service#118)
- fix(deps): update github.com/matrix-org/gomatrixserverlib digest to [`6697d93`](element-hq/lk-jwt-service@6697d93) by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;120](element-hq/lk-jwt-service#120)
- chore(deps): update dependency go to v1.25.3 by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;121](element-hq/lk-jwt-service#121)
- Refactor config parsing by [@&#8203;fkwp](https://github.com/fkwp) in [#&#8203;125](element-hq/lk-jwt-service#125)
- fix(deps): update module github.com/golang-jwt/jwt/v5 to v5.3.0 by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;127](element-hq/lk-jwt-service#127)
- chore(deps): update github actions by [@&#8203;renovate](https://github.com/renovate)\[bot] in [#&#8203;126](element-hq/lk-jwt-service#126)
- Implementation of MSC4195: MatrixRTC Transport using LiveKit Backend by [@&#8203;fkwp](https://github.com/fkwp) in [#&#8203;128](element-hq/lk-jwt-service#128)
- fix: add `expires_in` field to `OpenIDTokenType` by [@&#8203;fkwp](https://github.com/fkwp) in [#&#8203;130](element-hq/lk-jwt-service#130)

##### New Contributors

- [@&#8203;csett86](https://github.com/csett86) made their first contribution in [#&#8203;111](element-hq/lk-jwt-service#111)
- [@&#8203;MatthieuCoder](https://github.com/MatthieuCoder) made their first contribution in [#&#8203;118](element-hq/lk-jwt-service#118)

**Full Changelog**: <element-hq/lk-jwt-service@v0.3.0...v0.4.0>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xMDEuMSIsInVwZGF0ZWRJblZlciI6IjQzLjEwMS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9jb250YWluZXIiLCJ0eXBlL21pbm9yIl19-->

Reviewed-on: https://git.erwanleboucher.dev/eleboucher/homelab/pulls/485
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants