mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-10-23 23:33:14 +08:00
hotfix: add platform for cmd ssh
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/containerd/containerd/platforms"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@@ -28,6 +29,7 @@ import (
|
|||||||
func CmdSSH(_ cmdutil.Factory) *cobra.Command {
|
func CmdSSH(_ cmdutil.Factory) *cobra.Command {
|
||||||
var sshConf = &pkgssh.SshConfig{}
|
var sshConf = &pkgssh.SshConfig{}
|
||||||
var extraCIDR []string
|
var extraCIDR []string
|
||||||
|
var platform string
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "ssh",
|
Use: "ssh",
|
||||||
Short: "Ssh to jump server",
|
Short: "Ssh to jump server",
|
||||||
@@ -54,6 +56,10 @@ func CmdSSH(_ cmdutil.Factory) *cobra.Command {
|
|||||||
return daemon.StartupDaemon(cmd.Context())
|
return daemon.StartupDaemon(cmd.Context())
|
||||||
},
|
},
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
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")
|
config, err := websocket.NewConfig("ws://test/ws", "http://test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -77,6 +83,7 @@ func CmdSSH(_ cmdutil.Factory) *cobra.Command {
|
|||||||
ExtraCIDR: extraCIDR,
|
ExtraCIDR: extraCIDR,
|
||||||
Width: width,
|
Width: width,
|
||||||
Height: height,
|
Height: height,
|
||||||
|
Platform: platforms.Format(platforms.Normalize(parse)),
|
||||||
SessionID: sessionID,
|
SessionID: sessionID,
|
||||||
}
|
}
|
||||||
bytes, err := json.Marshal(ssh)
|
bytes, err := json.Marshal(ssh)
|
||||||
@@ -117,6 +124,7 @@ func CmdSSH(_ cmdutil.Factory) *cobra.Command {
|
|||||||
}
|
}
|
||||||
pkgssh.AddSshFlags(cmd.Flags(), sshConf)
|
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().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
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,6 +17,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/containerd/containerd/platforms"
|
||||||
|
specs "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
"golang.org/x/net/websocket"
|
"golang.org/x/net/websocket"
|
||||||
@@ -38,6 +40,7 @@ type wsHandler struct {
|
|||||||
width int
|
width int
|
||||||
height int
|
height int
|
||||||
sessionId string
|
sessionId string
|
||||||
|
platform specs.Platform
|
||||||
condReady context.CancelFunc
|
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_ISPEED: 14400,
|
||||||
ssh.TTY_OP_OSPEED: 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)
|
w.Log("Request pty error: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -270,7 +273,7 @@ func (w *wsHandler) installKubevpnOnRemote(ctx context.Context, sshClient *ssh.C
|
|||||||
if config.GitHubOAuthToken != "" {
|
if config.GitHubOAuthToken != "" {
|
||||||
client = oauth2.NewClient(ctx, oauth2.StaticTokenSource(&oauth2.Token{AccessToken: config.GitHubOAuthToken, TokenType: "Bearer"}))
|
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 {
|
if err != nil {
|
||||||
w.Log("Get latest kubevpn version failed: %v", err)
|
w.Log("Get latest kubevpn version failed: %v", err)
|
||||||
return err
|
return err
|
||||||
@@ -346,6 +349,7 @@ type Ssh struct {
|
|||||||
ExtraCIDR []string
|
ExtraCIDR []string
|
||||||
Width int
|
Width int
|
||||||
Height int
|
Height int
|
||||||
|
Platform string
|
||||||
SessionID string
|
SessionID string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,6 +374,7 @@ func init() {
|
|||||||
width: conf.Width,
|
width: conf.Width,
|
||||||
height: conf.Height,
|
height: conf.Height,
|
||||||
sessionId: conf.SessionID,
|
sessionId: conf.SessionID,
|
||||||
|
platform: platforms.MustParse(conf.Platform),
|
||||||
condReady: cancelFunc,
|
condReady: cancelFunc,
|
||||||
}
|
}
|
||||||
CondReady[conf.SessionID] = ctx
|
CondReady[conf.SessionID] = ctx
|
||||||
|
@@ -430,7 +430,7 @@ func (config SshConfig) Dial(ctx context.Context, stopChan <-chan struct{}) (cli
|
|||||||
User: config.User,
|
User: config.User,
|
||||||
Auth: authMethod,
|
Auth: authMethod,
|
||||||
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
|
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
|
||||||
BannerCallback: ssh.BannerDisplayStderr(),
|
//BannerCallback: ssh.BannerDisplayStderr(),
|
||||||
Timeout: time.Second * 10,
|
Timeout: time.Second * 10,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -484,7 +484,7 @@ func JumpTo(ctx context.Context, bClient *ssh.Client, to SshConfig, stopChan <-c
|
|||||||
User: to.User,
|
User: to.User,
|
||||||
Auth: authMethod,
|
Auth: authMethod,
|
||||||
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
|
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
|
||||||
BannerCallback: ssh.BannerDisplayStderr(),
|
//BannerCallback: ssh.BannerDisplayStderr(),
|
||||||
Timeout: time.Second * 10,
|
Timeout: time.Second * 10,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -596,6 +596,14 @@ func PortMapUntil(ctx context.Context, conf *SshConfig, remote, local netip.Addr
|
|||||||
defer cancelFunc3()
|
defer cancelFunc3()
|
||||||
conn, err = client.DialContext(ctx3, "tcp", remote.String())
|
conn, err = client.DialContext(ctx3, "tcp", remote.String())
|
||||||
if err != nil {
|
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)
|
log.Debugf("Failed to dial remote addr: %s: %v", remote.String(), err)
|
||||||
client.Close()
|
client.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Reference in New Issue
Block a user