Files
cozystack/packages/extra/monitoring/tests/helmrelease_test.yaml
T
Myasnikov DaniilandTimofei Larkin 4b8eaffa53 security(apps): quote and validate tenant values in chart templates
Application values reach chart templates as strings, maps and lists,
and several templates rendered them as-is. Values are now quoted or
converted to their type where they are rendered, map keys used as
names or config keys are checked against what their target accepts,
hook Jobs read their data from environment variables, and values
handed to upstream charts are passed in the form those charts expect.

cozy-lib gains cozy-lib.yaml.toYaml and cozy-lib.yaml.fromYaml, which
fail the render on a value they cannot encode or decode instead of
returning an empty result. external-dns GoDaddy credentials move from
args to a Secret.

Values that were valid before keep rendering: NATS units, restic short
keep flags, MongoDB database names by MongoDB's own rule, uppercase and
IPv6 VPN hosts, bootbox hostnames that are subdomains, netmask
whitelists, bracketed IPv6 registries for the Talos installer, time
zones and intervals in the MongoDB backup schedule.

Co-authored-by: Timofei Larkin <lllamnyp@gmail.com>
Assisted-by: LLM
Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
2026-12-03 10:03:17 +00:00

220 lines
8.0 KiB
YAML

suite: monitoring-system HelmRelease readiness gate
templates:
- templates/helmrelease.yaml
release:
name: monitoring
namespace: tenant-root
# The monitoring-system HelmRelease owns the VLCluster(s) rendered from
# logsStorages. Without a health gate it flips Ready as soon as helm applies the
# CR, so a missing or broken VictoriaLogs stays invisible while fluent-bit drops
# logs at a dead-end vlinsert-generic (issue #3181). A `poller` waitStrategy plus
# a VLCluster healthCheckExpr makes that failure surface as not-ready.
tests:
- it: names the child release <release>-system
asserts:
- containsDocument:
kind: HelmRelease
apiVersion: helm.toolkit.fluxcd.io/v2
name: monitoring-system
- it: uses the poller waitStrategy so healthCheckExprs are evaluated
asserts:
- equal:
path: spec.waitStrategy.name
value: poller
- it: passes tenant-set oidc values through to the inner chart
set:
oidc.mode: System
oidc.users:
- email: alice@example.com
role: Admin
asserts:
- equal:
path: spec.values.oidc.mode
value: System
- equal:
path: spec.values.oidc.users[0].email
value: alice@example.com
- equal:
path: spec.values.oidc.users[0].role
value: Admin
- it: gates readiness on the VLCluster status.updateStatus
asserts:
- equal:
path: spec.healthCheckExprs[0].apiVersion
value: operator.victoriametrics.com/v1
- equal:
path: spec.healthCheckExprs[0].kind
value: VLCluster
- equal:
path: spec.healthCheckExprs[0].current
value: "has(status.updateStatus) && status.updateStatus == 'operational'"
- equal:
path: spec.healthCheckExprs[0].inProgress
value: "has(status.updateStatus) && status.updateStatus == 'expanding'"
- equal:
path: spec.healthCheckExprs[0].failed
value: "has(status.updateStatus) && status.updateStatus != 'operational' && status.updateStatus != 'expanding'"
# The traces backend (VTCluster/VTSingle from tracingStorages) is gated the
# same way and by the same operator status contract. tracingStorages is empty
# by default, so these exprs are usually inert (no CR to match); when a backend
# is configured they gate readiness on it. Pin both entries so a
# dropped/reordered block or a typo'd CEL expression fails a test rather than
# silently regressing the gate.
- it: gates readiness on the VTCluster status.updateStatus
asserts:
- equal:
path: spec.healthCheckExprs[1].apiVersion
value: operator.victoriametrics.com/v1
- equal:
path: spec.healthCheckExprs[1].kind
value: VTCluster
- equal:
path: spec.healthCheckExprs[1].current
value: "has(status.updateStatus) && status.updateStatus == 'operational'"
- equal:
path: spec.healthCheckExprs[1].inProgress
value: "has(status.updateStatus) && status.updateStatus == 'expanding'"
- equal:
path: spec.healthCheckExprs[1].failed
value: "has(status.updateStatus) && status.updateStatus != 'operational' && status.updateStatus != 'expanding'"
- it: gates readiness on the VTSingle status.updateStatus
asserts:
- equal:
path: spec.healthCheckExprs[2].apiVersion
value: operator.victoriametrics.com/v1
- equal:
path: spec.healthCheckExprs[2].kind
value: VTSingle
- equal:
path: spec.healthCheckExprs[2].current
value: "has(status.updateStatus) && status.updateStatus == 'operational'"
- equal:
path: spec.healthCheckExprs[2].inProgress
value: "has(status.updateStatus) && status.updateStatus == 'expanding'"
- equal:
path: spec.healthCheckExprs[2].failed
value: "has(status.updateStatus) && status.updateStatus != 'operational' && status.updateStatus != 'expanding'"
# The shared-central vmauth carries the same operator status contract. Every
# central tenant writes and reads through it, so a failed vmauth must not
# leave tenant-root's release Ready; outside a hosting tenant-root no VMAuth
# is in the inventory and the entry is inert.
- it: gates readiness on the VMAuth status.updateStatus
asserts:
- equal:
path: spec.healthCheckExprs[3].apiVersion
value: operator.victoriametrics.com/v1beta1
- equal:
path: spec.healthCheckExprs[3].kind
value: VMAuth
- equal:
path: spec.healthCheckExprs[3].current
value: "has(status.updateStatus) && status.updateStatus == 'operational'"
- equal:
path: spec.healthCheckExprs[3].inProgress
value: "has(status.updateStatus) && status.updateStatus == 'expanding'"
- equal:
path: spec.healthCheckExprs[3].failed
value: "has(status.updateStatus) && status.updateStatus != 'operational' && status.updateStatus != 'expanding'"
# The collector a central tenant writes through enforces the rate the
# platform sets for it, so its image is the platform's. The apps API defaults the
# Monitoring spec but does not prune keys its schema leaves out, so a key set
# there would otherwise reach the inner chart and swap the collector for one
# without the limiter.
- it: does not pass a collector image set on the Monitoring application through
set:
tracingCollector:
enabled: true
replicas: 1
samplingPercentage: 10
image: docker.io/example/collector:1
asserts:
- notExists:
path: spec.values.tracingCollector.image
- equal:
path: spec.values.tracingCollector.replicas
value: 1
# The Grafana pod may reach a central tenant's vmauth and mounts the Secret
# a tenant names in oidc.customConfig.secretRef, so an image of the tenant's
# choosing could read a login from it; the image is the platform's too.
- it: does not pass a Grafana image set on the Monitoring application through
set:
grafana:
image: docker.io/example/grafana:1
resources:
requests:
cpu: 100m
asserts:
- notExists:
path: spec.values.grafana.image
- equal:
path: spec.values.grafana.resources.requests.cpu
value: 100m
# Both maps reach the inner chart key by key: a label key becomes a vmagent
# label name and an OIDC key a grafana.ini key, so a key that is neither
# would reach those configs unchecked.
- it: refuses an external label key that is not a label name
set:
vmagent:
externalLabels:
$tplYaml: '{{ print "x" }}'
asserts:
- failedTemplate:
errorPattern: 'vmagent.externalLabels key "\$tplYaml" must be a label name'
- it: refuses an OIDC config key that is not a grafana.ini key
set:
oidc:
mode: CustomConfig
customConfig:
config:
"client_id\n[server]\nroot_url": x
asserts:
- failedTemplate:
errorPattern: 'oidc.customConfig.config key ".*" must be a grafana.ini key'
- it: passes label and OIDC config keys of the right shape through
set:
vmagent:
externalLabels:
cluster: tenant-a
_region: eu
oidc:
mode: CustomConfig
customConfig:
config:
client_id: grafana
role_attribute_path: role
asserts:
- equal:
path: spec.values.vmagent.externalLabels
value:
cluster: tenant-a
_region: eu
- equal:
path: spec.values.oidc.customConfig.config
value:
client_id: grafana
role_attribute_path: role
# A label value may be any UTF-8; the inner chart quotes it.
- it: passes a cluster label of any characters through
set:
vmagent:
externalLabels:
cluster: "prod: eu/west #1"
asserts:
- equal:
path: spec.values.vmagent.externalLabels.cluster
value: "prod: eu/west #1"