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

Initialize http Request Header before RoundTrip to avoid panic #88064

Merged
merged 1 commit into from
Feb 13, 2020

Conversation

wongma7
Copy link
Contributor

@wongma7 wongma7 commented Feb 12, 2020

What type of PR is this?
/kind bug

What this PR does / why we need it: This test panics if authenticated with a credential plugin https://kubernetes.io/docs/reference/access-authn-authz/authentication/#client-go-credential-plugins due to a bug in the credential plugin code (see #88060 for details) where it can try to write to a nil map.

To avoid this, make sure a nil map is never passed to RoundTrip in case it's the exec RoundTripper.

I guess this function is deliberately leaving Headers unset because its purpose is to find out what headers are added to an http request by wrappers and such so that websocket requests can then include the same headers. Anyway it's better to initialize Headers to an empty map instead of leaving it nil.

Which issue(s) this PR fixes:

Fixes #

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 k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. 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 Feb 12, 2020
@k8s-ci-robot k8s-ci-robot added area/e2e-test-framework Issues or PRs related to refactoring the kubernetes e2e test framework area/test sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Feb 12, 2020
@wongma7
Copy link
Contributor Author

wongma7 commented Feb 12, 2020

/sig testing

This is a Conformance test so would love for it to be fixed.

@nckturner
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 12, 2020
@wongma7
Copy link
Contributor Author

wongma7 commented Feb 12, 2020

/assign @krzyzacy

Please approve, 1 liner change, TY.

@oomichi
Copy link
Member

oomichi commented Feb 12, 2020

If #88060 is merged, is this still necessary?
Both PRs are k/k, I am not sure the necessity of this PR after that.

@oomichi
Copy link
Member

oomichi commented Feb 12, 2020

/cc @oomichi

@wongma7
Copy link
Contributor Author

wongma7 commented Feb 13, 2020

@oomichi yes because it's possible for one to compile a version of these tests (e2e.test) that depends on a version of client-go without the change in #88060 and then they would see the panic. So to cover all cases we need both PRs (I considered putting them together.)

@oomichi
Copy link
Member

oomichi commented Feb 13, 2020

@wongma7 Thanks for your explanation, I got the point.
The change itself doesn't seem any harm, I am fine to merge this.

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: oomichi, wongma7

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 Feb 13, 2020
@k8s-ci-robot k8s-ci-robot merged commit 1aa2163 into kubernetes:master Feb 13, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.18 milestone Feb 13, 2020
@@ -1536,7 +1536,7 @@ func headersForConfig(c *restclient.Config, url *url.URL) (http.Header, error) {
if err != nil {
return nil, err
}
if _, err := rt.RoundTrip(&http.Request{URL: url}); err != nil {
if _, err := rt.RoundTrip(&http.Request{Header: make(http.Header), URL: url}); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Why doesn't this use http.NewRequest? are there other things wrong with this construction?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know, I guess the original author avoided a constructor to show that this is a "dummy" request whose only purpose is to figure out Headers.

Either way, I did the bare minimum change to fix my problem, but best practice would probably be to do

NewRequest("GET", url, nil).

So let me open another PR.

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/e2e-test-framework Issues or PRs related to refactoring the kubernetes e2e test framework area/test 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. release-note-none Denotes a PR that doesn't merit a release note. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants