-
Notifications
You must be signed in to change notification settings - Fork 20
fix(agent/git_ssh_signature): ssh signature forwarding fails when signing #648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ac4856a
294d23e
f3f1c0b
2df87b4
6ee2cd2
edffef8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package agent | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/skevetter/devpod/cmd/flags" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/suite" | ||
| ) | ||
|
|
||
| type GitSSHSignatureTestSuite struct { | ||
| suite.Suite | ||
| } | ||
|
|
||
| func TestGitSSHSignatureSuite(t *testing.T) { | ||
| suite.Run(t, new(GitSSHSignatureTestSuite)) | ||
| } | ||
|
|
||
| func (s *GitSSHSignatureTestSuite) TestAcceptsUnknownFlags() { | ||
| cmd := NewGitSSHSignatureCmd(&flags.GlobalFlags{}) | ||
|
|
||
| // Git passes: -Y sign -n git -f /path/to/key -U /dev/stdin /tmp/buffer | ||
| // -U is an unknown flag that consumes /dev/stdin as its value. | ||
| // /tmp/buffer remains as a positional argument. | ||
| err := cmd.ParseFlags( | ||
| []string{ | ||
| "-Y", | ||
| "sign", | ||
| "-n", | ||
| "git", | ||
| "-f", | ||
| "/path/to/key", | ||
| "-U", | ||
| "/dev/stdin", | ||
| "/tmp/buffer", | ||
| }, | ||
| ) | ||
| assert.NoError(s.T(), err, "flag parsing should succeed with unknown flag -U") | ||
|
|
||
| args := cmd.Flags().Args() | ||
| s.Require().NotEmpty(args, "should have positional args") | ||
| assert.Equal(s.T(), "/tmp/buffer", args[len(args)-1], | ||
| "buffer file should be preserved as last positional arg") | ||
| } | ||
|
|
||
| func (s *GitSSHSignatureTestSuite) TestBufferFileAsPositionalArg() { | ||
| cmd := NewGitSSHSignatureCmd(&flags.GlobalFlags{}) | ||
|
|
||
| err := cmd.ParseFlags( | ||
| []string{"-Y", "sign", "-n", "git", "-f", "/path/to/key", "/tmp/buffer"}, | ||
| ) | ||
| assert.NoError(s.T(), err) | ||
|
|
||
| args := cmd.Flags().Args() | ||
| s.Require().NotEmpty(args, "should have positional args") | ||
| assert.Equal(s.T(), "/tmp/buffer", args[len(args)-1], | ||
| "last positional arg should be the buffer file") | ||
| } | ||
|
|
||
| func (s *GitSSHSignatureTestSuite) TestKnownFlagsParsed() { | ||
| cmd := NewGitSSHSignatureCmd(&flags.GlobalFlags{}) | ||
|
|
||
| err := cmd.ParseFlags( | ||
| []string{"-Y", "sign", "-n", "git", "-f", "/path/to/key", "/tmp/buffer"}, | ||
| ) | ||
| assert.NoError(s.T(), err) | ||
|
|
||
| val, err := cmd.Flags().GetString("command") | ||
| assert.NoError(s.T(), err) | ||
| assert.Equal(s.T(), "sign", val, "command flag should be 'sign'") | ||
|
|
||
| args := cmd.Flags().Args() | ||
| s.Require().NotEmpty(args, "should have positional args") | ||
| assert.Equal(s.T(), "/tmp/buffer", args[len(args)-1], | ||
| "last positional arg should be the buffer file") | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ import ( | |
| "strings" | ||
| "syscall" | ||
|
|
||
| "al.essio.dev/pkg/shellescape" | ||
| "github.com/blang/semver/v4" | ||
| "github.com/sirupsen/logrus" | ||
| "github.com/skevetter/devpod/cmd/flags" | ||
|
|
@@ -382,21 +383,27 @@ func (cmd *UpCmd) configureWorkspace( | |
| log.Info("SSH configuration completed in workspace") | ||
| } | ||
|
|
||
| if cmd.GitSSHSigningKey != "" { | ||
| if err := setupGitSSHSignature(cmd.GitSSHSigningKey, client, log); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| return setupDotfiles( | ||
| if err := setupDotfiles( | ||
| cmd.DotfilesSource, | ||
| cmd.DotfilesScript, | ||
| cmd.DotfilesScriptEnvFile, | ||
| cmd.DotfilesScriptEnv, | ||
| client, | ||
| devPodConfig, | ||
| log, | ||
| ) | ||
| ); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Run after dotfiles so the signing config isn't overwritten by a | ||
| // dotfiles installer that replaces .gitconfig. | ||
| if cmd.GitSSHSigningKey != "" { | ||
| if err := setupGitSSHSignature(cmd.GitSSHSigningKey, client); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // openIDE opens the configured IDE. | ||
|
|
@@ -1539,7 +1546,6 @@ func collectDotfilesScriptEnvKeyvaluePairs(envFiles []string) ([]string, error) | |
| func setupGitSSHSignature( | ||
| signingKey string, | ||
| client client2.BaseWorkspaceClient, | ||
| log log.Logger, | ||
| ) error { | ||
| execPath, err := os.Executable() | ||
| if err != nil { | ||
|
|
@@ -1555,7 +1561,8 @@ func setupGitSSHSignature( | |
| remoteUser = "root" | ||
| } | ||
|
|
||
| err = exec.Command( | ||
| // #nosec G204 -- execPath is from os.Executable(), not user input | ||
| out, err := exec.Command( | ||
| execPath, | ||
| "ssh", | ||
| "--agent-forwarding=true", | ||
|
|
@@ -1565,10 +1572,13 @@ func setupGitSSHSignature( | |
| "--context", | ||
| client.Context(), | ||
| client.Workspace(), | ||
| "--command", fmt.Sprintf("devpod agent git-ssh-signature-helper %s", signingKey), | ||
| ).Run() | ||
| "--command", | ||
| shellescape.QuoteCommand( | ||
| []string{"devpod", "agent", "git-ssh-signature-helper", signingKey}, | ||
| ), | ||
|
Comment on lines
+1575
to
+1578
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This calls the runtime helper with the wrong argv shape.
🤖 Prompt for AI Agents |
||
| ).CombinedOutput() | ||
| if err != nil { | ||
| log.Error("failure in setting up git ssh signature helper") | ||
| return fmt.Errorf("setup git ssh signature helper: %w, output: %s", err, string(out)) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "name": "SSH Signing Test", | ||
| "image": "mcr.microsoft.com/devcontainers/go:1" | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.