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

Skip to content

Commit bf06e92

Browse files
committed
Merge branch 'users-table/presleyp/592' of github.com:coder/coder into users-table/presleyp/592
2 parents a50ea8a + 91ac0d5 commit bf06e92

File tree

138 files changed

+5472
-2756
lines changed

Some content is hidden

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

138 files changed

+5472
-2756
lines changed

.github/dependabot.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ updates:
4141
timezone: "America/Chicago"
4242
commit-message:
4343
prefix: "chore"
44+
labels:
45+
- "dependencies"
46+
- "typescript/js"
4447
ignore:
4548
# Ignore major updates to Node.js types, because they need to
4649
# correspond to the Node.js engine version

.github/workflows/coder.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ concurrency:
2626
jobs:
2727
style-lint-golangci:
2828
name: style/lint/golangci
29+
timeout-minutes: 5
2930
runs-on: ubuntu-latest
3031
steps:
3132
- uses: actions/checkout@v3
@@ -39,6 +40,7 @@ jobs:
3940

4041
style-lint-typescript:
4142
name: "style/lint/typescript"
43+
timeout-minutes: 5
4244
runs-on: ubuntu-latest
4345
steps:
4446
- name: Checkout
@@ -64,6 +66,7 @@ jobs:
6466

6567
gen:
6668
name: "style/gen"
69+
timeout-minutes: 5
6770
runs-on: ubuntu-latest
6871
steps:
6972
- uses: actions/checkout@v3
@@ -87,6 +90,7 @@ jobs:
8790
style-fmt:
8891
name: "style/fmt"
8992
runs-on: ubuntu-latest
93+
timeout-minutes: 5
9094
steps:
9195
- name: Checkout
9296
uses: actions/checkout@v3
@@ -114,6 +118,7 @@ jobs:
114118
test-go:
115119
name: "test/go"
116120
runs-on: ${{ matrix.os }}
121+
timeout-minutes: 20
117122
strategy:
118123
matrix:
119124
os:
@@ -158,6 +163,10 @@ jobs:
158163
terraform_version: 1.1.2
159164
terraform_wrapper: false
160165

166+
- name: Install socat
167+
if: runner.os == 'Linux'
168+
run: sudo apt-get install -y socat
169+
161170
- name: Test with Mock Database
162171
shell: bash
163172
env:
@@ -188,6 +197,7 @@ jobs:
188197
test-go-postgres:
189198
name: "test/go/postgres"
190199
runs-on: ubuntu-latest
200+
timeout-minutes: 20
191201
steps:
192202
- uses: actions/checkout@v3
193203

@@ -273,6 +283,7 @@ jobs:
273283
deploy:
274284
name: "deploy"
275285
runs-on: ubuntu-latest
286+
timeout-minutes: 20
276287
if: github.ref == 'refs/heads/main' && github.repository_owner == 'coder'
277288
permissions:
278289
contents: read
@@ -348,6 +359,7 @@ jobs:
348359
test-js:
349360
name: "test/js"
350361
runs-on: ubuntu-latest
362+
timeout-minutes: 20
351363
steps:
352364
- uses: actions/checkout@v3
353365

@@ -400,6 +412,7 @@ jobs:
400412
test-e2e:
401413
name: "test/e2e/${{ matrix.os }}"
402414
runs-on: ${{ matrix.os }}
415+
timeout-minutes: 20
403416
strategy:
404417
matrix:
405418
os:

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"emeraldwalk.runonsave": {
6363
"commands": [
6464
{
65-
"match": "database/query.sql",
65+
"match": "database/queries/*.sql",
6666
"cmd": "make gen"
6767
}
6868
]

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ fmt/sql: $(wildcard coderd/database/queries/*.sql)
4242

4343
sed -i 's/@ /@/g' ./coderd/database/queries/*.sql
4444

45-
fmt: fmt/prettier fmt/sql
45+
fmt/terraform: $(wildcard *.tf)
46+
terraform fmt -recursive
47+
48+
fmt: fmt/prettier fmt/sql fmt/terraform
4649
.PHONY: fmt
4750

4851
gen: coderd/database/generate peerbroker/proto provisionersdk/proto provisionerd/proto

agent/agent.go

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"github.com/coder/coder/pty"
2222
"github.com/coder/retry"
2323

24+
"github.com/pkg/sftp"
25+
2426
"github.com/gliderlabs/ssh"
2527
gossh "golang.org/x/crypto/ssh"
2628
"golang.org/x/xerrors"
@@ -101,6 +103,11 @@ func (a *agent) run(ctx context.Context) {
101103

102104
func (a *agent) handlePeerConn(ctx context.Context, conn *peer.Conn) {
103105
go func() {
106+
select {
107+
case <-a.closed:
108+
_ = conn.Close()
109+
case <-conn.Closed():
110+
}
104111
<-conn.Closed()
105112
a.connCloseWait.Done()
106113
}()
@@ -116,7 +123,7 @@ func (a *agent) handlePeerConn(ctx context.Context, conn *peer.Conn) {
116123

117124
switch channel.Protocol() {
118125
case "ssh":
119-
a.sshServer.HandleConn(channel.NetConn())
126+
go a.sshServer.HandleConn(channel.NetConn())
120127
default:
121128
a.options.Logger.Warn(ctx, "unhandled protocol from channel",
122129
slog.F("protocol", channel.Protocol()),
@@ -141,7 +148,10 @@ func (a *agent) init(ctx context.Context) {
141148
sshLogger := a.options.Logger.Named("ssh-server")
142149
forwardHandler := &ssh.ForwardedTCPHandler{}
143150
a.sshServer = &ssh.Server{
144-
ChannelHandlers: ssh.DefaultChannelHandlers,
151+
ChannelHandlers: map[string]ssh.ChannelHandler{
152+
"direct-tcpip": ssh.DirectTCPIPHandler,
153+
"session": ssh.DefaultSessionHandler,
154+
},
145155
ConnectionFailedCallback: func(conn net.Conn, err error) {
146156
sshLogger.Info(ctx, "ssh connection ended", slog.Error(err))
147157
},
@@ -180,61 +190,54 @@ func (a *agent) init(ctx context.Context) {
180190
NoClientAuth: true,
181191
}
182192
},
193+
SubsystemHandlers: map[string]ssh.SubsystemHandler{
194+
"sftp": func(session ssh.Session) {
195+
server, err := sftp.NewServer(session)
196+
if err != nil {
197+
a.options.Logger.Debug(session.Context(), "initialize sftp server", slog.Error(err))
198+
return
199+
}
200+
defer server.Close()
201+
err = server.Serve()
202+
if errors.Is(err, io.EOF) {
203+
return
204+
}
205+
a.options.Logger.Debug(session.Context(), "sftp server exited with error", slog.Error(err))
206+
},
207+
},
183208
}
184209

185210
go a.run(ctx)
186211
}
187212

188213
func (a *agent) handleSSHSession(session ssh.Session) error {
189-
var (
190-
command string
191-
args = []string{}
192-
err error
193-
)
194-
195214
currentUser, err := user.Current()
196215
if err != nil {
197216
return xerrors.Errorf("get current user: %w", err)
198217
}
199218
username := currentUser.Username
200219

220+
shell, err := usershell.Get(username)
221+
if err != nil {
222+
return xerrors.Errorf("get user shell: %w", err)
223+
}
224+
201225
// gliderlabs/ssh returns a command slice of zero
202226
// when a shell is requested.
227+
command := session.RawCommand()
203228
if len(session.Command()) == 0 {
204-
command, err = usershell.Get(username)
205-
if err != nil {
206-
return xerrors.Errorf("get user shell: %w", err)
207-
}
208-
} else {
209-
command = session.Command()[0]
210-
if len(session.Command()) > 1 {
211-
args = session.Command()[1:]
212-
}
229+
command = shell
213230
}
214231

215-
signals := make(chan ssh.Signal)
216-
breaks := make(chan bool)
217-
defer close(signals)
218-
defer close(breaks)
219-
go func() {
220-
for {
221-
select {
222-
case <-session.Context().Done():
223-
return
224-
// Ignore signals and breaks for now!
225-
case <-signals:
226-
case <-breaks:
227-
}
228-
}
229-
}()
230-
231-
cmd := exec.CommandContext(session.Context(), command, args...)
232+
// OpenSSH executes all commands with the users current shell.
233+
// We replicate that behavior for IDE support.
234+
cmd := exec.CommandContext(session.Context(), shell, "-c", command)
232235
cmd.Env = append(os.Environ(), session.Environ()...)
233236
executablePath, err := os.Executable()
234237
if err != nil {
235238
return xerrors.Errorf("getting os executable: %w", err)
236239
}
237-
cmd.Env = append(session.Environ(), fmt.Sprintf(`GIT_SSH_COMMAND="%s gitssh --"`, executablePath))
240+
cmd.Env = append(cmd.Env, fmt.Sprintf(`GIT_SSH_COMMAND="%s gitssh --"`, executablePath))
238241

239242
sshPty, windowSize, isPty := session.Pty()
240243
if isPty {
@@ -263,7 +266,7 @@ func (a *agent) handleSSHSession(session ssh.Session) error {
263266
}
264267

265268
cmd.Stdout = session
266-
cmd.Stderr = session
269+
cmd.Stderr = session.Stderr()
267270
// This blocks forever until stdin is received if we don't
268271
// use StdinPipe. It's unknown what causes this.
269272
stdinPipe, err := cmd.StdinPipe()
@@ -277,8 +280,7 @@ func (a *agent) handleSSHSession(session ssh.Session) error {
277280
if err != nil {
278281
return xerrors.Errorf("start: %w", err)
279282
}
280-
_ = cmd.Wait()
281-
return nil
283+
return cmd.Wait()
282284
}
283285

284286
// isClosed returns whether the API is closed or not.

0 commit comments

Comments
 (0)