From d4a54d1ba8752e07b4bd95c34e6f6f92f3ebf5e4 Mon Sep 17 00:00:00 2001 From: Brian Pursley Date: Tue, 17 Mar 2020 15:13:50 -0400 Subject: [PATCH] Changed kubectl config view to redact token Kubernetes-commit: 6fad4ee5e5f5fa6fbf38e88f165b012fa0ae5795 --- tools/clientcmd/api/helpers.go | 3 +++ tools/clientcmd/api/helpers_test.go | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/clientcmd/api/helpers.go b/tools/clientcmd/api/helpers.go index 65a36936..d677d651 100644 --- a/tools/clientcmd/api/helpers.go +++ b/tools/clientcmd/api/helpers.go @@ -98,6 +98,9 @@ func ShortenConfig(config *Config) { if len(authInfo.ClientCertificateData) > 0 { authInfo.ClientCertificateData = redactedBytes } + if len(authInfo.Token) > 0 { + authInfo.Token = "REDACTED" + } config.AuthInfos[key] = authInfo } for key, cluster := range config.Clusters { diff --git a/tools/clientcmd/api/helpers_test.go b/tools/clientcmd/api/helpers_test.go index 48b3cec2..67231710 100644 --- a/tools/clientcmd/api/helpers_test.go +++ b/tools/clientcmd/api/helpers_test.go @@ -243,7 +243,7 @@ func Example_minifyAndShorten() { // LocationOfOrigin: "" // client-certificate-data: REDACTED // client-key-data: REDACTED - // token: red-token + // token: REDACTED } func TestShortenSuccess(t *testing.T) { @@ -299,4 +299,7 @@ func TestShortenSuccess(t *testing.T) { if string(mutatingConfig.AuthInfos[changingAuthInfo].ClientKeyData) != redacted { t.Errorf("expected %v, got %v", redacted, string(mutatingConfig.AuthInfos[changingAuthInfo].ClientKeyData)) } + if mutatingConfig.AuthInfos[changingAuthInfo].Token != "REDACTED" { + t.Errorf("expected REDACTED, got %v", mutatingConfig.AuthInfos[changingAuthInfo].Token) + } }