-
Notifications
You must be signed in to change notification settings - Fork 40.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changed kubectl config view to redact user token #88985
Conversation
Hi @brianpursley. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/assign smarterclayton |
IIRC the reason for redacting the cert data was that it made the output hard to read (since it is long). You can always // Flatten redacts raw data entries from the config object for a human-readable view.
func ShortenConfig(config *Config) { The go doc and function name hint that this is not related to security. |
@enj you are correct, it is not related to security. I found some related discussion that its purpose is to shorten long data, like you said. For reference, on my machine, the pertinent output without redaction looks like this for an AKS cluster:
I guess it is debatable whether this is long enough for "redaction". I personally don't have a preference, just trying to close out this issue. So if we want to leave it as-is and close the issue, I'm fine with that too. |
@@ -98,6 +98,9 @@ func ShortenConfig(config *Config) { | |||
if len(authInfo.ClientCertificateData) > 0 { | |||
authInfo.ClientCertificateData = redactedBytes | |||
} | |||
if len(authInfo.Token) > 0 { | |||
authInfo.Token = string(redactedBytes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised this works after being cast to a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, It is different than the others which are byte arrays. Token is a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does the output of this look like? tokens are strings, and the bytes you're assigning here are base-64 decoded versions of "REDACTED+"... I don't expect that would display well
we also have other potentially sensitive fields in the config (password, auth config); see corresponding sanitization of rest.Config printing in https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/client-go/rest/config.go#L158-L175
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal of ShortenConfig was not to keep confidential data from the output (if you're running this command, you already have read access to the data), but to prevent massively long output from byte-serialized certificates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed that it doesn't provide security.
I think you questioning is right though. There is a problem. The unit test passes, but the output is not "REDACTED" it is garbage. Good catch. I will re-visit this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was the test wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was the test wrong?
It was a new test case I added that was wrong, so it wasn't a problem in an existing test. I made an assumption that string(redactedBytes)
would result in "REDACTED" but that was wrong.
redactedBytes is defined as:
sDec, _ := base64.StdEncoding.DecodeString("REDACTED+")
redactedBytes = []byte(string(sDec))
I didn't look closely enough at how that actually worked.
It is sort of tricky in that it is starting with a "base-64 encoded" value of "REDACTED+" and then decoding it, storing it in bytes, so that later when it is re-encoded, it displays as a human-readable "REDACTED".
When I did string(redactedBytes)
I got the base64 decode of "REDACTED+" which is actually "D@�\t1\x03".
My test was wrong in the same way, I was inadvertently checking for "D@�\t1\x03" instead of "REDACTED".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a comment basically saying how the"trick" works, somehow I glossed right over it.
https://github.com/kubernetes/kubernetes/blob/fd0eb5dff627238fdb3a68e93abefc8a267a863a/staging/src/k8s.io/client-go/tools/clientcmd/api/helpers.go#L91
I think it is fine to redact this for readability. It's not a security thing, though. /approve |
Looks like I need to update some bazel tests... /hold |
7c1ad2d
to
75e7e78
Compare
75e7e78
to
fd0eb5d
Compare
/unhold |
I was 100% fooled by the test. Why did the test output not match reality? Please fix that? |
@lavalamp as mentioned in my comment above, the wrong test was added by me in this commit, so it wasn't a problem with an existing test. I have updated the test and checked the output. |
Thanks for the explanation! Are we not running the "Example" function as a
test, then? Is it configured wrong? It sounds like that really should have
failed.
…On Wed, Mar 11, 2020 at 10:26 AM Brian Pursley ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In staging/src/k8s.io/client-go/tools/clientcmd/api/helpers.go
<#88985 (comment)>
:
> @@ -98,6 +98,9 @@ func ShortenConfig(config *Config) {
if len(authInfo.ClientCertificateData) > 0 {
authInfo.ClientCertificateData = redactedBytes
}
+ if len(authInfo.Token) > 0 {
+ authInfo.Token = string(redactedBytes)
There is a comment basically saying how the"trick" works, somehow I
glossed right over it.
https://github.com/kubernetes/kubernetes/blob/fd0eb5dff627238fdb3a68e93abefc8a267a863a/staging/src/k8s.io/client-go/tools/clientcmd/api/helpers.go#L91
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#88985 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAE6BFUH7R2UPWIIAYFWMFTRG7CULANCNFSM4LEQWUTA>
.
|
6945854
to
2d03d44
Compare
to be honest, I don't know what that Example function was doing in the unit test. I just updated the commented out yaml so that it would be consistent with the change I made. It appears not to be an actual test. I just committed an update that turned it into a real unit test and checks the output against what was previously in the comment, so hopefully it will serve some purpose in the future. |
It's supposed to actually test stuff: https://blog.golang.org/examples |
2d03d44
to
fd0eb5d
Compare
Thanks, I'm still sort of new to Go, so wasn't familiar with that convention. TIL. 👨🎓 I reverted it back to the original "Example" test and confirmed the test DOES fail when running it locally.
This PR never actually got the I am a member now, so let me try it... Once the tests pass, I think this PR should be ready for re-review. |
fd0eb5d
to
6fad4ee
Compare
/retest |
/priority backlog |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: brianpursley, lavalamp, liggitt The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind bug
What this PR does / why we need it:
When you run
kubectl config view
, the user token is not redacted like client-certificate-data and client-key-data. This PR redacts the user token.Which issue(s) this PR fixes:
xref kubernetes/kubectl#667
Special notes for your reviewer:
None
Does this PR introduce a user-facing change?:
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: