cortex-gateway

command module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

README

Cortex Gateway

License Go Report Card GitHub release Docker Repository on Quay

Cortex Gateway is a microservice which strives to help you administrating and operating your Cortex Cluster in multi tenant environments.

Features

  • Authentication of Prometheus & Grafana instances with JSON Web Tokens
  • Prometheus & Jager instrumentation, compatible with the rest of the Cortex microservices
Authentication Feature

If you run Cortex for multiple tenants you need to identify your tenants every time they send metrics or query them. This is needed to ensure that metrics can be ingested and queried separately from each other. For this purpose the Cortex microservices require you to pass a Header called X-Scope-OrgID. Unfortunately the Prometheus Remote write API has no config option to send headers and for Grafana you must provision a datasource to do so. Therefore the Cortex k8s manifests suggest deploying an NGINX server inside of each tenant which acts as reverse proxy. It's sole purpose is proxying the traffic and setting the X-Scope-OrgID header for your tenant.

We try to solve this problem by adding a Gateway which can be considered the entry point for all requests towards Cortex (see Architecture). Prometheus and Grafana can both send a self contained JSON Web Token (JWT) along with each request. This JWT carries a claim which is the tenant's identifier. Once this JWT is validated we'll set the required X-Scope-OrgID header and pipe the traffic to the upstream Cortex microservices (distributor / query frontend).

Architecture

Cortex Gateway Architecture

Configuration

Flag Description Default
-gateway.distributor.address Upstream HTTP URL for Cortex Distributor (empty string)
-gateway.query-frontend.address Upstream HTTP URL for Cortex Query Frontend (empty string)
-gateway.rules.address Upstream HTTP URL for Cortex ruler (empty string)
-gateway.alertmanager.address Upstream HTTP URL for Cortex Alertmanager (empty string)
-gateway.auth.jwt-secret HMAC secret to sign JSON Web Tokens (empty string)
-gateway.auth.jwt-extra-headers A comma supported list of additional headers to scan for JSON web tokens presence (empty string)
-gateway.auth.tenant-name The tenant name to use when you want to disable jwt auth, if specified the jwt secret value is ignored (empty string)
-gateway.auth.tenant-id-claim The name of the tenant ID Claim 'tenant_id'
Expected JWT payload

The expected Bearer token payload can be found here: https://github.com/rewe-digital/cortex-gateway/blob/b74de65d10a93e1ec0d223e92c08d16d59bbf3c4/gateway/tenant.go#L7-L11

  • "tenant_id"
  • "aud"
  • "version" (must be an integer)

The audience and version claim is currently unused, but might be used in the future (e. g. to invalidate tokens).

Forked from: https://github.com/rewe-digital/cortex-gateway

How to run locally

Simply build and run with following commands:

go build
./cortex-gateway
How to release

Add a new release tag and build and publish the docker image. Commands to build and publish image:

docker image build . -f ./Dockerfile --tag $CONTAINER_REGISTRY/cortex-gateway:v0.0.0
docker push $CONTAINER_REGISTRY/cortex-gateway:v0.0.0

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL