Apply ttl check only when authenticate allocation creating (#4526)

* Apply ttl check only when authenticate allocation creating

TTL check could reject allocation/persmission refresh in
security enhancement #4505, cause long-live session disconnect
when turn credential is expired.
Only check ttl on allocation creating to prevent abusing leaked
credential but keep long-live session work.
This commit is contained in:
cnderrauber
2026-05-15 14:55:05 +08:00
committed by GitHub
parent b32933b0d4
commit 89faaeba82
9 changed files with 180 additions and 32 deletions
+15 -6
View File
@@ -17,7 +17,7 @@ package telemetry
import (
"net"
"github.com/pion/turn/v4"
"github.com/pion/turn/v5"
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
)
@@ -113,8 +113,8 @@ func NewRelayAddressGenerator(g turn.RelayAddressGenerator) *RelayAddressGenerat
return &RelayAddressGenerator{RelayAddressGenerator: g}
}
func (g *RelayAddressGenerator) AllocatePacketConn(network string, requestedPort int) (net.PacketConn, net.Addr, error) {
conn, addr, err := g.RelayAddressGenerator.AllocatePacketConn(network, requestedPort)
func (g *RelayAddressGenerator) AllocatePacketConn(c turn.AllocateListenerConfig) (net.PacketConn, net.Addr, error) {
conn, addr, err := g.RelayAddressGenerator.AllocatePacketConn(c)
if err != nil {
return nil, addr, err
}
@@ -122,11 +122,20 @@ func (g *RelayAddressGenerator) AllocatePacketConn(network string, requestedPort
return NewPacketConn(conn, prometheus.Outgoing), addr, err
}
func (g *RelayAddressGenerator) AllocateConn(network string, requestedPort int) (net.Conn, net.Addr, error) {
conn, addr, err := g.RelayAddressGenerator.AllocateConn(network, requestedPort)
func (g *RelayAddressGenerator) AllocateConn(c turn.AllocateConnConfig) (net.Conn, error) {
conn, err := g.RelayAddressGenerator.AllocateConn(c)
if err != nil {
return nil, err
}
return NewConn(conn, prometheus.Outgoing), err
}
func (g *RelayAddressGenerator) AllocateListener(c turn.AllocateListenerConfig) (net.Listener, net.Addr, error) {
l, addr, err := g.RelayAddressGenerator.AllocateListener(c)
if err != nil {
return nil, addr, err
}
return NewConn(conn, prometheus.Outgoing), addr, err
return NewListener(l), addr, err
}