Skip to content
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

Merged
merged 2 commits into from Sep 21, 2020
Merged

Limit the max number of splitting. #94803

merged 2 commits into from Sep 21, 2020

Conversation

a2ush
Copy link
Contributor

@a2ush a2ush commented Sep 15, 2020

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.

root@test:/# for i in {0..10000};do echo -n $i' ' >> 10k; done
root@test:/# KK=`cat 10k`
root@test:/# TOKEN=`cat /var/run/secrets/kubernetes.io/serviceaccount/token`
root@test:/# curl -H "Authorization: Bearer ${TOKEN} ${KK}" --cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt https://kubernetes/api/v1/namespaces/default/pods
{
  "kind": "PodList",
  "apiVersion": "v1",
  "metadata": {
...

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 to len(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 to len(parts)!= 2), could you tell me that?

Does this PR introduce a user-facing change?:

None

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

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/feature Categorizes issue or PR as related to a new feature. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Sep 15, 2020
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Sep 15, 2020
@k8s-ci-robot k8s-ci-robot added area/apiserver sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/auth Categorizes an issue or PR as relevant to SIG Auth. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Sep 15, 2020
@a2ush
Copy link
Contributor Author

a2ush commented Sep 15, 2020

/assign @mikedanese

@liggitt
Copy link
Member

liggitt commented Sep 15, 2020

/hold

Since this is a breaking change, the scope of the impact and the benefit needs to be made clear and justify the break.

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Sep 15, 2020
@a2ush a2ush changed the title Change to accept only the format "Authorization: Bearer TOKEN". Limit the max number of splitting. Sep 15, 2020
@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Sep 15, 2020
@liggitt
Copy link
Member

liggitt commented Sep 15, 2020

/hold cancel
/ok-to-test

go ahead and squash to a single commit and add a unit test showing this behaves the same if there are trailing spaces

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 15, 2020
@fedebongio
Copy link
Contributor

/remove-sig api-machinery

@k8s-ci-robot k8s-ci-robot removed the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Sep 15, 2020
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Sep 18, 2020
@a2ush
Copy link
Contributor Author

a2ush commented Sep 20, 2020

go ahead and squash to a single commit and add a unit test showing this behaves the same if there are trailing spaces

I squashed the previous commit to a single one, and added a unit test.
Could you confirm that?

@liggitt
Copy link
Member

liggitt commented Sep 21, 2020

/lgtm
/approve
/milestone v1.20

@k8s-ci-robot k8s-ci-robot added this to the v1.20 milestone Sep 21, 2020
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 21, 2020
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 21, 2020
@k8s-ci-robot k8s-ci-robot merged commit 0c3286e into kubernetes:master Sep 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/apiserver cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/auth Categorizes an issue or PR as relevant to SIG Auth. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants