Skip to content

fix(agent/git_ssh_signature): remove agent-forwarding and start-services flags from setupGitSSHSignature#662

Merged
skevetter merged 9 commits intomainfrom
followup-ssh-signing
Apr 5, 2026
Merged

fix(agent/git_ssh_signature): remove agent-forwarding and start-services flags from setupGitSSHSignature#662
skevetter merged 9 commits intomainfrom
followup-ssh-signing

Conversation

@skevetter
Copy link
Copy Markdown
Owner

@skevetter skevetter commented Apr 2, 2026

Fixes #645

Summary by CodeRabbit

  • Bug Fixes

    • Git SSH signing helper accepts git/ssh-keygen-style arguments, ignores unknown flags, forwards non-sign invocations to the system ssh-keygen, and reports clear errors when required signing inputs are missing.
  • Tests

    • End-to-end tests expanded to exercise real commit signing and signature verification with longer timeouts and stricter assertions.
    • Unit tests updated to validate the revised argument parsing behavior and edge cases.
  • Chores

    • SSH helper invocation no longer requests agent forwarding or automatic service startup.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 844693b4-d47b-44cf-892b-c9645d48e95e

📥 Commits

Reviewing files that changed from the base of the PR and between 3bb2ca0 and 34b242e.

📒 Files selected for processing (1)
  • cmd/agent/git_ssh_signature.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/agent/git_ssh_signature.go

📝 Walkthrough

Walkthrough

Disabled Cobra flag parsing in the git SSH signature helper, added manual ssh-keygen -Y-style arg parsing and delegation to system ssh-keygen for non-sign subcommands, enforced explicit validation for sign, removed an exported CLI struct, adjusted helper construction, removed two SSH flags in up flow, and extended e2e tests to sign+verify commits.

Changes

Cohort / File(s) Summary
Git SSH signature CLI
cmd/agent/git_ssh_signature.go
Disabled Cobra flag parsing; added parseSSHKeygenArgs and flag-consumption helpers; RunE now dispatches on parsed -Y (delegates non-sign to system ssh-keygen forwarding stdio); validates -f, -n, and positional buffer for sign; removed exported GitSSHSignatureCmd and prior Cobra flag bindings.
Git SSH signature helper
cmd/agent/git_ssh_signature_helper.go
Now constructs GitSSHSignatureHelperCmd (rename of internal struct usage) while preserving argument validation and call to gitsshsigning.ConfigureHelper.
Workspace setup / up command
cmd/up.go
Removed explicit --agent-forwarding=true and --start-services=true flags from the SSH invocation used to launch the signature helper.
Unit tests (CLI parsing)
cmd/agent/git_ssh_signature_test.go
Replaced Cobra-based tests with direct tests of parseSSHKeygenArgs; covers -Y presence/absence (default sign), -n/-f, buffer-file detection and edge cases like trailing -U.
E2E SSH tests
e2e/tests/ssh/ssh.go
Converted to ginkgo.SpecTimeout style; expanded to assert helper installation, perform a signed commit over SSH, configure allowed_signers, run git verify-commit, and assert signature and signer identity in git log --show-signature.

Sequence Diagram(s)

sequenceDiagram
  participant GitClient as Git client
  participant Helper as devpod-ssh-signature
  participant Host as Host shell
  participant SSHKeygen as system ssh-keygen

  GitClient->>Helper: invoke helper (argv with -Y ...)
  Helper->>Helper: parse args (parseSSHKeygenArgs)
  alt subcommand == "sign"
    Helper->>Helper: validate -f, -n and positional buffer file
    Helper->>Host: read buffer file and sign using configured cert/key
    Host-->>Helper: signature bytes
    Helper-->>GitClient: write signature to stdout
  else other subcommand
    Helper->>Host: exec.LookPath("ssh-keygen")
    Helper->>SSHKeygen: exec ssh-keygen with reconstructed argv (stdio forwarded)
    SSHKeygen-->>GitClient: stdout/stderr passthrough
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title specifically references removing agent-forwarding and start-services flags from setupGitSSHSignature, which directly aligns with cmd/up.go changes removing those two flags.
Linked Issues check ✅ Passed The PR addresses issue #645's core problems: fixes flag parsing errors by disabling Cobra flag parsing and manually parsing ssh-keygen arguments [645], improves error handling with explicit error messages [645], and removes problematic SSH flags that were causing failures [645].
Out of Scope Changes check ✅ Passed All changes directly support fixing issue #645: git_ssh_signature.go refactors flag parsing to resolve the -U error, cmd/up.go removes problematic flags, tests verify the fix works end-to-end, and git_ssh_signature_helper.go aligns with the refactored implementation.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch followup-ssh-signing

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added the size/m label Apr 2, 2026
@skevetter skevetter marked this pull request as ready for review April 2, 2026 20:10
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (5)
e2e/tests/ssh/ssh.go (3)

