Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
74221bd
add new ENV variable LIVEKIT_LOCAL_HOMESERVERS to allow different han…
fkwp Feb 26, 2025
c7ca2ef
local/remote user detection
fkwp Feb 26, 2025
7251eb4
use is_local_user information to issue the JWT token
fkwp Feb 26, 2025
44a3449
Create LiveKit room on the SFU in case of a local user prior to issui…
fkwp Feb 26, 2025
b914daa
add documentation for LIVEKIT_LOCAL_HOMESERVER feature
fkwp Feb 26, 2025
b3f2a32
add server sdk lib
fkwp Feb 26, 2025
b306e12
added test case for LIVEKIT_LOCAL_HOMESERVER
fkwp Feb 26, 2025
9e214f4
more idomatic variable nameing
fkwp Mar 12, 2025
8f4be24
irgnore build artifact
fkwp Apr 2, 2025
76a2ecc
readd add server sdk lib -- was lost during rebasing
fkwp Apr 2, 2025
d0a554d
readd test TestReadKeySecret
fkwp Apr 2, 2025
56e20c5
correct variable name to not confuse OpenID bearer tokens with OIDC
fkwp Apr 2, 2025
8ef5431
linting
fkwp Apr 2, 2025
cc057a3
Merge branch 'main' into fkwp/add_different_permissions
fkwp Apr 4, 2025
4135b2d
more idomatic variable nameing
fkwp Apr 8, 2025
590b6ff
Merge branch 'main' into fkwp/add_different_permissions
fkwp May 15, 2025
41b4ec0
Rename isLocalUser related variables into fullAccessUser semantic
fkwp Jul 24, 2025
d366e0b
update deps
fkwp Jul 24, 2025
a1d3295
Merge branch 'main' into fkwp/add_different_permissions
fkwp Jul 24, 2025
d485a85
Refactor access control logic to use isFullAccessUser method and upda…
fkwp Jul 24, 2025
52fb03b
Support full access via wildcard for all homeservers
fkwp Jul 24, 2025
be8d0b2
make the wildcard '*' the default of LIVEKIT_FULL_ACCESS_HOMESERVERS …
fkwp Jul 24, 2025
9282124
More ideomatic order for if functions in main.go
fkwp Jul 24, 2025
c280b23
Remove differentiation between restircted and isFullAccessUser from g…
fkwp Jul 24, 2025
ff1502b
Infer from timestamps if the LiveKit room has actually been created a…
fkwp Jul 24, 2025
3d51622
rewording
fkwp Jul 24, 2025
8cfc4db
update LIVEKIT_FULL_ACCESS_HOMESERVERS readme description reflecting …
fkwp Jul 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.vscode
lk-jwt-service
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# LiveKit Token Management Service

This service is currently used for a single reason: generate JWT tokens with a given identity for a given room, so that users can use them to authenticate against LiveKit SFU.
This service is used for two reasons:
- generate JWT tokens with a given LiveKit identity for a given LiveKit room, so that users can use them to authenticate against LiveKit SFU,
- In case of local Matrix users which belong to the same deployment, the corresponding LiveKit room on the SFU will be created if necessary.

