Merge pull request #88985 from brianpursley/kubectl-667

Changed kubectl config view to redact user token
This commit is contained in:
Kubernetes Prow Robot 2020-03-18 09:22:48 -07:00 committed by GitHub
commit 4bc907f3c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 10 deletions

View File

@ -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 {

View File

@ -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)
}
}

View File

@ -72,7 +72,7 @@ func Example_view() {
// users:
// - name: red-user
// user:
// token: red-token
// token: REDACTED
}
func TestCurrentContext(t *testing.T) {

View File

@ -48,8 +48,8 @@ func TestViewCluster(t *testing.T) {
},
CurrentContext: "minikube",
AuthInfos: map[string]*clientcmdapi.AuthInfo{
"minikube": {Token: "minikube-token"},
"mu-cluster": {Token: "minikube-token"},
"minikube": {Token: "REDACTED"},
"mu-cluster": {Token: "REDACTED"},
},
}
@ -79,10 +79,10 @@ preferences: {}
users:
- name: minikube
user:
token: minikube-token
token: REDACTED
- name: mu-cluster
user:
token: minikube-token` + "\n",
token: REDACTED` + "\n",
}
test.run(t)
@ -103,8 +103,8 @@ func TestViewClusterMinify(t *testing.T) {
},
CurrentContext: "minikube",
AuthInfos: map[string]*clientcmdapi.AuthInfo{
"minikube": {Token: "minikube-token"},
"mu-cluster": {Token: "minikube-token"},
"minikube": {Token: "REDACTED"},
"mu-cluster": {Token: "REDACTED"},
},
}
@ -134,7 +134,7 @@ preferences: {}
users:
- name: minikube
user:
token: minikube-token` + "\n",
token: REDACTED` + "\n",
},
{
description: "Testing for kubectl config view --minify=true --context=my-cluster",
@ -156,7 +156,7 @@ preferences: {}
users:
- name: mu-cluster
user:
token: minikube-token` + "\n",
token: REDACTED` + "\n",
},
}