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

Add google cloud configuration object for kubeclient #88

Merged
merged 1 commit into from
May 1, 2017

Conversation

xldenis
Copy link
Contributor

@xldenis xldenis commented May 1, 2017

Kubeclient doesn't support GCE authentication and there is currently no plan to merge the PR that would add support for it. To solve our problem I've added a small wrapper class based off the kubeclient PR. It provides a subclass of the Kubeclient::Config which will look for the approriate auth type and if found will fetch a new (1 hour lifetime) token.

Kubeclient GCE PR

@jeremywadsack, since you were the author of the original PR you may be interested in this.

@@ -28,7 +29,7 @@ def build_v1beta1_kubeclient(context)
end

def _build_kubeclient(api_version:, context:, endpoint_path: nil)
config = Kubeclient::Config.read(ENV.fetch("KUBECONFIG"))
config = GoogleConfig.read(ENV.fetch("KUBECONFIG"))
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sold about naming because someone reading this code could think that it only supports GKE config. What about KubeconfigWithGoogleSupport or whatever?

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 dont have any particular attachment to the name, though I'm not a huge fan of enormous names either.

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about GoogleConfig incorrectly telling someone that the tool only supports google auth?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about just ConfigWithGoogle ? I'm just not a huge fan of having KubernetesDeploy::KubeclientBuilder::KubeconfigWithGoogleSupport

scopes = ['https://www.googleapis.com/auth/cloud-platform']
authorization = Google::Auth.get_application_default(scopes)

authorization.apply({})
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does it need an empty apply? Can you add a comment to the code with the reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well apply adds the access token to a set of headers in a hash. Since we just want to recover the token we don't need to pass in anything.

WebMock.allow_net_connect!
end

def test_auth_use_default_gcp_success
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it also makes sense to check that the config works as usual if auth provider isn't GCP.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

class GoogleConfig < Kubeclient::Config
def fetch_user_auth_options(user)
if user['auth-provider'] && (user['auth-provider']['name'] == 'gcp')
{ bearer_token: self.get_token }
Copy link
Contributor

Choose a reason for hiding this comment

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

Is self required here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not anymore.

@xldenis xldenis force-pushed the gcp-auth-kubeclient branch 6 times, most recently from 559afa1 to ec5fdbc Compare May 1, 2017 16:31
@xldenis
Copy link
Contributor Author

xldenis commented May 1, 2017

I've addressed the review comments the configuration is now called GoogleFriendlyConfig.

@xldenis xldenis merged commit a746148 into master May 1, 2017
@xldenis xldenis deleted the gcp-auth-kubeclient branch May 1, 2017 19:51
end

def set_google_env_vars
ENV["GOOGLE_PRIVATE_KEY"] ||= "FAKE"
Copy link
Contributor

Choose a reason for hiding this comment

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

There's probably a reason why it's necessary, but I'd prefer them to be reset on teardown

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its because the googleauth gem does a bunch of magic inspection to determine how to load configuration for a host (ie checking if creds are locally stored on disk, whether this is a GCE host, etc...).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants