Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fc3fbb5

Browse files
committed
Merge branch 'main' into jon/version
2 parents 6e8c3c0 + 2353687 commit fc3fbb5

File tree

179 files changed

+2270
-824
lines changed

Some content is hidden

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

179 files changed

+2270
-824
lines changed

.github/workflows/coder.yaml

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -267,30 +267,8 @@ jobs:
267267
terraform_version: 1.1.9
268268
terraform_wrapper: false
269269

270-
- name: Start PostgreSQL Database
271-
env:
272-
POSTGRES_PASSWORD: postgres
273-
POSTGRES_USER: postgres
274-
POSTGRES_DB: postgres
275-
PGDATA: /tmp
276-
run: |
277-
docker run \
278-
-e POSTGRES_PASSWORD=postgres \
279-
-e POSTGRES_USER=postgres \
280-
-e POSTGRES_DB=postgres \
281-
-e PGDATA=/tmp \
282-
-p 5432:5432 \
283-
-d postgres:11 \
284-
-c shared_buffers=1GB \
285-
-c max_connections=1000
286-
while ! pg_isready -h 127.0.0.1
287-
do
288-
echo "$(date) - waiting for database to start"
289-
sleep 0.5
290-
done
291-
292270
- name: Test with PostgreSQL Database
293-
run: "make test-postgres"
271+
run: make test-postgres
294272

295273
- name: Upload DataDog Trace
296274
if: always() && github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ node_modules
1313
vendor
1414
.eslintcache
1515
yarn-error.log
16+
gotests.xml
17+
gotests.coverage
1618
.idea
1719
.DS_Store
1820

Makefile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,15 @@ test: test-clean
171171
gotestsum -- -v -short ./...
172172
.PHONY: test
173173

174-
test-postgres: test-clean
175-
DB=ci gotestsum --junitfile="gotests.xml" --packages="./..." -- \
176-
-covermode=atomic -coverprofile="gotests.coverage" -timeout=30m \
177-
-coverpkg=./...,github.com/coder/coder/codersdk \
178-
-count=1 -race -failfast
174+
test-postgres: test-clean test-postgres-docker
175+
DB_FROM=$(shell go run scripts/migrate-ci/main.go) gotestsum --junitfile="gotests.xml" --packages="./..." -- \
176+
-covermode=atomic -coverprofile="gotests.coverage" -timeout=30m \
177+
-coverpkg=./...,github.com/coder/coder/codersdk \
178+
-count=2 -race -failfast
179179
.PHONY: test-postgres
180180

181181
test-postgres-docker:
182+
docker rm -f test-postgres-docker || true
182183
docker run \
183184
--env POSTGRES_PASSWORD=postgres \
184185
--env POSTGRES_USER=postgres \
@@ -189,12 +190,17 @@ test-postgres-docker:
189190
--name test-postgres-docker \
190191
--restart no \
191192
--detach \
192-
postgres:11 \
193+
postgres:13 \
193194
-c shared_buffers=1GB \
194195
-c max_connections=1000 \
195196
-c fsync=off \
196197
-c synchronous_commit=off \
197198
-c full_page_writes=off
199+
while ! pg_isready -h 127.0.0.1
200+
do
201+
echo "$(date) - waiting for database to start"
202+
sleep 0.5
203+
done
198204
.PHONY: test-postgres-docker
199205

200206
test-clean:

agent/agent.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ func (a *agent) handleSSHSession(session ssh.Session) error {
467467
}
468468
go func() {
469469
_, _ = io.Copy(stdinPipe, session)
470+
_ = stdinPipe.Close()
470471
}()
471472
err = cmd.Start()
472473
if err != nil {

agent/agent_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"testing"
1717
"time"
1818

19+
scp "github.com/bramvdbogaerde/go-scp"
1920
"github.com/google/uuid"
2021
"github.com/pion/udp"
2122
"github.com/pion/webrtc/v3"
@@ -149,6 +150,20 @@ func TestAgent(t *testing.T) {
149150
require.NoError(t, err)
150151
})
151152

