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

Fix multiple problems in K8s::Client.autoconfig #107

Merged
merged 4 commits into from
Apr 30, 2019
Merged

Conversation

kke
Copy link
Contributor

@kke kke commented Feb 14, 2019

The K8s::Client.autoconfig had several problems:

  • The base64 check for KUBE_TOKEN was not working
  • The KUBE_CA was not checked for base64 at all. The check in this PR is a little so-and-so.
  • The multi-path KUBECONFIG merge mechanism had a leftover debug puts
  • The KUBECONFIG loader did not expand paths, ~/.kube/config would not have worked.
  • There were no specs

@kke kke added the bug Something isn't working label Feb 14, 2019
@@ -68,7 +68,17 @@ def self.in_cluster_config(namespace: nil, **options)
# @return [K8s::Client]
def self.autoconfig(namespace: nil, **options)
if ENV.values_at('KUBE_TOKEN', 'KUBE_CA', 'KUBE_SERVER').none? { |v| v.nil? || v.empty? }
configuration = K8s::Config.build(server: ENV['KUBE_SERVER'], ca: ENV['KUBE_CA'], auth_token: options[:auth_token] || ENV['KUBE_TOKEN'])
unless Base64.decode64(ENV['KUBE_CA']).match?(/CERTIFICATE/)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this worth anything?

(The KUBE_CA must be base64, it's decoded and ran through various magics of OpenSSL in transport.rb)

It does not strict_decode64 because transport.rb doesn't either, maybe it could?

Copy link
Contributor

Choose a reason for hiding this comment

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

That should validate that KUBE_CA is actually something usable 👍

@@ -68,7 +68,17 @@ def self.in_cluster_config(namespace: nil, **options)
# @return [K8s::Client]
def self.autoconfig(namespace: nil, **options)
if ENV.values_at('KUBE_TOKEN', 'KUBE_CA', 'KUBE_SERVER').none? { |v| v.nil? || v.empty? }
configuration = K8s::Config.build(server: ENV['KUBE_SERVER'], ca: ENV['KUBE_CA'], auth_token: options[:auth_token] || ENV['KUBE_TOKEN'])
unless Base64.decode64(ENV['KUBE_CA']).match?(/CERTIFICATE/)
Copy link
Contributor

Choose a reason for hiding this comment

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

That should validate that KUBE_CA is actually something usable 👍

end

begin
token = options[:auth_token] || Base64.strict_decode64(ENV['KUBE_TOKEN'])
Copy link
Contributor

Choose a reason for hiding this comment

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

This forces the token to always be base64 encoded. the previous version tried to figure out if it's base64 or not. but yes, it was not perfect in any way...

This might break existing use cases for people. :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's impossible to detect base64 reliably. Either we should allow only plain or only base64. And some tokens may contain characters that are unsuitable for env / config files, so it might be better to just allow base64.

If the base64 decoding fails, it gives a fairly clear error message:

          raise ArgumentError, 'KUBE_TOKEN does not seem to be base64 encoded'

@kke
Copy link
Contributor Author

kke commented Apr 5, 2019

#112 warrants a release, can we get this in as well?

@jakolehm jakolehm merged commit 087eedb into master Apr 30, 2019
@jakolehm jakolehm deleted the fix/autoconfig branch April 30, 2019 08:15
@jakolehm jakolehm mentioned this pull request May 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants