Files
cozystack/hack/tracing-central-credentials.bats
T
Alexey Artamonov 27b7376bb9 feat(monitoring): add a shared-central tracing topology
A per-tenant traces backend costs every tenant its own VictoriaTraces
stack. A tenant can now send new spans to one shared store in
tenant-root instead, switched on by _namespace.tracingCentral, which
the tenant chart publishes and the apps API does not let an
application set. tenant-root decides whether it hosts that store, with
tracingCentralHost next to a cluster-mode store named generic.

VictoriaTraces takes the tenant account from request headers and does
no authorization of its own, so other tenants reach the store only
through a vmauth in tenant-root; tenant-root itself, with whoever it
admits to its Grafana, stays inside the trust boundary. Each central
tenant gets a VMUser that pins an account derived from its namespace
name and UID for both writes and reads and caps its requests in
flight, which the collector's two export senders stay under; its
collector exports and its Grafana reads with credentials the chart
generates and keeps, and vmauth overrides any account a client sends.
The chart owns those credentials because the operator publishes a
VMUser's own Secret only once a VMAuth selects it; the collector rolls
when they change, since it reads them at start. The vmauth internal
routes, whose /metrics names every tenant's user, are served on a port
tenants cannot reach, and the vmauth is sized by a VPA, spread across
nodes under a disruption budget, has a WorkloadMonitor like the other
monitoring workloads, and may reach the apiserver, where its
config-reloader reads its config Secret.

Renders refuse the states in which spans would be dropped with every
object Ready: a central tenant while tenant-root hosts nothing,
tenant-root dropping the hosting while central tenants remain, and
the host flag without a store to host. Each refusal reads the other
side at render time, so a concurrent opt-in and stop-hosting can pass
both; the values text names that race and its recovery. At run time
tenant-root's release is not Ready while the vmauth has failed.
Only the collector's export moves: local stores the tenant still lists
keep rendering with their datasources, because the switch belongs to
the parent tenant and the stores to this one, and the one-store limit
of the collector holds in both modes, since turning central off makes
it export locally again. tenant-root never counts as central.

Signed-off-by: Alexey Artamonov <aleksei.artamonov@aenix.io>
2026-09-30 22:23:47 +03:00

30 lines
1.4 KiB
Bash

#!/usr/bin/env bats
# The central traces collector reads its vmauth password at start and is rolled
# by a checksum of it. On a first install the password is random, and it is
# rendered twice, into the Secret and into that checksum: if the two renders
# disagree, the collector rolls on every reconcile and the checksum proves
# nothing. helm-unittest asserts one template at a time and cannot compare them,
# so this renders both together and compares.
#
# Run via hack/cozytest.sh from the repo root (make bats-unit-tests).
MONITORING_CHART=packages/system/monitoring
@test "a first install hashes the same password it stores" {
out=$(mktemp -d)
for run in 1 2 3; do
helm template monitoring "$MONITORING_CHART" --namespace tenant-foo \
--show-only templates/vtraces/central-credentials.yaml \
--show-only templates/vtraces/collector.yaml \
--set _namespace.tracingCentral=true --set _namespace.host=example.org \
> "$out/render-$run.yaml"
password=$(yq eval 'select(.kind == "Secret") | .stringData.password' "$out/render-$run.yaml")
checksum=$(yq eval 'select(.kind == "Deployment") | .spec.template.metadata.annotations["checksum/credentials"]' "$out/render-$run.yaml")
# Separate commands: under set -e a failure on the left of && is not fatal.
[ -n "$password" ]
[ "$password" != "null" ]
[ "$(printf '%s' "$password" | sha256sum | cut -d' ' -f1)" = "$checksum" ]
done
rm -rf "$out"
}