Exempt egress participant from track permissions. (#3322)
* Exempt egress participant from track permissions. * test
This commit is contained in:
+8
-2
@@ -830,7 +830,7 @@ func (r *Room) UpdateSubscriptionPermission(participant types.LocalParticipant,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Room) ResolveMediaTrackForSubscriber(subIdentity livekit.ParticipantIdentity, trackID livekit.TrackID) types.MediaResolverResult {
|
func (r *Room) ResolveMediaTrackForSubscriber(sub types.LocalParticipant, trackID livekit.TrackID) types.MediaResolverResult {
|
||||||
res := types.MediaResolverResult{}
|
res := types.MediaResolverResult{}
|
||||||
|
|
||||||
info := r.trackManager.GetTrackInfo(trackID)
|
info := r.trackManager.GetTrackInfo(trackID)
|
||||||
@@ -848,7 +848,7 @@ func (r *Room) ResolveMediaTrackForSubscriber(subIdentity livekit.ParticipantIde
|
|||||||
pub := r.GetParticipantByID(info.PublisherID)
|
pub := r.GetParticipantByID(info.PublisherID)
|
||||||
// when publisher is not found, we will assume it doesn't have permission to access
|
// when publisher is not found, we will assume it doesn't have permission to access
|
||||||
if pub != nil {
|
if pub != nil {
|
||||||
res.HasPermission = pub.HasPermission(trackID, subIdentity)
|
res.HasPermission = IsParticipantExemptFromTrackPermissionsRestrictions(sub) || pub.HasPermission(trackID, sub.Identity())
|
||||||
}
|
}
|
||||||
|
|
||||||
return res
|
return res
|
||||||
@@ -1809,6 +1809,12 @@ func IsCloseNotifySkippable(closeReason types.ParticipantCloseReason) bool {
|
|||||||
return closeReason == types.ParticipantCloseReasonDuplicateIdentity
|
return closeReason == types.ParticipantCloseReasonDuplicateIdentity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsParticipantExemptFromTrackPermissionsRestrictions(p types.LocalParticipant) bool {
|
||||||
|
// egress/recorder participants bypass permissions as auto-egress does not
|
||||||
|
// have enough context to check permissions
|
||||||
|
return p.IsRecorder()
|
||||||
|
}
|
||||||
|
|
||||||
func connectionDetailsFields(infos []*types.ICEConnectionInfo) []interface{} {
|
func connectionDetailsFields(infos []*types.ICEConnectionInfo) []interface{} {
|
||||||
var fields []interface{}
|
var fields []interface{}
|
||||||
connectionType := types.ICEConnectionTypeUnknown
|
connectionType := types.ICEConnectionTypeUnknown
|
||||||
|
|||||||
@@ -503,7 +503,7 @@ func (m *SubscriptionManager) subscribe(s *trackSubscription) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
trackID := s.trackID
|
trackID := s.trackID
|
||||||
res := m.params.TrackResolver(m.params.Participant.Identity(), trackID)
|
res := m.params.TrackResolver(m.params.Participant, trackID)
|
||||||
s.logger.Debugw("resolved track", "result", res)
|
s.logger.Debugw("resolved track", "result", res)
|
||||||
|
|
||||||
if res.TrackChangedNotifier != nil && s.setChangedNotifier(res.TrackChangedNotifier) {
|
if res.TrackChangedNotifier != nil && s.setChangedNotifier(res.TrackChangedNotifier) {
|
||||||
@@ -517,7 +517,7 @@ func (m *SubscriptionManager) subscribe(s *trackSubscription) error {
|
|||||||
if res.TrackRemovedNotifier != nil && s.setRemovedNotifier(res.TrackRemovedNotifier) {
|
if res.TrackRemovedNotifier != nil && s.setRemovedNotifier(res.TrackRemovedNotifier) {
|
||||||
res.TrackRemovedNotifier.AddObserver(string(m.params.Participant.ID()), func() {
|
res.TrackRemovedNotifier.AddObserver(string(m.params.Participant.ID()), func() {
|
||||||
// re-resolve the track in case the same track had been re-published
|
// re-resolve the track in case the same track had been re-published
|
||||||
res := m.params.TrackResolver(m.params.Participant.Identity(), trackID)
|
res := m.params.TrackResolver(m.params.Participant, trackID)
|
||||||
if res.Track != nil {
|
if res.Track != nil {
|
||||||
// do not unsubscribe, track is still available
|
// do not unsubscribe, track is still available
|
||||||
return
|
return
|
||||||
@@ -627,7 +627,7 @@ func (m *SubscriptionManager) subscribeSynchronous(trackID livekit.TrackID) erro
|
|||||||
return ErrNoSubscribePermission
|
return ErrNoSubscribePermission
|
||||||
}
|
}
|
||||||
|
|
||||||
res := m.params.TrackResolver(m.params.Participant.Identity(), trackID)
|
res := m.params.TrackResolver(m.params.Participant, trackID)
|
||||||
m.params.Logger.Debugw("resolved track", "trackID", trackID, " result", res)
|
m.params.Logger.Debugw("resolved track", "trackID", trackID, " result", res)
|
||||||
|
|
||||||
track := res.Track
|
track := res.Track
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ const (
|
|||||||
|
|
||||||
func TestSubscribe(t *testing.T) {
|
func TestSubscribe(t *testing.T) {
|
||||||
t.Run("happy path subscribe", func(t *testing.T) {
|
t.Run("happy path subscribe", func(t *testing.T) {
|
||||||
sm := newTestSubscriptionManager(t)
|
sm := newTestSubscriptionManager()
|
||||||
defer sm.Close(false)
|
defer sm.Close(false)
|
||||||
resolver := newTestResolver(true, true, "pub", "pubID")
|
resolver := newTestResolver(true, true, "pub", "pubID")
|
||||||
sm.params.TrackResolver = resolver.Resolve
|
sm.params.TrackResolver = resolver.Resolve
|
||||||
@@ -118,7 +118,7 @@ func TestSubscribe(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("no track permission", func(t *testing.T) {
|
t.Run("no track permission", func(t *testing.T) {
|
||||||
sm := newTestSubscriptionManager(t)
|
sm := newTestSubscriptionManager()
|
||||||
defer sm.Close(false)
|
defer sm.Close(false)
|
||||||
resolver := newTestResolver(false, true, "pub", "pubID")
|
resolver := newTestResolver(false, true, "pub", "pubID")
|
||||||
sm.params.TrackResolver = resolver.Resolve
|
sm.params.TrackResolver = resolver.Resolve
|
||||||
@@ -159,7 +159,7 @@ func TestSubscribe(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("publisher left", func(t *testing.T) {
|
t.Run("publisher left", func(t *testing.T) {
|
||||||
sm := newTestSubscriptionManager(t)
|
sm := newTestSubscriptionManager()
|
||||||
defer sm.Close(false)
|
defer sm.Close(false)
|
||||||
resolver := newTestResolver(true, true, "pub", "pubID")
|
resolver := newTestResolver(true, true, "pub", "pubID")
|
||||||
sm.params.TrackResolver = resolver.Resolve
|
sm.params.TrackResolver = resolver.Resolve
|
||||||
@@ -188,7 +188,7 @@ func TestSubscribe(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestUnsubscribe(t *testing.T) {
|
func TestUnsubscribe(t *testing.T) {
|
||||||
sm := newTestSubscriptionManager(t)
|
sm := newTestSubscriptionManager()
|
||||||
defer sm.Close(false)
|
defer sm.Close(false)
|
||||||
unsubCount := atomic.Int32{}
|
unsubCount := atomic.Int32{}
|
||||||
sm.params.OnTrackUnsubscribed = func(subTrack types.SubscribedTrack) {
|
sm.params.OnTrackUnsubscribed = func(subTrack types.SubscribedTrack) {
|
||||||
@@ -208,7 +208,7 @@ func TestUnsubscribe(t *testing.T) {
|
|||||||
logger: logger.GetLogger(),
|
logger: logger.GetLogger(),
|
||||||
}
|
}
|
||||||
// a bunch of unfortunate manual wiring
|
// a bunch of unfortunate manual wiring
|
||||||
res := resolver.Resolve("sub", s.trackID)
|
res := resolver.Resolve(nil, s.trackID)
|
||||||
res.TrackChangedNotifier.AddObserver(string(sm.params.Participant.ID()), func() {})
|
res.TrackChangedNotifier.AddObserver(string(sm.params.Participant.ID()), func() {})
|
||||||
s.changedNotifier = res.TrackChangedNotifier
|
s.changedNotifier = res.TrackChangedNotifier
|
||||||
st, err := res.Track.AddSubscriber(sm.params.Participant)
|
st, err := res.Track.AddSubscriber(sm.params.Participant)
|
||||||
@@ -257,7 +257,7 @@ func TestUnsubscribe(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSubscribeStatusChanged(t *testing.T) {
|
func TestSubscribeStatusChanged(t *testing.T) {
|
||||||
sm := newTestSubscriptionManager(t)
|
sm := newTestSubscriptionManager()
|
||||||
defer sm.Close(false)
|
defer sm.Close(false)
|
||||||
resolver := newTestResolver(true, true, "pub", "pubID")
|
resolver := newTestResolver(true, true, "pub", "pubID")
|
||||||
sm.params.TrackResolver = resolver.Resolve
|
sm.params.TrackResolver = resolver.Resolve
|
||||||
@@ -320,7 +320,7 @@ func TestSubscribeStatusChanged(t *testing.T) {
|
|||||||
// clients may send update subscribed settings prior to subscription events coming through
|
// clients may send update subscribed settings prior to subscription events coming through
|
||||||
// settings should be persisted and used when the subscription does take place.
|
// settings should be persisted and used when the subscription does take place.
|
||||||
func TestUpdateSettingsBeforeSubscription(t *testing.T) {
|
func TestUpdateSettingsBeforeSubscription(t *testing.T) {
|
||||||
sm := newTestSubscriptionManager(t)
|
sm := newTestSubscriptionManager()
|
||||||
defer sm.Close(false)
|
defer sm.Close(false)
|
||||||
resolver := newTestResolver(true, true, "pub", "pubID")
|
resolver := newTestResolver(true, true, "pub", "pubID")
|
||||||
sm.params.TrackResolver = resolver.Resolve
|
sm.params.TrackResolver = resolver.Resolve
|
||||||
@@ -351,7 +351,7 @@ func TestUpdateSettingsBeforeSubscription(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSubscriptionLimits(t *testing.T) {
|
func TestSubscriptionLimits(t *testing.T) {
|
||||||
sm := newTestSubscriptionManagerWithParams(t, testSubscriptionParams{
|
sm := newTestSubscriptionManagerWithParams(testSubscriptionParams{
|
||||||
SubscriptionLimitAudio: 1,
|
SubscriptionLimitAudio: 1,
|
||||||
SubscriptionLimitVideo: 1,
|
SubscriptionLimitVideo: 1,
|
||||||
})
|
})
|
||||||
@@ -452,11 +452,11 @@ type testSubscriptionParams struct {
|
|||||||
SubscriptionLimitVideo int32
|
SubscriptionLimitVideo int32
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestSubscriptionManager(t *testing.T) *SubscriptionManager {
|
func newTestSubscriptionManager() *SubscriptionManager {
|
||||||
return newTestSubscriptionManagerWithParams(t, testSubscriptionParams{})
|
return newTestSubscriptionManagerWithParams(testSubscriptionParams{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestSubscriptionManagerWithParams(t *testing.T, params testSubscriptionParams) *SubscriptionManager {
|
func newTestSubscriptionManagerWithParams(params testSubscriptionParams) *SubscriptionManager {
|
||||||
p := &typesfakes.FakeLocalParticipant{}
|
p := &typesfakes.FakeLocalParticipant{}
|
||||||
p.CanSubscribeReturns(true)
|
p.CanSubscribeReturns(true)
|
||||||
p.IDReturns("subID")
|
p.IDReturns("subID")
|
||||||
@@ -468,7 +468,7 @@ func newTestSubscriptionManagerWithParams(t *testing.T, params testSubscriptionP
|
|||||||
OnTrackSubscribed: func(subTrack types.SubscribedTrack) {},
|
OnTrackSubscribed: func(subTrack types.SubscribedTrack) {},
|
||||||
OnTrackUnsubscribed: func(subTrack types.SubscribedTrack) {},
|
OnTrackUnsubscribed: func(subTrack types.SubscribedTrack) {},
|
||||||
OnSubscriptionError: func(trackID livekit.TrackID, fatal bool, err error) {},
|
OnSubscriptionError: func(trackID livekit.TrackID, fatal bool, err error) {},
|
||||||
TrackResolver: func(identity livekit.ParticipantIdentity, trackID livekit.TrackID) types.MediaResolverResult {
|
TrackResolver: func(sub types.LocalParticipant, trackID livekit.TrackID) types.MediaResolverResult {
|
||||||
return types.MediaResolverResult{}
|
return types.MediaResolverResult{}
|
||||||
},
|
},
|
||||||
Telemetry: &telemetryfakes.FakeTelemetryService{},
|
Telemetry: &telemetryfakes.FakeTelemetryService{},
|
||||||
@@ -502,7 +502,7 @@ func (t *testResolver) SetPause(paused bool) {
|
|||||||
t.paused = paused
|
t.paused = paused
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *testResolver) Resolve(identity livekit.ParticipantIdentity, trackID livekit.TrackID) types.MediaResolverResult {
|
func (t *testResolver) Resolve(_subscriber types.LocalParticipant, trackID livekit.TrackID) types.MediaResolverResult {
|
||||||
t.lock.Lock()
|
t.lock.Lock()
|
||||||
defer t.lock.Unlock()
|
defer t.lock.Unlock()
|
||||||
res := types.MediaResolverResult{
|
res := types.MediaResolverResult{
|
||||||
|
|||||||
@@ -476,7 +476,7 @@ type Room interface {
|
|||||||
UpdateSubscriptionPermission(participant LocalParticipant, permissions *livekit.SubscriptionPermission) error
|
UpdateSubscriptionPermission(participant LocalParticipant, permissions *livekit.SubscriptionPermission) error
|
||||||
SyncState(participant LocalParticipant, state *livekit.SyncState) error
|
SyncState(participant LocalParticipant, state *livekit.SyncState) error
|
||||||
SimulateScenario(participant LocalParticipant, scenario *livekit.SimulateScenario) error
|
SimulateScenario(participant LocalParticipant, scenario *livekit.SimulateScenario) error
|
||||||
ResolveMediaTrackForSubscriber(subIdentity livekit.ParticipantIdentity, trackID livekit.TrackID) MediaResolverResult
|
ResolveMediaTrackForSubscriber(sub LocalParticipant, trackID livekit.TrackID) MediaResolverResult
|
||||||
GetLocalParticipants() []LocalParticipant
|
GetLocalParticipants() []LocalParticipant
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -593,7 +593,7 @@ type MediaResolverResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MediaTrackResolver locates a specific media track for a subscriber
|
// MediaTrackResolver locates a specific media track for a subscriber
|
||||||
type MediaTrackResolver func(livekit.ParticipantIdentity, livekit.TrackID) MediaResolverResult
|
type MediaTrackResolver func(LocalParticipant, livekit.TrackID) MediaResolverResult
|
||||||
|
|
||||||
// Supervisor/operation monitor related definitions
|
// Supervisor/operation monitor related definitions
|
||||||
type OperationMonitorEvent int
|
type OperationMonitorEvent int
|
||||||
|
|||||||
@@ -46,10 +46,10 @@ type FakeRoom struct {
|
|||||||
arg2 livekit.ParticipantID
|
arg2 livekit.ParticipantID
|
||||||
arg3 types.ParticipantCloseReason
|
arg3 types.ParticipantCloseReason
|
||||||
}
|
}
|
||||||
ResolveMediaTrackForSubscriberStub func(livekit.ParticipantIdentity, livekit.TrackID) types.MediaResolverResult
|
ResolveMediaTrackForSubscriberStub func(types.LocalParticipant, livekit.TrackID) types.MediaResolverResult
|
||||||
resolveMediaTrackForSubscriberMutex sync.RWMutex
|
resolveMediaTrackForSubscriberMutex sync.RWMutex
|
||||||
resolveMediaTrackForSubscriberArgsForCall []struct {
|
resolveMediaTrackForSubscriberArgsForCall []struct {
|
||||||
arg1 livekit.ParticipantIdentity
|
arg1 types.LocalParticipant
|
||||||
arg2 livekit.TrackID
|
arg2 livekit.TrackID
|
||||||
}
|
}
|
||||||
resolveMediaTrackForSubscriberReturns struct {
|
resolveMediaTrackForSubscriberReturns struct {
|
||||||
@@ -299,11 +299,11 @@ func (fake *FakeRoom) RemoveParticipantArgsForCall(i int) (livekit.ParticipantId
|
|||||||
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
|
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fake *FakeRoom) ResolveMediaTrackForSubscriber(arg1 livekit.ParticipantIdentity, arg2 livekit.TrackID) types.MediaResolverResult {
|
func (fake *FakeRoom) ResolveMediaTrackForSubscriber(arg1 types.LocalParticipant, arg2 livekit.TrackID) types.MediaResolverResult {
|
||||||
fake.resolveMediaTrackForSubscriberMutex.Lock()
|
fake.resolveMediaTrackForSubscriberMutex.Lock()
|
||||||
ret, specificReturn := fake.resolveMediaTrackForSubscriberReturnsOnCall[len(fake.resolveMediaTrackForSubscriberArgsForCall)]
|
ret, specificReturn := fake.resolveMediaTrackForSubscriberReturnsOnCall[len(fake.resolveMediaTrackForSubscriberArgsForCall)]
|
||||||
fake.resolveMediaTrackForSubscriberArgsForCall = append(fake.resolveMediaTrackForSubscriberArgsForCall, struct {
|
fake.resolveMediaTrackForSubscriberArgsForCall = append(fake.resolveMediaTrackForSubscriberArgsForCall, struct {
|
||||||
arg1 livekit.ParticipantIdentity
|
arg1 types.LocalParticipant
|
||||||
arg2 livekit.TrackID
|
arg2 livekit.TrackID
|
||||||
}{arg1, arg2})
|
}{arg1, arg2})
|
||||||
stub := fake.ResolveMediaTrackForSubscriberStub
|
stub := fake.ResolveMediaTrackForSubscriberStub
|
||||||
@@ -325,13 +325,13 @@ func (fake *FakeRoom) ResolveMediaTrackForSubscriberCallCount() int {
|
|||||||
return len(fake.resolveMediaTrackForSubscriberArgsForCall)
|
return len(fake.resolveMediaTrackForSubscriberArgsForCall)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fake *FakeRoom) ResolveMediaTrackForSubscriberCalls(stub func(livekit.ParticipantIdentity, livekit.TrackID) types.MediaResolverResult) {
|
func (fake *FakeRoom) ResolveMediaTrackForSubscriberCalls(stub func(types.LocalParticipant, livekit.TrackID) types.MediaResolverResult) {
|
||||||
fake.resolveMediaTrackForSubscriberMutex.Lock()
|
fake.resolveMediaTrackForSubscriberMutex.Lock()
|
||||||
defer fake.resolveMediaTrackForSubscriberMutex.Unlock()
|
defer fake.resolveMediaTrackForSubscriberMutex.Unlock()
|
||||||
fake.ResolveMediaTrackForSubscriberStub = stub
|
fake.ResolveMediaTrackForSubscriberStub = stub
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fake *FakeRoom) ResolveMediaTrackForSubscriberArgsForCall(i int) (livekit.ParticipantIdentity, livekit.TrackID) {
|
func (fake *FakeRoom) ResolveMediaTrackForSubscriberArgsForCall(i int) (types.LocalParticipant, livekit.TrackID) {
|
||||||
fake.resolveMediaTrackForSubscriberMutex.RLock()
|
fake.resolveMediaTrackForSubscriberMutex.RLock()
|
||||||
defer fake.resolveMediaTrackForSubscriberMutex.RUnlock()
|
defer fake.resolveMediaTrackForSubscriberMutex.RUnlock()
|
||||||
argsForCall := fake.resolveMediaTrackForSubscriberArgsForCall[i]
|
argsForCall := fake.resolveMediaTrackForSubscriberArgsForCall[i]
|
||||||
|
|||||||
Reference in New Issue
Block a user