141-143: No per-step timeout for DevPodUp.

Unlike the first test in this file (lines 46-50), this test uses the shared ctx directly for DevPodUp without a dedicated deadline. This means DevPodUp shares the entire 7-minute spec timeout with subsequent SSH calls and the commit test.

If DevPodUp hangs or takes longer than expected, it could consume most of the timeout budget, leaving insufficient time for the actual signing verification to complete (or provide misleading timeout errors).

Consider adding a dedicated context with a shorter deadline for DevPodUp to ensure predictable timeout behavior for each step.

Suggested fix
 			// Start workspace with git-ssh-signing-key flag
-			err = f.DevPodUp(ctx, tempDir, "--git-ssh-signing-key", keyPath+".pub")
+			devpodUpCtx, cancel := context.WithTimeout(ctx, 5*time.Minute)
+			defer cancel()
+			err = f.DevPodUp(devpodUpCtx, tempDir, "--git-ssh-signing-key", keyPath+".pub")
 			framework.ExpectNoError(err)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@e2e/tests/ssh/ssh.go` around lines 141 - 143, The DevPodUp call is using the
shared test context (ctx) without its own deadline; create a short-lived child
context (e.g., ctxStep := context.WithTimeout(ctx, <reasonable duration>) with a
deferred cancel()) and pass that child context to f.DevPodUp(ctxStep, tempDir,
"--git-ssh-signing-key", keyPath+".pub") so the DevPodUp step has its own
timeout budget and cannot exhaust the overall test timeout.

145-162: Same timeout concern applies to verification SSH calls.

The DevPodSSH calls on lines 146, 156, and 160 also use the shared ctx. Per the relevant code snippets, DevPodSSH blocks until the SSH command completes. If any of these calls hang, the only backstop is the 7-minute spec timeout.

For consistency with the first test (which uses a 20-second SSH deadline), consider wrapping these calls with shorter per-call timeouts.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@e2e/tests/ssh/ssh.go` around lines 145 - 162, The three synchronous SSH
verification calls to f.DevPodSSH (the test that checks
/usr/local/bin/devpod-ssh-signature and the two git config checks) currently use
the shared ctx and can hang the whole spec; wrap each call in its own short
per-call context (e.g., context.WithTimeout of ~20s) and pass that derived
context to DevPodSSH, remembering to call the cancel function after the call;
update all three places (the DevPodSSH invocations that assign to out, err
around the EXISTS check and the two git config checks) so each uses its own
timeout-limited context.

167-177: Chain of commands fails fast but error source is unclear.

Using && to chain shell commands ensures early exit on failure, which is good. However, if any intermediate command fails (e.g., git init, git config), the error message won't clearly indicate which step failed since ExecCommandCapture only returns the final error.

Consider adding set -e or checking individual command outputs if debugging flaky tests becomes necessary.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@e2e/tests/ssh/ssh.go` around lines 167 - 177, The chained shell commands
built in commitCmd produce an opaque failure when run via ExecCommandCapture;
prepend a strict shell mode (e.g., add "set -euo pipefail" or "set -e") before
the existing commands in commitCmd so the shell exits with a clearer error and
context on the failing command, or alternatively split the sequence and
capture/return each command's stderr to surface which specific git/config step
failed (referencing the commitCmd variable and where ExecCommandCapture is
invoked).
cmd/agent/git_ssh_signature.go (2)

44-44: Unused cobraCmd parameter.

The cobraCmd parameter is declared but never used. While this is a common pattern in Cobra handlers (to satisfy the RunE signature), consider using _ to make the intent explicit.

Suggested fix
-		RunE: func(cobraCmd *cobra.Command, args []string) error {
+		RunE: func(_ *cobra.Command, args []string) error {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/agent/git_ssh_signature.go` at line 44, The RunE handler declares an
unused parameter named cobraCmd; change the parameter name to the blank
identifier to indicate it's intentionally unused. Update the RunE signature in
git_ssh_signature.go from func(cobraCmd *cobra.Command, args []string) error to
use func(_ *cobra.Command, args []string) error so the handler still matches
Cobra's expected signature but avoids the unused variable warning.