It works by allowing a token obtained via the Matrix Client-Server API [OpenID endpoint](https://spec.matrix.org/v1.13/client-server-api/#openid) to be exchanged for a LiveKit JWT token which can be used to access a LiveKit SFU.

This functionality is defined by [MSC4195: MatrixRTC using LiveKit backend](https://github.com/matrix-org/matrix-spec-proposals/pull/4195).

Only for Matrix users of homeservers belonging to the same deployment (called local users) corresponding rooms on the LiveKit SFU will be automatically created. Hence, local homeservers need to be declared via the `LIVEKIT_FULL_ACCESS_HOMESERVERS` environment variable (see below).

Note access to LiveKit SFU is restricted for remote users (not belonging to the same deployment). Those users can join existing LiveKit SFU rooms, but missing rooms will not be automatically created to prevent misuse of infrastructure. Due to the SFU selection algorithm and the order of events this will NOT limit or prevent video conferences across Matrix federation.

## Usage

This service is used when hosting the [Element Call](https://github.com/element-hq/element-call) video conferencing application against a LiveKit backend.
Expand Down Expand Up @@ -56,6 +62,13 @@ Variable | Description | Required
`LIVEKIT_SECRET` or `LIVEKIT_SECRET_FROM_FILE` | The secret or secret file path for the LiveKit SFU | Yes
`LIVEKIT_KEY_FILE` | file path to LiveKit SFU key-file format (`APIkey: secret`) | mutually exclusive with `LIVEKIT_KEY` and `LIVEKIT_SECRET`
`LIVEKIT_JWT_PORT` | The port the service listens on | No - defaults to 8080
`LIVEKIT_FULL_ACCESS_HOMESERVERS` | Comma-separated list of Matrix homeservers whose users are authorized with full access to LiveKit SFU features (supports `*` as a wildcard to allow all homeservers) | No - defaults to `*`

Please double check that LiveKit SFU room default settings ([config.yaml](https://github.com/livekit/livekit/blob/7350e9933107ecdea4ada8f8bcb0d6ca78b3f8f7/config-sample.yaml#L170)) are configured as
```
room:
auto_create: false
```

### Reverse Proxy and well-known requirements

Expand Down
18 changes: 12 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ toolchain go1.24.4
require (
github.com/golang-jwt/jwt/v5 v5.2.2
github.com/livekit/protocol v1.34.0
github.com/livekit/server-sdk-go/v2 v2.5.0
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530
github.com/matrix-org/gomatrixserverlib v0.0.0-20250619052822-904c8f04597e
)
Expand All @@ -17,6 +18,7 @@ require (
cel.dev/expr v0.19.0 // indirect
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/bep/debounce v1.2.1 // indirect
github.com/bufbuild/protovalidate-go v0.8.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/dennwc/iters v1.0.1 // indirect
Expand All @@ -26,22 +28,26 @@ require (
github.com/gammazero/deque v1.0.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/google/cel-go v0.22.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/jxskiss/base62 v1.1.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/lithammer/shortuuid/v4 v4.2.0 // indirect
github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 // indirect
github.com/livekit/mediatransportutil v0.0.0-20241220010243-a2bdee945564 // indirect
github.com/livekit/psrpc v0.6.1-0.20250205181828-a0beed2e4126 // indirect
github.com/magefile/mage v1.15.0 // indirect
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 // indirect
github.com/nats-io/nats.go v1.36.0 // indirect
github.com/nats-io/nkeys v0.4.7 // indirect
github.com/nats-io/nats.go v1.38.0 // indirect
github.com/nats-io/nkeys v0.4.9 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/pion/datachannel v1.5.10 // indirect
github.com/pion/dtls/v3 v3.0.4 // indirect
github.com/pion/ice/v4 v4.0.5 // indirect
github.com/pion/ice/v4 v4.0.6 // indirect
github.com/pion/interceptor v0.1.39 // indirect
github.com/pion/logging v0.2.3 // indirect
github.com/pion/mdns/v2 v2.0.7 // indirect
Expand All @@ -54,7 +60,7 @@ require (
github.com/pion/stun/v3 v3.0.0 // indirect
github.com/pion/transport/v3 v3.0.7 // indirect
github.com/pion/turn/v4 v4.0.0 // indirect
github.com/pion/webrtc/v4 v4.0.8 // indirect
github.com/pion/webrtc/v4 v4.0.9 // indirect
github.com/puzpuzpuz/xsync/v3 v3.5.0 // indirect
github.com/redis/go-redis/v9 v9.7.3 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
Expand All @@ -71,7 +77,7 @@ require (
go.uber.org/zap v1.27.0 // indirect
go.uber.org/zap/exp v0.3.0 // indirect
golang.org/x/crypto v0.38.0 // indirect
golang.org/x/exp v0.0.0-20250128182459-e0ece0dbea4c // indirect
golang.org/x/exp v0.0.0-20250207012021-f9890c6ad9f3 // indirect
golang.org/x/net v0.40.0 // indirect
golang.org/x/sync v0.14.0 // indirect
golang.org/x/sys v0.33.0 // indirect
Expand Down
Loading
Loading