153+
t.Run("SCP", func(t *testing.T) {
154+
t.Parallel()
155+
sshClient, err := setupAgent(t, agent.Metadata{}, 0).SSHClient()
156+
require.NoError(t, err)
157+
scpClient, err := scp.NewClientBySSH(sshClient)
158+
require.NoError(t, err)
159+
tempFile := filepath.Join(t.TempDir(), "scp")
160+
content := "hello world"
161+
err = scpClient.CopyFile(context.Background(), strings.NewReader(content), tempFile, "0755")
162+
require.NoError(t, err)
163+
_, err = os.Stat(tempFile)
164+
require.NoError(t, err)
165+
})
166+
152167
t.Run("EnvironmentVariables", func(t *testing.T) {
153168
t.Parallel()
154169
key := "EXAMPLE"

agent/wireguard.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package agent
22

33
import (
44
"context"
5+
"net"
6+
"strconv"
57

68
"golang.org/x/xerrors"
79
"inet.af/netaddr"
@@ -58,6 +60,38 @@ func (a *agent) startWireguard(ctx context.Context, addrs []netaddr.IPPrefix) er
5860
}
5961
}()
6062

63+
a.startWireguardListeners(ctx, wg, []handlerPort{
64+
{port: 12212, handler: a.sshServer.HandleConn},
65+
})
66+
6167
a.network = wg
6268
return nil
6369
}
70+
71+
type handlerPort struct {
72+
handler func(conn net.Conn)
73+
port uint16
74+
}
75+
76+
func (a *agent) startWireguardListeners(ctx context.Context, network *peerwg.Network, handlers []handlerPort) {
77+
for _, h := range handlers {
78+
go func(h handlerPort) {
79+
a.logger.Debug(ctx, "starting wireguard listener", slog.F("port", h.port))
80+
81+
listener, err := network.Listen("tcp", net.JoinHostPort("", strconv.Itoa(int(h.port))))
82+
if err != nil {
83+
a.logger.Warn(ctx, "listen wireguard", slog.F("port", h.port), slog.Error(err))
84+
return
85+
}
86+
87+
for {
88+
conn, err := listener.Accept()
89+
if err != nil {
90+
return
91+
}
92+
93+
go h.handler(conn)
94+
}
95+
}(h)
96+
}
97+
}

cli/configssh.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ func configSSH() *cobra.Command {
135135
coderConfigFile string
136136
dryRun bool
137137
skipProxyCommand bool
138+
wireguard bool
138139
)
139140
cmd := &cobra.Command{
140141
Annotations: workspaceCommand,
@@ -287,7 +288,11 @@ func configSSH() *cobra.Command {
287288
"\tLogLevel ERROR",
288289
)
289290
if !skipProxyCommand {
290-
configOptions = append(configOptions, fmt.Sprintf("\tProxyCommand %q --global-config %q ssh --stdio %s", binaryFile, root, hostname))
291+
if !wireguard {
292+
configOptions = append(configOptions, fmt.Sprintf("\tProxyCommand %q --global-config %q ssh --stdio %s", binaryFile, root, hostname))
293+
} else {
294+
configOptions = append(configOptions, fmt.Sprintf("\tProxyCommand %q --global-config %q ssh --wireguard --stdio %s", binaryFile, root, hostname))
295+
}
291296
}
292297

293298
_, _ = buf.WriteString(strings.Join(configOptions, "\n"))
@@ -374,6 +379,8 @@ func configSSH() *cobra.Command {
374379
cmd.Flags().BoolVarP(&skipProxyCommand, "skip-proxy-command", "", false, "Specifies whether the ProxyCommand option should be skipped. Useful for testing.")
375380
_ = cmd.Flags().MarkHidden("skip-proxy-command")
376381
cliflag.BoolVarP(cmd.Flags(), &usePreviousOpts, "use-previous-options", "", "CODER_SSH_USE_PREVIOUS_OPTIONS", false, "Specifies whether or not to keep options from previous run of config-ssh.")
382+
cliflag.BoolVarP(cmd.Flags(), &wireguard, "wireguard", "", "CODER_CONFIG_SSH_WIREGUARD", false, "Whether to use Wireguard for SSH tunneling.")
383+
_ = cmd.Flags().MarkHidden("wireguard")
377384

378385
// Deprecated: Remove after migration period.
379386
cmd.Flags().StringVar(&coderConfigFile, "test.ssh-coder-config-file", sshDefaultCoderConfigFileName, "Specifies the path to an Coder SSH config file. Useful for testing.")
@@ -539,7 +546,7 @@ func currentBinPath(w io.Writer) (string, error) {
539546
_, _ = fmt.Fprint(w, "\n")
540547
}
541548

542-
return binName, nil
549+
return exePath, nil
543550
}
544551

545552
// diffBytes takes two byte slices and diffs them as if they were in a

0 commit comments

Comments
 (0)