-
Notifications
You must be signed in to change notification settings - Fork 816
Add TLS support to HTTP/GRPC clients #2502
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
Merged
Merged
Changes from 34 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
67ac979
Checkpoint
annanay25 828e968
Add tls options to grpc client
annanay25 e85437b
Merge branch 'master' into add-tls-support
annanay25 1ee9ddb
Add new httpclient util package for use in all client configs
annanay25 ef58c41
Merge branch 'master' into add-tls-support
annanay25 745299d
Merge branch 'master' into add-tls-support
annanay25 b93af11
Change all grpc clients to use grpcclient
annanay25 8a71ce9
Fix build, add docs
annanay25 bab4c82
Fix tests
annanay25 8fee619
Fix lint, add tls to store-gw-client
annanay25 2ff0a73
Merge branch 'master' into add-tls-support
annanay25 d24a44d
Rename config parameters
annanay25 485f8ba
Lint
annanay25 5561a0f
Nit fix
annanay25 598b00f
Merge branch 'master' into add-tls-support
annanay25 548ddfa
Checkpoint
annanay25 1a185b5
Checkpoint
annanay25 1ccefbf
Checkpoint
annanay25 5fd056c
Merge branch 'master' into add-tls-support
annanay25 0a8c4eb
Add integration tests for TLS
annanay25 b6aafa9
Merge branch 'master' into add-tls-support
annanay25 d28a3d6
Correct package names, fix config file reference
annanay25 480308e
Fix cert paths
annanay25 ca7a6d9
Fix lint, add sample tls config file
annanay25 db64cd4
Crash quickly if certs are bad
annanay25 ee48ed3
Fixed linter and doc generation
pracucci b9325bd
Cleaned white noise
pracucci 721fed1
Merge commit 'refs/pull/2502/head' of github.com:cortexproject/cortex…
annanay25 af4935d
Address review comments
annanay25 8f9f2e7
Fix docs, flags
annanay25 668e988
Fix test
annanay25 ef761f5
Fix lint, docs
annanay25 24919ee
Do not use TLS options with GCP clients
annanay25 9939303
Add client auth type, go mod tidy/vendor
annanay25 6eb9331
Address comments
annanay25 5aa65d1
Fix lint, add new integration test
annanay25 ae5f6f7
Revert logging level to warn, add CHANGELOG entry
annanay25 d645572
Merge branch 'master' into add-tls-support
annanay25 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
docs/configuration/single-process-config-blocks-tls.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
|
||
# Configuration for running Cortex in single-process mode. | ||
# This should not be used in production. It is only for getting started | ||
# and development. | ||
|
||
# Disable the requirement that every request to Cortex has a | ||
# X-Scope-OrgID header. `fake` will be substituted in instead. | ||
auth_enabled: false | ||
|
||
server: | ||
http_listen_port: 9009 | ||
|
||
# Configure the server to allow messages up to 100MB. | ||
grpc_server_max_recv_msg_size: 104857600 | ||
grpc_server_max_send_msg_size: 104857600 | ||
grpc_server_max_concurrent_streams: 1000 | ||
grpc_tls_config: | ||
cert_file: "server.crt" | ||
key_file: "server.key" | ||
client_auth_type: "RequireAndVerifyClientCert" | ||
client_ca_file: "root.crt" | ||
|
||
|
||
distributor: | ||
shard_by_all_labels: true | ||
pool: | ||
health_check_ingesters: true | ||
|
||
ingester_client: | ||
grpc_client_config: | ||
# Configure the client to allow messages up to 100MB. | ||
max_recv_msg_size: 104857600 | ||
max_send_msg_size: 104857600 | ||
use_gzip_compression: true | ||
tls_cert_path: "client.crt" | ||
tls_key_path: "client.key" | ||
tls_ca_path: "root.crt" | ||
|
||
ingester: | ||
# Disable blocks transfers on ingesters shutdown or rollout. | ||
max_transfer_retries: 0 | ||
|
||
lifecycler: | ||
# The address to advertise for this ingester. Will be autodiscovered by | ||
# looking up address on eth0 or en0; can be specified if this fails. | ||
# address: 127.0.0.1 | ||
|
||
# We want to start immediately and flush on shutdown. | ||
join_after: 0 | ||
min_ready_duration: 0s | ||
final_sleep: 0s | ||
num_tokens: 512 | ||
|
||
# Use an in memory ring store, so we don't need to launch a Consul. | ||
ring: | ||
kvstore: | ||
store: inmemory | ||
replication_factor: 1 | ||
|
||
storage: | ||
engine: tsdb | ||
|
||
tsdb: | ||
dir: /tmp/cortex/tsdb | ||
bucket_store: | ||
sync_dir: /tmp/cortex/tsdb-sync | ||
|
||
# You can choose between local storage and Amazon S3, Google GCS and Azure storage. Each option requires additional configuration | ||
# as shown below. All options can be configured via flags as well which might be handy for secret inputs. | ||
backend: s3 # s3, gcs, azure or filesystem are valid options | ||
s3: | ||
bucket_name: cortex | ||
endpoint: s3.dualstack.us-east-1.amazonaws.com | ||
# Configure your S3 credentials below. | ||
# secret_access_key: "TODO" | ||
# access_key_id: "TODO" | ||
# gcs: | ||
# bucket_name: cortex | ||
# service_account: # if empty or omitted Cortex will use your default service account as per Google's fallback logic | ||
# azure: | ||
# account_name: | ||
# account_key: | ||
# container_name: | ||
# endpoint_suffix: | ||
# max_retries: # Number of retries for recoverable errors (defaults to 20) | ||
# filesystem: | ||
# dir: ./data/tsdb | ||
|
||
compactor: | ||
data_dir: /tmp/cortex/compactor | ||
sharding_ring: | ||
kvstore: | ||
store: inmemory | ||
|
||
frontend_worker: | ||
match_max_concurrent: true | ||
grpc_client_config: | ||
tls_cert_path: "client.crt" | ||
tls_key_path: "client.key" | ||
tls_ca_path: "root.crt" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
--- | ||
title: "Securing communication between cortex components with TLS" | ||
annanay25 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
linkTitle: "Securing communication between cortex components with TLS" | ||
weight: 5 | ||
slug: tls | ||
--- | ||
|
||
Cortex is a distributed system with significant traffic between its services. | ||
To allow for secure communication, Cortex supports TLS between all its | ||
components. This guide describes the process of setting up TLS. | ||
|
||
### Generation of certs to configure TLS | ||
|
||
The first step to securing inter-service communication in Cortex with TLS is | ||
generating certificates. A Certifying Authority (CA) will be used for this | ||
purpose which should be private to the organization, as any certificates signed | ||
by this CA will have permissions to communicate with the cluster. | ||
|
||
We will use the following script to generate self signed certs for the cluster: | ||
|
||
``` | ||
# Refer: https://github.com/joe-elliott/cert-exporter/blob/69d3d7230378325a1de4fa313432d3d6ced4a518/test/files/genCerts.sh | ||
annanay25 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# keys | ||
openssl genrsa -out root.key | ||
openssl genrsa -out client.key | ||
openssl genrsa -out server.key | ||
|
||
# root cert / certifying authority | ||
openssl req -x509 -new -nodes -key root.key -subj "/C=US/ST=KY/O=Org/CN=root" -sha256 -days 100000 -out root.crt | ||
|
||
# csrs - certificate signing requests | ||
openssl req -new -sha256 -key client.key -subj "/C=US/ST=KY/O=Org/CN=client" -out client.csr | ||
openssl req -new -sha256 -key server.key -subj "/C=US/ST=KY/O=Org/CN=localhost" -out server.csr | ||
|
||
# certificates | ||
openssl x509 -req -in client.csr -CA root.crt -CAkey root.key -CAcreateserial -out client.crt -days 100000 -sha256 | ||
openssl x509 -req -in server.csr -CA root.crt -CAkey root.key -CAcreateserial -out server.crt -days 100000 -sha256 | ||
``` | ||
|
||
Note that the above script generates certificates that are valid for 100000 days. | ||
This can be changed by adjusting the `-days` option in the above commands. | ||
It is recommended that the certs be replaced atleast once every 2 years. | ||
|
||
The above script generates keys `client.key, server.key` and certs | ||
`client.crt, server.crt` for both the client and server. The CA cert is | ||
generated as `root.crt`. | ||
|
||
### Load certs into the HTTP/GRPC server/client | ||
|
||
Every HTTP/GRPC link between Cortex components supports TLS configuration | ||
through the following config parameters: | ||
|
||
#### Server flags | ||
|
||
``` | ||
# Path to the TLS Cert for the HTTP Server | ||
-server.http-tls-cert-path=/path/to/server.crt | ||
|
||
# Path to the TLS Key for the HTTP Server | ||
-server.http-tls-key-path=/path/to/server.key | ||
|
||
# Type of Client Auth for the HTTP Server | ||
-server.http-tls-client-auth="RequireAndVerifyClientCert" | ||
|
||
# Path to the Client CA Cert for the HTTP Server | ||
-server.http-tls-ca-path="/path/to/root.crt" | ||
|
||
# Path to the TLS Cert for the GRPC Server | ||
-server.grpc-tls-cert-path=/path/to/server.crt | ||
|
||
# Path to the TLS Key for the GRPC Server | ||
-server.grpc-tls-key-path=/path/to/server.key | ||
|
||
# Type of Client Auth for the GRPC Server | ||
-server.grpc-tls-client-auth="RequireAndVerifyClientCert" | ||
|
||
# Path to the Client CA Cert for the GRPC Server | ||
-server.grpc-tls-ca-path=/path/to/root.crt | ||
``` | ||
|
||
#### Client flags | ||
annanay25 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Client flags are component specific. | ||
|
||
For an HTTP client in the Alertmanager: | ||
``` | ||
# Path to the TLS Cert for the HTTP Client | ||
-alertmanager.configs.tls-cert-path=/path/to/client.crt | ||
|
||
# Path to the TLS Key for the HTTP Client | ||
-alertmanager.configs.tls-key-path=/path/to/client.key | ||
|
||
# Path to the TLS CA for the HTTP Client | ||
-alertmanager.configs.tls-ca-path=/path/to/root.crt | ||
``` | ||
|
||
For a GRPC client in the Querier: | ||
``` | ||
# Path to the TLS Cert for the GRPC Client | ||
-querier.frontend-client.tls-cert-path=/path/to/client.crt | ||
|
||
# Path to the TLS Key for the GRPC Client | ||
-querier.frontend-client.tls-key-path=/path/to/client.key | ||
|
||
# Path to the TLS CA for the GRPC Client | ||
-querier.frontend-client.tls-ca-path=/path/to/root.crt | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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).