move agent token (#3669)

This commit is contained in:
Paul Wells
2025-05-15 10:30:14 -07:00
committed by GitHub
parent c9385edd1e
commit 13b55a80ad
8 changed files with 15 additions and 45 deletions
-5
View File
@@ -60,11 +60,6 @@ var baseFlags = []cli.Flag{
Usage: "api keys (key: secret\\n)",
EnvVars: []string{"LIVEKIT_KEYS"},
},
&cli.StringFlag{
Name: "agents-jwt-keys",
Usage: "one or more JWT keys for agents",
EnvVars: []string{"AGENTS_JWT_KEYS"},
},
&cli.StringFlag{
Name: "region",
Usage: "region of the current node. Used by regionaware node selector",
+1 -1
View File
@@ -23,7 +23,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-20250416051815-7632a9d1b50d
github.com/livekit/protocol v1.38.1-0.20250515151618-2b00a15c76e2
github.com/livekit/protocol v1.38.1-0.20250515171358-c442e9709acb
github.com/livekit/psrpc v0.6.1-0.20250511053145-465289d72c3c
github.com/mackerelio/go-osstat v0.2.5
github.com/magefile/mage v1.15.0
+2 -2
View File
@@ -169,8 +169,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-20250416051815-7632a9d1b50d h1:okulvWxyywxCffnvgNbfHxpO8v5ISV9bTjF2O1764IU=
github.com/livekit/mediatransportutil v0.0.0-20250416051815-7632a9d1b50d/go.mod h1:CMenkOQQjEbjvs0oJa2ye84oHSfr7tRiXO+sCIZiG9A=
github.com/livekit/protocol v1.38.1-0.20250515151618-2b00a15c76e2 h1:hLZzPe2zP677A7au2x4W28BpvufFzBv58i3MrIRo+sA=
github.com/livekit/protocol v1.38.1-0.20250515151618-2b00a15c76e2/go.mod h1:F5GLzgMUFFFgm7ajoYLIEXxlZVnRNusV5Qlnok4dtlc=
github.com/livekit/protocol v1.38.1-0.20250515171358-c442e9709acb h1:QwpjVj92IkUiniXdfvsf4Rm0ashI94TfE/Cytcp3lBw=
github.com/livekit/protocol v1.38.1-0.20250515171358-c442e9709acb/go.mod h1:F5GLzgMUFFFgm7ajoYLIEXxlZVnRNusV5Qlnok4dtlc=
github.com/livekit/psrpc v0.6.1-0.20250511053145-465289d72c3c h1:WwEr0YBejYbKzk8LSaO9h8h0G9MnE7shyDu8yXQWmEc=
github.com/livekit/psrpc v0.6.1-0.20250511053145-465289d72c3c/go.mod h1:kmD+AZPkWu0MaXIMv57jhNlbiSZZ/Jx4bzlxBDVmJes=
github.com/mackerelio/go-osstat v0.2.5 h1:+MqTbZUhoIt4m8qzkVoXUJg1EuifwlAJSk4Yl2GXh+o=
-9
View File
@@ -34,7 +34,6 @@ import (
"github.com/livekit/livekit-server/pkg/sfu/pacer"
"github.com/livekit/livekit-server/pkg/sfu/streamallocator"
"github.com/livekit/mediatransportutil/pkg/rtcconfig"
"github.com/livekit/protocol/agent"
"github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/logger"
redisLiveKit "github.com/livekit/protocol/redis"
@@ -65,7 +64,6 @@ type Config struct {
TURN TURNConfig `yaml:"turn,omitempty"`
Ingress IngressConfig `yaml:"ingress,omitempty"`
SIP SIPConfig `yaml:"sip,omitempty"`
Agents AgentsConfig `yaml:"agents,omitempty"`
WebHook webhook.WebHookConfig `yaml:"webhook,omitempty"`
NodeSelector NodeSelectorConfig `yaml:"node_selector,omitempty"`
KeyFile string `yaml:"key_file,omitempty"`
@@ -275,10 +273,6 @@ type IngressConfig struct {
type SIPConfig struct{}
type AgentsConfig struct {
WorkerToken agent.WorkerTokenConfig `yaml:"worker_token,omitempty"`
}
type APIConfig struct {
// amount of time to wait for API to execute, default 2s
ExecutionTimeout time.Duration `yaml:"execution_timeout,omitempty"`
@@ -731,9 +725,6 @@ func (conf *Config) updateFromCLI(c *cli.Context, baseFlags []cli.Flag) error {
return errors.New("Could not parse keys, it needs to be exactly, \"key: secret\", including the space")
}
}
if c.String("agents-jwt-keys") != "" {
conf.Agents.WorkerToken.Keys = c.String("agents-jwt-keys")
}
if c.IsSet("region") {
conf.Region = c.String("region")
}
+3 -19
View File
@@ -34,7 +34,6 @@ import (
"github.com/livekit/livekit-server/pkg/rtc"
"github.com/livekit/livekit-server/pkg/rtc/types"
"github.com/livekit/livekit-server/version"
pagent "github.com/livekit/protocol/agent"
"github.com/livekit/protocol/auth"
"github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/logger"
@@ -45,7 +44,6 @@ import (
type AgentSocketUpgrader struct {
websocket.Upgrader
WorkerTokenProvider *pagent.WorkerTokenProvider
}
func (u AgentSocketUpgrader) Upgrade(
@@ -74,26 +72,16 @@ func (u AgentSocketUpgrader) Upgrade(
// require a claim
claims := GetGrants(r.Context())
if claims == nil || claims.Video == nil || !claims.Video.Agent {
handleError(w, r, http.StatusUnauthorized, rtc.ErrPermissionDenied)
HandleError(w, r, http.StatusUnauthorized, rtc.ErrPermissionDenied)
return
}
registration = agent.MakeWorkerRegistration()
workerToken := r.FormValue("worker_token")
if workerToken != "" {
claims, err := u.WorkerTokenProvider.Decode(workerToken)
if err != nil {
handleError(w, r, http.StatusUnauthorized, rtc.ErrPermissionDenied)
return
}
registration.ID = claims.Subject
}
// upgrade
conn, err := u.Upgrader.Upgrade(w, r, responseHeader)
if err != nil {
handleError(w, r, http.StatusInternalServerError, err)
HandleError(w, r, http.StatusInternalServerError, err)
return
}
@@ -179,11 +167,7 @@ func NewAgentService(
bus psrpc.MessageBus,
keyProvider auth.KeyProvider,
) (*AgentService, error) {
s := &AgentService{
upgrader: AgentSocketUpgrader{
WorkerTokenProvider: pagent.NewWorkerTokenProvider(currentNode.NodeID(), conf.Agents.WorkerToken),
},
}
s := &AgentService{}
serverInfo := &livekit.ServerInfo{
Edition: livekit.ServerInfo_Standard,
+4 -4
View File
@@ -67,7 +67,7 @@ func (m *APIKeyAuthMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request,
if authHeader != "" {
if !strings.HasPrefix(authHeader, bearerPrefix) {
handleError(w, r, http.StatusUnauthorized, ErrMissingAuthorization)
HandleError(w, r, http.StatusUnauthorized, ErrMissingAuthorization)
return
}
@@ -80,19 +80,19 @@ func (m *APIKeyAuthMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request,
if authToken != "" {
v, err := auth.ParseAPIToken(authToken)
if err != nil {
handleError(w, r, http.StatusUnauthorized, ErrInvalidAuthorizationToken)
HandleError(w, r, http.StatusUnauthorized, ErrInvalidAuthorizationToken)
return
}
secret := m.provider.GetSecret(v.APIKey())
if secret == "" {
handleError(w, r, http.StatusUnauthorized, errors.New("invalid API key: "+v.APIKey()))
HandleError(w, r, http.StatusUnauthorized, errors.New("invalid API key: "+v.APIKey()))
return
}
grants, err := v.Verify(secret)
if err != nil {
handleError(w, r, http.StatusUnauthorized, errors.New("invalid token: "+authToken+", error: "+err.Error()))
HandleError(w, r, http.StatusUnauthorized, errors.New("invalid token: "+authToken+", error: "+err.Error()))
return
}
+4 -4
View File
@@ -99,7 +99,7 @@ func (s *RTCService) SetupRoutes(mux *http.ServeMux) {
func (s *RTCService) validate(w http.ResponseWriter, r *http.Request) {
_, _, code, err := s.validateInternal(r)
if err != nil {
handleError(w, r, code, err)
HandleError(w, r, code, err)
return
}
_, _ = w.Write([]byte("success"))
@@ -265,7 +265,7 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
roomName, pi, code, err = s.validateInternal(r)
if err != nil {
handleError(w, r, code, err)
HandleError(w, r, code, err)
return
}
@@ -293,7 +293,7 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if errors.As(err, &psrpcErr) {
status = psrpcErr.ToHttp()
}
handleError(w, r, status, err, getLoggerFields()...)
HandleError(w, r, status, err, getLoggerFields()...)
return
}
@@ -339,7 +339,7 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// upgrade only once the basics are good to go
conn, err := s.upgrader.Upgrade(w, r, nil)
if err != nil {
handleError(w, r, http.StatusInternalServerError, err, getLoggerFields()...)
HandleError(w, r, http.StatusInternalServerError, err, getLoggerFields()...)
return
}
+1 -1
View File
@@ -26,7 +26,7 @@ import (
"github.com/livekit/protocol/livekit"
)
func handleError(w http.ResponseWriter, r *http.Request, status int, err error, keysAndValues ...interface{}) {
func HandleError(w http.ResponseWriter, r *http.Request, status int, err error, keysAndValues ...interface{}) {
keysAndValues = append(keysAndValues, "status", status)
if r != nil && r.URL != nil {
keysAndValues = append(keysAndValues, "method", r.Method, "path", r.URL.Path)