From c5d16622448977f0b5f16d38c55c8a552a272c91 Mon Sep 17 00:00:00 2001 From: Nuno Diegues Date: Mon, 28 Mar 2022 10:53:22 +0100 Subject: [PATCH] TUN-5960: Do not log the tunnel token or json credentials --- CHANGES.md | 5 ++++ cmd/cloudflared/tunnel/configuration.go | 37 +++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 0a09668b..21d581cf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +## 2022.4.0 +### Bug Fixes +- `cloudflared tunnel run` no longer logs the Tunnel token or JSON credentials in clear text as those are the secret +that allows to run the Tunnel. + ## 2022.3.4 ### New Features - It is now possible to retrieve the credentials that allow to run a Tunnel in case you forgot/lost them. This is diff --git a/cmd/cloudflared/tunnel/configuration.go b/cmd/cloudflared/tunnel/configuration.go index d7d6da8d..1ff02c93 100644 --- a/cmd/cloudflared/tunnel/configuration.go +++ b/cmd/cloudflared/tunnel/configuration.go @@ -14,6 +14,7 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" "github.com/urfave/cli/v2" + "github.com/urfave/cli/v2/altsrc" "golang.org/x/crypto/ssh/terminal" "github.com/cloudflare/cloudflared/cmd/cloudflared/cliutil" @@ -31,14 +32,16 @@ import ( ) const LogFieldOriginCertPath = "originCertPath" +const secretValue = "*****" var ( developerPortal = "https://developers.cloudflare.com/argo-tunnel" - quickStartUrl = developerPortal + "/quickstart/quickstart/" serviceUrl = developerPortal + "/reference/service/" argumentsUrl = developerPortal + "/reference/arguments/" LogFieldHostname = "hostname" + + secretFlags = [2]*altsrc.StringFlag{credentialsContentsFlag, tunnelTokenFlag} ) // returns the first path that contains a cert.pem file. If none of the DefaultConfigSearchDirectories @@ -65,7 +68,11 @@ func generateRandomClientID(log *zerolog.Logger) (string, error) { func logClientOptions(c *cli.Context, log *zerolog.Logger) { flags := make(map[string]interface{}) for _, flag := range c.FlagNames() { - flags[flag] = c.Generic(flag) + if isSecretFlag(flag) { + flags[flag] = secretValue + } else { + flags[flag] = c.Generic(flag) + } } if len(flags) > 0 { @@ -79,7 +86,11 @@ func logClientOptions(c *cli.Context, log *zerolog.Logger) { if strings.Contains(env, "TUNNEL_") { vars := strings.Split(env, "=") if len(vars) == 2 { - envs[vars[0]] = vars[1] + if isSecretEnvVar(vars[0]) { + envs[vars[0]] = secretValue + } else { + envs[vars[0]] = vars[1] + } } } } @@ -88,6 +99,26 @@ func logClientOptions(c *cli.Context, log *zerolog.Logger) { } } +func isSecretFlag(key string) bool { + for _, flag := range secretFlags { + if flag.Name == key { + return true + } + } + return false +} + +func isSecretEnvVar(key string) bool { + for _, flag := range secretFlags { + for _, secretEnvVar := range flag.EnvVars { + if secretEnvVar == key { + return true + } + } + } + return false +} + func dnsProxyStandAlone(c *cli.Context, namedTunnel *connection.NamedTunnelProperties) bool { return c.IsSet("proxy-dns") && (!c.IsSet("hostname") && !c.IsSet("tag") && !c.IsSet("hello-world") && namedTunnel == nil) }