mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-10-23 15:23:13 +08:00
hotfix: add platform for cmd ssh
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/containerd/containerd/platforms"
|
||||
"github.com/google/uuid"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -28,6 +29,7 @@ import (
|
||||
func CmdSSH(_ cmdutil.Factory) *cobra.Command {
|
||||
var sshConf = &pkgssh.SshConfig{}
|
||||
var extraCIDR []string
|
||||
var platform string
|
||||
cmd := &cobra.Command{
|
||||
Use: "ssh",
|
||||
Short: "Ssh to jump server",
|
||||
@@ -54,6 +56,10 @@ func CmdSSH(_ cmdutil.Factory) *cobra.Command {
|
||||
return daemon.StartupDaemon(cmd.Context())
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
parse, err2 := platforms.Parse(platform)
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
config, err := websocket.NewConfig("ws://test/ws", "http://test")
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -77,6 +83,7 @@ func CmdSSH(_ cmdutil.Factory) *cobra.Command {
|
||||
ExtraCIDR: extraCIDR,
|
||||
Width: width,
|
||||
Height: height,
|
||||
Platform: platforms.Format(platforms.Normalize(parse)),
|
||||
SessionID: sessionID,
|
||||
}
|
||||
bytes, err := json.Marshal(ssh)
|
||||
@@ -117,6 +124,7 @@ func CmdSSH(_ cmdutil.Factory) *cobra.Command {
|
||||
}
|
||||
pkgssh.AddSshFlags(cmd.Flags(), sshConf)
|
||||
cmd.Flags().StringArrayVar(&extraCIDR, "extra-cidr", []string{}, "Extra network CIDR string, eg: --extra-cidr 192.168.0.159/24 --extra-cidr 192.168.1.160/32")
|
||||
cmd.Flags().StringVar(&platform, "platform", util.If(os.Getenv("KUBEVPN_DEFAULT_PLATFORM") != "", os.Getenv("KUBEVPN_DEFAULT_PLATFORM"), "linux/amd64"), "Set ssh server platform if needs to install command kubevpn")
|
||||
return cmd
|
||||
}
|
||||
|
||||
|
@@ -17,6 +17,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd/platforms"
|
||||
specs "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"golang.org/x/crypto/ssh"
|
||||
"golang.org/x/net/websocket"
|
||||
@@ -38,6 +40,7 @@ type wsHandler struct {
|
||||
width int
|
||||
height int
|
||||
sessionId string
|
||||
platform specs.Platform
|
||||
condReady context.CancelFunc
|
||||
}
|
||||
|
||||
@@ -240,7 +243,7 @@ func (w *wsHandler) terminal(ctx context.Context, cli *ssh.Client, conn io.ReadW
|
||||
ssh.TTY_OP_ISPEED: 14400,
|
||||
ssh.TTY_OP_OSPEED: 14400,
|
||||
}
|
||||
if err = session.RequestPty("xterm", height, width, modes); err != nil {
|
||||
if err = session.RequestPty("xterm-256color", height, width, modes); err != nil {
|
||||
w.Log("Request pty error: %v", err)
|
||||
return err
|
||||
}
|
||||
@@ -270,7 +273,7 @@ func (w *wsHandler) installKubevpnOnRemote(ctx context.Context, sshClient *ssh.C
|
||||
if config.GitHubOAuthToken != "" {
|
||||
client = oauth2.NewClient(ctx, oauth2.StaticTokenSource(&oauth2.Token{AccessToken: config.GitHubOAuthToken, TokenType: "Bearer"}))
|
||||
}
|
||||
latestVersion, url, err := util.GetManifest(client, "linux", "amd64")
|
||||
latestVersion, url, err := util.GetManifest(client, w.platform.OS, w.platform.Architecture)
|
||||
if err != nil {
|
||||
w.Log("Get latest kubevpn version failed: %v", err)
|
||||
return err
|
||||
@@ -346,6 +349,7 @@ type Ssh struct {
|
||||
ExtraCIDR []string
|
||||
Width int
|
||||
Height int
|
||||
Platform string
|
||||
SessionID string
|
||||
}
|
||||
|
||||
@@ -370,6 +374,7 @@ func init() {
|
||||
width: conf.Width,
|
||||
height: conf.Height,
|
||||
sessionId: conf.SessionID,
|
||||
platform: platforms.MustParse(conf.Platform),
|
||||
condReady: cancelFunc,
|
||||
}
|
||||
CondReady[conf.SessionID] = ctx
|
||||
|
@@ -430,7 +430,7 @@ func (config SshConfig) Dial(ctx context.Context, stopChan <-chan struct{}) (cli
|
||||
User: config.User,
|
||||
Auth: authMethod,
|
||||
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
|
||||
BannerCallback: ssh.BannerDisplayStderr(),
|
||||
//BannerCallback: ssh.BannerDisplayStderr(),
|
||||
Timeout: time.Second * 10,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -484,7 +484,7 @@ func JumpTo(ctx context.Context, bClient *ssh.Client, to SshConfig, stopChan <-c
|
||||
User: to.User,
|
||||
Auth: authMethod,
|
||||
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
|
||||
BannerCallback: ssh.BannerDisplayStderr(),
|
||||
//BannerCallback: ssh.BannerDisplayStderr(),
|
||||
Timeout: time.Second * 10,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -596,6 +596,14 @@ func PortMapUntil(ctx context.Context, conf *SshConfig, remote, local netip.Addr
|
||||
defer cancelFunc3()
|
||||
conn, err = client.DialContext(ctx3, "tcp", remote.String())
|
||||
if err != nil {
|
||||
var openChannelError *ssh.OpenChannelError
|
||||
// if ssh server not permitted ssh port-forward, do nothing until exit
|
||||
if errors.As(err, &openChannelError) && openChannelError.Reason == ssh.Prohibited {
|
||||
_ = client.Close()
|
||||
log.Debugf("Failed to open ssh port-forward: %s: %v", remote.String(), err)
|
||||
<-connCtx.Done()
|
||||
return nil, err
|
||||
}
|
||||
log.Debugf("Failed to dial remote addr: %s: %v", remote.String(), err)
|
||||
client.Close()
|
||||
return nil, err
|
||||
|
Reference in New Issue
Block a user