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
Limit the max number of splitting. #94803
Conversation
Hi @azush26. 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 @mikedanese |
staging/src/k8s.io/apiserver/pkg/authentication/request/bearertoken/bearertoken.go
Outdated
Show resolved
Hide resolved
/hold Since this is a breaking change, the scope of the impact and the benefit needs to be made clear and justify the break. |
/hold cancel go ahead and squash to a single commit and add a unit test showing this behaves the same if there are trailing spaces |
/remove-sig api-machinery |
I squashed the previous commit to a single one, and added a unit test. |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: azush26, 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 feature
What this PR does / why we need it:
Currently, kubernetes api-server authenticates a request that has header that includes "bearer", "token", and " strings"(space + strings).
For example, we can get the information form the api-server when we do the bellow command in a pod with serviceAccount.
If there is the header including many spaces and strings, unnecessary slicing will occur, and processing time will be late.
I confirm that strings.Split() and strings.SplitN() are doing the same[1][2].
So I think it is better to limit the max number of splitting with strings.SplitN().
And also, as far as I read the RFC[3], I think the format "Authorization: Bearer token" is the expected to be specify to the header.
Even if there is a value(space + strings) after the token, this value is not used in any place.
In addition, if we change the condition from
len(parts) > 2
tolen(parts)!= 2
, we can prevent the api-server from doing a authentication process when a invalid value inputs after token.In a typical web server (apache, nginx and so on), the maximum size of HTTP header values is about 8K.(That is, they have the limit of the header length.)
So, I think it is better to set the limit to header, and if there is the format except "Authorization: Bearer token" in the header, kubernetes api-server should not perform the authentication process.
Special notes for your reviewer:
I think this PR is close to the specification change.
If you have opinions about this change (especially changing the condition from
len(parts) > 2
tolen(parts)!= 2
), could you tell me that?Does this PR introduce a user-facing change?:
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:
[1] https://golang.org/src/strings/strings.go?s=7164:7198#L289
[2] https://golang.org/src/strings/strings.go?h=func+genSplit#236
[3] https://tools.ietf.org/html/rfc6750#section-2.1