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

Warn on receiving a space before the token #109587

Conversation

slaskawi
Copy link
Contributor

@slaskawi slaskawi commented Apr 21, 2022

What type of PR is this?

/kind bug

What this PR does / why we need it:

This Pull Request adds a warning when someone tries to send a request with a space before the token:

$ curl -k https://IP -H "Authorization: Bearer  asdf"

Which issue(s) this PR fixes:

xref #106142

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot
Copy link
Contributor

Please note that we're already in Test Freeze for the release-1.24 branch. This means every merged PR has to be cherry-picked into the release branch to be part of the upcoming v1.24.0 release.

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 21, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @slaskawi. 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 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 do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Apr 21, 2022
@leilajal
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 Apr 21, 2022
@slaskawi
Copy link
Contributor Author

@aramase Could I ask you for a review?

@@ -48,6 +50,10 @@ func (a *Authenticator) AuthenticateRequest(req *http.Request) (*authenticator.R

// Empty bearer tokens aren't valid
if len(token) == 0 {
// The space before the token case
if len(parts) == 3 {
klog.Warning("WARNING: the support for spaces before the token will be removed shortly")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A kube-apiserver log warning is not visible to the person making the request, who is the one that is likely to be confused by lack of authentication and is the one who needs to make a change. Also, we haven't decided that this type of request will turn into an error in the future, so don't include that in the message.

This should be something like this:

warning.AddWarning(req.Context(), "", "the provided Authorization header contains extra space before the bearer token, and is ignored")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! I just changed the text slightly: the provided Authorization header contains extra space before the bearer token, which is ignored. I hope it's OK.

@slaskawi slaskawi force-pushed the 106142-warn-on-white-characters-at-the-beginning-of-a-token-2 branch from 7562e1b to 2d902db Compare April 25, 2022 10:50
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 25, 2022
@slaskawi
Copy link
Contributor Author

Thanks a lot for the review @liggitt !

I addressed all the comments according to your guidance. Please have another look once CI is happy.

)

const (
invalidTokenWithSpaceWarning = "the provided Authorization header contains extra space before the bearer token, which is ignored"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is hard to tell whether the extra space is ignored, or the bearer token is ignored

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aaah... I see :)

Ok, I changed to the version that You suggested. Thanks again for looking into this!

@slaskawi slaskawi force-pushed the 106142-warn-on-white-characters-at-the-beginning-of-a-token-2 branch from 2d902db to f0af12b Compare April 25, 2022 13:22
@liggitt
Copy link
Member

liggitt commented Apr 25, 2022

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 25, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: liggitt, slaskawi

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 Apr 25, 2022
@enj enj added this to Needs Triage in SIG Auth Old Apr 25, 2022
@slaskawi
Copy link
Contributor Author

The [sig-storage] CSI Volumes [Driver: csi-hostpath] [Testpattern: Dynamic PV (default fs)] subPath should support non-existent path expand_more failure doesn't seem to be related. Let's retrigger it.

/retest

@k8s-ci-robot
Copy link
Contributor

@slaskawi: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

The [sig-storage] CSI Volumes [Driver: csi-hostpath] [Testpattern: Dynamic PV (default fs)] subPath should support non-existent path expand_more failure doesn't seem to be related. Let's retrigger it.

/retest

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.

@s-urbaniak
Copy link
Contributor

/ok-to-test

@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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 26, 2022
@slaskawi
Copy link
Contributor Author

/retest-required

@slaskawi
Copy link
Contributor Author

@enj @liggitt Could you please advice me what milestone we're targeting at with this PR? tide is complaining that v1.24 is not set.

@liggitt
Copy link
Member

liggitt commented Apr 26, 2022

1.25, which will start merging things once 1.24 is released (target is May 3rd)

@slaskawi
Copy link
Contributor Author

Thank you @liggitt !

@fedebongio
Copy link
Contributor

/triage accepted
/remove-sig api-machinery

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Apr 26, 2022
@k8s-ci-robot k8s-ci-robot merged commit d11eec7 into kubernetes:master May 4, 2022
SIG Auth Old automation moved this from Needs Triage to Closed / Done May 4, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.25 milestone May 4, 2022
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/bug Categorizes issue or PR as related to a bug. 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/auth Categorizes an issue or PR as relevant to SIG Auth. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Archived in project
SIG Auth Old
Closed / Done
Development

Successfully merging this pull request may close these issues.

None yet

6 participants