fix(server): keep script chunks within legacy client read limits
This commit is contained in:
1 parent
1b5c6dbf98
commit
474afb3484
5 files changed
+107
-1
No files matched your search
@@ -136,6 +136,12 @@ exact ignored `dist/` directory after preserving any evidence.
|
|||||||
Preserve spool/history: rebooting cannot remove a replayable oversized event.
|
Preserve spool/history: rebooting cannot remove a replayable oversized event.
|
||||||
New server logs include bounded read/reconciliation errors and an
|
New server logs include bounded read/reconciliation errors and an
|
||||||
`agent_message_too_big` counter; new clients advertise the actual build version.
|
`agent_message_too_big` counter; new clients advertise the actual build version.
|
||||||
|
If the server reports receiving that close code from an older client, the
|
||||||
|
client rejected a server-to-client frame. Outbound script chunks target
|
||||||
|
16 KiB (or a lower configured chunk ceiling), preserving offsets/digests and
|
||||||
|
the 1 MiB send window, so pending uploads can reach older clients. This does
|
||||||
|
not lower the server's inbound limits. Large inline command text, stdin, or
|
||||||
|
reconciliation responses still require the corrected client reader.
|
||||||
- **`terminal command cannot accept script data` during reconnect:** the server
|
- **`terminal command cannot accept script data` during reconnect:** the server
|
||||||
may replay an upload while the client is still delivering that command's
|
may replay an upload while the client is still delivering that command's
|
||||||
terminal events. Corrected clients ignore these frames only after verifying
|
terminal events. Corrected clients ignore these frames only after verifying
|
||||||
|
|||||||
@@ -513,7 +513,10 @@ func (server *AgentServer) enqueueNextDispatch(ctx context.Context, queue *Write
|
|||||||
return candidate.IssueUUID, true, nil
|
return candidate.IssueUUID, true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const scriptSendWindowBytes uint64 = 1 << 20
|
const (
|
||||||
|
scriptSendWindowBytes uint64 = 1 << 20
|
||||||
|
scriptChunkTargetBytes uint64 = 16 << 10
|
||||||
|
)
|
||||||
|
|
||||||
type scriptTransfer struct {
|
type scriptTransfer struct {
|
||||||
Body []byte
|
Body []byte
|
||||||
@@ -531,6 +534,12 @@ func (server *AgentServer) enqueueNextScript(queue *WriterQueue, sessionID strin
|
|||||||
if chunkLimit == 0 {
|
if chunkLimit == 0 {
|
||||||
return false, errors.New("script chunk limit is zero")
|
return false, errors.New("script chunk limit is zero")
|
||||||
}
|
}
|
||||||
|
// The protocol ceiling is an upper bound, not a required chunk size.
|
||||||
|
// Leave room for envelope metadata below the historical 32 KiB client
|
||||||
|
// reader so an installed older client can receive its pending script.
|
||||||
|
if chunkLimit > scriptChunkTargetBytes {
|
||||||
|
chunkLimit = scriptChunkTargetBytes
|
||||||
|
}
|
||||||
sentMu.Lock()
|
sentMu.Lock()
|
||||||
keys := make([]string, 0, len(transfers))
|
keys := make([]string, 0, len(transfers))
|
||||||
for key := range transfers {
|
for key := range transfers {
|
||||||
|
|||||||
@@ -50,6 +50,12 @@ command payloads, and count `agent_message_too_big` failures. Earlier clients
|
|||||||
reported the placeholder daemon version `v1`; use the installed executable's
|
reported the placeholder daemon version `v1`; use the installed executable's
|
||||||
`--version` or PE product version when the server cannot identify the release.
|
`--version` or PE product version when the server cannot identify the release.
|
||||||
|
|
||||||
|
If the server log says it **received** a `StatusMessageTooBig` close from the
|
||||||
|
client, inspect outbound traffic: the old client reader rejected it. Corrected
|
||||||
|
servers send scripts in 16 KiB chunks, allowing pending uploads to reach older
|
||||||
|
clients without lowering inbound validation limits. Large inline commands,
|
||||||
|
stdin, and reconciliation responses still need the updated client reader.
|
||||||
|
|
||||||
## Windows identity, GUI, and shells
|
## Windows identity, GUI, and shells
|
||||||
|
|
||||||
`--elevated` is the only execution-context request toggle. Selection and
|
`--elevated` is the only execution-context request toggle. Selection and
|
||||||
|
|||||||
@@ -1163,6 +1163,12 @@ layer = "integration"
|
|||||||
status = "implemented"
|
status = "implemented"
|
||||||
tests = ["test/integration/clientagent/websocket_limits_integration_test.go:TestLargeOutputReplaysAfterReconnect_REC_WS_01"]
|
tests = ["test/integration/clientagent/websocket_limits_integration_test.go:TestLargeOutputReplaysAfterReconnect_REC_WS_01"]
|
||||||
|
|
||||||
|
[[requirements]]
|
||||||
|
id = "REC-WS-02"
|
||||||
|
layer = "integration"
|
||||||
|
status = "implemented"
|
||||||
|
tests = ["test/integration/clientagent/websocket_limits_integration_test.go:TestLargeScriptFitsLegacyReader_REC_WS_02"]
|
||||||
|
|
||||||
[[requirements]]
|
[[requirements]]
|
||||||
id = "REC-RUNTIME-06"
|
id = "REC-RUNTIME-06"
|
||||||
layer = "unit"
|
layer = "unit"
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package clientagent_test
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/sha256"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -91,6 +92,84 @@ func TestLargeDispatchAndReconciliation_HP_WS_01(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLargeScriptFitsLegacyReader_REC_WS_02(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
fixture := newFrameFixture(t)
|
||||||
|
legacy := agentproto.DefaultLimits()
|
||||||
|
legacy.MaxEnvelopeBytes = 32 << 10
|
||||||
|
transport, err := agent.DialWebSocketWithLimits(ctx, "wss"+strings.TrimPrefix(fixture.server.URL, "https")+"/v1/agent", fixture.server.Client(), legacy)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer transport.Close()
|
||||||
|
accepted, err := agent.Handshake(ctx, transport, fixture.hello, legacy)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := agent.Reconcile(ctx, transport, accepted, &rvboxv1.ReconcileSnapshot{}, legacy); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
body := bytes.Repeat([]byte("echo large-script\r\n"), 10000)
|
||||||
|
digest := sha256.Sum256(body)
|
||||||
|
queued, err := fixture.control.RunCommand(ctx, &rvboxv1.RunCommandRequest{TargetClientId: fixture.hello.ClientId,
|
||||||
|
Spec: &rvboxv1.ExecutionSpec{ShellType: rvboxv1.ShellType_SHELL_CMD,
|
||||||
|
Source: &rvboxv1.ExecutionSpec_Script{Script: &rvboxv1.ScriptDescriptor{
|
||||||
|
Filename: "large.cmd", SizeBytes: uint64(len(body)), Sha256: digest[:],
|
||||||
|
}}}, ScriptContent: body})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
dispatch := readFrame(t, ctx, transport).GetCommandDispatch()
|
||||||
|
if dispatch == nil || dispatch.IssueUuid != queued.IssueUuid {
|
||||||
|
t.Fatal("missing script dispatch")
|
||||||
|
}
|
||||||
|
ack, _ := proto.Marshal(&rvboxv1.AgentEnvelope{SessionId: accepted.ID, SessionGeneration: accepted.Generation,
|
||||||
|
Payload: &rvboxv1.AgentEnvelope_CommandAccepted{CommandAccepted: &rvboxv1.CommandAccepted{
|
||||||
|
IssueUuid: dispatch.IssueUuid, CommandRevision: 1, Accepted: true,
|
||||||
|
}}})
|
||||||
|
if err := transport.Write(ctx, ack); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
var received []byte
|
||||||
|
for {
|
||||||
|
envelope := readFrame(t, ctx, transport)
|
||||||
|
if chunk := envelope.GetScriptChunk(); chunk != nil {
|
||||||
|
if chunk.Offset != uint64(len(received)) || sha256.Sum256(chunk.Data) != bytesToSHA(chunk.Sha256) {
|
||||||
|
t.Fatal("script offset/checksum changed")
|
||||||
|
}
|
||||||
|
received = append(received, chunk.Data...)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
commit := envelope.GetScriptCommit()
|
||||||
|
if commit == nil || commit.SizeBytes != uint64(len(body)) || !bytes.Equal(commit.Sha256, digest[:]) || !bytes.Equal(received, body) {
|
||||||
|
t.Fatal("script commit/body changed")
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
for i, phase := range []rvboxv1.CommandLifecycle{rvboxv1.CommandLifecycle_COMMAND_RUNNING, rvboxv1.CommandLifecycle_COMMAND_SUCCEEDED} {
|
||||||
|
if err := agent.SendCommandEvent(ctx, transport, accepted, &rvboxv1.CommandEvent{IssueUuid: dispatch.IssueUuid,
|
||||||
|
EventSeq: uint64(i + 1), ObservedAt: timestamppb.Now(), Payload: &rvboxv1.CommandEvent_Lifecycle{
|
||||||
|
Lifecycle: &rvboxv1.LifecycleChange{Lifecycle: phase, CommandRevision: 1},
|
||||||
|
}}, agentproto.DefaultLimits()); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if ack := readFrame(t, ctx, transport).GetEventAck(); ack == nil || ack.ThroughEventSeq != uint64(i+1) {
|
||||||
|
t.Fatal("script completion not acknowledged")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if next := fixture.dispatch(t, ctx, transport, "echo still-connected"); next.Spec.GetCommandText() != "echo still-connected" {
|
||||||
|
t.Fatal("legacy session failed after script upload")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func bytesToSHA(value []byte) [sha256.Size]byte {
|
||||||
|
var result [sha256.Size]byte
|
||||||
|
copy(result[:], value)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
type frameFixture struct {
|
type frameFixture struct {
|
||||||
persistence *store.Store
|
persistence *store.Store
|
||||||
control *control.Service
|
control *control.Service
|
||||||
|
|||||||
Reference in new issue
Block a user