48-51: Consider whether exposing os.Args[1:] in error messages is appropriate.

Including the full raw CLI arguments in the error message is useful for debugging, but could potentially expose sensitive information if any flags contain secrets (e.g., tokens, keys). Since this is an agent command invoked by git, the risk is likely low, but worth considering whether the additional flags: %v portion is necessary or if just the positional args count and values suffice.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/agent/git_ssh_signature.go` around lines 48 - 51, The error message in
the return statement exposes raw CLI flags via os.Args[1:]—locate the fmt.Errorf
call (the return fmt.Errorf(...) that mentions "buffer file is required") in
git_ssh_signature.go and remove or sanitize the flags portion; either drop the
", flags: %v" argument entirely and only log positional args (len(args), args)
or implement a small sanitizer (e.g., maskFlagValues or a sanitizeArgs function)
to redact values before including flags. Ensure the final fmt.Errorf call no
longer prints unredacted os.Args[1:] and update the format string/arguments
accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@cmd/agent/git_ssh_signature.go`:
- Line 44: The RunE handler declares an unused parameter named cobraCmd; change
the parameter name to the blank identifier to indicate it's intentionally
unused. Update the RunE signature in git_ssh_signature.go from func(cobraCmd
*cobra.Command, args []string) error to use func(_ *cobra.Command, args
[]string) error so the handler still matches Cobra's expected signature but
avoids the unused variable warning.
- Around line 48-51: The error message in the return statement exposes raw CLI
flags via os.Args[1:]—locate the fmt.Errorf call (the return fmt.Errorf(...)
that mentions "buffer file is required") in git_ssh_signature.go and remove or
sanitize the flags portion; either drop the ", flags: %v" argument entirely and
only log positional args (len(args), args) or implement a small sanitizer (e.g.,
maskFlagValues or a sanitizeArgs function) to redact values before including
flags. Ensure the final fmt.Errorf call no longer prints unredacted os.Args[1:]
and update the format string/arguments accordingly.

In `@e2e/tests/ssh/ssh.go`:
- Around line 141-143: The DevPodUp call is using the shared test context (ctx)
without its own deadline; create a short-lived child context (e.g., ctxStep :=
context.WithTimeout(ctx, <reasonable duration>) with a deferred cancel()) and
pass that child context to f.DevPodUp(ctxStep, tempDir, "--git-ssh-signing-key",
keyPath+".pub") so the DevPodUp step has its own timeout budget and cannot
exhaust the overall test timeout.
- Around line 145-162: The three synchronous SSH verification calls to
f.DevPodSSH (the test that checks /usr/local/bin/devpod-ssh-signature and the
two git config checks) currently use the shared ctx and can hang the whole spec;
wrap each call in its own short per-call context (e.g., context.WithTimeout of
~20s) and pass that derived context to DevPodSSH, remembering to call the cancel
function after the call; update all three places (the DevPodSSH invocations that
assign to out, err around the EXISTS check and the two git config checks) so
each uses its own timeout-limited context.
- Around line 167-177: The chained shell commands built in commitCmd produce an
opaque failure when run via ExecCommandCapture; prepend a strict shell mode
(e.g., add "set -euo pipefail" or "set -e") before the existing commands in
commitCmd so the shell exits with a clearer error and context on the failing
command, or alternatively split the sequence and capture/return each command's
stderr to surface which specific git/config step failed (referencing the
commitCmd variable and where ExecCommandCapture is invoked).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9315c1cd-a19e-4c96-b0b4-05fc47c0193a

📥 Commits

Reviewing files that changed from the base of the PR and between 31f783b and 196187d.

📒 Files selected for processing (3)
  • cmd/agent/git_ssh_signature.go
  • cmd/up.go
  • e2e/tests/ssh/ssh.go
💤 Files with no reviewable changes (1)
  • cmd/up.go

Add Step 4 to the SSH signing test that cryptographically verifies the
commit is actually signed:
- Reads the public key used for signing
- Creates an allowed signers file inside the workspace
- Runs git verify-commit HEAD and asserts "Good" signature
- Runs git log --show-signature and confirms the signature is
  associated with the correct email principal
@skevetter skevetter force-pushed the followup-ssh-signing branch from f4b2c67 to 2afcf52 Compare April 4, 2026 03:27
@github-actions github-actions bot added size/l and removed size/m labels Apr 4, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
e2e/tests/ssh/ssh.go (1)

213-239: Cover verify/log without tunnel-only flags.

The new production path delegates non-sign operations to local ssh-keygen, so these two assertions would be stronger if they ran without --agent-forwarding and --start-services. That way the spec proves verify/log do not depend on the credentials tunnel.

Possible simplification
 			stdout, stderr, err = f.ExecCommandCapture(ctx, []string{
 				"ssh",
-				"--agent-forwarding",
-				"--start-services",
 				tempDir,
 				"--command", verifyCmd,
 			})
@@
 			stdout, stderr, err = f.ExecCommandCapture(ctx, []string{
 				"ssh",
-				"--agent-forwarding",
-				"--start-services",
 				tempDir,
 				"--command", logCmd,
 			})
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@e2e/tests/ssh/ssh.go` around lines 213 - 239, The verify and log assertions
currently call f.ExecCommandCapture with tunnel-related flags
("--agent-forwarding", "--start-services"); update the two calls that run
verifyCmd and logCmd so they invoke f.ExecCommandCapture without those
tunnel-only flags (i.e., remove "--agent-forwarding" and "--start-services" from
the argument slices passed where verifyCmd and logCmd are executed) so the test
exercises the local ssh-keygen production path for VerifySignature/LogSignature;
keep the same verifyCmd and logCmd strings and existing assertions
(stdout/stderr combine and git log checks) but call ExecCommandCapture with a
simpler slice like []string{"ssh", tempDir, "--command", verifyCmd} and
similarly for logCmd.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/agent/git_ssh_signature.go`:
- Around line 87-102: The code currently reconstructs sshArgs from os.Args and
always calls exec.Command(sshKeygen, sshArgs...), which can invoke ssh-keygen
with empty/missing Git request if no matching os.Args entry is found; before
creating the command, check whether the loop actually found a match (i.e.,
sshArgs is non-nil/non-empty or track a boolean found flag), and if not, log an
explicit error with the original os.Args (use logger.Errorf or logger.Debugf)
and return a non-zero error instead of delegating to ssh-keygen; ensure this
guard is placed before exec.Command and c.Run() so you never launch ssh-keygen
with an incomplete argv.

---

Nitpick comments:
In `@e2e/tests/ssh/ssh.go`:
- Around line 213-239: The verify and log assertions currently call
f.ExecCommandCapture with tunnel-related flags ("--agent-forwarding",
"--start-services"); update the two calls that run verifyCmd and logCmd so they
invoke f.ExecCommandCapture without those tunnel-only flags (i.e., remove
"--agent-forwarding" and "--start-services" from the argument slices passed
where verifyCmd and logCmd are executed) so the test exercises the local
ssh-keygen production path for VerifySignature/LogSignature; keep the same
verifyCmd and logCmd strings and existing assertions (stdout/stderr combine and
git log checks) but call ExecCommandCapture with a simpler slice like
[]string{"ssh", tempDir, "--command", verifyCmd} and similarly for logCmd.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 65332727-d55f-4257-b336-c01b11b9bd54

📥 Commits

Reviewing files that changed from the base of the PR and between f4b2c67 and 2afcf52.

📒 Files selected for processing (3)
  • cmd/agent/git_ssh_signature.go
  • cmd/up.go
  • e2e/tests/ssh/ssh.go
💤 Files with no reviewable changes (1)
  • cmd/up.go

Comment thread cmd/agent/git_ssh_signature.go Outdated
@skevetter skevetter marked this pull request as draft April 4, 2026 16:24
- Rename unused cobraCmd parameter to _ in RunE closure
- Remove os.Args[1:] from buffer-file-missing error message
- Add nil guard in delegateToSSHKeygen when git-ssh-signature not found in os.Args
…ormat

