Skip to content

Commit 9dc436a

Browse files
iQQBotroboquat
authored andcommitted
[SSH Gateway] remove priavte key requirement when ownerToken is provide
1 parent d050af0 commit 9dc436a

File tree

10 files changed

+34
-7
lines changed

10 files changed

+34
-7
lines changed

components/ws-proxy/cmd/run.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
"time"
1414

1515
"github.com/bombsimon/logrusr/v2"
16+
"github.com/gitpod-io/golang-crypto/ssh"
1617
"github.com/spf13/cobra"
17-
"golang.org/x/crypto/ssh"
1818
"google.golang.org/grpc"
1919
"google.golang.org/grpc/credentials"
2020
"google.golang.org/grpc/credentials/insecure"

components/ws-proxy/go.mod

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/gitpod-io/gitpod/registry-facade/api v0.0.0-00010101000000-000000000000
99
github.com/gitpod-io/gitpod/supervisor/api v0.0.0-00010101000000-000000000000
1010
github.com/gitpod-io/gitpod/ws-manager/api v0.0.0-00010101000000-000000000000
11+
github.com/gitpod-io/golang-crypto v0.0.0-20220616163018-a0e3d8407552
1112
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible
1213
github.com/google/go-cmp v0.5.7
1314
github.com/gorilla/handlers v1.5.1
@@ -20,6 +21,7 @@ require (
2021
golang.org/x/net v0.0.0-20211209124913-491a49abca63
2122
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
2223
google.golang.org/grpc v1.45.0
24+
google.golang.org/protobuf v1.28.0
2325
k8s.io/api v0.23.5
2426
k8s.io/apimachinery v0.23.5
2527
k8s.io/client-go v0.23.5
@@ -72,7 +74,6 @@ require (
7274
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
7375
google.golang.org/appengine v1.6.7 // indirect
7476
google.golang.org/genproto v0.0.0-20210831024726-fe130286e0e2 // indirect
75-
google.golang.org/protobuf v1.28.0 // indirect
7677
gopkg.in/inf.v0 v0.9.1 // indirect
7778
gopkg.in/segmentio/analytics-go.v3 v3.1.0 // indirect
7879
gopkg.in/yaml.v2 v2.4.0 // indirect

components/ws-proxy/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5
145145
github.com/getkin/kin-openapi v0.76.0/go.mod h1:660oXbgy5JFMKreazJaQTw7o+X00qeSyhcnluiMv+Xg=
146146
github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ=
147147
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
148+
github.com/gitpod-io/golang-crypto v0.0.0-20220616163018-a0e3d8407552 h1:11beloYl4JFQZAj6VfJwZcPtrBqulK5Wzrs624m8qHI=
149+
github.com/gitpod-io/golang-crypto v0.0.0-20220616163018-a0e3d8407552/go.mod h1:tJgr4p01k+N5SV9KHeHLPsEYMCEpc0dTSNGPif2ZWac=
148150
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
149151
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
150152
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=

components/ws-proxy/pkg/proxy/proxy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"os"
1111
"path/filepath"
1212

13+
"github.com/gitpod-io/golang-crypto/ssh"
1314
"github.com/gorilla/mux"
1415
"github.com/klauspost/cpuid/v2"
15-
"golang.org/x/crypto/ssh"
1616

1717
"github.com/gitpod-io/gitpod/common-go/log"
1818
)

components/ws-proxy/pkg/proxy/routes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import (
2020
"strings"
2121
"time"
2222

23+
"github.com/gitpod-io/golang-crypto/ssh"
2324
"github.com/gorilla/handlers"
2425
"github.com/gorilla/mux"
2526
"github.com/sirupsen/logrus"
26-
"golang.org/x/crypto/ssh"
2727
"golang.org/x/xerrors"
2828

2929
"github.com/gitpod-io/gitpod/common-go/log"

components/ws-proxy/pkg/proxy/routes_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import (
2121
"testing"
2222
"time"
2323

24+
"github.com/gitpod-io/golang-crypto/ssh"
2425
"github.com/google/go-cmp/cmp"
2526
"github.com/sirupsen/logrus"
26-
"golang.org/x/crypto/ssh"
2727

2828
"github.com/gitpod-io/gitpod/common-go/log"
2929
"github.com/gitpod-io/gitpod/common-go/util"

components/ws-proxy/pkg/sshproxy/forward.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/gitpod-io/gitpod/common-go/log"
13-
"golang.org/x/crypto/ssh"
13+
"github.com/gitpod-io/golang-crypto/ssh"
1414
"golang.org/x/net/context"
1515
)
1616

components/ws-proxy/pkg/sshproxy/server.go

+22-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717
supervisor "github.com/gitpod-io/gitpod/supervisor/api"
1818
tracker "github.com/gitpod-io/gitpod/ws-proxy/pkg/analytics"
1919
p "github.com/gitpod-io/gitpod/ws-proxy/pkg/proxy"
20+
"github.com/gitpod-io/golang-crypto/ssh"
2021
"github.com/prometheus/client_golang/prometheus"
21-
"golang.org/x/crypto/ssh"
2222
"golang.org/x/xerrors"
2323
"google.golang.org/grpc"
2424
"google.golang.org/grpc/credentials/insecure"
@@ -106,6 +106,27 @@ func New(signers []ssh.Signer, workspaceInfoProvider p.WorkspaceInfoProvider, he
106106

107107
server.sshConfig = &ssh.ServerConfig{
108108
ServerVersion: "SSH-2.0-GITPOD-GATEWAY",
109+
NoClientAuth: true,
110+
NoClientAuthCallback: func(conn ssh.ConnMetadata) (*ssh.Permissions, error) {
111+
args := strings.Split(conn.User(), "#")
112+
workspaceId := args[0]
113+
wsInfo, err := server.GetWorkspaceInfo(workspaceId)
114+
if err != nil {
115+
return nil, err
116+
}
117+
defer func() {
118+
server.TrackSSHConnection(wsInfo, "auth", err)
119+
}()
120+
// workspaceId#ownerToken
121+
if len(args) != 2 || wsInfo.Auth.OwnerToken != args[1] {
122+
return nil, ErrAuthFailed
123+
}
124+
return &ssh.Permissions{
125+
Extensions: map[string]string{
126+
"workspaceId": workspaceId,
127+
},
128+
}, nil
129+
},
109130
PasswordCallback: func(conn ssh.ConnMetadata, password []byte) (perm *ssh.Permissions, err error) {
110131
workspaceId, ownerToken := conn.User(), string(password)
111132
wsInfo, err := server.GetWorkspaceInfo(workspaceId)

install/installer/go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ require (
100100
github.com/fvbommel/sortorder v1.0.1 // indirect
101101
github.com/gitpod-io/gitpod/content-service v0.0.0-00010101000000-000000000000 // indirect
102102
github.com/gitpod-io/gitpod/registry-facade v0.0.0-00010101000000-000000000000 // indirect
103+
github.com/gitpod-io/golang-crypto v0.0.0-20220616163018-a0e3d8407552 // indirect
103104
github.com/go-errors/errors v1.0.1 // indirect
104105
github.com/go-logr/logr v1.2.3 // indirect
105106
github.com/go-openapi/jsonpointer v0.19.5 // indirect

install/installer/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,8 @@ github.com/garyburd/redigo v1.6.0 h1:0VruCpn7yAIIu7pWVClQC8wxCJEcG3nyzpMSHKi1PQc
548548
github.com/getkin/kin-openapi v0.76.0/go.mod h1:660oXbgy5JFMKreazJaQTw7o+X00qeSyhcnluiMv+Xg=
549549
github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ=
550550
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
551+
github.com/gitpod-io/golang-crypto v0.0.0-20220616163018-a0e3d8407552 h1:11beloYl4JFQZAj6VfJwZcPtrBqulK5Wzrs624m8qHI=
552+
github.com/gitpod-io/golang-crypto v0.0.0-20220616163018-a0e3d8407552/go.mod h1:tJgr4p01k+N5SV9KHeHLPsEYMCEpc0dTSNGPif2ZWac=
551553
github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
552554
github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98=
553555
github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w=

0 commit comments

Comments
 (0)