Skip to content
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

fix: launch gpg-forwarding during UP if flag is specified #803

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ func (cmd *UpCmd) Run(
)
case string(config.IDEOpenVSCode):
return startVSCodeInBrowser(
cmd.GPGAgentForwarding,
ctx,
devPodConfig,
client,
Expand Down Expand Up @@ -226,6 +227,7 @@ func (cmd *UpCmd) Run(
return startFleet(ctx, client, log)
case string(config.IDEJupyterNotebook):
return startJupyterNotebookInBrowser(
cmd.GPGAgentForwarding,
ctx,
devPodConfig,
client,
Expand Down Expand Up @@ -403,13 +405,21 @@ func (cmd *UpCmd) devPodUpMachine(
}

func startJupyterNotebookInBrowser(
forwardGpg bool,
ctx context.Context,
devPodConfig *config.Config,
client client2.BaseWorkspaceClient,
user string,
ideOptions map[string]config.OptionValue,
logger log.Logger,
) error {
if forwardGpg {
err := performGpgForwarding(client, logger)
if err != nil {
return err
}
}

// determine port
jupyterAddress, jupyterPort, err := parseAddressAndPort(
jupyter.Options.GetValue(ideOptions, jupyter.BindAddressOption),
Expand Down Expand Up @@ -485,13 +495,21 @@ func startFleet(ctx context.Context, client client2.BaseWorkspaceClient, logger
}

func startVSCodeInBrowser(
forwardGpg bool,
ctx context.Context,
devPodConfig *config.Config,
client client2.BaseWorkspaceClient,
workspaceFolder, user string,
ideOptions map[string]config.OptionValue,
logger log.Logger,
) error {
if forwardGpg {
err := performGpgForwarding(client, logger)
if err != nil {
return err
}
}

// determine port
vscodeAddress, vscodePort, err := parseAddressAndPort(
openvscode.Options.GetValue(ideOptions, openvscode.BindAddressOption),
Expand Down Expand Up @@ -776,3 +794,47 @@ func setupDotfiles(

return nil
}

func performGpgForwarding(
client client2.BaseWorkspaceClient,
log log.Logger,
) error {
log.Debug("gpg forwarding enabled, performing immediately")

execPath, err := os.Executable()
if err != nil {
return err
}

remoteUser, err := devssh.GetUser(client.Workspace())
if err != nil {
remoteUser = "root"
}

log.Info("forwarding gpg-agent")

// perform in background an ssh command forwarding the
// gpg agent, in order to have it immediately take effect
go func() {
err = exec.Command(
execPath,
"ssh",
"--gpg-agent-forwarding=true",
"--agent-forwarding=true",
"--start-services=true",
"--user",
remoteUser,
"--context",
client.Context(),
client.Workspace(),
"--log-output=raw",
"--command", "sleep infinity",
).Run()

if err != nil {
log.Error("failure in forwarding gpg-agent")
}
}()

return nil
}