Skip to content

Instantly share code, notes, and snippets.

@danajp
Created May 23, 2017 19:01
Show Gist options
  • Save danajp/87fdc886ca899401dee945185465ee5b to your computer and use it in GitHub Desktop.
Save danajp/87fdc886ca899401dee945185465ee5b to your computer and use it in GitHub Desktop.
[net http blog] monkey patch kubeclient config
module MonkeyPatches
module KubeclientConfigMixin
def context(context_name = nil)
old = super(context_name)
new_ssl_options = old.ssl_options.merge(
:extra_chain_cert => client_certificate_intermediate_chain(context_name)
)
Context.new(old.api_endpoint, old.api_version, new_ssl_options, old.auth_options)
end
private
def client_certificate_data(context_name)
_, user = fetch_context(context_name || @kcfg['current-context'])
fetch_user_cert_data(user)
end
def client_certificate_chain(context_name)
# yes, we have to parse this ourselves
cert_end = '-----END CERTIFICATE-----'
client_certificate_data(context_name).
split(/(?<=#{cert_end})/).
reject { |s| s.strip.empty? }
end
def client_certificate_intermediate_chain(context_name)
client_certificate_chain(context_name).
drop(1).
map { |cert| OpenSSL::X509::Certificate.new(cert) }
end
end
end
Kubeclient::Config.send(:prepend, MonkeyPatches::KubeclientConfigMixin)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment