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 support for FQDN K8s API servers and Root CA chains #144

Merged
merged 4 commits into from
Mar 8, 2022

Conversation

thephw
Copy link
Contributor

@thephw thephw commented Mar 8, 2022

Problem

Our k8s API servers use a fully qualified domain name and TLS certs from LetsEncrypt. In the current implementation no root CA certfiles are provided to HTTPoison. This causes an error when trying to configure and use a connection like below with :verify_peer. This is a bit unexpected.

> {:ok, auth} = K8s.Conn.Auth.Token.create(%{"token" => "avalidbearertokenhere"})
...
> conn = %K8s.Conn{auth: auth, cluster_name: "thephw", ca_cert: nil, user_name: "thephw", url: "https://k8s.flowerwork.net/"}
...
> operation = K8s.Client.list("v1", "Node") 
...
> conn  |> K8s.Client.run(operation)
{:error, %HTTPoison.Error{id: nil, reason: {:options, {:cacertfile, []}}}}

Prior Art

Looked at a handful of other elixir libraries to see how they were managing root CA files. Most of them were using CAStore

Solution

Add CAStore dependency and integrate cacertfile option into K8s.Conn with CAStore.file_path() as the default.

Changelog

  • Add CAStore dependency for root CAs
  • This adds support for k8s servers using TLS certs with a custody chain back to a root certificate authority. i.e. no intermediate certificates
  • This would be typical of any k8s server with a public API available at a FQDN with a TLS cert whose chain of custody is covered by the root certificate authorities.
  • Sets the default ca_provider on K8s.Conn to CAStore
  • Sets the default cacertfile parameter for ssl_options to conn. cacertfile
  • Update conn_test.exs assertions for ssl_options
  • This makes the default when not using an intermediate certificate chain to use the root CA certificate chain.
  • This does not change the behavior when using connection configuration with intermediate certificate authorities

thephw added 3 commits March 8, 2022 00:17
* Add [CAStore](https://github.com/elixir-mint/castore) dependency
  for root CAs
* This adds support for k8s servers using TLS certs with a custody chain
  back to a root certificate authority. i.e. no intermediate certificates
* This would be typical of any k8s server with a public API available at
  a FQDN with a TLS cert whose chain of custody is covered by the root
  certificate authorities.
* Sets the default ca_provider on K8s.Conn to CAStore
* Sets the default cacertfile parameter for ssl_options to
  `conn.ca_provider`
* Update `conn_test.exs` assertions for ssl_options
* This makes the default when not using an intermediate certificate chain
  to use the root CA certificate chain.
Copy link
Collaborator

@mruoss mruoss left a comment

Choose a reason for hiding this comment

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

This is great, thanks @thephw!

mix.exs Outdated
@@ -35,6 +35,7 @@ defmodule K8s.MixProject do
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:castore, ">= 0.0.0"},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not {:castore, "~> 0.1.0"}?

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 think you're right it'd probably be better to pin to the minor version. At the moment they are functionally equivalent all releases are 0.1.X, but we could protect against any major API changes by pinning it to the minor version. Let me update that real quick.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated 👍🏻

@mruoss mruoss merged commit a91689f into coryodaniel:develop Mar 8, 2022
thephw added a commit to thephw/k8s that referenced this pull request May 19, 2022
- Ref: coryodaniel#144
- I missed a codepath in the original PR that makes this not work with a
  call from K8s.Conn.from_file when using a FQDN for the server url.
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.

2 participants