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 TLS support to HTTP Server #185

Merged
merged 10 commits into from
Apr 22, 2020
Merged

Conversation

annanay25
Copy link
Contributor

@annanay25 annanay25 commented Apr 9, 2020

Part of cortexproject/cortex#2350

Changes

  • Adds six new config flags which will accept path to the Cert, Key and ClientCA, for HTTP and GRPC servers.
    • server.http-cert-path, server.http-key-path, server.http-ca-path
    • server.grpc-cert-path, server.grpc-key-path, server.grpc-ca-path
  • Either both server and client auth will be enabled, or neither.
  • Added tests, and scripts to generate certs at runtime.
  • Changes in dependencies are because of the following addition:
github.com/prometheus/node_exporter v1.0.0-rc.0.0.20200417100735-fa4edd700ebc
  • ConfigToTLSConfig, which is used from the prometheus node_exporter library and generates a *tls.Config struct from the config options, is awaiting security review.
  • The following breaking change has been made to the prometheus client_golang library:
github.com/prometheus/client_golang v1.4.1

/cc @bboreham

Signed-off-by: Annanay <annanayagarwal@gmail.com>
Signed-off-by: Annanay <annanayagarwal@gmail.com>
Signed-off-by: Annanay <annanayagarwal@gmail.com>
Signed-off-by: Annanay <annanayagarwal@gmail.com>
@bboreham
Copy link
Collaborator

bboreham commented Apr 9, 2020

Q: Should dummy certs for testing be included in this PR, or a script to generate certs at test runtime?

I don't know; what are the trade-offs? What did someone else do when faced with this question?

Signed-off-by: Annanay <annanayagarwal@gmail.com>
@annanay25
Copy link
Contributor Author

Adding certs to the repo for testing purposes seems like the most common solution, the only trade-off being that the test will fail once the certs expire.

@halcyondude
Copy link

I would like to confirm that both variants (enabled, not enabled) of this functionality will be tested in CI.

Scenario

Now that cortex is 1.0+ we plan to begin using it in production. We have been rolling out a service mesh across our infra, for a few reasons - one of which is consistent mTLS across all k8s services which are on the mesh. We expect this to be how we handle service <-> service encryption.

While The motivation to bake this into the project is rational, I would hope that it doesn’t over time become mandatory as it adds another layer/place where certificates need to be managed. The mesh we are using is able to integrate with external CA’s, and cert rotation/renewal is handled by cert-manager (using LetsEncrypt).

We are planning to run Cortex atop this existing infra, which in addition to providing mTLS, also enables observability, a layer of resiliency, and (I’m hoping) the ability to have blue-greens via traffic split for cortex service versions.

If I’m misunderstanding the use case here or intent apologies! We are still learning about the project, code, and operational aspects of running cortex in our infra.

@annanay25
Copy link
Contributor Author

annanay25 commented Apr 13, 2020

Thanks for your feedback, I completely agree with your reasoning @halcyondude.

The PR has been designed to remain backward compatible. TLS remains optional, and can be setup via a service mesh as you have mentioned. If the relevant flags are not initialised, tls will not be initiated and the server will work exactly as before.

That said, some users may not want to add a service mesh dependency and IMO it makes sense to bake this feature into the server :)

@annanay25 annanay25 changed the title All TLS support to HTTP Server Add TLS support to HTTP Server Apr 13, 2020
@tomwilkie
Copy link
Contributor

Q: Should dummy certs for testing be included in this PR, or a script to generate certs at test runtime?

I think having certs (even dummy certs) checked in is undesirable; it makes it looks like a leak of secrets, even if it isn't. Can we easily generate them in the unit test?

server/server.go Outdated Show resolved Hide resolved
server/server.go Outdated Show resolved Hide resolved
@tomwilkie
Copy link
Contributor

Can we reuse https://github.com/prometheus/node_exporter/blob/master/https/tls_config.go instead of building it ourself? This also has more options for client cert - which might be a good thing.

I think we'll need to be able to specify different TLS settings for gRPC and HTTP - for instance, not needing client cert verification on HTTP but needing it on gRPC sounds reasonable to me.

Signed-off-by: Annanay <annanayagarwal@gmail.com>
Signed-off-by: Annanay <annanayagarwal@gmail.com>
@gouthamve
Copy link
Contributor

I tried exposing the function upstream but I am not sure it will be done anytime soon prometheus/node_exporter#1677 (comment)

I don't think we should block this PR on that but we should add a TODO in the code and in an issue to move to the upstream function when its exposed. I also see that upstream is waiting for a security review, and I don't think we should block on that imo. The upstream code has already gone through robust code review here: prometheus/node_exporter#1277 and from what I can see, by reusing that code, we're getting a free security review :)

Signed-off-by: Annanay <annanayagarwal@gmail.com>
Signed-off-by: Annanay <annanayagarwal@gmail.com>
Copy link
Collaborator

@bboreham bboreham left a comment

Choose a reason for hiding this comment

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

A few more thoughts below.

server/server.go Show resolved Hide resolved
server/server_test.go Outdated Show resolved Hide resolved
go.mod Show resolved Hide resolved
go.mod Show resolved Hide resolved
Signed-off-by: Annanay <annanayagarwal@gmail.com>
@annanay25
Copy link
Contributor Author

Updated PR description as well. Please let me know if this is sufficient to move forward. :)

Copy link
Collaborator

@bboreham bboreham left a comment

Choose a reason for hiding this comment

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

lgtm, thanks!

@@ -0,0 +1,23 @@
# From https://github.com/joe-elliott/cert-exporter/blob/master/test/files/genCerts.sh
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note this is under Apache 2 licence.
(also it's more future-proof to use a commit hash than master in the URL)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, right. I could send a follow up PR to change this.

@bboreham bboreham merged commit 5790e74 into weaveworks:master Apr 22, 2020
@annanay25
Copy link
Contributor Author

Thanks!

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.

5 participants