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

Make gcp auth provider not to override the Auth header if it's already exits #45575

Merged
merged 1 commit into from
Jun 9, 2017

Conversation

wanghaoran1988
Copy link
Contributor

@wanghaoran1988 wanghaoran1988 commented May 10, 2017

What this PR does / why we need it:
Make AuthProvider not wrap the transport if beartoken or basic auth is enabled
Which issue this PR fixes :
fixes #44476

Special notes for your reviewer:

Release note:

GCP auth plugin no longer overwrites existing Authorization headers.

@k8s-reviewable
Copy link

This change is Reviewable

@k8s-ci-robot
Copy link
Contributor

Hi @wanghaoran1988. 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 @k8s-bot 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.

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. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 10, 2017
@k8s-github-robot k8s-github-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. release-note Denotes a PR that will be considered when it comes time to generate release notes. labels May 10, 2017
@wanghaoran1988
Copy link
Contributor Author

/cc @ericchiang I think maybe we can disable the authProvider wrap for transport if the beartokens or basic auth enabled ?

@deads2k
Copy link
Contributor

deads2k commented May 10, 2017

Why shouldn't the auth provider be able to wrap at his pleasure? For instance, couldn't you have an auth provider that used some native tooling to produce a bearertoken that was never stored inside of the kubeconfig file?

@wanghaoran1988
Copy link
Contributor Author

wanghaoran1988 commented May 10, 2017 via email

@ericchiang
Copy link
Contributor

The way the current interface is written, as a transport wrapper, has nothing to do with bearer tokens. Doing this starts to make decisions based on the existing implementations, so the abstraction is starting to leak.

We should either change the interface to be about bearer tokens and declare a clear priority, or continue to modify auth providers to not override the authorization headers.

@deads2k
Copy link
Contributor

deads2k commented May 11, 2017

We should either change the interface to be about bearer tokens and declare a clear priority, or continue to modify auth providers to not override the authorization headers.

I think the transport wrapper should be allowed to wrap in any way it sees fit. What is the value in artificially restricting it?

@ericchiang
Copy link
Contributor

I think the transport wrapper should be allowed to wrap in any way it sees fit. What is the value in artificially restricting it?

@deads2k My interface refactor point is that all or current (and proposed) client auth plugins are actually just bearer token sources, but the interface deals with wrapping transports.

If we want explicit bearer tokens/basic auth defined in the kubeconfig to override the client auth plugin's (what this PR is trying to do) we should probably refactor the client auth plugin interface into a bearer token source, instead of what this PR is doing and conditionally not wrapping the transports based on the Authorization header.

I'm not attached to a Authorization header priority, but the idea of the client auth plugin as a bearer token source instead of a transport wrapper has come up in other PRs #39587 (comment)

@cjcullen
Copy link
Member

If you want to get this in instead of #46666, I'd be happy to close my PR.

@ericchiang
Copy link
Contributor

@cjcullen @wanghaoran1988 maybe we should get this or #46666 in for 1.7 then work on the interface refactoring for 1.8? Add a TODO and open an issue?

@ericchiang
Copy link
Contributor

@k8s-bot ok to test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 31, 2017
@cjcullen
Copy link
Member

Opened up #46728 to track refactoring the interface for 1.8. I marked #44476 on the 1.7 milestone.

@cjcullen
Copy link
Member

@k8s-bot pull-kubernetes-e2e-gce-etcd3 test this

@cjcullen
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 31, 2017
@cjcullen
Copy link
Member

@caesarxuchao @deads2k @lavalamp @smarterclayton for approval

@cjcullen
Copy link
Member

@k8s-bot pull-kubernetes-e2e-gce-etcd3 test this

1 similar comment
@wanghaoran1988
Copy link
Contributor Author

@k8s-bot pull-kubernetes-e2e-gce-etcd3 test this

@wanghaoran1988
Copy link
Contributor Author

/sig auth

@k8s-ci-robot k8s-ci-robot added the sig/auth Categorizes an issue or PR as relevant to SIG Auth. label Jun 1, 2017
@deads2k
Copy link
Contributor

deads2k commented Jun 1, 2017

I think the auth provider plugin should have the ability to wrap the transport regardless. The plugin can preserve the header information. Looks like the oidc one already did this: #45529

@wanghaoran1988
Copy link
Contributor Author

@deads2k Yeah, the oidc plugin already have, but for GCP plugin doesn't now, it use "golang.org.oauth2.Transport" to wrap the token, we need update the dependency to preserve the header if you like this way. but this pr is the simpler fix for now.

@liggitt
Copy link
Member

liggitt commented Jun 2, 2017

I think the auth provider plugin should have the ability to wrap the transport regardless.

I agree, I'd rather leave the power in the hands of the auth provider

@liggitt
Copy link
Member

liggitt commented Jun 2, 2017

to wrap the token, we need update the dependency to preserve the header if you like this way. but this pr is the simpler fix for now.

can choose whether to delegate to the oauth round tripper or the base round tripper:

func (g *gcpAuthProvider) WrapTransport(rt http.RoundTripper) http.RoundTripper {
	return &conditionalTransport{&oauth2.Transport{Source: g.tokenSource, Base: rt}}
}

type conditionalTransport struct {
	oauthTransport *oauth2.Transport
}

func (t *conditionalTransport) RoundTrip(req *http.Request) (*http.Response, error) {
	if len(req.Header.Get("Authorization")) != 0 {
		return t.oauthTransport.Base.RoundTrip(req)
	}
	return t.oauthTransport.RoundTrip(req)
}

@wanghaoran1988
Copy link
Contributor Author

@liggitt Cool !, will update soon :)

@k8s-github-robot k8s-github-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jun 2, 2017
@wanghaoran1988 wanghaoran1988 changed the title Make AuthProvider not wrap the transport if beartoken or basic auth is enabled Make gcp auth provider not to override the Auth header if it's already exits Jun 2, 2017
@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 2, 2017
@wanghaoran1988
Copy link
Contributor Author

@k8s-bot pull-kubernetes-kubemark-e2e-gce test this

@wanghaoran1988
Copy link
Contributor Author

@k8s-bot pull-kubernetes-unit test this

@ericchiang
Copy link
Contributor

@wanghaoran1988 thanks! please update the release notes to say that the GCP auth plugin no longer overwrites existing Authorization headers.

This is a bug fix so I'm going to nominate this for 1.7.

@wanghaoran1988
Copy link
Contributor Author

@ericchiang Done

@liggitt liggitt added the kind/bug Categorizes issue or PR as related to a bug. label Jun 8, 2017
@liggitt liggitt added this to the v1.7 milestone Jun 8, 2017
@liggitt
Copy link
Member

liggitt commented Jun 8, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 8, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cjcullen, liggitt, wanghaoran1988

Associated issue: 44476

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@liggitt
Copy link
Member

liggitt commented Jun 8, 2017

/retest

@wanghaoran1988
Copy link
Contributor Author

@k8s-bot pull-kubernetes-e2e-gce-etcd3 test this

@ericchiang
Copy link
Contributor

/retest

@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit 8c2a07f into kubernetes:master Jun 9, 2017
@wanghaoran1988 wanghaoran1988 deleted the fix_44476 branch November 22, 2017 05:59
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. 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. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

kubectl --token is not honored when ~/.kube/config has an authentication token
9 participants