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/GRPC clients #2502

Merged
merged 38 commits into from
May 14, 2020

Conversation

annanay25
Copy link
Contributor

@annanay25 annanay25 commented Apr 22, 2020

What this PR does:

  • go.mod updated to vendor latest commit of weaveworks/common which adds TLS support to the server.
  • Adds TLS support to all HTTP and GRPC clients in cortex.
    • GRPC:
      • pkg/util/grpcclient updated to include TLS info.
      • All GRPC clients updated to use grpcclient.DialOptions() which provides TLS options as well.
    • HTTP:
      • Util package pkg/util/httpclient created with a Config struct that stores necessary endpoint, timeout and tls config parameters.
      • All HTTP clients updated to use this config struct.

Which issue(s) this PR fixes:
Fixes #2350

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Signed-off-by: Annanay <[email protected]>
Signed-off-by: Annanay <[email protected]>
Signed-off-by: Annanay <[email protected]>
Signed-off-by: Annanay <[email protected]>
@annanay25 annanay25 changed the title WIP - Add TLS support to HTTP/GRPC clients Add TLS support to HTTP/GRPC clients May 7, 2020
annanay25 and others added 2 commits May 7, 2020 18:03
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

Thanks @annanay25 for working on it! Adding TLS support between Cortex components/services is very neat.

I've some concerns about the generic httpclient.Config struct because this causes you some troubles to keep backward compatibility and also add extra options to clients where such options are not necessarily required. Pretty much the same with gprcclient.Config.

I will reach you offline to further discuss a sligthly different design.

pracucci and others added 3 commits May 8, 2020 17:43
annanay25 added 3 commits May 11, 2020 18:28
Signed-off-by: Annanay <[email protected]>
Signed-off-by: Annanay <[email protected]>
Signed-off-by: Annanay <[email protected]>
Copy link
Contributor

@jtlisi jtlisi left a comment

Choose a reason for hiding this comment

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

This PR looks close to ready. Can you take a look at the GCP clients you configured. I don't think we want to instrument those with support for TLS. It will only confuse the Auth support Google already has.

Copy link
Contributor

@jtlisi jtlisi left a comment

Choose a reason for hiding this comment

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

You need to update the clients used by the integration tests to support TLS as well.

Copy link
Contributor

@jtlisi jtlisi left a comment

Choose a reason for hiding this comment

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

You need to refactor the integration tests to support TLS. Consider limiting the scope of this PR to add a single TLS integration test that ensures the server and clients work.

Later, other integration tests can be updated to check for TLS.

Comment on lines 101 to 108
cmd := exec.Command("bash", "certs/genCerts.sh", "certs", "1")
require.NoError(t, cmd.Run())
require.NoError(t, copyFileToSharedDir(s, integrationHomeFolder+clientCertFile, clientCertFile))
require.NoError(t, copyFileToSharedDir(s, integrationHomeFolder+clientKeyFile, clientKeyFile))
require.NoError(t, copyFileToSharedDir(s, integrationHomeFolder+rootCertFile, rootCertFile))
require.NoError(t, copyFileToSharedDir(s, integrationHomeFolder+serverCertFile, serverCertFile))
require.NoError(t, copyFileToSharedDir(s, integrationHomeFolder+serverKeyFile, serverKeyFile))

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
cmd := exec.Command("bash", "certs/genCerts.sh", "certs", "1")
require.NoError(t, cmd.Run())
require.NoError(t, copyFileToSharedDir(s, integrationHomeFolder+clientCertFile, clientCertFile))
require.NoError(t, copyFileToSharedDir(s, integrationHomeFolder+clientKeyFile, clientKeyFile))
require.NoError(t, copyFileToSharedDir(s, integrationHomeFolder+rootCertFile, rootCertFile))
require.NoError(t, copyFileToSharedDir(s, integrationHomeFolder+serverCertFile, serverCertFile))
require.NoError(t, copyFileToSharedDir(s, integrationHomeFolder+serverKeyFile, serverKeyFile))
cmd := exec.Command("bash", "certs/genCerts.sh", s.SharedDir()+"/certs", "1")
require.NoError(t, cmd.Run())

You don't need to mount each file into the env, you can generate the certs directly into the e2e shared directory.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would actually suggest to commit certs in the integration/certs and then copy all of them to the shared dir.

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good, better than generating them for every run.

queryFrontend := e2ecortex.NewQueryFrontendWithConfigFile("query-frontend", configFile, flags, "")
ingester := e2ecortex.NewIngesterWithConfigFile("ingester", consul.NetworkHTTPEndpoint(), configFile, flags, "")
distributor := e2ecortex.NewDistributorWithConfigFile("distributor", consul.NetworkHTTPEndpoint(), configFile, flags, "")
queryFrontend := e2ecortex.NewQueryFrontendWithConfigFile("query-frontend", configFile, mergeFlags(flags, GetServerTLSFlags()), "")
Copy link
Contributor

