fix(rpc): bind io streams to target agents

Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>
This commit is contained in:
naiba
2026-05-21 02:01:54 +00:00
co-authored by naiba/CloudCode
parent a5e2b0c36d
commit 0f7af0bcb2
7 changed files with 99 additions and 19 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ func createFM(c *gin.Context) (*model.CreateFMResponse, error) {
return nil, err
}
rpc.NezhaHandlerSingleton.CreateStream(streamId, getUid(c))
rpc.NezhaHandlerSingleton.CreateStream(streamId, getUid(c), server.ID)
fmData, _ := json.Marshal(&model.TaskFM{
StreamID: streamId,
@@ -50,7 +50,7 @@ func TestTerminalStreamRejectsForeignMember(t *testing.T) {
gin.SetMode(gin.TestMode)
ensureLocalizerForStreamTests(t)
rpc.NezhaHandlerSingleton = rpc.NewNezhaHandler()
rpc.NezhaHandlerSingleton.CreateStream("alice-terminal", 100)
rpc.NezhaHandlerSingleton.CreateStream("alice-terminal", 100, 1)
r := gin.New()
r.Use(func(c *gin.Context) {
@@ -76,7 +76,7 @@ func TestFMStreamRejectsForeignMember(t *testing.T) {
gin.SetMode(gin.TestMode)
ensureLocalizerForStreamTests(t)
rpc.NezhaHandlerSingleton = rpc.NewNezhaHandler()
rpc.NezhaHandlerSingleton.CreateStream("alice-fm", 100)
rpc.NezhaHandlerSingleton.CreateStream("alice-fm", 100, 1)
r := gin.New()
r.Use(func(c *gin.Context) {
@@ -160,4 +160,3 @@ func TestWriteOauth2StateCookieIsHttpOnly(t *testing.T) {
t.Fatalf("nz-o2s must be HttpOnly to prevent XSS reading OAuth state, got %q", header)
}
}
+1 -1
View File
@@ -44,7 +44,7 @@ func createTerminal(c *gin.Context) (*model.CreateTerminalResponse, error) {
return nil, err
}
rpc.NezhaHandlerSingleton.CreateStream(streamId, getUid(c))
rpc.NezhaHandlerSingleton.CreateStream(streamId, getUid(c), server.ID)
terminalData, _ := json.Marshal(&model.TerminalTask{
StreamID: streamId,
+5 -2
View File
@@ -140,8 +140,11 @@ func ServeNAT(w http.ResponseWriter, r *http.Request, natConfig *model.NAT) {
// NAT streams are anonymous HTTP-facing tunnels; they are NOT reachable
// via /ws/terminal or /ws/file (which check stream ownership), so the
// creator user ID does not need to identify a real user.
rpcService.NezhaHandlerSingleton.CreateStream(streamId, 0)
// creator user ID does not need to identify a real user. The targetServerID
// IS required though — the receiving agent must prove it is the server the
// NAT config addressed, otherwise any agent that snoops the streamId can
// answer NAT traffic on behalf of an unrelated host.
rpcService.NezhaHandlerSingleton.CreateStream(streamId, 0, server.ID)
defer rpcService.NezhaHandlerSingleton.CloseStream(streamId)
taskData, err := json.Marshal(model.TaskNAT{