Skip to content

Commit c5d1662

Browse files
committed
TUN-5960: Do not log the tunnel token or json credentials
1 parent 8fd6074 commit c5d1662

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2022.4.0
2+
### Bug Fixes
3+
- `cloudflared tunnel run` no longer logs the Tunnel token or JSON credentials in clear text as those are the secret
4+
that allows to run the Tunnel.
5+
16
## 2022.3.4
27
### New Features
38
- It is now possible to retrieve the credentials that allow to run a Tunnel in case you forgot/lost them. This is

cmd/cloudflared/tunnel/configuration.go

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/pkg/errors"
1515
"github.com/rs/zerolog"
1616
"github.com/urfave/cli/v2"
17+
"github.com/urfave/cli/v2/altsrc"
1718
"golang.org/x/crypto/ssh/terminal"
1819

1920
"github.com/cloudflare/cloudflared/cmd/cloudflared/cliutil"
@@ -31,14 +32,16 @@ import (
3132
)
3233

3334
const LogFieldOriginCertPath = "originCertPath"
35+
const secretValue = "*****"
3436

3537
var (
3638
developerPortal = "https://developers.cloudflare.com/argo-tunnel"
37-
quickStartUrl = developerPortal + "/quickstart/quickstart/"
3839
serviceUrl = developerPortal + "/reference/service/"
3940
argumentsUrl = developerPortal + "/reference/arguments/"
4041

4142
LogFieldHostname = "hostname"
43+
44+
secretFlags = [2]*altsrc.StringFlag{credentialsContentsFlag, tunnelTokenFlag}
4245
)
4346

4447
// 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) {
6568
func logClientOptions(c *cli.Context, log *zerolog.Logger) {
6669
flags := make(map[string]interface{})
6770
for _, flag := range c.FlagNames() {
68-
flags[flag] = c.Generic(flag)
71+
if isSecretFlag(flag) {
72+
flags[flag] = secretValue
73+
} else {
74+
flags[flag] = c.Generic(flag)
75+
}
6976
}
7077

7178
if len(flags) > 0 {
@@ -79,7 +86,11 @@ func logClientOptions(c *cli.Context, log *zerolog.Logger) {
7986
if strings.Contains(env, "TUNNEL_") {
8087
vars := strings.Split(env, "=")
8188
if len(vars) == 2 {
82-
envs[vars[0]] = vars[1]
89+
if isSecretEnvVar(vars[0]) {
90+
envs[vars[0]] = secretValue
91+
} else {
92+
envs[vars[0]] = vars[1]
93+
}
8394
}
8495
}
8596
}
@@ -88,6 +99,26 @@ func logClientOptions(c *cli.Context, log *zerolog.Logger) {
8899
}
89100
}
90101

102+
func isSecretFlag(key string) bool {
103+
for _, flag := range secretFlags {
104+
if flag.Name == key {
105+
return true
106+
}
107+
}
108+
return false
109+
}
110+
111+
func isSecretEnvVar(key string) bool {
112+
for _, flag := range secretFlags {
113+
for _, secretEnvVar := range flag.EnvVars {
114+
if secretEnvVar == key {
115+
return true
116+
}
117+
}
118+
}
119+
return false
120+
}
121+
91122
func dnsProxyStandAlone(c *cli.Context, namedTunnel *connection.NamedTunnelProperties) bool {
92123
return c.IsSet("proxy-dns") && (!c.IsSet("hostname") && !c.IsSet("tag") && !c.IsSet("hello-world") && namedTunnel == nil)
93124
}

0 commit comments

Comments
 (0)