Skip to content

Commit 97bee82

Browse files
Merge pull request #1785 from loft-sh/feature/tailscale-network-rewrite
Feature/tailscale network rewrite
2 parents 4b010b4 + e764d5c commit 97bee82

File tree

5,276 files changed

+733622
-63527
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

5,276 files changed

+733622
-63527
lines changed

.github/workflows/release.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ jobs:
112112
target: x86_64-unknown-linux-gnu
113113
os: linux
114114
arch: amd64
115-
cli_only: false
115+
cli_only: true
116116
- host: ubuntu-22.04
117117
target: aarch64-unknown-linux-gnu
118118
os: linux
@@ -241,6 +241,7 @@ jobs:
241241
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
242242
APPLE_ID: ${{ secrets.APPLE_ID }}
243243
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
244+
CI: false # https://github.com/tauri-apps/tauri-action/issues/740
244245

245246
- name: Build linux tar.gz
246247
if: matrix.settings.host == 'ubuntu-22.04' && matrix.settings.cli_only == false

.gitignore

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
.DS_Store
33
/test
44
/e2e/bin
5-
devpod
6-
devpod.exe
7-
devpod-cli
5+
/devpod
6+
/devpod.exe
7+
/devpod-cli
88
# Unit test targets
9-
main
10-
profile.out
11-
package-lock.json
12-
tags
9+
/main
10+
/profile.out
11+
/package-lock.json
12+
/tags

Makefile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
GOOS := $(shell go env GOOS)
22
GOARCH := $(shell go env GOARCH)
33

4+
# Platform host
5+
PLATFORM_HOST := localhost:8080
6+
47
# Build the CLI and Desktop
58
.PHONY: build
69
build:
7-
BUILD_PLATFORMS=$(GOOS) ./hack/rebuild.sh
10+
BUILD_PLATFORMS=$(GOOS) BUILD_ARCHS=$(GOARCH) ./hack/rebuild.sh
11+
12+
# Run the desktop app
13+
.PHONY: run-desktop
14+
run-desktop: build
15+
cd desktop && yarn desktop:dev
16+
17+
# Run the daemon against loft host
18+
.PHONY: run-daemon
19+
run-daemon: build
20+
devpod pro daemon start --host $(PLATFORM_HOST)
821

922
# Copy the devpod binary to the platform pod
1023
.PHONY: cp-to-platform
1124
cp-to-platform:
12-
SKIP_INSTALL=true BUILD_PLATFORMS=linux ./hack/rebuild.sh
25+
SKIP_INSTALL=true BUILD_PLATFORMS=linux BUILD_ARCHS=$(GOARCH) ./hack/rebuild.sh
1326
POD=$$(kubectl get pod -n loft -l app=loft,release=loft -o jsonpath='{.items[0].metadata.name}'); \
1427
echo "Copying ./test/devpod-linux-$(GOARCH) to pod $$POD"; \
1528
kubectl cp -n loft ./test/devpod-linux-$(GOARCH) $$POD:/usr/local/bin/devpod

cmd/agent/container/container.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ func NewContainerCmd(flags *flags.GlobalFlags) *cobra.Command {
1818
containerCmd.AddCommand(NewOpenVSCodeAsyncCmd())
1919
containerCmd.AddCommand(NewCredentialsServerCmd(flags))
2020
containerCmd.AddCommand(NewSetupLoftPlatformAccessCmd(flags))
21+
containerCmd.AddCommand(NewSSHServerCmd(flags))
2122
return containerCmd
2223
}
Lines changed: 5 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package container
22

33
import (
4-
"bytes"
54
"context"
65
"encoding/base64"
76
"encoding/json"
87
"fmt"
98
"net"
10-
"net/http"
119
"os"
1210
"strconv"
1311

@@ -18,7 +16,6 @@ import (
1816
"github.com/loft-sh/devpod/pkg/dockercredentials"
1917
"github.com/loft-sh/devpod/pkg/gitcredentials"
2018
"github.com/loft-sh/devpod/pkg/gitsshsigning"
21-
devpodhttp "github.com/loft-sh/devpod/pkg/http"
2219
"github.com/loft-sh/devpod/pkg/netstat"
2320
portpkg "github.com/loft-sh/devpod/pkg/port"
2421
"github.com/loft-sh/log"
@@ -38,7 +35,6 @@ type CredentialsServerCmd struct {
3835

3936
ForwardPorts bool
4037
GitUserSigningKey string
41-
Runner bool
4238
}
4339

4440
// NewCredentialsServerCmd creates a new command
@@ -51,20 +47,12 @@ func NewCredentialsServerCmd(flags *flags.GlobalFlags) *cobra.Command {
5147
Short: "Starts a credentials server",
5248
Args: cobra.NoArgs,
5349
RunE: func(c *cobra.Command, args []string) error {
54-
runnerPort, err := credentials.GetRunnerPort()
55-
if err != nil {
56-
return err
57-
}
58-
if cmd.Runner {
59-
return cmd.RunRunner(c.Context(), runnerPort)
60-
}
61-
6250
port, err := credentials.GetPort()
6351
if err != nil {
6452
return err
6553
}
6654

67-
return cmd.Run(c.Context(), port, runnerPort)
55+
return cmd.Run(c.Context(), port)
6856
},
6957
}
7058
credentialsServerCmd.Flags().BoolVar(&cmd.ConfigureGitHelper, "configure-git-helper", false, "If true will configure git helper")
@@ -73,13 +61,12 @@ func NewCredentialsServerCmd(flags *flags.GlobalFlags) *cobra.Command {
7361
credentialsServerCmd.Flags().StringVar(&cmd.GitUserSigningKey, "git-user-signing-key", "", "")
7462
credentialsServerCmd.Flags().StringVar(&cmd.User, "user", "", "The user to use")
7563
_ = credentialsServerCmd.MarkFlagRequired("user")
76-
credentialsServerCmd.Flags().BoolVar(&cmd.Runner, "runner", false, "If true will create a credentials server connected to the runner")
7764

7865
return credentialsServerCmd
7966
}
8067

8168
// Run runs the command logic
82-
func (cmd *CredentialsServerCmd) Run(ctx context.Context, port int, runnerPort int) error {
69+
func (cmd *CredentialsServerCmd) Run(ctx context.Context, port int) error {
8370
// create a grpc client
8471
tunnelClient, err := tunnelserver.NewTunnelClient(os.Stdin, os.Stdout, true, ExitCodeIO)
8572
if err != nil {
@@ -112,10 +99,8 @@ func (cmd *CredentialsServerCmd) Run(ctx context.Context, port int, runnerPort i
11299
return nil
113100
}
114101

115-
runnerAddr := checkRunnerCredentialServer(runnerPort)
116-
117102
// configure docker credential helper
118-
if cmd.ConfigureDockerHelper && dockerCredentialsAllowed(runnerAddr) {
103+
if cmd.ConfigureDockerHelper {
119104
err = dockercredentials.ConfigureCredentialsContainer(cmd.User, port, log)
120105
if err != nil {
121106
return err
@@ -130,7 +115,7 @@ func (cmd *CredentialsServerCmd) Run(ctx context.Context, port int, runnerPort i
130115
}
131116

132117
// configure git credential helper
133-
if cmd.ConfigureGitHelper && gitCredentialsAllowed(runnerAddr) {
118+
if cmd.ConfigureGitHelper {
134119
binaryPath, err := os.Executable()
135120
if err != nil {
136121
return err
@@ -163,86 +148,7 @@ func (cmd *CredentialsServerCmd) Run(ctx context.Context, port int, runnerPort i
163148
}(cmd.User)
164149
}
165150

166-
return credentials.RunCredentialsServer(ctx, port, tunnelClient, runnerAddr, log)
167-
}
168-
169-
// RunRunner starts the runners credentials server
170-
// It's connected directly to a services server on the runner instead of on the origin developer machine
171-
//
172-
// The origin credentials server (default: port 12049) and the runner credentials server (default: port 12050)
173-
// communicate through https. Since both are connected to their respective peers over stdio, the default mode is
174-
// to always connect external tools (git, docker) to the origin instance. It is then responsible
175-
// for pinging the runners server first.
176-
// The runner will either send a valid response to use, an empty response meaning "no decision" or an error, indicating abortion.
177-
func (cmd *CredentialsServerCmd) RunRunner(ctx context.Context, port int) error {
178-
// create a grpc client
179-
tunnelClient, err := tunnelserver.NewTunnelClient(os.Stdin, os.Stdout, true, ExitCodeIO)
180-
if err != nil {
181-
return fmt.Errorf("error creating tunnel client: %w", err)
182-
}
183-
184-
// this message serves as a ping to the client
185-
_, err = tunnelClient.Ping(ctx, &tunnel.Empty{})
186-
if err != nil {
187-
return fmt.Errorf("ping client: %w", err)
188-
}
189-
190-
// create debug logger
191-
log := tunnelserver.NewTunnelLogger(ctx, tunnelClient, cmd.Debug)
192-
193-
addr := net.JoinHostPort("localhost", strconv.Itoa(port))
194-
if ok, err := portpkg.IsAvailable(addr); !ok || err != nil {
195-
log.Debugf("Port %d not available, exiting", port)
196-
return nil
197-
}
198-
199-
// We go through the same startup procedure the origin credentials server goes through as well
200-
// This ensures we set up everything according to platform settings if we are in scenarios where we
201-
// don't have an origin server, for example in web mode.
202-
203-
if cmd.ConfigureDockerHelper {
204-
err = dockercredentials.ConfigureCredentialsContainer(cmd.User, port, log)
205-
if err != nil {
206-
return err
207-
}
208-
}
209-
210-
err = configureGitUserLocally(ctx, cmd.User, tunnelClient)
211-
if err != nil {
212-
log.Debugf("Error configuring git user: %v", err)
213-
}
214-
215-
// configure git credential helper
216-
if cmd.ConfigureGitHelper {
217-
binaryPath, err := os.Executable()
218-
if err != nil {
219-
return err
220-
}
221-
err = gitcredentials.ConfigureHelper(binaryPath, cmd.User, port)
222-
if err != nil {
223-
return fmt.Errorf("configure git helper: %w", err)
224-
}
225-
226-
// cleanup when we are done
227-
defer func(userName string) {
228-
_ = gitcredentials.RemoveHelper(userName)
229-
}(cmd.User)
230-
}
231-
232-
// configure git ssh signature helper
233-
if cmd.GitUserSigningKey != "" {
234-
err = gitsshsigning.ConfigureHelper(cmd.User, cmd.GitUserSigningKey, log)
235-
if err != nil {
236-
return fmt.Errorf("configure git ssh signature helper: %w", err)
237-
}
238-
239-
// cleanup when we are done
240-
defer func(userName string) {
241-
_ = gitsshsigning.RemoveHelper(userName)
242-
}(cmd.User)
243-
}
244-
245-
return credentials.RunCredentialsServer(ctx, port, tunnelClient, "", log)
151+
return credentials.RunCredentialsServer(ctx, port, tunnelClient, log)
246152
}
247153

248154
func configureGitUserLocally(ctx context.Context, userName string, client tunnel.TunnelClient) error {
@@ -303,46 +209,3 @@ func (f *forwarder) StopForward(port string) error {
303209
_, err := f.client.StopForwardPort(f.ctx, &tunnel.StopForwardPortRequest{Port: port})
304210
return err
305211
}
306-
307-
// dockerCredentialsAllowed checks if the runner allows docker credential forwarding
308-
// if we can connect to it
309-
func dockerCredentialsAllowed(runnerAddr string) bool {
310-
if runnerAddr == "" {
311-
return true
312-
}
313-
314-
rawJSON, err := json.Marshal(&dockercredentials.Request{})
315-
if err != nil {
316-
return false
317-
}
318-
res, err := devpodhttp.GetHTTPClient().Post(fmt.Sprintf("http://%s/%s", runnerAddr, "docker-credentials"),
319-
"application/json", bytes.NewReader(rawJSON))
320-
321-
return res.StatusCode == http.StatusOK && err == nil
322-
}
323-
324-
// gitCredentialsAllowed checks if the runner allows git credential forwarding
325-
// if we can connect to it
326-
func gitCredentialsAllowed(runnerAddr string) bool {
327-
if runnerAddr == "" {
328-
return true
329-
}
330-
331-
res, err := devpodhttp.GetHTTPClient().Post(fmt.Sprintf("http://%s/%s", runnerAddr, "git-credentials"),
332-
"application/json", bytes.NewReader([]byte("")))
333-
334-
return res.StatusCode == http.StatusOK && err == nil
335-
}
336-
337-
// checkRunnerCredentialServer tries to contact the runner credentials server
338-
// and returns it's host:port address if available
339-
func checkRunnerCredentialServer(runnerPort int) string {
340-
runnerAddr := net.JoinHostPort("localhost", strconv.Itoa(runnerPort))
341-
runnerAvailable, _ := portpkg.IsAvailable(runnerAddr)
342-
if runnerAvailable {
343-
// If the port is free we don't have to check in with runner server
344-
return ""
345-
}
346-
347-
return runnerAddr
348-
}

0 commit comments

Comments
 (0)