This page is for the main branch. It can describe changes that are not in a release. Read this page for v0.1.2
Operations
This page is the reference for the operator who installs, configures, runs and observes Querdian.
In short:
- Querdian does not terminate TLS. Put an ingress, a gateway or a service mesh in front of Querdian. Clients must reach the backends only through Querdian.
- The management port (
/metrics,/healthz,/readyz) has no authentication. Keep it in the cluster. - Querdian reads the configuration file only at startup. After a change, restart the pods.
- Set the pod memory limit to at least 100 MiB + 6 x
limits.maxInflightMergeBytes, plus headroom for the regex compiles (see Scaling).
Releases are a signed multi-arch image ghcr.io/querdian-dev/querdian and a Helm chart
oci://ghcr.io/querdian-dev/charts/querdian (latest: 0.1.2, see the
release notes). The chart README describes the
packaged installation and its values. This page describes what the binary needs in each type of deployment. For the policy
resources, see policy-guide.md. For denials, see troubleshooting.md.
Installation checklist#
The Helm chart installs the CRDs (only at the first installation, see
Upgrade) and the RBAC (rbac.create). Without the chart, apply them
yourself.
| Item | Necessary for an installation |
|---|---|
| CRDs | config/crd/policy.querdian.dev_clusteraccesspolicies.yaml and config/crd/policy.querdian.dev_accesspolicies.yaml (generated by make manifests). With the multicluster block, also config/crd/policy.querdian.dev_spokeclusters.yaml and config/crd/policy.querdian.dev_spokepolicies.yaml. The CRDs contain the CEL validations (at least one subject; exactly one of unrestricted or matchers). |
| RBAC | See the table below. |
| Network isolation | Clients must not reach the backends except through Querdian (NetworkPolicy or equivalent). The security model depends on it. |
| Configuration | A ConfigMap with the static configuration, mounted at the path of --config. |
| Replicas | Several replicas behind one Service. The pods are stateless. |
| Tenants | If a user has more than one tenant, configure the backends for cross-tenant requests (multi-tenant query federation), see policy-guide.md. |
| Grafana | Disable Tempo streaming over gRPC in the Grafana Tempo data source. It is out of scope. |
RBAC of the service account:
| API group | Resources | Verbs |
|---|---|---|
policy.querdian.dev | clusteraccesspolicies, accesspolicies | get, list, watch |
policy.querdian.dev | clusteraccesspolicies/status, accesspolicies/status | update, patch |
"" | namespaces | get, list, watch |
policy.querdian.dev (only with multicluster) | spokeclusters, spokepolicies | get, list, watch |
policy.querdian.dev (only with multicluster) | spokepolicies/status | update, patch |
coordination.k8s.io, in the namespace of the pod | leases (the lease is querdian-leader-election) | get, list, watch, create, update, patch |
The chart also gives create and patch on events in the namespace of the pod. The service account
needs no access to workloads or secrets. Querdian finds the Kubernetes API with the usual
controller-runtime discovery (in-cluster service account, or KUBECONFIG / ~/.kube/config for local runs).
Process model#
One binary, querdian, runs these parts:
| Part | Flag (default) | Function |
|---|---|---|
| Proxy listener | --listen (:8080) | Plain HTTP and WebSocket. No TLS. |
| Management listener | --management-listen (:9090) | GET /metrics, GET /healthz, GET /readyz. No authentication. |
| Dashboard listener | --ui-listen (off) | Read-only view of the active policies, see dashboard.md. |
| Controller | Informers on ClusterAccessPolicy, AccessPolicy and Namespace (with the multicluster block, also SpokeCluster and SpokePolicy), a 250 ms debounce, the snapshot compilation and, on the leader only, the status writer. |
Each replica builds its own snapshot and serves traffic independently. Replicas share no state. On
SIGINT or SIGTERM, Querdian drains the in-flight requests for up to 30 s.
For a hub that enforces the policies of several clusters, the binary has the subcommands
querdian receiver (on the hub) and querdian agent (in each spoke). See
multicluster.md for them, the multicluster block and the migration steps.
Static configuration#
Flags give the process settings. One YAML file gives the structured settings (--config, default
/etc/querdian/config.yaml). Querdian reads it one time, at startup. An unknown field is an error.
If a validation fails, the process stops before it listens. Policies refer to backends by name, so a
changed backend name makes the policies UnknownBackend.
Sample configuration#
auth:
issuer: https://keycloak.example.com/realms/observability
audiences: [querdian]
claims:
username: preferred_username
groups: groups
backends:
- name: metrics
type: prometheus
url: http://thanos-query.monitoring:10902
pathPrefix: /prometheus
namespaceLabel: namespace
- name: logs
type: loki
url: http://loki-gateway.monitoring
pathPrefix: /loki
namespaceLabel: k8s_namespace_name
tenantHeader: X-Scope-OrgID
tenantFederation: tenantIdLabel
- name: traces
type: tempo
url: http://tempo-query-frontend.monitoring:3200
pathPrefix: /tempo
namespaceLabel: resource.k8s.namespace.name
tenantHeader: X-Scope-OrgID
tenantFederation: none
traceByID: filter
limits:
maxPolicyTerms: 16
maxFanout: 16
maxQueryRegexWeight: 32768
maxRequestRegexWeight: 131072
maxMergeBytes: 67108864
maxInflightMergeBytes: 67108864
upstreamTimeout: 5m
A Grafana data source uses the proxy URL plus the pathPrefix (for example
https://querdian.example.com/loki), and forwards the OAuth token of the user.
auth#
| Field | Default | Meaning |
|---|---|---|
issuer | required | OIDC issuer URL (http or https). The iss of the token must be exactly this string. Discovery runs in the background with exponential backoff (1 s up to 30 s). Each failed attempt writes the log line issuer discovery failed with the error. |
audiences | required, not empty, no empty entries | The aud of the token must contain at least one of these values. |
caFile | empty | PEM bundle that Querdian trusts for the discovery and JWKS requests of the issuer (TLS 1.2 minimum). Not for backends. A file that is not readable, or that has no certificates, stops the startup. |
claims.username | preferred_username | Claim with the username. A dotted path is permitted (Querdian first tries a literal key with dots). Missing or empty gives 401 unauthorized. |
claims.groups | groups | Claim with the groups: a string or an array of strings. A dotted path is permitted (for example realm_access.roles). A missing claim means no groups. A different shape, or elements that are not strings, gives 401. |
Querdian verifies the signature, expiry, issuer and audience of each token. There is no token cache, no introspection, and no revocation check other than the token expiry.
backends[]#
| Field | Default | Meaning |
|---|---|---|
name | required, unique | Policy rules refer to it. It is the backend metric label. |
type | required | prometheus (Prometheus and Thanos Query; the Prometheus-compatible API of Mimir was only examined for tenant federation, not tested end to end), loki or tempo. |
url | required | http or https URL with a host. A path in the URL becomes a prefix of the upstream path. Upstream TLS uses the system trust store. |
pathPrefix | required | Route prefix on the proxy. It must start with /. It must not be /. It must not end with /. Prefixes must not be equal or nest (/a and /a/b conflict). |
namespaceLabel | required | Label or attribute with the namespace in this backend, for the implicit matcher of AccessPolicy. It must be a valid name for the type (Tempo: resource.<name> or span.<name>), or each AccessPolicy for the backend is InvalidMatcher. Its integrity is a security requirement, see policy-guide.md. |
tenantHeader | empty | Header that selects the tenant upstream (for example X-Scope-OrgID). Empty means single-tenant: Querdian ignores the tenants in policies. The proxy sets this header itself and drops client tenant headers (see forwardHeaders). For Thanos Query with --query.enforce-tenancy, set the tenant header of Thanos (THANOS-TENANT, unless --query.tenant-header changes it). Without it, Thanos applies its default tenant to each request. |
tenantFederation | none | none or tenantIdLabel. tenantIdLabel needs a tenantHeader. It tells Querdian that the backend can filter __tenant_id__ under a t1|t2 header (Loki, Mimir). Use none for Tempo. See policy-guide.md. |
forwardHeaders | [Accept, Accept-Encoding, User-Agent]; on Loki also X-Loki-Response-Encoding-Flags | Client headers that go to the backend. See below. |
traceByID | deny on Tempo | Tempo only (an error on other types). deny answers trace-by-ID requests with 403 trace_by_id_denied. filter gets the trace and removes the spans that the policy does not admit. |
clusterLabel | empty | Label or attribute with the cluster in this backend. Required on each backend with the multicluster block, forbidden without it. It must be a valid name for the type, must not start with __ and must differ from namespaceLabel. On Tempo, it must be a resource. attribute. Its integrity is a security requirement, see multicluster.md. |
forwardHeaders rules:
- Querdian drops each client header that is not in the list. A list replaces the default.
[]forwards none. - These headers stop the startup: credentials (
Authorization,Cookie,Proxy-Authorization), tenant headers (X-Scope-OrgID,THANOS-TENANT, thetenantHeaderof this backend), trace context (traceparent,tracestate,baggage), forwarding headers (Forwarded,X-Forwarded-*,X-Real-IP), hop-by-hop headers (Connection,Upgrade,TE, …),Host,Content-TypeandContent-Length. - Add a header only if you know what it does in the backend. A header that selects a tenant under a
different name, or that changes limits (for example
X-Loki-Query-Limitsof Loki), gives that control to each client. - A response in a format that a filter cannot parse fails with
502. - The list applies to plans with one request. Fan-out requests and
tailhandshakes carry no client headers.
multicluster#
Optional. Without it, Querdian is a single-cluster proxy. With it, one Querdian on a hub enforces the policies of the hub and of the spoke clusters, see multicluster.md.
| Field | Default | Meaning |
|---|---|---|
hubCluster | required | Cluster label value of the telemetry of the hub. Hub AccessPolicy rules get the implicit matcher <clusterLabel>="<hubCluster>". It must not be empty. |
maxStaleness | 48h | Time limit of spoke policies: they stop when the spoke has not synced for this time. It must be positive. SpokeCluster.spec.maxStaleness overrides it for one spoke. |
limits#
All values must be positive. For what happens when a limit trips, and for the fixed limits, see Limits and what happens when they trip.
| Field | Default | Meaning |
|---|---|---|
maxPolicyTerms | 16 | Maximum number of terms of the effective policy of a user, after simplification. |
maxFanout | 16 | Maximum number of upstream requests for one client request, and the number that run in parallel. |
maxQueryRegexWeight | 32768 | Maximum weight of the regexes of one PromQL or LogQL client query (all selectors, all match[] values). It also sets the work budget of the regex parse (32 steps for each unit), which stops a costly regex before a compile. From 1 to 262144. |
maxRequestRegexWeight | 131072 | Maximum regex weight that the proxy compiles for one request (the request regex weight, see below). From 1 to 262144. |
maxMergeBytes | 67108864 (64 MiB) | Total size of the buffered upstream bodies of one merged request, for all branches together. The branches count the bytes while they read, so the read stops when the total is above the limit. Also the buffer limit of the trace-by-ID filter. |
maxInflightMergeBytes | maxMergeBytes (64 MiB) | Total size of the buffered fan-out bodies (and then merged responses) of all concurrent requests of one replica. It must be at least maxMergeBytes; other values stop the startup. When it is full, the oldest fan-out that still reads waits for space, and the others fail with 503 (merge_budget_exhausted). See Scaling. |
upstreamTimeout | 5m | Deadline of one proxied request (all of its upstream requests together). Go duration syntax. |
The request regex weight is (2 x terms + 1) x client regex weight + (2 x selectors + 1) x policy weight. Thus a client regex counts again for each term of the policy of the user: a client regex of weight 2000 under a policy with 16 terms counts 33 x 2000 = 66000. A compile allocates at most about 2 KiB for each unit. Thus the regex memory of one request is at most about 256 MiB at the default, and 512 MiB at 262144. Measured requests at the default use some tens of MiB.
Flags#
| Flag | Default | Meaning |
|---|---|---|
--config | /etc/querdian/config.yaml | Static configuration file. |
--listen | :8080 | Proxy listener. |
--management-listen | :9090 | /metrics, /healthz, /readyz. Must differ from --listen. |
--ui-listen | empty (off) | Read-only policy dashboard, see dashboard.md. Must differ from the other listeners. |
--ui-auth | oidc | oidc (bearer token necessary) or none. |
--ui-admin-group | empty | With oidc: the group that a token must have. Empty: each valid token. |
--ui-allowed-host | none | Repeatable. A host name that the dashboard accepts in the Host header, with any port. localhost, 127.0.0.1, [::1] and the host of --ui-listen are always accepted. See dashboard.md. |
--leader-elect | true | Leader election for the status writer. |
--log-level | info | debug, info, warn, error. |
--log-format | json | json or text. |
--tracing.record-user | false | Privacy flag, see Tracing. |
--tracing.record-queries | false | Privacy flag, see Tracing. |
--tracing.trust-inbound-context | false | Uses the trace context of the client as the parent of the server span. When false, the server span starts a new trace and links the trace context of the client. |
--version | Prints the version and stops. |
Run and scale#
Readiness and health#
| Endpoint | Returns 200 when |
|---|---|
/healthz | the process serves (always ok). |
/readyz | a first policy snapshot exists and the OIDC issuer discovery is complete (with the multicluster block also: Querdian has read all SpokeCluster objects one time). If not, 503 with the missing part in the body. |
Until then, the proxy answers 503 unavailable (snapshot_not_ready or auth_unavailable). After that,
the replica stays ready when the Kubernetes API is not reachable: it uses the last good snapshot (see
Upgrade and failure behaviour).
Scaling#
- CPU: each request costs one parse and rewrite (
querdian_rewrite_duration_seconds, usually microseconds to milliseconds) plus the stream of the response. Scale horizontally on CPU. - Fan-out multiplies the upstream load: a log query of a user with N terms is N upstream requests,
up to
maxFanout. Watchquerdian_policy_termsandquerdian_upstream_requests_total. Prefer policy shapes that simplify to one term (the single-label merge helps). - No rate limit: Querdian has no built-in rate limit. Apply one at the ingress.
- Snapshot: each replica holds it in memory. It rebuilds it completely at each change of a policy or a namespace label (about 250 ms after the last change). The size grows with the number of rules.
- WebSocket tails. Each open WebSocket tail keeps one connection to the client and one upstream connection for each term.
Memory sizing. Set the memory limit of the pod to at least 100 MiB + 6 x maxInflightMergeBytes.
If you increase maxMergeBytes or maxInflightMergeBytes, increase the memory limit by 6 x the
difference. Keep headroom above this rule for the regex compiles of a request: the regex weight limits
keep them at about 256 MiB for each request in the worst case (measured requests use some tens of MiB).
The chart default of 768 MiB (with maxMergeBytes and maxInflightMergeBytes at 64 MiB) is above the
rule and keeps this headroom. Watch querdian_requests_total{reason="merge_budget_exhausted"}.
The chart gives the container memory limit to Querdian (QUERDIAN_MEMORY_LIMIT, in bytes). Querdian
sets the Go memory limit to 90 percent of it, unless GOMEMLIMIT is set. An empty value or 0 sets no
Go memory limit. A value that is not a number of bytes stops the start.
How Querdian limits the memory:
- Streaming requests use constant memory.
- A merged request buffers at most
maxMergeBytesof bodies for all its branches together. Each branch can read at most 32 KiB past the limit before the request fails. - All merged requests of a replica together buffer at most
maxInflightMergeBytesof bodies. When this budget is full, the oldest fan-out that still reads waits for space (up toupstreamTimeout). Each other fan-out fails with503andRetry-After; the client must try again. - After the merge, the budget holds only the merged response until Querdian has written it. The write has a deadline of 10 seconds plus 1 second for each MiB (at most 2 minutes). Thus a client that does not read cannot hold the budget for longer.
- The budget counts body bytes only. The buffers can be larger than the bodies (the capacity doubles below 1 MiB and grows by a quarter above it), and the merge step decodes the bodies. Measured with Loki log queries of 16 branches and short lines, the merge needs about 5 x the body bytes, and about 6 x with redaction. This gives the factor 6 of the rule.
- Single-request filters (trace by ID, Prometheus labels/series, redaction of a single request) buffer up to their own limits, outside this budget.
Leader election#
--leader-elect=true (default) uses a Kubernetes Lease (querdian-leader-election, released at
shutdown, controller-runtime default timings). Only the status writer needs the leader: exactly one
replica patches status.conditions. All replicas build snapshots and serve requests. Thus a leader loss
never stops the enforcement. It only pauses the status updates until a new leader gets the lease. With a
single replica, or for local runs, you can use --leader-elect=false. Each replica exports
querdian_policies and querdian_snapshot_*.
Observability#
Querdian serves Prometheus metrics on the management port. The operations reference lists the metrics and the spans.
Tracing#
Only the standard OTEL_* environment variables configure tracing: OTEL_SERVICE_NAME (default
querdian), OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_PROTOCOL, OTEL_TRACES_EXPORTER,
OTEL_TRACES_SAMPLER, OTEL_TRACES_SAMPLER_ARG, OTEL_RESOURCE_ATTRIBUTES.
- If there is no OTLP endpoint and no
OTEL_TRACES_EXPORTER, Querdian discards the spans. - If
OTEL_TRACES_SAMPLERis not set, the sampler isparentbased_traceidratiowith ratio 1.0. The Helm chart setsOTEL_TRACES_SAMPLER=parentbased_traceidratio(tracing.sampler) and the ratio0.1(tracing.samplerArg). - The server span does not use the trace context of the client as its parent. It starts a new trace with
a span link to the trace context of the client. Thus a client cannot select the trace ID or force
sampling. Set
--tracing.trust-inbound-contextonly if all clients that can reach the proxy are trusted. Then the trace context of the client is the parent. - The propagation is fixed in the code: inbound W3C
tracecontextandbaggage, outboundtracecontextonly. Querdian ignoresOTEL_PROPAGATORSon purpose, so client baggage never gets to a backend. - Each response has
X-Trace-Id, and each error body has atraceId. Use it to find the trace.
The span tree is in the operations reference.
Privacy flags, both off by default:
| Flag | Records |
|---|---|
--tracing.record-user | enduser.id on the server span, and user in the request log line. |
--tracing.record-queries | querdian.query.original and querdian.query.rewritten on the server span, and the full upstream URL with the query string in url.full on each upstream span. For a GET request, this query string contains the rewritten query with the matchers of the policy. |
Queries can contain sensitive values. Enable --tracing.record-queries only where the trace backend has
equivalent access controls. Querdian never writes queries to the log.
Without these flags, Querdian records no username and no query text: the server span records only the
path (url.path), and each upstream span records url.full without the query string.
querdian.policies records the names of the matched policies. Paths can contain values from the client,
for example a trace ID or a tag name.
Logging#
Querdian writes log/slog lines to stderr, JSON by default (--log-format=text for humans). Each
proxied request gives one request line with backend, route, decision, reason, status,
duration, and trace_id and span_id when the request is traced. With --tracing.record-user, the
line also has user. At startup, Querdian writes a querdian started line.
Upgrade and failure behaviour#
Querdian is pre-release. The API group is policy.querdian.dev/v1alpha1, and it can change in an
incompatible way before a stable version.
To upgrade:
- Read the release notes and the changelog of each release.
- Apply the updated CRDs before the rollout:
kubectl apply --server-side -f config/crd. The directorycrds/of the chart is a copy ofconfig/crd. Helm installs the CRDs of the chart only at the first installation. It does not upgrade or delete them. Thus apply the CRDs manually at each chart upgrade. - Roll out the deployment. Querdian reads the static configuration at startup, so a configuration change also needs a rollout.
| Event | Behaviour |
|---|---|
| Rolling update | Safe for availability: a new pod is ready only after its first snapshot and the issuer discovery. If the new version changed rewrite rules, old and new replicas can enforce slightly different behaviour during the rollout. There is no coordination between replicas. |
| Policy change | Each replica gets it within the watch latency plus about 250 ms. A continuous stream of changes delays a rebuild by at most 8 debounce intervals (2 s). In-flight requests and open WebSocket tails continue under the policy that they started with. An open tail does not close when the token expires. In a multi-cluster setup, a tail closes within 10 seconds when a spoke whose rules gave its terms expires or is suspended. |
| Kubernetes API outage | Replicas continue to serve with the last snapshot (they do not fail open or closed). A failed rebuild keeps the previous snapshot, increments querdian_snapshot_rebuilds_total{result="error"} and runs again after one second. A new pod cannot become ready. |
| Issuer outage | Querdian can verify tokens only with the keys in the cache of the verifier. If the issuer discovery fails at startup, the pod stays not ready (auth_unavailable). |
| Removed backend names or labels | Policies that refer to an unknown backend become UnknownBackend and grant nothing. |