This page is for the main branch. It can describe changes that are not in a release. Open the v0.1.2 documentation

How Querdian works

Source: docs/architecture.md · Edit on GitHub

Querdian is a reverse proxy between a client, for example Grafana, and Prometheus, Loki and Tempo. It gives each user only the data that the policies permit. This page shows the parts and the paths.

In short:

  • The client sends each query with the OIDC token of the user.
  • Querdian adds label matchers to the query, with a real parser for PromQL, LogQL and TraceQL.
  • Policies are Kubernetes objects. They only grant access.
  • Querdian fails closed: it rejects each request that it cannot check.

The path of a query#

How Querdian handles a queryA client sends a query with an OIDC token to Querdian. Querdian verifies the token with the keys of the OIDC provider, finds the rules of the user in the policies from the Kubernetes API, rewrites the query with a parser and sends it to Prometheus, Loki or Tempo. If Querdian cannot check a request, it rejects the request. The telemetry pipeline sets the namespace label in the backends.OIDC providersuch as KeycloakKubernetes APIClusterAccessPolicyAccessPolicyGrafanaor an API clientQuerdian1 Verify the token2 Find the rules of the user3 Rewrite the query4 Send the queryPrometheusPromQLLokiLogQLTempoTraceQLRejectedwith a status and a reasonTelemetry pipelinesets the namespacelabel of the datatokenkeyspoliciesand statusquerywith tokenrewrittenqueryif a check failsdata
  1. Verify the token. Querdian verifies the signature, the issuer and the audience of the token with the keys of the OIDC provider. The user name and the groups come from the token.
  2. Find the rules of the user. Querdian watches the policies in the Kubernetes API and compiles them. The access of a request is the union of all rules that match the user name or a group of the user.
  3. Rewrite the query. Querdian parses the query and adds the matchers of a rule to each selector. If more than one rule matches, the query gets one copy of the selector for each rule. Querdian does not use string replacement.
  4. Send the query to the backend. Querdian also changes some answers: it replaces the values of redacted labels (see the policy guide), and it filters some answers of Tempo (see limitations).

Example for a user of the group order-team, with access to the namespace order-service:

sum by (route) (rate(http_requests_total{status=~"5.."}[5m]))
sum by (route) (rate(http_requests_total{namespace="order-service",status=~"5.."}[5m]))

The first line is the query of the user. The second line is the query that Prometheus gets.

If Querdian cannot check a request, it rejects the request and gives a reason:

CaseAnswer
No token, or a token that is not valid401
No rule for the user, a path that is not in the endpoint list, a denied label403
A query that does not parse, or that Querdian cannot rewrite exactly400
Querdian is not ready, for example it has no policies or no keys of the OIDC provider503

See troubleshooting for all reasons, and limitations for the queries that Querdian rejects.

Policies#

KindScopeAuthorGrants
AccessPolicyone namespacethe team of the namespacedata with the namespace label of that namespace; its matchers can only make the access smaller
ClusterAccessPolicythe clusterthe platform admindata that its matchers select, or all data (unrestricted: true)

Querdian writes the result of each policy to its status. A policy that is not valid grants nothing. See the policy guide.

The assumption#

The isolation depends on the namespace label of the data in the backends. The telemetry pipeline must set this label. A workload must not be able to set it. Querdian cannot verify this. See the threat model.

Hub and spoke#

One Querdian on a central hub cluster can enforce the policies of more than one cluster. The spoke clusters keep their policies, and the hub stores the telemetry.

Hub and spoke: policies, telemetry and queriesIn the spoke cluster, the querdian agent reads the policies and namespaces from the spoke API server and sends them over mTLS to the querdian receiver on the hub. The receiver writes SpokePolicy objects and the status of the SpokeCluster object to the hub API server. The querdian proxy on the hub watches these objects and the hub policies. The collector of the spoke sends telemetry to the ingest gateway on the hub, which must overwrite the cluster label and writes to Prometheus, Loki and Tempo. The gateway is not a part of Querdian. Grafana sends queries to the proxy, and the proxy sends the rewritten queries to the backends.SPOKE CLUSTERHUB CLUSTERquerdianagentsends the spoke policiesquerdianreceiverthe only write pathHub API serverSpokePolicySpokeClusterand the hub policiesSpoke API serverClusterAccessPolicyAccessPolicy, NamespaceGrafanauser with a tokenquerdianproxyenforces all policiesCollectortelemetry of the spokeIngest gatewaymust overwrite thecluster labelPrometheusLokiTemporeadsmTLSagent certwriteswatchesqueryrewrittenqueriestelemetryingest cert

The drawing has three paths:

  • Policies (top). The agent in each spoke reads the policies and the namespaces of the spoke. It sends them to the receiver on the hub over mTLS. The receiver is the only component that accepts data from the spokes. It stores each spoke policy as a SpokePolicy object.
  • Queries (middle). The proxy watches the hub policies and the SpokePolicy objects, and enforces all of them. It takes the cluster of a policy from the origin of the policy, not from its text: each spoke policy gets a matcher on the cluster label of its spoke.
  • Telemetry (bottom). Each spoke sends its telemetry to an ingest gateway on the hub with a credential of its own. The gateway must overwrite the cluster label from that credential.

The ingest gateway is not a part of Querdian, and Querdian cannot verify the cluster label. A spoke policy grants only the data of its spoke if the gateway obeys this requirement (see cluster label integrity).

The policies of a spoke grant nothing when the spoke does not sync for 48 hours (the default). See multi-cluster for the requirements and the steps, and the multi-cluster quickstart for a demo.

Type to search the documentation for main.