Skip to content

fix(api): exec streams open within 10 seconds, rechecked, and waiting input is dropped at the end - #494

Merged
samuelmbabhazi merged 7 commits into
mainfrom
fix/478-479-exec-opening
Nov 25, 2026
Merged

samuelmbabhazi merged 7 commits into
mainfrom
fix/478-479-exec-opening

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

What changed

Two hardening findings from the 2026-11-25 audit on exec sessions (SPEC 3.1).

#478, opening an ExecStream.

  • relayExecStream reads the first frame through opening(), which bounds the wait to EXEC_OPEN_MS (10 s) and ends with DEADLINE_EXCEEDED.
  • The transport's cancellation (context.signal, now passed by the gateway) also ends the wait, with CANCELED. The pending read is released with the stream.
  • The node's credential is checked again (stillValid) before it joins. A node removed or revoked while opening gets UNAUTHENTICATED, and the session stays joinable by a valid agent.
  • The existing checks are unchanged: open first, the same node and organization, one join, the same NOT_FOUND.

#479, waiting input at the end.

  • ExecRelay.end() now empties the frames waiting for the agent, whatever the end. The agent's next frame is the final ExecClose{kill: true}, or nothing after an exit.
  • New input stays refused once ended, and the end is audited once.
  • closed and exited come from the agent after the command ended, so nothing it was meant to receive is lost.
  • For browser_left, input typed just before the tab closed no longer runs before the kill. One existing test expected that and was updated.

Why

A silent stream held an RPC with no credential check, and input accepted before a revocation could still reach the container after it.

How it was tested

  • exec-relay.spec.ts:
    • waiting stdin and resize are dropped for access_removed, signed_out, time_limit, failed, browser_left and shutdown;
    • input after the end is refused, and there is one audit event;
    • the waiting iterator wakes with the final close;
    • nothing is sent after an exit.
  • exec-stream.spec.ts (fake timers):
    • no first frame;
    • cancellation during the wait, and an already-cancelled signal;
    • a revocation before the join, after which the session is still joinable;
    • the normal path checks once, and the existing revocation-during-session test still passes.
  • The new tests fail on the previous code.
  • All fleet and deployments unit tests pass (345). gateway.integration.spec.ts against PostgreSQL passes (15). api:lint and api:typecheck are clean.

Security considerations

  • Hardening only: no new route, no change to the action list, no shell.
  • The 10 s deadline is well under the gateway's transport limits, and the agent opens its stream right after it receives ExecSession.

Closes #478
Closes #479

Ending a session did not empty the frames waiting for the agent, so
stdin typed before a sign-out, a loss of access or a browser leaving
reached the command before it was stopped (#479). Whatever the end, the
waiting frames are dropped and the agent's next frame stops the command.

Closes #479

Signed-off-by: samuel mbabhazi <[email protected]>
… again before it joins

An agent could open an ExecStream and stay silent before its first
frame, holding the stream with no credential check (#478). The first
frame must now come within 10 seconds, or the stream ends, and the
transport's cancellation ends the wait too. The node's credential is
checked again before it joins the session.

Closes #478

Signed-off-by: samuel mbabhazi <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 4 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 7c66ac1 and 2049cab.

Files selected for processing: 6

  • apps/api/src/modules/fleet/application/exec-relay.spec.ts
  • apps/api/src/modules/fleet/application/exec-relay.ts
  • apps/api/src/modules/fleet/interface/agent-gateway.ts
  • apps/api/src/modules/fleet/interface/exec-stream.spec.ts
  • apps/api/src/modules/fleet/interface/exec-stream.ts
  • docs/SPEC.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…what it should

Review of #494: the check before the join had no deadline and ignored
the transport's cancellation, so a stalled store held the stream and a
cancelled one could still join. Both waits of the opening now share the
10-second deadline and the cancellation, a session that is not this
node's is refused before any lookup, and only a refused credential is
UNAUTHENTICATED: a store failure is UNAVAILABLE.

Signed-off-by: samuel mbabhazi <[email protected]>
@samuelmbabhazi

Copy link
Copy Markdown
Collaborator Author

Code review (high), four findings, all fixed in 69500b3:

  1. Important: the credential check was not bounded. The read of the first frame and stillValid() now share one EXEC_OPEN_MS deadline and the transport's cancellation, in opened(). The signal is checked again before joinAgent, so a stream cancelled during the check joins nothing and the session stays joinable. Test: a stalled check ends with DEADLINE_EXCEEDED, and a check that resolves after a cancellation ends with CANCELED, the session still joinable.
  2. A store failure answered UNAUTHENTICATED. Only NodeAuthenticationError maps to UNAUTHENTICATED; anything else answers UNAVAILABLE, and the agent may open its stream again.
  3. The join assertions were weak. The tests now assert the join through joinAgent: undefined once joined, a relay when it was not.
  4. A database lookup for any session id. A session that is not this node's (registry.pending ownership) is refused with NOT_FOUND before any credential lookup. Test: a foreign node's open never calls the check.

Fleet unit tests: 157/157. api:lint and api:typecheck are clean. SPEC 3.1 is updated.

@samuelmbabhazi
samuelmbabhazi merged commit e4164ff into main Nov 25, 2026
25 of 27 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the fix/478-479-exec-opening branch November 25, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Discard pending exec input when access or sign-in is revoked Bound ExecStream opening time and revalidate credentials before joining

1 participant