mirror of
https://github.com/openziti/zrok.git
synced 2025-06-20 09:48:07 +02:00
temporary switch to support tcp/udp toggling (#306)
This commit is contained in:
parent
517eeb8412
commit
e19186c1a0
@ -4,6 +4,7 @@ import (
|
|||||||
"github.com/go-openapi/runtime"
|
"github.com/go-openapi/runtime"
|
||||||
httptransport "github.com/go-openapi/runtime/client"
|
httptransport "github.com/go-openapi/runtime/client"
|
||||||
"github.com/openziti/zrok/endpoints/tcpTunnel"
|
"github.com/openziti/zrok/endpoints/tcpTunnel"
|
||||||
|
"github.com/openziti/zrok/endpoints/udpTunnel"
|
||||||
"github.com/openziti/zrok/rest_client_zrok"
|
"github.com/openziti/zrok/rest_client_zrok"
|
||||||
"github.com/openziti/zrok/rest_client_zrok/share"
|
"github.com/openziti/zrok/rest_client_zrok/share"
|
||||||
"github.com/openziti/zrok/rest_model_zrok"
|
"github.com/openziti/zrok/rest_model_zrok"
|
||||||
@ -23,6 +24,7 @@ func init() {
|
|||||||
|
|
||||||
type accessPrivateTunnelCommand struct {
|
type accessPrivateTunnelCommand struct {
|
||||||
bindAddress string
|
bindAddress string
|
||||||
|
udp bool
|
||||||
cmd *cobra.Command
|
cmd *cobra.Command
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,6 +36,7 @@ func newAccessPrivateTunnelCommand() *accessPrivateTunnelCommand {
|
|||||||
}
|
}
|
||||||
command := &accessPrivateTunnelCommand{cmd: cmd}
|
command := &accessPrivateTunnelCommand{cmd: cmd}
|
||||||
cmd.Flags().StringVarP(&command.bindAddress, "bind", "b", "tcp:127.0.0.1:9191", "The address to bind the private tunnel")
|
cmd.Flags().StringVarP(&command.bindAddress, "bind", "b", "tcp:127.0.0.1:9191", "The address to bind the private tunnel")
|
||||||
|
cmd.Flags().BoolVar(&command.udp, "udp", false, "Use UDP")
|
||||||
cmd.Run = command.run
|
cmd.Run = command.run
|
||||||
return command
|
return command
|
||||||
}
|
}
|
||||||
@ -76,6 +79,20 @@ func (cmd *accessPrivateTunnelCommand) run(_ *cobra.Command, args []string) {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
if cmd.udp {
|
||||||
|
fe, err := udpTunnel.NewFrontend(&udpTunnel.FrontendConfig{
|
||||||
|
BindAddress: cmd.bindAddress,
|
||||||
|
IdentityName: "backend",
|
||||||
|
ShrToken: args[0],
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
if err := fe.Run(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
fe, err := tcpTunnel.NewFrontend(&tcpTunnel.FrontendConfig{
|
fe, err := tcpTunnel.NewFrontend(&tcpTunnel.FrontendConfig{
|
||||||
BindAddress: cmd.bindAddress,
|
BindAddress: cmd.bindAddress,
|
||||||
IdentityName: "backend",
|
IdentityName: "backend",
|
||||||
@ -87,6 +104,7 @@ func (cmd *accessPrivateTunnelCommand) run(_ *cobra.Command, args []string) {
|
|||||||
if err := fe.Run(); err != nil {
|
if err := fe.Run(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for {
|
for {
|
||||||
time.Sleep(30 * 24 * time.Hour)
|
time.Sleep(30 * 24 * time.Hour)
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/openziti/zrok/endpoints"
|
"github.com/openziti/zrok/endpoints"
|
||||||
"github.com/openziti/zrok/endpoints/proxy"
|
"github.com/openziti/zrok/endpoints/proxy"
|
||||||
"github.com/openziti/zrok/endpoints/tcpTunnel"
|
"github.com/openziti/zrok/endpoints/tcpTunnel"
|
||||||
|
"github.com/openziti/zrok/endpoints/udpTunnel"
|
||||||
"github.com/openziti/zrok/model"
|
"github.com/openziti/zrok/model"
|
||||||
"github.com/openziti/zrok/rest_client_zrok"
|
"github.com/openziti/zrok/rest_client_zrok"
|
||||||
"github.com/openziti/zrok/rest_client_zrok/share"
|
"github.com/openziti/zrok/rest_client_zrok/share"
|
||||||
@ -32,6 +33,7 @@ type sharePrivateCommand struct {
|
|||||||
backendMode string
|
backendMode string
|
||||||
headless bool
|
headless bool
|
||||||
insecure bool
|
insecure bool
|
||||||
|
udp bool
|
||||||
cmd *cobra.Command
|
cmd *cobra.Command
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,6 +48,7 @@ func newSharePrivateCommand() *sharePrivateCommand {
|
|||||||
cmd.Flags().StringVar(&command.backendMode, "backend-mode", "proxy", "The backend mode {proxy, web, tunnel}")
|
cmd.Flags().StringVar(&command.backendMode, "backend-mode", "proxy", "The backend mode {proxy, web, tunnel}")
|
||||||
cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless")
|
cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless")
|
||||||
cmd.Flags().BoolVar(&command.insecure, "insecure", false, "Enable insecure TLS certificate validation for <target>")
|
cmd.Flags().BoolVar(&command.insecure, "insecure", false, "Enable insecure TLS certificate validation for <target>")
|
||||||
|
cmd.Flags().BoolVar(&command.udp, "udp", false, "Enable UDP for tunnel backend")
|
||||||
cmd.Run = command.run
|
cmd.Run = command.run
|
||||||
return command
|
return command
|
||||||
}
|
}
|
||||||
@ -173,17 +176,44 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case "tunnel":
|
case "tunnel":
|
||||||
|
if cmd.udp {
|
||||||
|
cfg := &udpTunnel.BackendConfig{
|
||||||
|
IdentityPath: zif,
|
||||||
|
EndpointAddress: target,
|
||||||
|
ShrToken: resp.Payload.ShrToken,
|
||||||
|
}
|
||||||
|
be, err := udpTunnel.NewBackend(cfg)
|
||||||
|
if err != nil {
|
||||||
|
if !panicInstead {
|
||||||
|
tui.Error("unable to create udp tunnel backend", err)
|
||||||
|
}
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
if err := be.Run(); err != nil {
|
||||||
|
logrus.Errorf("error running udp tunnel backend: %v", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
} else {
|
||||||
cfg := &tcpTunnel.BackendConfig{
|
cfg := &tcpTunnel.BackendConfig{
|
||||||
IdentityPath: zif,
|
IdentityPath: zif,
|
||||||
EndpointAddress: target,
|
EndpointAddress: target,
|
||||||
ShrToken: resp.Payload.ShrToken,
|
ShrToken: resp.Payload.ShrToken,
|
||||||
}
|
}
|
||||||
if err := cmd.tunnelBackendMode(cfg); err != nil {
|
be, err := tcpTunnel.NewBackend(cfg)
|
||||||
|
if err != nil {
|
||||||
if !panicInstead {
|
if !panicInstead {
|
||||||
tui.Error("unable to create tunnel backend", err)
|
tui.Error("unable to create tunnel backend", err)
|
||||||
}
|
}
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
go func() {
|
||||||
|
if err := be.Run(); err != nil {
|
||||||
|
logrus.Errorf("error running tunnel backend: %v", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
tui.Error("invalid backend mode", nil)
|
tui.Error("invalid backend mode", nil)
|
||||||
@ -253,21 +283,6 @@ func (cmd *sharePrivateCommand) webBackendMode(cfg *proxy.WebBackendConfig) (end
|
|||||||
return be, nil
|
return be, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cmd *sharePrivateCommand) tunnelBackendMode(cfg *tcpTunnel.BackendConfig) error {
|
|
||||||
be, err := tcpTunnel.NewBackend(cfg)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "error creating tunnel backend")
|
|
||||||
}
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
if err := be.Run(); err != nil {
|
|
||||||
logrus.Errorf("error running tunnel backend: %v", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cmd *sharePrivateCommand) destroy(id string, shrToken string, zrok *rest_client_zrok.Zrok, auth runtime.ClientAuthInfoWriter) {
|
func (cmd *sharePrivateCommand) destroy(id string, shrToken string, zrok *rest_client_zrok.Zrok, auth runtime.ClientAuthInfoWriter) {
|
||||||
logrus.Debugf("shutting down '%v'", shrToken)
|
logrus.Debugf("shutting down '%v'", shrToken)
|
||||||
req := share.NewUnshareParams()
|
req := share.NewUnshareParams()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user