forked from loft-sh/devpod
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathforward.go
More file actions
58 lines (48 loc) · 1.28 KB
/
forward.go
File metadata and controls
58 lines (48 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package gpg
import (
"os"
"os/exec"
client2 "github.com/skevetter/devpod/pkg/client"
devssh "github.com/skevetter/devpod/pkg/ssh"
"github.com/skevetter/log"
)
// ForwardAgent starts a background SSH connection that forwards the local GPG agent.
func ForwardAgent(client client2.BaseWorkspaceClient, logger log.Logger) error {
logger.Debug("gpg forwarding enabled, performing immediately")
execPath, err := os.Executable()
if err != nil {
return err
}
remoteUser, err := devssh.GetUser(
client.WorkspaceConfig().ID,
client.WorkspaceConfig().SSHConfigPath,
client.WorkspaceConfig().SSHConfigIncludePath,
)
if err != nil {
remoteUser = "root"
}
logger.Info("forwarding gpg-agent")
args := buildForwardArgs(remoteUser, client.Context(), client.Workspace())
go func() {
//nolint:gosec // execPath comes from os.Executable()
if runErr := exec.Command(execPath, args...).Run(); runErr != nil {
logger.Errorf("failure in forwarding gpg-agent: %v", runErr)
}
}()
return nil
}
func buildForwardArgs(user, context, workspace string) []string {
return []string{
"ssh",
"--gpg-agent-forwarding=true",
"--agent-forwarding=true",
"--start-services=true",
"--user",
user,
"--context",
context,
workspace,
"--log-output=raw",
"--command", "sleep infinity",
}
}