Replace the cobra flag-parsing approach with DisableFlagParsing:true and a
dedicated parseSSHKeygenArgs parser. This command implements the ssh-keygen
protocol used by git, not a standard CLI; cobra's flag parser cannot handle
boolean flags like -U (ssh-agent mode) that git passes before the buffer file
because pflag consumes the following argument as the flag's value, leaving
positional args empty.

With DisableFlagParsing, RunE receives the raw args and parseSSHKeygenArgs
parses -Y/-f/-n by position, treating the last non-flag argument as the buffer
file regardless of what flags precede it. delegateToSSHKeygen now takes args
directly instead of parsing os.Args.
@skevetter skevetter force-pushed the followup-ssh-signing branch from 7247df2 to 0b879fe Compare April 4, 2026 16:50
@skevetter skevetter marked this pull request as ready for review April 4, 2026 20:43
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
cmd/agent/git_ssh_signature.go (1)

15-22: Consider removing the unused GitSSHSignatureCmd struct.

This struct is defined but never instantiated or used. The new implementation returns a cobra.Command directly and stores parsed values in the local sshKeygenArgs struct instead.

🧹 Proposed cleanup
-type GitSSHSignatureCmd struct {
-	*flags.GlobalFlags
-
-	CertPath   string
-	Namespace  string
-	BufferFile string
-	Command    string
-}
-
 // NewGitSSHSignatureCmd creates new git-ssh-signature command

If removed, also remove the "github.com/skevetter/devpod/cmd/flags" import if it becomes unused.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/agent/git_ssh_signature.go` around lines 15 - 22, Remove the unused
GitSSHSignatureCmd type declaration (the struct that embeds *flags.GlobalFlags
and fields CertPath, Namespace, BufferFile, Command) since the command now
builds and returns a cobra.Command and uses the local sshKeygenArgs; also remove
the "github.com/skevetter/devpod/cmd/flags" import if it becomes unused after
deleting GitSSHSignatureCmd to keep imports clean.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@cmd/agent/git_ssh_signature.go`:
- Around line 15-22: Remove the unused GitSSHSignatureCmd type declaration (the
struct that embeds *flags.GlobalFlags and fields CertPath, Namespace,
BufferFile, Command) since the command now builds and returns a cobra.Command
and uses the local sshKeygenArgs; also remove the
"github.com/skevetter/devpod/cmd/flags" import if it becomes unused after
deleting GitSSHSignatureCmd to keep imports clean.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5ec005d0-6399-49e0-94df-8bd2ccb9c97b

📥 Commits

Reviewing files that changed from the base of the PR and between 2afcf52 and 0b879fe.

📒 Files selected for processing (2)
  • cmd/agent/git_ssh_signature.go
  • cmd/agent/git_ssh_signature_test.go

The struct was no longer used after the command switched to
DisableFlagParsing with a local sshKeygenArgs struct. Also fix
git_ssh_signature_helper.go to use its own GitSSHSignatureHelperCmd
type instead of the now-removed GitSSHSignatureCmd.
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
cmd/agent/git_ssh_signature.go (1)

74-77: Edge case: buffer file detection when arguments are malformed.

If the command is invoked incorrectly without a buffer file (e.g., -Y sign -n git -f /path/key), the -f value would be mistakenly treated as the buffer file. This wouldn't occur in normal git usage since git always appends the buffer file, but could cause confusing errors in manual debugging scenarios.

Consider this defensive improvement if robustness is desired:

