feat(git): opt-in run glab on SSH execution host
Summary
- Opt-in per SSH target: "Run GitLab CLI (glab) on this host" so forge credentials that live only on the remote box work.
- When enabled, glab runs via relay
glab.exec(binary allowlist, argv-only, size caps) with capability cache and silent local fallback when the method is unavailable. - Default remains local/WSL resolution when the flag is off.
Fixes
Closes #10559
Test plan
- [x] glab-ssh-execution capability isolation, runner routing, relay handler allowlist, form/save tests
- [ ] Manual: SSH target with glab + GitLab auth only on remote; enable flag; open MR/pipeline actions
ELI5
For SSH hosts where GitLab credentials only exist on the remote machine, you can opt in to run glab on that host instead of locally so forge operations use the right tokens.
[!NOTE]
Reviews paused
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
- [ ] ▶️ Resume reviews
- [ ] 🔍 Trigger review
📝 Walkthrough
Walkthrough
Adds an opt-in SSH target setting for running repository-scoped glab commands remotely. Registers a relay glab.exec handler with timeout, cancellation, output limits, and structured errors. Routes remote execution through the SSH multiplexer with capability caching and local fallback. Extends repository execution options and SSH target persistence. Adds renderer, relay, routing, capability, fallback, and error-handling tests.
🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (2 warnings)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Description check | ⚠️ Warning | The description explains the feature and tests but omits the required Screenshots, AI Review Report, Security Audit, and Notes sections. | Add all required template sections, including Screenshots, AI Review Report, Security Audit, and Notes, and include the standard testing checklist. |
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 31.58% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title clearly and concisely describes the opt-in GitLab CLI execution change on SSH hosts. |
| Linked Issues check | ✅ Passed | The changes satisfy the coding objectives in [#10559], including opt-in routing, relay safeguards, capability caching, fallback, isolation, and preserved local behavior. |
| Out of Scope Changes check | ✅ Passed | The changes remain within [#10559] and do not add the explicitly excluded gh routing, Tasks iteration, rate-limit keys, or integrations UI status. |
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.
Comment @coderabbitai help to get the list of available commands.
Sync update (6075d850a)
Address CodeRabbit: thread AbortSignal through tryGlabOnSshHost/requestRemoteGlab into mux.request so remote glab cancels like local execFileCapture.
- Commit:
6075d850a4ca515b7ed3e8ee0ed6fcfc453d388f - Upstream: https://github.com/stablyai/orca/pull/10653
- Fork portfolio: https://github.com/innocarpe/orca/pull/96
Went through this as the #10559 author — it solves the exact scenario I filed it for (GitLab self-managed where credentials exist only on the SSH host), and the shape is what I'd hoped for:
- Opt-in per SSH target with local/WSL resolution untouched when the flag is off — verified the default-off path in
ssh-target-draftand the runner routing. - The capability cache being keyed to the mux instance (WeakMap) is a nice touch — reconnects get a fresh probe for free, and the in-flight dedup avoids a probe stampede from concurrent MR polls.
- Relay side looks appropriately paranoid: hard-coded binary, argv-only spawn, output/timeout caps, and
MethodNotFoundcleanly degrading to the local path for older relays. - Confirmed the last sync threaded
AbortSignalthroughtryGlabOnSshHost→mux.request, so remote glab cancels like the localexecFileCapturepath.
One non-blocking thought: glab-exec-handler spreads client-supplied env over process.env unfiltered. Same trust domain as the existing relay exec surface, so no objection — but if a hardening pass ever happens, an env-key allowlist (e.g. GITLAB_HOST/GLAB_*) would make this endpoint self-documenting.
I have a real environment matching the manual test-plan item (self-managed GitLab, remote-only auth) and will run it through that as soon as I'm able. Thanks @innocarpe — great turnaround on this.
Thanks @dcieslak19973 — really appreciate the #10559-author walkthrough (opt-in default, mux-keyed cache, relay spawn caps, and the AbortSignal path).
Noted on the non-blocking env-key allowlist idea for glab-exec-handler; happy to treat that as a later hardening pass rather than expand this PR. Looking forward to your self-managed GitLab manual run when you get a chance.
Greptile Summary
This PR adds an opt-in per-SSH-target flag (runGitLabCliOnHost) that routes glab CLI calls through the relay to the remote machine instead of running locally, enabling GitLab forge operations when credentials exist only on the SSH host.
- Relay handler (
GlabExecHandler): hard-pins the binary toglabwith argv-only spawn (no shell), enforces a 4 MiB output cap, and is intentionally a distinct method (glab.exec) so older relays return-32601and the desktop falls back silently. - Capability cache (
glab-ssh-execution.ts): WeakMap keyed on the mux object so reconnects auto-expire stale state; concurrent probes are coalesced to avoid duplicate round-trips;method-not-foundis cached with a back-off interval. - UI + persistence: toggle appears under SSH advanced fields; field is omitted when false to keep persisted targets compact and default-off.
Confidence Score: 5/5
Safe to merge — the feature is strictly opt-in, all existing SSH targets default off, and the local-glab code path is unchanged.
The new relay handler hard-pins the binary, uses argv-only spawn, caps output at 4 MiB with immediate settle (as fixed in this PR), and the capability cache correctly falls back silently on older relays. The one noted asymmetry (abort path does not call finish inline) is benign because the mux transport discards the result once the request is cancelled. The change is fully opt-in and the entire existing non-SSH code path is unaffected.
Files Needing Attention: src/relay/glab-exec-handler.ts — the abort signal path in cancelCurrent is the only inconsistency worth a follow-up.
Important Files Changed
| Filename | Overview |
|---|---|
| src/relay/glab-exec-handler.ts | New relay handler that hard-pins the binary to glab, enforces arg-only argv (no shell), caps output at 4 MiB, and calls finish inline for timeout and output-limit. The abort path omits the inline finish, leaving the timer live until onClose. |
| src/main/git/glab-ssh-execution.ts | Clean capability-probe+cache layer using WeakMap keyed on the mux object so reconnects auto-invalidate stale state. Concurrent probe coalescing, per-target isolation, and method-not-found fallback are all correct. |
| src/main/git/runner.ts | Adds sshTargetId/remoteCwd options to GlabExecOptions and inserts the remote-glab probe before local resolution; null-guard falls through to the existing local path transparently. |
| src/main/gitlab/gitlab-project-ref-resolution.ts | glabRepoExecOptions now threads sshTargetId and remoteCwd into glab options. Backward-compatible: without the flag, tryGlabOnSshHost returns null and local execution is unchanged. |
| src/main/persistence.ts | Persists runGitLabCliOnHost using the same opt-in-only pattern as systemSshConnectionReuse: field is omitted when false to keep stored targets compact. |
| src/renderer/src/components/settings/SshHostAdvancedFields.tsx | Adds the toggle for 'Run GitLab CLI (glab) on this host' consistent with adjacent advanced-field patterns. |
| src/shared/ssh-types.ts | Adds runGitLabCliOnHost?: boolean to SshTarget and exports the GLAB_EXEC_METHOD constant; correctly modeled as optional to default off. |
| src/relay/relay.ts | Instantiates GlabExecHandler alongside the other per-dispatcher handlers. |
Sequence Diagram
sequenceDiagram
participant C as glabExecFileAsync
participant T as tryGlabOnSshHost
participant M as Mux (relay transport)
participant H as GlabExecHandler (on SSH host)
C->>T: args, sshTargetId, remoteCwd
T->>T: check runGitLabCliOnHost flag
alt flag off or no mux
T-->>C: null (use local glab)
else capability cached unsupported
T-->>C: null (use local glab)
else capability unknown
T->>M: glab.exec args cwd timeoutMs
M->>H: dispatch request
H->>H: spawn glab shell false argv-only
H-->>M: stdout stderr exitCode
M-->>T: GlabRemoteExecResult
alt exitCode 0
T-->>C: stdout stderr
else method-not-found
T->>T: cache unsupported back-off
T-->>C: null use local glab
else glab error
T->>T: mark supported throw
T-->>C: throws error
end
else capability supported
T->>M: glab.exec args cwd timeoutMs
M->>H: dispatch request
H-->>M: stdout stderr exitCode
M-->>T: GlabRemoteExecResult
T-->>C: stdout stderr or throws
end
Reviews (2): Last reviewed commit: "fix(relay): finish glab.exec immediately..." | Re-trigger Greptile
Sync update (20fa72fe0)
Address Greptile: output-limit finish path (20fa72fe0)
When glab.exec hits the 4 MiB capture limit, the handler now calls finish immediately (same shape as the timeout path) with outputLimitExceeded: 'stdout' | 'stderr', instead of only killing and waiting for close (which produced exitCode: null → "exited with code unknown").
Desktop maps the flag to: glab stdout|stderr exceeded capture limit on SSH host.
Evidence
pnpm exec vitest run --config config/vitest.config.ts src/relay/glab-exec-handler.test.ts src/main/git/glab-ssh-execution.test.ts— 15 passed
Upstream: https://github.com/stablyai/orca/pull/10653
- Commit:
20fa72fe00261fa86a1bdf86295833b67bb3eeae - Upstream: https://github.com/stablyai/orca/pull/10653
- Fork portfolio: https://github.com/innocarpe/orca/pull/96
Sync update (69f11f71f8)
Rebased onto latest main to clear conflicts. Kept main's experimentalPtySourceCreditV1 normalization and saveNewSshHostFromForm path; runGitLabCliOnHost still flows via ssh-target-save-payload. Focused glab SSH suite 58 passed.
- Commit:
69f11f71f812b6ca7b2ac02004f013fbc77aa0e6 - Upstream: https://github.com/stablyai/orca/pull/10653
- Fork portfolio: https://github.com/innocarpe/orca/pull/96
[!NOTE] GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.
Sync update (00ec492b81)
Address CodeRabbit: define GLAB_EXEC_METHOD locally in the relay bundle and decode glab stdout/stderr with StringDecoder (UTF-8 split-chunk test). Focused glab suite 19 passed.
- Commit:
00ec492b81d6f22dd3f33b19089066875da91f3a - Upstream: https://github.com/stablyai/orca/pull/10653
- Fork portfolio: https://github.com/innocarpe/orca/pull/96
[!NOTE] GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.
thanks for the PR. Will take a look
Sync update (8c1c7653de)
Address CodeRabbit: add abort-signal coverage for glab.exec (already-aborted + post-spawn abort). Handler tests 8 passed.
- Commit:
8c1c7653de9f9b5b0585d30ec3168fab15d893ea - Upstream: https://github.com/stablyai/orca/pull/10653
- Fork portfolio: https://github.com/innocarpe/orca/pull/96
[!NOTE] GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.
[!NOTE] GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.
Sync update (db7df486fe)
Address review: glab.exec now returns the existing cancellation-shaped result before spawn when the request signal is already aborted, with a regression asserting spawn is not called.
- Commit:
db7df486fe40af8a3b495e3c57223a741e79da7b - Upstream: https://github.com/stablyai/orca/pull/10653
- Fork portfolio: https://github.com/innocarpe/orca/pull/96
Sync update (d5271639a1)
Address security review: glab.exec now allowlists caller-provided GitLab/glab env vars and ignores PATH/Path/PATHEXT so request parameters cannot redirect the glab binary lookup.
- Commit:
d5271639a1665e0f96d38286de43173eea398677 - Upstream: https://github.com/stablyai/orca/pull/10653
- Fork portfolio: https://github.com/innocarpe/orca/pull/96
Sync update (ca338c910f)
Address security review: preserve trusted PATH/Path entries while excluding hostile executable-resolution overrides, with regression coverage for the safe environment contract.
- Commit:
ca338c910fd7e70ff725a2302131853b1ae214c8 - Upstream: https://github.com/stablyai/orca/pull/10653
- Fork portfolio: https://github.com/innocarpe/orca/pull/96
Thank you @innocarpe for this. The SSH relay (and so the glab.exec relay handler) was removed in #27214/#27215; SSH hosts now run Orca's managed remote server. Running glab on the SSH host is still a valid request, so it stays tracked in #10559 (with your PR as the reference for the allowlist/env hardening); closing this one since its code targets the removed relay.