Choose a reason for hiding this comment

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

When you create the Service you need to ensure that the built in ReadinessCheck supports TLS. Same with any external client that accesses the service.

Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

Thanks @annanay25 for addressing my initial comments. Much appreciated! This PR looks in a better shape now and I think we're quite close. I left some comments to further polish the config and nits here and there.

@@ -0,0 +1,100 @@

Copy link
Contributor

Choose a reason for hiding this comment

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

For each pre-cooked config we provide, we have an integration test in integration/getting_started_single_process_config_test.go. Would be great if you could add a test there for this file (a new test, which can be an existing one you copy, paste and modify as needed).

Comment on lines 101 to 108
cmd := exec.Command("bash", "certs/genCerts.sh", "certs", "1")
require.NoError(t, cmd.Run())
require.NoError(t, copyFileToSharedDir(s, integrationHomeFolder+clientCertFile, clientCertFile))
require.NoError(t, copyFileToSharedDir(s, integrationHomeFolder+clientKeyFile, clientKeyFile))
require.NoError(t, copyFileToSharedDir(s, integrationHomeFolder+rootCertFile, rootCertFile))
require.NoError(t, copyFileToSharedDir(s, integrationHomeFolder+serverCertFile, serverCertFile))
require.NoError(t, copyFileToSharedDir(s, integrationHomeFolder+serverKeyFile, serverKeyFile))

Copy link
Contributor

Choose a reason for hiding this comment

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

I would actually suggest to commit certs in the integration/certs and then copy all of them to the shared dir.

Signed-off-by: Annanay <[email protected]>
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

Could you also add a CHANGELOG entry, please?

Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

Thanks @annanay25 for addressing my feedback! LGTM 🎉 (I left one very last nit)

Copy link
Contributor

@jtlisi jtlisi left a comment

Choose a reason for hiding this comment

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

LGTM

@pracucci pracucci merged commit bca34cb into cortexproject:master May 14, 2020
tomwilkie pushed a commit that referenced this pull request Jun 8, 2020
* Checkpoint

Signed-off-by: Annanay <[email protected]>

* Add tls options to grpc client

Signed-off-by: Annanay <[email protected]>

* Add new httpclient util package for use in all client configs

Signed-off-by: Annanay <[email protected]>

* Change all grpc clients to use grpcclient

Signed-off-by: Annanay <[email protected]>

* Fix build, add docs

Signed-off-by: Annanay <[email protected]>

* Fix tests

Signed-off-by: Annanay <[email protected]>

* Fix lint, add tls to store-gw-client

Signed-off-by: Annanay <[email protected]>

* Rename config parameters

Signed-off-by: Annanay <[email protected]>

* Lint

Signed-off-by: Annanay <[email protected]>

* Nit fix

Signed-off-by: Annanay <[email protected]>

* Checkpoint

Signed-off-by: Annanay <[email protected]>

* Checkpoint

Signed-off-by: Annanay <[email protected]>

* Checkpoint

Signed-off-by: Annanay <[email protected]>

* Add integration tests for TLS

Signed-off-by: Annanay <[email protected]>

* Correct package names, fix config file reference

Signed-off-by: Annanay <[email protected]>

* Fix cert paths

Signed-off-by: Annanay <[email protected]>

* Fix lint, add sample tls config file

Signed-off-by: Annanay <[email protected]>

* Crash quickly if certs are bad

Signed-off-by: Annanay <[email protected]>

* Fixed linter and doc generation

Signed-off-by: Marco Pracucci <[email protected]>

* Cleaned white noise

Signed-off-by: Marco Pracucci <[email protected]>

* Address review comments

Signed-off-by: Annanay <[email protected]>

* Fix docs, flags

Signed-off-by: Annanay <[email protected]>

* Fix test

Signed-off-by: Annanay <[email protected]>

* Fix lint, docs

Signed-off-by: Annanay <[email protected]>

* Do not use TLS options with GCP clients

Signed-off-by: Annanay <[email protected]>

* Add client auth type, go mod tidy/vendor

Signed-off-by: Annanay <[email protected]>

* Address comments

Signed-off-by: Annanay <[email protected]>

* Fix lint, add new integration test

Signed-off-by: Annanay <[email protected]>

* Revert logging level to warn, add CHANGELOG entry

Signed-off-by: Annanay <[email protected]>

Co-authored-by: Marco Pracucci <[email protected]>
Signed-off-by: Jacob Lisi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support TLS
3 participants