mirror of
https://github.com/openziti/ziti.git
synced 2026-10-10 22:54:58 +00:00
Add ziti tunnel command
This commit is contained in:
@@ -14,6 +14,10 @@
|
||||
* Add `ziti controller` and `ziti router` commands
|
||||
* They should work exactly the same as `ziti-controller` and `ziti router`
|
||||
* The standalone binaries for `ziti-controller` and `ziti-router` are deprecated and will be removed in a future release
|
||||
* Add hidden `ziti tunnel` command
|
||||
* Should work exactly the same as `ziti-tunnel`
|
||||
* Is hidden as `ziti-edge-tunnel` is the preferred tunnelling application
|
||||
* The standalone binary `ziti-tunnel` is deprecated and will be removed in a future release
|
||||
|
||||
# Release 0.26.11
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ package main
|
||||
import (
|
||||
"github.com/michaelquigley/pfxlog"
|
||||
"github.com/openziti/foundation/v2/debugz"
|
||||
"github.com/openziti/ziti/ziti-tunnel/cmd/ziti-tunnel/subcmd"
|
||||
"github.com/openziti/ziti/ziti/tunnel"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -29,5 +29,5 @@ func init() {
|
||||
|
||||
func main() {
|
||||
debugz.AddStackDumpHandler()
|
||||
subcmd.Execute()
|
||||
tunnel.Execute()
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"github.com/openziti/ziti/ziti/controller"
|
||||
"github.com/openziti/ziti/ziti/internal/log"
|
||||
"github.com/openziti/ziti/ziti/router"
|
||||
"github.com/openziti/ziti/ziti/tunnel"
|
||||
"github.com/openziti/ziti/ziti/util"
|
||||
"io"
|
||||
"os"
|
||||
@@ -124,6 +125,7 @@ func NewCmdRoot(in io.Reader, out, err io.Writer, cmd *cobra.Command) *cobra.Com
|
||||
initCommands := NewCmdInit(out, err)
|
||||
createCommands := NewCmdCreate(out, err)
|
||||
controllerCmd := controller.NewRunCmd()
|
||||
tunnelCmd := tunnel.NewTunnelCmd()
|
||||
routerCmd := router.NewRunCmd()
|
||||
agentCommands := agentcli.NewAgentCmd(p)
|
||||
pkiCommands := NewCmdPKI(out, err)
|
||||
@@ -159,6 +161,7 @@ func NewCmdRoot(in io.Reader, out, err io.Writer, cmd *cobra.Command) *cobra.Com
|
||||
agentCommands,
|
||||
controllerCmd,
|
||||
routerCmd,
|
||||
tunnelCmd,
|
||||
pkiCommands,
|
||||
unwrapIdentityFileCommand,
|
||||
},
|
||||
|
||||
@@ -14,27 +14,26 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package subcmd
|
||||
package tunnel
|
||||
|
||||
import (
|
||||
"github.com/openziti/edge/tunnel/intercept/host"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var runHostCmd = &cobra.Command{
|
||||
Use: "host",
|
||||
Short: "Run in 'host' mode",
|
||||
Long: "The 'host' mode will only host services",
|
||||
Args: cobra.ExactArgs(0),
|
||||
RunE: runHost,
|
||||
PostRun: rootPostRun,
|
||||
func NewHostCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "host",
|
||||
Short: "Run in 'host' mode",
|
||||
Long: "The 'host' mode will only host services",
|
||||
Args: cobra.ExactArgs(0),
|
||||
RunE: runHost,
|
||||
PostRun: rootPostRun,
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
root.AddCommand(runHostCmd)
|
||||
}
|
||||
|
||||
func runHost(_ *cobra.Command, args []string) error {
|
||||
func runHost(cmd *cobra.Command, args []string) error {
|
||||
root := cmd.Root()
|
||||
if !root.Flag(resolverCfgFlag).Changed {
|
||||
_ = root.PersistentFlags().Set(resolverCfgFlag, "")
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package subcmd
|
||||
package tunnel
|
||||
|
||||
import (
|
||||
"github.com/openziti/edge/tunnel/intercept/proxy"
|
||||
@@ -25,20 +25,19 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var runProxyCmd = &cobra.Command{
|
||||
Use: "proxy <service-name:port> [sevice-name:port]",
|
||||
Short: "Run in 'proxy' mode",
|
||||
Long: "The 'proxy' intercept mode creates a network listener for each service that is intercepted.",
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
RunE: runProxy,
|
||||
PostRun: rootPostRun,
|
||||
func NewProxyCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "proxy <service-name:port> [sevice-name:port]",
|
||||
Short: "Run in 'proxy' mode",
|
||||
Long: "The 'proxy' intercept mode creates a network listener for each service that is intercepted.",
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
RunE: runProxy,
|
||||
PostRun: rootPostRun,
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
root.AddCommand(runProxyCmd)
|
||||
}
|
||||
|
||||
func runProxy(_ *cobra.Command, args []string) error {
|
||||
func runProxy(cmd *cobra.Command, args []string) error {
|
||||
root := cmd.Root()
|
||||
// Fiddle with the poll rate and resolver settings if the user didn't wan't anything special.
|
||||
if !root.Flag(svcPollRateFlag).Changed {
|
||||
_ = root.PersistentFlags().Set(svcPollRateFlag, strconv.FormatUint(math.MaxUint32, 10))
|
||||
@@ -14,13 +14,12 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package subcmd
|
||||
package tunnel
|
||||
|
||||
import (
|
||||
"github.com/openziti/ziti/ziti/cmd/common"
|
||||
"github.com/openziti/ziti/ziti/constants"
|
||||
"github.com/openziti/ziti/ziti/util"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
@@ -45,7 +44,14 @@ const (
|
||||
dnsSvcIpRangeFlag = "dnsSvcIpRange"
|
||||
)
|
||||
|
||||
func init() {
|
||||
func NewTunnelCmd() *cobra.Command {
|
||||
var root = &cobra.Command{
|
||||
Use: filepath.Base(os.Args[0]),
|
||||
Short: "Ziti Tunnel",
|
||||
PersistentPreRun: rootPreRun,
|
||||
Hidden: true,
|
||||
}
|
||||
|
||||
root.PersistentFlags().BoolP("verbose", "v", false, "Enable verbose mode")
|
||||
root.PersistentFlags().StringP("identity", "i", "", "Path to JSON file that contains an enrolled identity")
|
||||
root.PersistentFlags().String("identity-dir", "", "Path to directory file that contains one or more enrolled identities")
|
||||
@@ -58,12 +64,13 @@ func init() {
|
||||
|
||||
p := common.NewOptionsProvider(os.Stdout, os.Stderr)
|
||||
root.AddCommand(enrollment.NewEnrollCommand(p))
|
||||
}
|
||||
root.AddCommand(NewHostCmd())
|
||||
root.AddCommand(NewProxyCmd())
|
||||
root.AddCommand(NewRunCmd())
|
||||
root.AddCommand(NewTProxyCmd())
|
||||
root.AddCommand(NewVersionCmd())
|
||||
|
||||
var root = &cobra.Command{
|
||||
Use: filepath.Base(os.Args[0]),
|
||||
Short: "Ziti Tunnel",
|
||||
PersistentPreRun: rootPreRun,
|
||||
return root
|
||||
}
|
||||
|
||||
var interceptor intercept.Interceptor
|
||||
@@ -72,7 +79,7 @@ var cliAgentEnabled bool
|
||||
var cliAgentAddr string
|
||||
|
||||
func Execute() {
|
||||
if err := root.Execute(); err != nil {
|
||||
if err := NewTunnelCmd().Execute(); err != nil {
|
||||
pfxlog.Logger().Errorf("error: %s", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
@@ -125,7 +132,7 @@ func rootPostRun(cmd *cobra.Command, _ []string) {
|
||||
}
|
||||
|
||||
if idDir := cmd.Flag("identity-dir").Value.String(); idDir != "" {
|
||||
files, err := ioutil.ReadDir(idDir)
|
||||
files, err := os.ReadDir(idDir)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to scan directory %s: %v", idDir, err)
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
//go:build linux
|
||||
// +build linux
|
||||
|
||||
/*
|
||||
@@ -16,7 +17,7 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package subcmd
|
||||
package tunnel
|
||||
|
||||
import (
|
||||
"github.com/michaelquigley/pfxlog"
|
||||
@@ -25,17 +26,15 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var runCmd = &cobra.Command{
|
||||
Use: "run <config>",
|
||||
Short: "Auto-select interceptor",
|
||||
Long: "Provided for backwards compatibility with scripts that were coded around older ziti-tunnel versions.",
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
Run: run,
|
||||
PostRun: rootPostRun,
|
||||
}
|
||||
|
||||
func init() {
|
||||
root.AddCommand(runCmd)
|
||||
func NewRunCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "run <config>",
|
||||
Short: "Auto-select interceptor",
|
||||
Long: "Provided for backwards compatibility with scripts that were coded around older ziti-tunnel versions.",
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
Run: run,
|
||||
PostRun: rootPostRun,
|
||||
}
|
||||
}
|
||||
|
||||
func run(cmd *cobra.Command, args []string) {
|
||||
@@ -1,3 +1,4 @@
|
||||
//go:build linux
|
||||
// +build linux
|
||||
|
||||
/*
|
||||
@@ -16,7 +17,7 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package subcmd
|
||||
package tunnel
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -24,17 +25,16 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var runTProxyCmd = &cobra.Command{
|
||||
Use: "tproxy",
|
||||
Short: "Use the 'tproxy' interceptor",
|
||||
Long: "The 'tproxy' interceptor captures packets by using the TPROXY iptables target.",
|
||||
RunE: runTProxy,
|
||||
PostRun: rootPostRun,
|
||||
}
|
||||
|
||||
func init() {
|
||||
func NewTProxyCmd() *cobra.Command {
|
||||
var runTProxyCmd = &cobra.Command{
|
||||
Use: "tproxy",
|
||||
Short: "Use the 'tproxy' interceptor",
|
||||
Long: "The 'tproxy' interceptor captures packets by using the TPROXY iptables target.",
|
||||
RunE: runTProxy,
|
||||
PostRun: rootPostRun,
|
||||
}
|
||||
runTProxyCmd.PersistentFlags().String("lanIf", "", "if specified, INPUT rules for intercepted service addresses are assigned to this interface ")
|
||||
root.AddCommand(runTProxyCmd)
|
||||
return runTProxyCmd
|
||||
}
|
||||
|
||||
func runTProxy(cmd *cobra.Command, args []string) error {
|
||||
@@ -14,22 +14,20 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package subcmd
|
||||
package tunnel
|
||||
|
||||
import (
|
||||
"github.com/openziti/ziti/common/version"
|
||||
"fmt"
|
||||
"github.com/openziti/ziti/common/version"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
root.AddCommand(versionCmd)
|
||||
}
|
||||
|
||||
var versionCmd = &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Show component version",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println(version.GetVersion())
|
||||
},
|
||||
func NewVersionCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Show component version",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println(version.GetVersion())
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user