You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds a POST /v1/run-command WinRM endpoint so the control plane can run one operator-supplied command on a Windows host after a certificate sync delivers its files.
The command is wrapped in a PowerShell script that reports its own outcome in a trailer tagged with a per-run nonce, rather than relying on the process exit code. Measured on a real host, an exit inside the wrapper is swallowed and arrives as 0, so a failed command would otherwise be reported as a successful sync. The script uses $? rather than $LASTEXITCODE so the outcome is the last statement's, matching how sh -c decides it on Linux; reading $LASTEXITCODE alone fails a run where findstr or robocopy exited non-zero routinely.
Output is capped per stream, with the last bytes retained so a command that floods stdout and then fails is still reported as failed. PowerShell's CLIXML stderr is decoded to plain text. A requested timeout above the ceiling is clamped rather than reset to the default.
Type ✨
Bug fix
New feature
Improvement
Breaking change
Documentation
Tests 🛠️
# Here's some code block to paste some code snippets
Adds a bounded WinRM command-execution endpoint for Windows gateway targets.
Wraps supplied PowerShell commands with nonce-tagged outcome reporting and CLIXML stderr normalization.
Adds command length, timeout, and per-stream output limits.
Adds unit tests for timeout clamping, trailer parsing, output bounds, encoding limits, and stderr normalization.
Confidence Score: 4/5
The exit-status collision must be fixed before merging because valid PowerShell commands can cause the gateway to report the wrong command outcome.
The supplied command shares scope with the wrapper's result variable, allowing ordinary command text to overwrite the reported status; additionally, capped responses expose the beginning rather than the retained diagnostic tail.
Adds command execution and bounded result handling, but wrapper-variable collisions can corrupt exit status and truncated responses discard retained tail diagnostics.
packages/gateway-v2/winrm_handler.go
Registers and validates the new route while preserving certificate-derived target routing and bounded timeouts.
packages/gateway-v2/winrm/winrm_command_test.go
Adds broad helper-level coverage but does not cover wrapper-variable collisions or returned tail diagnostics.
packages/gateway-v2/winrm_run_command_test.go
Verifies timeout defaults, clamping, overflow handling, and consistency with the outer operation deadline.
The reason will be displayed to describe this comment to others. Learn more.
Not an issue with this PR specifically but I noticed we're missing a forwardConfig.ActorType != ActorTypePlatform check in this if branch in gateway.go. Can we add that here?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description 📣
Adds a
POST /v1/run-commandWinRM endpoint so the control plane can run one operator-supplied command on a Windows host after a certificate sync delivers its files.The command is wrapped in a PowerShell script that reports its own outcome in a trailer tagged with a per-run nonce, rather than relying on the process exit code. Measured on a real host, an
exitinside the wrapper is swallowed and arrives as 0, so a failed command would otherwise be reported as a successful sync. The script uses$?rather than$LASTEXITCODEso the outcome is the last statement's, matching howsh -cdecides it on Linux; reading$LASTEXITCODEalone fails a run wherefindstrorrobocopyexited non-zero routinely.Output is capped per stream, with the last bytes retained so a command that floods stdout and then fails is still reported as failed. PowerShell's CLIXML stderr is decoded to plain text. A requested timeout above the ceiling is clamped rather than reset to the default.
Type ✨
Tests 🛠️
# Here's some code block to paste some code snippets