From 9644b99247f5bf770e83d61d186315588372e408 Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Fri, 23 Oct 2026 23:35:15 +0530 Subject: [PATCH] rtc: log the API key that issued the join token (#5050) Thread the issuing API key from the /rtc join path to the media node via StartSession, and include it in the "starting RTC session" log and the twirp API-request log, so participant activity can be correlated with the key. Logs the key id only, never the secret. Co-authored-by: Claude Opus 4.8 --- go.mod | 4 ++-- go.sum | 4 ++-- pkg/routing/interfaces.go | 3 +++ pkg/service/roommanager.go | 1 + pkg/service/rtcservice.go | 1 + pkg/service/twirp.go | 4 ++++ pkg/service/whipservice.go | 1 + 7 files changed, 14 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 8b8a1e78b..5b93017e4 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/jxskiss/base62 v1.1.0 github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731 github.com/livekit/mediatransportutil v0.0.0-20261014192331-dd8e31a0adc0 - github.com/livekit/protocol v1.53.1-0.20261021070436-f09f87aab29b + github.com/livekit/protocol v1.53.1-0.20261023175527-46332a036e25 github.com/livekit/psrpc v0.8.2 github.com/mackerelio/go-osstat v0.2.8 github.com/magefile/mage v1.17.2 @@ -143,7 +143,7 @@ require ( github.com/pion/srtp/v3 v3.0.13 // indirect github.com/pion/stun/v3 v3.1.7 github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect - github.com/prometheus/client_model v0.6.3 // indirect + github.com/prometheus/client_model v0.6.3 github.com/prometheus/common v0.72.0 // indirect github.com/prometheus/procfs v0.22.0 // indirect github.com/urfave/cli/v3 v3.11.0 diff --git a/go.sum b/go.sum index a02bbe501..2cd875cd8 100644 --- a/go.sum +++ b/go.sum @@ -166,8 +166,8 @@ github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731 h1:9x+U2HGLrSw5AT github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ= github.com/livekit/mediatransportutil v0.0.0-20261014192331-dd8e31a0adc0 h1:BSLyHr3Lsl71bHGHsfiYNmbohugR2yoaf9HjAZeFJnc= github.com/livekit/mediatransportutil v0.0.0-20261014192331-dd8e31a0adc0/go.mod h1:o8CFmAdrVwzJNOCsQCLUzXRjokkufNshnQHOe4fRaqU= -github.com/livekit/protocol v1.53.1-0.20261021070436-f09f87aab29b h1:SrvXlVsWYxgdk6VRasJ9HCHFE+psFf17jQwriLBArgY= -github.com/livekit/protocol v1.53.1-0.20261021070436-f09f87aab29b/go.mod h1:kUTAI2TrTngGOiWP6MTAOkJpru6YYGd0MP9wzlDATy4= +github.com/livekit/protocol v1.53.1-0.20261023175527-46332a036e25 h1:v9UMGn8kGnrs0gja5795d8RBCQqKCVlXVeH14UDiuwc= +github.com/livekit/protocol v1.53.1-0.20261023175527-46332a036e25/go.mod h1:h9P4KCc3K715NCgCrkkFsb8/RRY1kKqOS1EIHUNRlCk= github.com/livekit/psrpc v0.8.2 h1:7tbkhBJoYlK5Csfkdv1XYbZjyAQeaEZgupvIXNCv7Dc= github.com/livekit/psrpc v0.8.2/go.mod h1:6KnU8vULoizX0Er9NNfeKJDV8ug87j3fuo19M0bhj6Q= github.com/livekit/webrtc-pion/v4 v4.2.18-warp.7 h1:I1UkbeJI5V6slqLmef0JoaGF8wPnFsKzzXGUzz4KDvs= diff --git a/pkg/routing/interfaces.go b/pkg/routing/interfaces.go index 08395efa0..8cf66b9ba 100644 --- a/pkg/routing/interfaces.go +++ b/pkg/routing/interfaces.go @@ -193,6 +193,7 @@ type ParticipantInit struct { AutoSubscribeDataTrack *bool Client *livekit.ClientInfo Grants *auth.ClaimGrants + APIKey string TokenExpiresAt time.Time Region string AdaptiveStream bool @@ -263,6 +264,7 @@ func (pi *ParticipantInit) ToStartSession(roomName livekit.RoomName, connectionI AutoSubscribe: pi.AutoSubscribe, Client: pi.Client, GrantsJson: string(claims), + ApiKey: pi.APIKey, TokenExpiresAt: tokenExpiresAt, AdaptiveStream: pi.AdaptiveStream, ParticipantId: string(pi.ID), @@ -303,6 +305,7 @@ func ParticipantInitFromStartSession(ss *livekit.StartSession, region string) (* Client: ss.Client, AutoSubscribe: ss.AutoSubscribe, Grants: claims, + APIKey: ss.ApiKey, TokenExpiresAt: tokenExpiresAt, Region: region, AdaptiveStream: ss.AdaptiveStream, diff --git a/pkg/service/roommanager.go b/pkg/service/roommanager.go index 59a0d9888..6a70c6b11 100644 --- a/pkg/service/roommanager.go +++ b/pkg/service/roommanager.go @@ -439,6 +439,7 @@ func (r *RoomManager) StartSession( "nodeID", r.currentNode.NodeID(), "numParticipants", room.GetParticipantCount(), "participantInit", &pi, + "apiKey", pi.APIKey, ) clientConf := r.clientConfManager.GetConfiguration(pi.Client) diff --git a/pkg/service/rtcservice.go b/pkg/service/rtcservice.go index bff1151d7..6ec8b62be 100644 --- a/pkg/service/rtcservice.go +++ b/pkg/service/rtcservice.go @@ -229,6 +229,7 @@ func (s *RTCService) validateInternal( Identity: livekit.ParticipantIdentity(res.grants.Identity), Name: livekit.ParticipantName(res.grants.Name), Grants: res.grants, + APIKey: GetAPIKey(r.Context()), TokenExpiresAt: res.tokenExpiresAt, Region: res.region, CreateRoom: res.createRoomRequest, diff --git a/pkg/service/twirp.go b/pkg/service/twirp.go index 030659144..f3db8738b 100644 --- a/pkg/service/twirp.go +++ b/pkg/service/twirp.go @@ -104,6 +104,10 @@ func loggerRequestReceived(ctx context.Context, twirpLoggerPool *sync.Pool) (con r.fields = append(r.fields, "service", svc) } + if apiKey := GetAPIKey(ctx); apiKey != "" { + r.fields = append(r.fields, "apiKey", apiKey) + } + return context.WithValue(ctx, twirpLoggerKey{}, r), nil } diff --git a/pkg/service/whipservice.go b/pkg/service/whipservice.go index b2d5d7f7a..5faca930a 100644 --- a/pkg/service/whipservice.go +++ b/pkg/service/whipservice.go @@ -188,6 +188,7 @@ func (s *WHIPService) validateCreate(w http.ResponseWriter, r *http.Request) (*c AutoSubscribe: true, Client: ci, Grants: claims, + APIKey: GetAPIKey(r.Context()), CreateRoom: &livekit.CreateRoomRequest{ Name: string(roomName), RoomPreset: claims.RoomPreset,