From e5172421940362720083d0c723ea924bb2342351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveirinha?= Date: Wed, 7 Dec 2022 16:13:21 +0000 Subject: [PATCH] TUN-6995: Disable quick-tunnels spin up by default Before this change when running cloudflare tunnel command without any subcommand and without any additional flag, we would spin up a QuickTunnel. This is really a strange behaviour because we can easily create unwanted tunnels and results in bad user experience. This also has the side effect on putting more burden in our services that are probably just mistakes. This commit fixes that by requiring user to specify the url command flag. Running cloudflared tunnel alone will result in an error message instead. --- cmd/cloudflared/tunnel/cmd.go | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/cmd/cloudflared/tunnel/cmd.go b/cmd/cloudflared/tunnel/cmd.go index 03ad6d49..3dc9c8a7 100644 --- a/cmd/cloudflared/tunnel/cmd.go +++ b/cmd/cloudflared/tunnel/cmd.go @@ -82,6 +82,15 @@ const ( LogFieldPIDPathname = "pidPathname" LogFieldTmpTraceFilename = "tmpTraceFilename" LogFieldTraceOutputFilepath = "traceOutputFilepath" + + tunnelCmdErrorMessage = `You did not specify any valid additional argument to the cloudflared tunnel command. + +If you are trying to run a Quick Tunnel then you need to explicitly pass the --url flag. +Eg. cloudflared tunnel --url localhost:8080/. + +Please note that Quick Tunnels are meant to be ephemeral and should only be used for testing purposes. +For production usage, we recommend creating Named Tunnels. (https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/tunnel-guide/) +` ) var ( @@ -166,21 +175,27 @@ func TunnelCommand(c *cli.Context) error { if err != nil { return err } + if name := c.String("name"); name != "" { // Start a named tunnel return runAdhocNamedTunnel(sc, name, c.String(CredFileFlag)) } + + // Unauthenticated named tunnel on ..com + shouldRunQuickTunnel := c.IsSet("url") || c.IsSet("hello-world") + if !dnsProxyStandAlone(c, nil) && c.String("hostname") == "" && c.String("quick-service") != "" && shouldRunQuickTunnel { + return RunQuickTunnel(sc) + } + if ref := config.GetConfiguration().TunnelID; ref != "" { return fmt.Errorf("Use `cloudflared tunnel run` to start tunnel %s", ref) } - // Unauthenticated named tunnel on ..com - // For now, default to legacy setup unless quick-service is specified - if !dnsProxyStandAlone(c, nil) && c.String("hostname") == "" && c.String("quick-service") != "" { - return RunQuickTunnel(sc) + // Start a classic tunnel if hostname is specified. + if c.String("hostname") != "" { + return runClassicTunnel(sc) } - // Start a classic tunnel - return runClassicTunnel(sc) + return errors.New(tunnelCmdErrorMessage) } func Init(info *cliutil.BuildInfo, gracefulShutdown chan struct{}) {