🔧 Optional: Track consumed positions to avoid misidentifying flag values
 func parseSSHKeygenArgs(args []string) sshKeygenArgs {
 	result := sshKeygenArgs{
 		command: "sign",
 	} // git only ever calls with sign, but default defensively
+	consumed := make(map[int]bool)
 	for i := 0; i < len(args); i++ {
-		consumeFlag(&result, args, &i)
+		if next := consumeFlag(&result, args, i); next > i {
+			consumed[i] = true
+			consumed[next] = true
+			i = next
+		}
 	}
 	// The buffer file is always the last argument and is never a flag.
-	if len(args) > 0 && !strings.HasPrefix(args[len(args)-1], "-") {
+	lastIdx := len(args) - 1
+	if lastIdx >= 0 && !consumed[lastIdx] && !strings.HasPrefix(args[lastIdx], "-") {
 		result.bufferFile = args[len(args)-1]
 	}
 	return result
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/agent/git_ssh_signature.go` around lines 74 - 77, The current logic sets
result.bufferFile = args[len(args)-1] which can misidentify a flag value as the
buffer file when arguments are malformed; update the parsing to mark consumed
positions and ignore known flag-value pairs before picking the last unconsumed
arg. Iterate args left-to-right, maintain a set of flags that accept a value
(e.g., "-f", "-n", etc.), skip the value following any such flag when marking
consumed indices, and then assign result.bufferFile to the last arg index that
was not consumed; this change should be applied around the existing bufferFile
detection logic that references args and result.bufferFile in
git_ssh_signature.go.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@cmd/agent/git_ssh_signature.go`:
- Around line 74-77: The current logic sets result.bufferFile =
args[len(args)-1] which can misidentify a flag value as the buffer file when
arguments are malformed; update the parsing to mark consumed positions and
ignore known flag-value pairs before picking the last unconsumed arg. Iterate
args left-to-right, maintain a set of flags that accept a value (e.g., "-f",
"-n", etc.), skip the value following any such flag when marking consumed
indices, and then assign result.bufferFile to the last arg index that was not
consumed; this change should be applied around the existing bufferFile detection
logic that references args and result.bufferFile in git_ssh_signature.go.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bb3a6176-34db-4fca-86b4-3d767b2dca74

📥 Commits

Reviewing files that changed from the base of the PR and between 0b879fe and 825c9ca.

📒 Files selected for processing (2)
  • cmd/agent/git_ssh_signature.go
  • cmd/agent/git_ssh_signature_helper.go

Track consumed argument positions in parseSSHKeygenArgs so that
flag values (e.g. the -f path) are not mistakenly identified as
the buffer file when arguments are malformed.
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/agent/git_ssh_signature.go`:
- Around line 43-48: The code only validates parsed.bufferFile before calling
gitsshsigning.HandleGitSSHProgramCall, allowing missing -f (certPath) or -n
(namespace) to propagate confusing errors; update the argument validation in the
same block to also check parsed.certPath and parsed.namespace are non-empty and
return clear fmt.Errorf messages (e.g., "cert path (-f) is required" and
"namespace (-n) is required") before invoking
gitsshsigning.HandleGitSSHProgramCall so missing flags fail fast with actionable
errors.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 98ab94b7-a850-4585-a35e-a6c4d7662623

📥 Commits

Reviewing files that changed from the base of the PR and between 0b879fe and 77a3fe2.

📒 Files selected for processing (2)
  • cmd/agent/git_ssh_signature.go
  • cmd/agent/git_ssh_signature_helper.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/agent/git_ssh_signature_helper.go

Comment thread cmd/agent/git_ssh_signature.go
Add upfront checks for -f (certPath) and -n (namespace) flags so
missing values fail fast with actionable errors instead of propagating
empty strings into the signing flow.
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/agent/git_ssh_signature.go`:
- Around line 96-111: The consumeFlag function currently treats any next token
as a value (setting result.command, certPath, or namespace) even when that token
is another flag; update consumeFlag to first check that i+1 < len(args) AND that
args[i+1] is not a flag-like token (e.g., strings.HasPrefix(args[i+1], "-"))
before consuming it, and if the next token is flag-like, do not consume it
(return i) so the higher-level missing-arg validation can catch the error; apply
this check for the "-Y" (result.command), "-f" (result.certPath) and "-n"
(result.namespace) cases.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 90759b57-1901-4d29-9042-47e511b7668d

📥 Commits

Reviewing files that changed from the base of the PR and between 0b879fe and 3bb2ca0.

📒 Files selected for processing (2)
  • cmd/agent/git_ssh_signature.go
  • cmd/agent/git_ssh_signature_helper.go
✅ Files skipped from review due to trivial changes (1)
  • cmd/agent/git_ssh_signature_helper.go

Comment thread cmd/agent/git_ssh_signature.go
Treat next-arg tokens starting with "-" as missing values so that
malformed args like `-f -U` leave certPath empty and get caught by
the upstream validation instead of silently setting a wrong value.
@skevetter skevetter merged commit 2738ef0 into main Apr 5, 2026
41 checks passed
@skevetter skevetter deleted the followup-ssh-signing branch April 5, 2026 04:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Git SSH signature forwarding doesn't work

1 participant