From a86ff7928c8843915a1cb9189cd53b7ca6f1f101 Mon Sep 17 00:00:00 2001 From: Paul Wells Date: Sun, 21 Dec 2025 16:12:20 -0800 Subject: [PATCH 1/2] redact metadata in agent protos (#1344) * redact metadata in agent protos * Create loud-flowers-sing.md * generated protobuf --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> --- .changeset/loud-flowers-sing.md | 5 +++ livekit/livekit_agent_dispatch.pb.go | 17 +++---- livekit/livekit_agent_dispatch.twirp.go | 60 +++++++++++++------------ protobufs/livekit_agent_dispatch.proto | 9 ++-- 4 files changed, 50 insertions(+), 41 deletions(-) create mode 100644 .changeset/loud-flowers-sing.md diff --git a/.changeset/loud-flowers-sing.md b/.changeset/loud-flowers-sing.md new file mode 100644 index 000000000..88cb7bea3 --- /dev/null +++ b/.changeset/loud-flowers-sing.md @@ -0,0 +1,5 @@ +--- +"@livekit/protocol": patch +--- + +redact metadata in agent protos diff --git a/livekit/livekit_agent_dispatch.pb.go b/livekit/livekit_agent_dispatch.pb.go index d9335f651..377f518c1 100644 --- a/livekit/livekit_agent_dispatch.pb.go +++ b/livekit/livekit_agent_dispatch.pb.go @@ -21,6 +21,7 @@ package livekit import ( + _ "github.com/livekit/protocol/livekit/logger" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -437,16 +438,16 @@ var File_livekit_agent_dispatch_proto protoreflect.FileDescriptor const file_livekit_agent_dispatch_proto_rawDesc = "" + "\n" + - "\x1clivekit_agent_dispatch.proto\x12\alivekit\x1a\x13livekit_agent.proto\"k\n" + + "\x1clivekit_agent_dispatch.proto\x12\alivekit\x1a\x13livekit_agent.proto\x1a\x14logger/options.proto\"q\n" + "\x1aCreateAgentDispatchRequest\x12\x1d\n" + "\n" + "agent_name\x18\x01 \x01(\tR\tagentName\x12\x12\n" + - "\x04room\x18\x02 \x01(\tR\x04room\x12\x1a\n" + - "\bmetadata\x18\x03 \x01(\tR\bmetadata\"N\n" + + "\x04room\x18\x02 \x01(\tR\x04room\x12 \n" + + "\bmetadata\x18\x03 \x01(\tB\x04\x88\xb5\x18\x01R\bmetadata\"T\n" + "\x11RoomAgentDispatch\x12\x1d\n" + "\n" + - "agent_name\x18\x01 \x01(\tR\tagentName\x12\x1a\n" + - "\bmetadata\x18\x02 \x01(\tR\bmetadata\"Q\n" + + "agent_name\x18\x01 \x01(\tR\tagentName\x12 \n" + + "\bmetadata\x18\x02 \x01(\tB\x04\x88\xb5\x18\x01R\bmetadata\"Q\n" + "\x1aDeleteAgentDispatchRequest\x12\x1f\n" + "\vdispatch_id\x18\x01 \x01(\tR\n" + "dispatchId\x12\x12\n" + @@ -456,13 +457,13 @@ const file_livekit_agent_dispatch_proto_rawDesc = "" + "dispatchId\x12\x12\n" + "\x04room\x18\x02 \x01(\tR\x04room\"^\n" + "\x19ListAgentDispatchResponse\x12A\n" + - "\x10agent_dispatches\x18\x01 \x03(\v2\x16.livekit.AgentDispatchR\x0fagentDispatches\"\xa1\x01\n" + + "\x10agent_dispatches\x18\x01 \x03(\v2\x16.livekit.AgentDispatchR\x0fagentDispatches\"\xa7\x01\n" + "\rAgentDispatch\x12\x0e\n" + "\x02id\x18\x01 \x01(\tR\x02id\x12\x1d\n" + "\n" + "agent_name\x18\x02 \x01(\tR\tagentName\x12\x12\n" + - "\x04room\x18\x03 \x01(\tR\x04room\x12\x1a\n" + - "\bmetadata\x18\x04 \x01(\tR\bmetadata\x121\n" + + "\x04room\x18\x03 \x01(\tR\x04room\x12 \n" + + "\bmetadata\x18\x04 \x01(\tB\x04\x88\xb5\x18\x01R\bmetadata\x121\n" + "\x05state\x18\x05 \x01(\v2\x1b.livekit.AgentDispatchStateR\x05state\"t\n" + "\x12AgentDispatchState\x12 \n" + "\x04jobs\x18\x01 \x03(\v2\f.livekit.JobR\x04jobs\x12\x1d\n" + diff --git a/livekit/livekit_agent_dispatch.twirp.go b/livekit/livekit_agent_dispatch.twirp.go index 93a9e9337..bf283930b 100644 --- a/livekit/livekit_agent_dispatch.twirp.go +++ b/livekit/livekit_agent_dispatch.twirp.go @@ -1645,33 +1645,35 @@ func callClientError(ctx context.Context, h *twirp.ClientHooks, err twirp.Error) } var twirpFileDescriptor0 = []byte{ - // 444 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xc1, 0x6e, 0xd3, 0x40, - 0x10, 0x95, 0xd7, 0x29, 0x90, 0x49, 0x1b, 0x60, 0x41, 0xc8, 0x18, 0x10, 0xc1, 0xbd, 0xe4, 0xe4, - 0x8a, 0x70, 0xeb, 0x2d, 0x50, 0x21, 0x01, 0xa5, 0x80, 0x11, 0x17, 0x0e, 0x58, 0x6b, 0x7b, 0xd4, - 0x2e, 0x8d, 0xb3, 0xc1, 0x3b, 0xcd, 0x4f, 0xf0, 0x15, 0x5c, 0xf9, 0x34, 0xbe, 0x02, 0x79, 0xbd, - 0xb6, 0xea, 0xe2, 0x85, 0x0b, 0x37, 0xcf, 0x7b, 0x33, 0x6f, 0xc6, 0x33, 0xcf, 0x86, 0x87, 0x2b, - 0xb9, 0xc5, 0x73, 0x49, 0xa9, 0x38, 0xc5, 0x35, 0xa5, 0x85, 0xd4, 0x1b, 0x41, 0xf9, 0x59, 0xbc, - 0xa9, 0x14, 0x29, 0x7e, 0xdd, 0xb2, 0xe1, 0x9d, 0x5e, 0x5a, 0xc3, 0x46, 0xe7, 0x10, 0xbe, 0xa8, - 0x50, 0x10, 0x2e, 0x6b, 0xf0, 0xc8, 0x96, 0x26, 0xf8, 0xed, 0x02, 0x35, 0xf1, 0x47, 0x00, 0x8d, - 0xe6, 0x5a, 0x94, 0x18, 0x78, 0x33, 0x6f, 0x3e, 0x4e, 0xc6, 0x06, 0x39, 0x11, 0x25, 0x72, 0x0e, - 0xa3, 0x4a, 0xa9, 0x32, 0x60, 0x86, 0x30, 0xcf, 0x3c, 0x84, 0x1b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xbf, 0x2d, 0x56, 0x5b, 0x99, 0x23, 0x7f, 0x0b, 0xd3, 0xc6, 0xf3, 0xdd, 0xca, 0xf6, 0xbb, 0xe6, - 0xee, 0x8f, 0x21, 0x74, 0x9c, 0xa4, 0x96, 0x6b, 0x5c, 0x38, 0x20, 0xe7, 0xb6, 0xa7, 0x53, 0xee, - 0x13, 0xec, 0xd6, 0x86, 0xe9, 0xe2, 0x27, 0x5d, 0x9e, 0xcb, 0x98, 0x61, 0xf4, 0xb7, 0x94, 0xc6, - 0x6a, 0xcf, 0x5f, 0x7e, 0xde, 0x3f, 0x95, 0x74, 0x76, 0x91, 0xc5, 0xb9, 0x2a, 0x0f, 0x6c, 0xfe, - 0x81, 0xf9, 0x09, 0xe4, 0x6a, 0xd5, 0x02, 0x3f, 0xd9, 0xde, 0xb1, 0xdc, 0xe2, 0x1b, 0x49, 0xf1, - 0xfb, 0x9a, 0xfa, 0xc5, 0xa6, 0x36, 0x3e, 0x3c, 0x34, 0x40, 0x76, 0xcd, 0x94, 0x3c, 0xfb, 0x1d, - 0x00, 0x00, 0xff, 0xff, 0x1d, 0x81, 0xd0, 0xbf, 0x75, 0x04, 0x00, 0x00, + // 468 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x4d, 0x6f, 0xd3, 0x40, + 0x10, 0x95, 0xed, 0x14, 0xc8, 0xa4, 0x0d, 0xb0, 0x54, 0xc8, 0x18, 0x10, 0xc6, 0xbd, 0xe4, 0xe4, + 0x88, 0x70, 0xeb, 0x2d, 0xa5, 0x42, 0x02, 0xca, 0x97, 0x81, 0x0b, 0x07, 0xa2, 0x8d, 0x3d, 0x4a, + 0x17, 0xe2, 0x6c, 0xea, 0x9d, 0xe6, 0x37, 0x20, 0xf1, 0x43, 0x90, 0xb8, 0xf3, 0xa7, 0xf8, 0x15, + 0xc8, 0xbb, 0x1b, 0xab, 0x06, 0x2f, 0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0xf7, 0x4e, 0xc4, 0x06, 0x5f, 0x08, 0x4a, 0xdf, 0xd4, 0xd4, 0x2f, 0x7f, 0x68, 0xcf, 0x87, 0x87, + 0x1a, 0x98, 0x5f, 0xd1, 0x9f, 0x3c, 0xfe, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x73, 0x73, 0x4a, 0xcb, + 0x9d, 0x04, 0x00, 0x00, } diff --git a/protobufs/livekit_agent_dispatch.proto b/protobufs/livekit_agent_dispatch.proto index 212843e7b..e40aaac8e 100644 --- a/protobufs/livekit_agent_dispatch.proto +++ b/protobufs/livekit_agent_dispatch.proto @@ -20,6 +20,7 @@ option csharp_namespace = "LiveKit.Proto"; option ruby_package = "LiveKit::Proto"; import "livekit_agent.proto"; +import "logger/options.proto"; service AgentDispatchService { rpc CreateDispatch(CreateAgentDispatchRequest) returns (AgentDispatch); @@ -30,12 +31,12 @@ service AgentDispatchService { message CreateAgentDispatchRequest { string agent_name = 1; string room = 2; - string metadata = 3; + string metadata = 3 [(logger.redact) = true]; } message RoomAgentDispatch { string agent_name = 1; - string metadata = 2; + string metadata = 2 [(logger.redact) = true]; } message DeleteAgentDispatchRequest { @@ -56,12 +57,12 @@ message AgentDispatch { string id = 1; string agent_name = 2; string room = 3; - string metadata = 4; + string metadata = 4 [(logger.redact) = true]; AgentDispatchState state = 5; } message AgentDispatchState { - // For dispatches of tyoe JT_ROOM, there will be at most 1 job. + // For dispatches of tyoe JT_ROOM, there will be at most 1 job. // For dispatches of type JT_PUBLISHER, there will be 1 per publisher. repeated Job jobs = 1; int64 created_at = 2; From 17875e94bb49c43d1f3fc16855c9073a449673e8 Mon Sep 17 00:00:00 2001 From: cnderrauber Date: Mon, 22 Dec 2025 11:19:42 +0800 Subject: [PATCH 2/2] Verify nbf (#1345) * return jwt.Claims when Verify token * fix test --- auth/accesstoken_test.go | 2 +- auth/verifier.go | 10 +++++----- auth/verifier_test.go | 12 ++++++------ livekit/types.go | 3 +++ webhook/verifier.go | 2 +- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/auth/accesstoken_test.go b/auth/accesstoken_test.go index d6255d67f..372a70fde 100644 --- a/auth/accesstoken_test.go +++ b/auth/accesstoken_test.go @@ -218,7 +218,7 @@ func TestAccessToken(t *testing.T) { v, err := ParseAPIToken(value) require.NoError(t, err) - claims, err := v.Verify(secret) + _, claims, err := v.Verify(secret) require.NoError(t, err) rc := (*livekit.RoomConfiguration)(claims.RoomConfig) diff --git a/auth/verifier.go b/auth/verifier.go index 715a5f4ed..bcaa22bff 100644 --- a/auth/verifier.go +++ b/auth/verifier.go @@ -58,9 +58,9 @@ func (v *APIKeyTokenVerifier) Identity() string { return v.identity } -func (v *APIKeyTokenVerifier) Verify(key interface{}) (*ClaimGrants, error) { +func (v *APIKeyTokenVerifier) Verify(key interface{}) (*jwt.Claims, *ClaimGrants, error) { if key == nil || key == "" { - return nil, ErrKeysMissing + return nil, nil, ErrKeysMissing } if s, ok := key.(string); ok { key = []byte(s) @@ -68,13 +68,13 @@ func (v *APIKeyTokenVerifier) Verify(key interface{}) (*ClaimGrants, error) { out := jwt.Claims{} claims := ClaimGrants{} if err := v.token.Claims(key, &out, &claims); err != nil { - return nil, err + return nil, nil, err } if err := out.Validate(jwt.Expected{Issuer: v.apiKey, Time: time.Now()}); err != nil { - return nil, err + return nil, nil, err } // copy over identity claims.Identity = v.identity - return &claims, nil + return &out, &claims, nil } diff --git a/auth/verifier_test.go b/auth/verifier_test.go index 27ff7d40a..37d8f2ab3 100644 --- a/auth/verifier_test.go +++ b/auth/verifier_test.go @@ -33,10 +33,10 @@ func TestVerifier(t *testing.T) { require.NoError(t, err) require.Equal(t, apiKey, v.APIKey()) - _, err = v.Verify("") + _, _, err = v.Verify("") require.Error(t, err) - _, err = v.Verify("anothersecret") + _, _, err = v.Verify("anothersecret") require.Error(t, err) }) @@ -44,7 +44,7 @@ func TestVerifier(t *testing.T) { v, err := auth.ParseAPIToken(accessToken) require.NoError(t, err) - _, err = v.Verify(secret) + _, _, err = v.Verify(secret) require.Error(t, err) }) @@ -62,7 +62,7 @@ func TestVerifier(t *testing.T) { require.Equal(t, apiKey, v.APIKey()) require.Equal(t, "me", v.Identity()) - decoded, err := v.Verify(secret) + _, decoded, err := v.Verify(secret) require.NoError(t, err) require.Equal(t, &claim, decoded.Video) }) @@ -88,7 +88,7 @@ func TestVerifier(t *testing.T) { v, err := auth.ParseAPIToken(authToken) require.NoError(t, err) - decoded, err := v.Verify(secret) + _, decoded, err := v.Verify(secret) require.NoError(t, err) require.EqualValues(t, string(md), decoded.Metadata) @@ -108,7 +108,7 @@ func TestVerifier(t *testing.T) { v, err := auth.ParseAPIToken(token) require.NoError(t, err) - decoded, err := v.Verify(secret) + _, decoded, err := v.Verify(secret) require.NoError(t, err) require.Nil(t, decoded.Video.CanSubscribe) diff --git a/livekit/types.go b/livekit/types.go index 37e3d4c6c..1dba514e1 100644 --- a/livekit/types.go +++ b/livekit/types.go @@ -59,6 +59,9 @@ func (s NodeID) String() string { return string(s) } func (s JobID) String() string { return string(s) } func (s DispatchID) String() string { return string(s) } func (s AgentName) String() string { return string(s) } +func (s ParticipantKey) String() string { + return fmt.Sprintf("%s_%s_%s", s.ProjectID, s.RoomName, s.Identity) +} type stringTypes interface { ParticipantID | RoomID | TrackID | ParticipantIdentity | ParticipantName | RoomName | ConnectionID | NodeID diff --git a/webhook/verifier.go b/webhook/verifier.go index 017557ca9..69eda2111 100644 --- a/webhook/verifier.go +++ b/webhook/verifier.go @@ -51,7 +51,7 @@ func Receive(r *http.Request, provider auth.KeyProvider) ([]byte, error) { return nil, ErrSecretNotFound } - claims, err := v.Verify(secret) + _, claims, err := v.Verify(secret) if err != nil { return nil, err }