Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/auto-egress-v2-fixes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"github.com/livekit/protocol": patch
---

v2 auto track egress writes each track to its own path, and `RedactUpload` redacts S3 and GCP proxy passwords.
31 changes: 21 additions & 10 deletions egress/auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package egress

import (
"fmt"
"strings"

"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -110,6 +109,18 @@ func AutoTrackRequest(internal *livekit.RoomInternal, roomName, trackID string,
} else {
media.Video = &livekit.MediaSource_VideoTrackId{VideoTrackId: trackID}
}
for _, o := range c.Outputs {
switch cfg := o.Config.(type) {
case *livekit.Output_File:
cfg.File.Filepath = trackFilepath(cfg.File.Filepath, trackID)
case *livekit.Output_Segments:
cfg.Segments.FilenamePrefix = trackFilepath(cfg.Segments.FilenamePrefix, trackID)
cfg.Segments.PlaylistName = trackFilepath(cfg.Segments.PlaylistName, trackID)
cfg.Segments.LivePlaylistName = trackFilepath(cfg.Segments.LivePlaylistName, trackID)
case *livekit.Output_Images:
cfg.Images.FilenamePrefix = trackFilepath(cfg.Images.FilenamePrefix, trackID)
}
}
req := &livekit.StartEgressRequest{
RoomName: roomName,
Source: &livekit.StartEgressRequest_Media{Media: media},
Expand All @@ -129,7 +140,7 @@ func AutoTrackRequest(internal *livekit.RoomInternal, roomName, trackID string,
if v1 := internal.GetTrackEgress(); v1 != nil {
c := proto.Clone(v1).(*livekit.AutoTrackEgress)
output := &livekit.DirectFileOutput{
Filepath: trackFilepath(c.Filepath),
Filepath: trackFilepath(c.Filepath, "{track_id}"),
DisableManifest: c.DisableManifest,
}
switch o := c.Output.(type) {
Expand All @@ -153,17 +164,17 @@ func AutoTrackRequest(internal *livekit.RoomInternal, roomName, trackID string,
return nil
}

func trackFilepath(filepath string) string {
if filepath == "" || strings.HasSuffix(filepath, "/") || strings.Contains(filepath, "{track_id}") {
func trackFilepath(filepath, trackID string) string {
if strings.Contains(filepath, "{track_id}") {
return strings.ReplaceAll(filepath, "{track_id}", trackID)
}
if filepath == "" || strings.HasSuffix(filepath, "/") {
return filepath
}

idx := strings.Index(filepath, ".")
if idx == -1 {
return fmt.Sprintf("%s-{track_id}", filepath)
} else {
return fmt.Sprintf("%s-%s%s", filepath[:idx], "{track_id}", filepath[idx:])
if idx := strings.Index(filepath, "."); idx != -1 {
return filepath[:idx] + "-" + trackID + filepath[idx:]
}
return filepath + "-" + trackID
}

// ValidateRoomEgress rejects v1 and v2 config for the same kind, and v2 config that egress would reject
Expand Down
6 changes: 6 additions & 0 deletions egress/redact.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,17 @@ func RedactUpload(req UploadRequest) {
s3.Secret = utils.Redact(s3.Secret, "{secret}")
s3.AssumeRoleExternalId = utils.Redact(s3.AssumeRoleExternalId, "{external_id}")
s3.SessionToken = utils.Redact(s3.SessionToken, "{session_token}")
if s3.Proxy != nil {
s3.Proxy.Password = utils.Redact(s3.Proxy.Password, "{proxy_password}")
}
return
}

if gcp := req.GetGcp(); gcp != nil {
gcp.Credentials = utils.Redact(gcp.Credentials, "{credentials}")
if gcp.Proxy != nil {
gcp.Proxy.Password = utils.Redact(gcp.Proxy.Password, "{proxy_password}")
}
return
}

Expand Down
4 changes: 4 additions & 0 deletions egress/redact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
Secret: "LONG_SECRET_STRING",
AssumeRoleExternalId: "EXTERNAL_ID",
SessionToken: "SESSION_TOKEN",
Proxy: &livekit.ProxyConfig{Password: "PROXY_PASSWORD"},
},
},
}
Expand All @@ -48,6 +49,7 @@ var (
Output: &livekit.SegmentedFileOutput_Gcp{
Gcp: &livekit.GCPUpload{
Credentials: "CREDENTIALS",
Proxy: &livekit.ProxyConfig{Password: "PROXY_PASSWORD"},
},
},
}
Expand All @@ -70,6 +72,7 @@ func TestRedactUpload(t *testing.T) {
require.Equal(t, "{secret}", cl.(*livekit.EncodedFileOutput).Output.(*livekit.EncodedFileOutput_S3).S3.Secret)
require.Equal(t, "{external_id}", cl.(*livekit.EncodedFileOutput).Output.(*livekit.EncodedFileOutput_S3).S3.AssumeRoleExternalId)
require.Equal(t, "{session_token}", cl.(*livekit.EncodedFileOutput).Output.(*livekit.EncodedFileOutput_S3).S3.SessionToken)
require.Equal(t, "{proxy_password}", cl.(*livekit.EncodedFileOutput).Output.(*livekit.EncodedFileOutput_S3).S3.Proxy.Password)

sessionTokenOnly := &livekit.EncodedFileOutput{
Output: &livekit.EncodedFileOutput_S3{
Expand All @@ -95,6 +98,7 @@ func TestRedactUpload(t *testing.T) {
RedactUpload(cl.(UploadRequest))

require.Equal(t, "{credentials}", cl.(*livekit.SegmentedFileOutput).Output.(*livekit.SegmentedFileOutput_Gcp).Gcp.Credentials)
require.Equal(t, "{proxy_password}", cl.(*livekit.SegmentedFileOutput).Output.(*livekit.SegmentedFileOutput_Gcp).Gcp.Proxy.Password)

cl = proto.Clone(directFile)
RedactUpload(cl.(UploadRequest))
Expand Down
Loading