-
Notifications
You must be signed in to change notification settings - Fork 26
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/) | ||
raise ArgumentError, 'KUBE_CA does not seem to be base64 encoded' | ||
end | ||
|
||
begin | ||
token = options[:auth_token] || Base64.strict_decode64(ENV['KUBE_TOKEN']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. :/ There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
|
||
rescue ArgumentError | ||
raise ArgumentError, 'KUBE_TOKEN does not seem to be base64 encoded' | ||
end | ||
|
||
configuration = K8s::Config.build(server: ENV['KUBE_SERVER'], ca: ENV['KUBE_CA'], auth_token: token) | ||
elsif !ENV['KUBECONFIG'].to_s.empty? | ||
configuration = K8s::Config.from_kubeconfig_env(ENV['KUBECONFIG']) | ||
elsif File.exist?(File.join(Dir.home, '.kube', 'config')) | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 👍