From 930fd29f485ba69229111cf477a4cb62004e8975 Mon Sep 17 00:00:00 2001 From: Luke Tornquist Date: Fri, 20 Nov 2026 16:07:30 -0500 Subject: [PATCH] deploy: run buzz-acceptance from the relay image as a chart CronJob (#9771) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Builds on #9767 (the `buzz-acceptance` binary, now merged). Based on main. - **Image:** the relay image now carries `buzz-acceptance` next to `buzz-admin` and `buzz-pair-relay`, so no new image or workflow is needed. - **Chart:** `acceptance.enabled=true` adds a CronJob that runs the probe from the relay image. - Requires `image.tag` or `image.digest`. The chart fails to render without one, because the default `Chart.AppVersion` image has no probe. - Every 5 minutes by default, `concurrencyPolicy: Forbid`, `backoffLimit: 0` (a retry would hide a failure), `activeDeadlineSeconds: 240`. - Runs with `acceptance.serviceAccountName` or the namespace default, never the relay's service account. No token mount, no service links. - `acceptance.relayUrl` (defaults to `relayUrl`), `acceptance.stageTimeoutSeconds`. - `acceptance.privateKeySecret.name` is required. Without a key the probe would sign with a new key each run: a members-only relay refuses it, and an open relay joins each new key to every auto-join channel. - `acceptance.statsdAddr` sends DogStatsD metrics. `$(HOST_IP)` expands to the node IP, for a node-local agent. - Every series carries `probe_revision`, the probe's own image (`image.digest`, else `image.tag`), plus `acceptance.tags`. It does not identify the relay build a run reached: during a rollout, or with `acceptance.relayUrl` set, the probe can reach another build. `acceptance.tags` keys must be canonical (lowercase `[a-z0-9_./-]`, starting with a letter, not ending in `_`), so the probe-owned and repeated-key checks see the key Datadog stores. - NIP-FI: minting an assertion is deployment-specific, so the chart takes it as a file. `acceptance.extraInitContainers`, `extraVolumes` and `extraVolumeMounts` let an init container write it, and `acceptance.assertionFile` points the probe at it. These follow the existing relay Pod extension points. - **README:** a new "Acceptance probe" section with an example. The example gives the minter init container the key Secret, keeps credentials in a memory `emptyDir`, and says how to size `activeDeadlineSeconds` against `stageTimeoutSeconds`. - **Chart version:** bumped once at the top of the stack, in https://github.com/block/buzz/pull/9773 ## What got simpler The chart no longer has a "no key" mode, so there is one way to give the probe its identity. The probe reuses the relay image and the chart's existing CronJob, image-identity, label-guard and extension patterns, so it adds no new image, no new publish workflow, and no new extension concept. ## Testing - `tests/acceptance_test.yaml` (helm-unittest): off by default; the default render (relay image, `relayUrl`, no key, no metrics, no extra volumes); a full render with a key Secret, metrics, tags, a digest-pinned image, and an init-container-minted assertion; the chart-owned Datadog version label; the required image tag or digest; `probe_revision` from the probe's image even with another `relayUrl`; no service account inheritance or token mount; and rejection of a missing probe key (also with an assertion file), a tag without a key, an uppercase tag key, a tag key with a space or a trailing `_`, a probe-owned tag key, a repeated tag key, and a chart-owned pod label. The init-container test pins the full `initContainers`, `volumes` and `volumeMounts`. - CI builds the relay image from the changed `Dockerfile`. - A kind run installed the chart and ran one Job against the in-cluster relay: exit 0, all checks passed, no service account token. That run had no key, no assertion and no statsd, so the key and assertion wiring is covered by the render tests above only. ## Follow-ups (not in this PR) - Relay build attribution: the relay does not expose its build id on a public surface yet, so a run can't name the relay build it reached. A deploy gate on these metrics stays report-only until it can. - A canary run against the Rollout's canary Service needs a dial override that keeps the canonical Host (see #9767). 🤖 Generated with [Claude Code](https://claude.com/claude-code) buzz-review-completed --------- Signed-off-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz> Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz> Co-authored-by: Claude Opus 5.5 --- Dockerfile | 10 +- deploy/charts/buzz/README.md | 97 +++++ deploy/charts/buzz/templates/_validate.tpl | 26 ++ .../buzz/templates/acceptance-cronjob.yaml | 103 +++++ deploy/charts/buzz/tests/acceptance_test.yaml | 392 ++++++++++++++++++ deploy/charts/buzz/values.schema.json | 32 ++ deploy/charts/buzz/values.yaml | 53 +++ 7 files changed, 711 insertions(+), 2 deletions(-) create mode 100644 deploy/charts/buzz/templates/acceptance-cronjob.yaml create mode 100644 deploy/charts/buzz/tests/acceptance_test.yaml diff --git a/Dockerfile b/Dockerfile index 39692acac9..2741397218 100644 --- a/Dockerfile +++ b/Dockerfile @@ -76,16 +76,20 @@ ARG BUZZ_BUILD_URL=unknown ENV BUZZ_SOURCE_SHA=${BUZZ_SOURCE_SHA} \ BUZZ_BUILD_ID=${BUZZ_BUILD_ID} \ BUZZ_BUILD_URL=${BUZZ_BUILD_URL} +# buzz-acceptance ships in the relay image, so a deployment can run the probe +# without a second image. The probe can still reach a relay of another build. RUN cargo build --release --locked -p buzz-relay --bin buzz-relay \ -p buzz-admin --bin buzz-admin \ - -p buzz-pair-relay --bin buzz-pair-relay + -p buzz-pair-relay --bin buzz-pair-relay \ + -p buzz-test-client --bin buzz-acceptance # Derive the normal release binaries from the same optimized ELF files as the # debug image so the two variants cannot drift at code-generation time. FROM builder AS stripped-binaries RUN strip target/release/buzz-relay \ && strip target/release/buzz-admin \ - && strip target/release/buzz-pair-relay + && strip target/release/buzz-pair-relay \ + && strip target/release/buzz-acceptance # ─── Stage 4: web bundle (pnpm + vite) ────────────────────────────────────── # Independent of the Rust layers so a CSS change doesn't bust Rust cache and @@ -179,6 +183,7 @@ FROM runtime-base AS runtime-debug COPY --from=builder /build/target/release/buzz-relay /usr/local/bin/buzz-relay COPY --from=builder /build/target/release/buzz-admin /usr/local/bin/buzz-admin COPY --from=builder /build/target/release/buzz-pair-relay /usr/local/bin/buzz-pair-relay +COPY --from=builder /build/target/release/buzz-acceptance /usr/local/bin/buzz-acceptance # Keep the stripped runtime as the final/default Dockerfile target so existing # `docker build .` callers and release tags retain their current behavior. @@ -186,3 +191,4 @@ FROM runtime-base AS runtime COPY --from=stripped-binaries /build/target/release/buzz-relay /usr/local/bin/buzz-relay COPY --from=stripped-binaries /build/target/release/buzz-admin /usr/local/bin/buzz-admin COPY --from=stripped-binaries /build/target/release/buzz-pair-relay /usr/local/bin/buzz-pair-relay +COPY --from=stripped-binaries /build/target/release/buzz-acceptance /usr/local/bin/buzz-acceptance diff --git a/deploy/charts/buzz/README.md b/deploy/charts/buzz/README.md index 380eec84f3..3f20f9b726 100644 --- a/deploy/charts/buzz/README.md +++ b/deploy/charts/buzz/README.md @@ -514,6 +514,103 @@ from the deployed image identity (`image.digest` when set, otherwise `image.tag`, otherwise `Chart.AppVersion`). The value is never hashed or sanitized. +## Acceptance probe + +`acceptance.enabled=true` adds a CronJob that runs `buzz-acceptance` from the +relay image. Each run checks the relay's core jobs once (NIP-11, connect and +NIP-42 auth, channel create, publish, fan-out, history, access control and +cleanup), prints a JSON report and exits: 0 when every check passed, 1 when +one failed, 2 when the probe could not run or report. The probe ships in the +relay image, so it needs an explicit `image.tag` or `image.digest`: the chart +fails to render when both are empty, because the default `Chart.AppVersion` +image predates the probe. + +- The probe connects to `acceptance.relayUrl`, or to `relayUrl` when that is + empty. Each run creates one private channel with a 1 h TTL and deletes it. +- `acceptance.privateKeySecret.name` names a Secret with the probe's key + (hex or nsec). It is required: the chart fails to render without it. A new + key per run would fail on a members-only relay, and an open relay would + join each new key to every auto-join channel. On a members-only relay, make + the key a relay member first. +- `acceptance.statsdAddr` sends DogStatsD metrics under + `acceptance.metricPrefix` (`.runs`, `.run.seconds`, + `.check.runs`, `.check.seconds`, `.stage.seconds`). + `$(HOST_IP)` expands to the node IP, for example `$(HOST_IP):8125` for a + node-local agent. Every series carries `probe_revision`, the relay's NIP-11 + `relay_version`, and each `acceptance.tags` entry. `probe_revision` names the + probe's own image (`image.digest`, else `image.tag`), not the relay build the + run reached: during a rollout, or with `acceptance.relayUrl` set, the probe + can reach pods of another build. `acceptance.tags` keys must be lowercase + (`a-z`, `0-9`, `_`, `.`, `/`, `-`, starting with a letter, with no `__` and + no trailing `_`), because Datadog lowercases keys, collapses `__` and trims + `_`. They can't reuse the + probe-owned keys `probe_revision`, `relay_version`, `check`, `stage` or + `result`, and each key may appear once. +- The Pod runs with `acceptance.serviceAccountName`, or the namespace default + service account when that is empty. It never inherits the relay's service + account and never mounts its token. +- `concurrencyPolicy` is `Forbid` and `backoffLimit` is 0: a retry would + hide a failed run. `acceptance.activeDeadlineSeconds` bounds the whole run, + including image pull and init containers. The probe sends metrics only when + the run ends, so a run killed at the deadline sends none. A run has 13 + serial stage timeouts, each `acceptance.stageTimeoutSeconds`, plus about + 30 s to close and send metrics. Keep the deadline above 13 × + `stageTimeoutSeconds` + 30 s plus pull and init time. + +On a relay that enforces NIP-FI, the probe needs a fresh assertion for its +key. Minting one is deployment-specific, so the chart takes it as a file: an +init container writes it to a shared volume and `acceptance.assertionFile` +points the probe at it. The probe re-reads the file before every connection. +The assertion must name the probe's key, so the init container needs the same +key Secret. Keep the Pod's `runAsUser` in the init container, so the probe can +read files the minter writes with mode 0600. + +```yaml +image: + tag: 1.2.3 # a relay build that includes buzz-acceptance +acceptance: + enabled: true + privateKeySecret: + name: buzz-acceptance-key + statsdAddr: "$(HOST_IP):8125" + tags: ["env:staging"] + assertionFile: /var/run/assertion/token + extraInitContainers: + - name: mint-assertion + image: example.com/assertion-minter:v1 + args: [--out, /var/run/assertion/token] + env: + - name: BUZZ_PRIVATE_KEY # the assertion must name the probe's key + valueFrom: + secretKeyRef: + name: buzz-acceptance-key + key: BUZZ_PRIVATE_KEY + securityContext: + runAsNonRoot: true + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: + drop: [ALL] + resources: + limits: + cpu: 100m + memory: 64Mi + volumeMounts: + - name: assertion + mountPath: /var/run/assertion + extraVolumes: + - name: assertion + emptyDir: + medium: Memory # holds a credential + extraVolumeMounts: + - name: assertion + mountPath: /var/run/assertion + readOnly: true +``` + +The extension values follow the same rules as the relay Pod extensions above. +Keep the assertion's lifetime longer than `acceptance.activeDeadlineSeconds`. + ## Datadog version label Every Pod the chart renders — relay, pairing relay, storage accounting, and the diff --git a/deploy/charts/buzz/templates/_validate.tpl b/deploy/charts/buzz/templates/_validate.tpl index 8d055f825e..99e00ea4a3 100644 --- a/deploy/charts/buzz/templates/_validate.tpl +++ b/deploy/charts/buzz/templates/_validate.tpl @@ -25,6 +25,32 @@ surface at template time regardless of which manifest helm renders first. {{- end -}} {{- end -}} +{{/* The acceptance probe ships only in relay images that include it, so the + chart's default appVersion image can't run it. The probe needs a key the + relay admits, so the chart never lets it fall back to a new key per run. + acceptance.tags keys are canonical (see values.schema.json) and can't + override probe-owned metric tag keys or repeat a key, so one run never + lands in two populations of the same tag. */}} +{{- if .Values.acceptance.enabled -}} + {{- if not (or .Values.image.tag .Values.image.digest) -}} + {{- fail "acceptance.enabled requires image.tag or image.digest: the probe binary is not in the chart's default appVersion image." -}} + {{- end -}} + {{- if not .Values.acceptance.privateKeySecret.name -}} + {{- fail "acceptance.enabled requires acceptance.privateKeySecret.name: without a key the probe signs with a new key each run, which a members-only relay refuses and an open relay joins to every auto-join channel." -}} + {{- end -}} + {{- $seen := dict -}} + {{- range .Values.acceptance.tags -}} + {{- $key := splitList ":" . | first -}} + {{- if has $key (list "probe_revision" "relay_version" "check" "stage" "result") -}} + {{- fail (printf "acceptance.tags: %q uses the probe-owned tag key %q." . $key) -}} + {{- end -}} + {{- if hasKey $seen $key -}} + {{- fail (printf "acceptance.tags: tag key %q appears more than once." $key) -}} + {{- end -}} + {{- $_ := set $seen $key true -}} + {{- end -}} +{{- end -}} + {{/* Multiple replicas do NOT require ReadWriteMany git storage. Git ref/object state is object-store-backed: every read and write hydrates diff --git a/deploy/charts/buzz/templates/acceptance-cronjob.yaml b/deploy/charts/buzz/templates/acceptance-cronjob.yaml new file mode 100644 index 0000000000..af788e96de --- /dev/null +++ b/deploy/charts/buzz/templates/acceptance-cronjob.yaml @@ -0,0 +1,103 @@ +{{- include "buzz.validate" . -}} +{{- if .Values.acceptance.enabled }} +{{- $a := .Values.acceptance }} +{{- range $label := list "app.kubernetes.io/name" "app.kubernetes.io/instance" "app.kubernetes.io/component" }} +{{- if hasKey ($a.podLabels | default dict) $label }} +{{- fail (printf "acceptance.podLabels may not set chart-owned label %q" $label) }} +{{- end }} +{{- end }} +apiVersion: batch/v1 +kind: CronJob +metadata: + name: {{ include "buzz.cronJobName" (dict "root" . "suffix" "acceptance") }} + labels: + {{- include "buzz.labels" . | nindent 4 }} + app.kubernetes.io/component: acceptance +spec: + schedule: {{ $a.schedule | quote }} + concurrencyPolicy: Forbid + successfulJobsHistoryLimit: {{ $a.successfulJobsHistoryLimit }} + failedJobsHistoryLimit: {{ $a.failedJobsHistoryLimit }} + jobTemplate: + spec: + activeDeadlineSeconds: {{ $a.activeDeadlineSeconds }} + backoffLimit: 0 + template: + metadata: + labels: + {{- include "buzz.selectorLabels" . | nindent 12 }} + app.kubernetes.io/component: acceptance + {{- include "buzz.podLabelsWithVersion" (dict "root" . "labels" $a.podLabels) | nindent 12 }} + {{- with $a.podAnnotations }} + annotations: + {{- toYaml . | nindent 12 }} + {{- end }} + spec: + restartPolicy: Never + {{- /* The probe needs no Kubernetes or cloud access, so it does not + inherit the relay's service account or its token. */}} + {{- with $a.serviceAccountName }} + serviceAccountName: {{ . }} + {{- end }} + automountServiceAccountToken: false + enableServiceLinks: false + securityContext: + {{- toYaml .Values.relay.securityContext | nindent 12 }} + {{- with .Values.image.pullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with $a.extraInitContainers }} + initContainers: + {{- toYaml . | nindent 12 }} + {{- end }} + containers: + - name: acceptance + image: {{ include "buzz.image" . }} + imagePullPolicy: {{ .Values.image.pullPolicy }} + securityContext: + {{- omit .Values.relay.containerSecurityContext "readOnlyRootFilesystem" | toYaml | nindent 16 }} + readOnlyRootFilesystem: true + command: ["/usr/local/bin/buzz-acceptance"] + args: + - --stage-timeout-secs + - {{ $a.stageTimeoutSeconds | int64 | quote }} + - --metric-prefix + - {{ $a.metricPrefix | quote }} + - --tag + - {{ printf "probe_revision:%s" (include "buzz.imageRevision" .) | quote }} + {{- range $a.tags }} + - --tag + - {{ . | quote }} + {{- end }} + env: + # Listed first so later values can use $(HOST_IP). + - name: HOST_IP + valueFrom: + fieldRef: + fieldPath: status.hostIP + - { name: BUZZ_RELAY_URL, value: {{ default .Values.relayUrl $a.relayUrl | quote }} } + {{- with $a.statsdAddr }} + - { name: BUZZ_ACCEPTANCE_STATSD_ADDR, value: {{ . | quote }} } + {{- end }} + {{- with $a.assertionFile }} + - { name: BUZZ_ACCEPTANCE_ASSERTION_FILE, value: {{ . | quote }} } + {{- end }} + {{- if $a.privateKeySecret.name }} + - name: BUZZ_PRIVATE_KEY + valueFrom: + secretKeyRef: + name: {{ $a.privateKeySecret.name | quote }} + key: {{ $a.privateKeySecret.key | quote }} + {{- end }} + {{- with $a.extraVolumeMounts }} + volumeMounts: + {{- toYaml . | nindent 16 }} + {{- end }} + resources: + {{- toYaml $a.resources | nindent 16 }} + {{- with $a.extraVolumes }} + volumes: + {{- toYaml . | nindent 12 }} + {{- end }} +{{- end }} diff --git a/deploy/charts/buzz/tests/acceptance_test.yaml b/deploy/charts/buzz/tests/acceptance_test.yaml new file mode 100644 index 0000000000..f8ea12aa32 --- /dev/null +++ b/deploy/charts/buzz/tests/acceptance_test.yaml @@ -0,0 +1,392 @@ +suite: acceptance probe +templates: + - templates/acceptance-cronjob.yaml +set: + relayUrl: wss://buzz.example.com + ownerPubkey: "0000000000000000000000000000000000000000000000000000000000000000" + externalPostgresql.url: postgres://u:p@h:5432/d + externalRedis.url: redis://h:6379 + s3.endpoint: https://s3.example.com + s3.accessKey: test + s3.secretKey: test +tests: + - it: renders nothing by default + asserts: + - hasDocuments: + count: 0 + + - it: runs the probe from the relay image against relayUrl with a key and no metrics + set: + image.tag: "1.2.3" + acceptance.enabled: true + acceptance.privateKeySecret.name: buzz-acceptance-key + asserts: + - hasDocuments: + count: 1 + - equal: + path: kind + value: CronJob + - equal: + path: metadata.name + value: RELEASE-NAME-buzz-acceptance + - equal: + path: spec.schedule + value: "*/5 * * * *" + - equal: + path: spec.concurrencyPolicy + value: Forbid + - equal: + path: spec.jobTemplate.spec.backoffLimit + value: 0 + - equal: + path: spec.jobTemplate.spec.activeDeadlineSeconds + value: 240 + - equal: + path: spec.jobTemplate.spec.template.spec.restartPolicy + value: Never + - equal: + path: spec.jobTemplate.spec.template.spec.containers[0].image + value: ghcr.io/block/buzz:1.2.3 + - equal: + path: spec.jobTemplate.spec.template.spec.containers[0].command + value: ["/usr/local/bin/buzz-acceptance"] + - equal: + path: spec.jobTemplate.spec.template.spec.containers[0].args + value: + - --stage-timeout-secs + - "10" + - --metric-prefix + - buzz.acceptance + - --tag + - probe_revision:1.2.3 + - equal: + path: spec.jobTemplate.spec.template.spec.containers[0].securityContext.readOnlyRootFilesystem + value: true + - contains: + path: spec.jobTemplate.spec.template.spec.containers[0].env + content: + name: BUZZ_RELAY_URL + value: wss://buzz.example.com + - notContains: + path: spec.jobTemplate.spec.template.spec.containers[0].env + content: + name: BUZZ_ACCEPTANCE_STATSD_ADDR + any: true + - contains: + path: spec.jobTemplate.spec.template.spec.containers[0].env + content: + name: BUZZ_PRIVATE_KEY + valueFrom: + secretKeyRef: + name: buzz-acceptance-key + key: BUZZ_PRIVATE_KEY + - notContains: + path: spec.jobTemplate.spec.template.spec.containers[0].env + content: + name: BUZZ_ACCEPTANCE_ASSERTION_FILE + any: true + # The probe needs no Kubernetes or cloud access: no relay service + # account, no token. + - notExists: + path: spec.jobTemplate.spec.template.spec.serviceAccountName + - equal: + path: spec.jobTemplate.spec.template.spec.automountServiceAccountToken + value: false + - equal: + path: spec.jobTemplate.spec.template.spec.enableServiceLinks + value: false + - notExists: + path: spec.jobTemplate.spec.template.spec.initContainers + - notExists: + path: spec.jobTemplate.spec.template.spec.volumes + + - it: wires the key, metrics, tags, digest identity and an assertion minted by an init container + set: + image.digest: sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef + acceptance: + enabled: true + relayUrl: wss://probe.example.com + schedule: "*/10 * * * *" + activeDeadlineSeconds: 120 + stageTimeoutSeconds: 5 + privateKeySecret: + name: buzz-acceptance-key + key: nsec + assertionFile: /var/run/assertion/token + statsdAddr: "$(HOST_IP):8125" + metricPrefix: example.acceptance + tags: ["env:staging", "target:stable"] + serviceAccountName: buzz-acceptance + podAnnotations: + example.com/probe: "true" + extraInitContainers: + - name: mint-assertion + image: example.com/minter:v1 + volumeMounts: + - name: assertion + mountPath: /var/run/assertion + extraVolumes: + - name: assertion + emptyDir: {} + extraVolumeMounts: + - name: assertion + mountPath: /var/run/assertion + readOnly: true + asserts: + - equal: + path: spec.schedule + value: "*/10 * * * *" + - equal: + path: spec.jobTemplate.spec.activeDeadlineSeconds + value: 120 + - equal: + path: spec.jobTemplate.spec.template.spec.serviceAccountName + value: buzz-acceptance + - equal: + path: spec.jobTemplate.spec.template.spec.automountServiceAccountToken + value: false + - equal: + path: spec.jobTemplate.spec.template.metadata.annotations + value: + example.com/probe: "true" + - equal: + path: spec.jobTemplate.spec.template.spec.containers[0].image + value: ghcr.io/block/buzz@sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef + - equal: + path: spec.jobTemplate.spec.template.spec.containers[0].args + value: + - --stage-timeout-secs + - "5" + - --metric-prefix + - example.acceptance + - --tag + - probe_revision:sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef + - --tag + - env:staging + - --tag + - target:stable + # HOST_IP must come first so "$(HOST_IP)" expands in later values. + - equal: + path: spec.jobTemplate.spec.template.spec.containers[0].env[0] + value: + name: HOST_IP + valueFrom: + fieldRef: + fieldPath: status.hostIP + - contains: + path: spec.jobTemplate.spec.template.spec.containers[0].env + content: + name: BUZZ_RELAY_URL + value: wss://probe.example.com + - contains: + path: spec.jobTemplate.spec.template.spec.containers[0].env + content: + name: BUZZ_ACCEPTANCE_STATSD_ADDR + value: "$(HOST_IP):8125" + - contains: + path: spec.jobTemplate.spec.template.spec.containers[0].env + content: + name: BUZZ_ACCEPTANCE_ASSERTION_FILE + value: /var/run/assertion/token + - contains: + path: spec.jobTemplate.spec.template.spec.containers[0].env + content: + name: BUZZ_PRIVATE_KEY + valueFrom: + secretKeyRef: + name: buzz-acceptance-key + key: nsec + - equal: + path: spec.jobTemplate.spec.template.spec.initContainers + value: + - name: mint-assertion + image: example.com/minter:v1 + volumeMounts: + - name: assertion + mountPath: /var/run/assertion + - equal: + path: spec.jobTemplate.spec.template.spec.volumes + value: + - name: assertion + emptyDir: {} + - equal: + path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts + value: + - name: assertion + mountPath: /var/run/assertion + readOnly: true + + - it: owns the Datadog version label over a stale pin + set: + image.tag: sha-abcdef1 + acceptance: + enabled: true + privateKeySecret: + name: buzz-acceptance-key + podLabels: + tags.datadoghq.com/service: buzz-acceptance + tags.datadoghq.com/version: sha-stale00 + asserts: + - equal: + path: spec.jobTemplate.spec.template.metadata.labels["tags.datadoghq.com/version"] + value: sha-abcdef1 + - equal: + path: spec.jobTemplate.spec.template.metadata.labels["tags.datadoghq.com/service"] + value: buzz-acceptance + - equal: + path: spec.jobTemplate.spec.template.metadata.labels["app.kubernetes.io/component"] + value: acceptance + + # probe_revision names the probe's image, which is the relay image this + # release deploys, even when acceptance.relayUrl points elsewhere. + - it: tags runs with the probe's image revision, not the target's + set: + image.tag: sha-abcdef1 + acceptance: + enabled: true + privateKeySecret: + name: buzz-acceptance-key + relayUrl: wss://other.example.com + asserts: + - contains: + path: spec.jobTemplate.spec.template.spec.containers[0].args + content: probe_revision:sha-abcdef1 + - notContains: + path: spec.jobTemplate.spec.template.spec.containers[0].args + content: image_revision:sha-abcdef1 + + # The chart's default appVersion image predates the probe binary. + - it: requires an explicit image tag or digest + chart: + appVersion: "1.2.3" + set: + acceptance.enabled: true + asserts: + - failedTemplate: + errorPattern: "acceptance.enabled requires image.tag or image.digest" + + - it: rejects a tag without a key + set: + image.tag: "1.2.3" + acceptance: + enabled: true + privateKeySecret: + name: buzz-acceptance-key + tags: ["staging"] + asserts: + - failedTemplate: {} + + - it: rejects a tag that reuses a probe-owned key + set: + image.tag: "1.2.3" + acceptance: + enabled: true + privateKeySecret: + name: buzz-acceptance-key + tags: ["env:staging", "relay_version:9.9.9"] + asserts: + - failedTemplate: + errorPattern: 'uses the probe-owned tag key "relay_version"' + + - it: rejects a tag key given twice + set: + image.tag: "1.2.3" + acceptance: + enabled: true + privateKeySecret: + name: buzz-acceptance-key + tags: ["target:stable", "env:staging", "target:canary"] + asserts: + - failedTemplate: + errorPattern: 'tag key "target" appears more than once' + + - it: rejects a pod label that overrides a chart-owned label + set: + image.tag: "1.2.3" + acceptance: + enabled: true + privateKeySecret: + name: buzz-acceptance-key + podLabels: + app.kubernetes.io/component: other + asserts: + - failedTemplate: + errorPattern: 'acceptance.podLabels may not set chart-owned label "app.kubernetes.io/component"' + + # A new key per run is refused by a members-only relay and joined to every + # auto-join channel on an open one, so the chart requires a key. + - it: requires a probe key + set: + image.tag: "1.2.3" + acceptance.enabled: true + asserts: + - failedTemplate: + errorPattern: "acceptance.enabled requires acceptance.privateKeySecret.name" + + - it: requires a probe key with an assertion file + set: + image.tag: "1.2.3" + acceptance: + enabled: true + assertionFile: /var/run/assertion/token + asserts: + - failedTemplate: + errorPattern: "acceptance.enabled requires acceptance.privateKeySecret.name" + + # The probe rewrites spaces to "_" and Datadog lowercases keys and trims + # "_", so only canonical keys pass the reserved and duplicate checks. + - it: rejects an uppercase tag key + set: + image.tag: "1.2.3" + acceptance: + enabled: true + privateKeySecret: + name: buzz-acceptance-key + tags: ["Env:staging"] + asserts: + - failedTemplate: {} + + - it: rejects a tag key with a space + set: + image.tag: "1.2.3" + acceptance: + enabled: true + privateKeySecret: + name: buzz-acceptance-key + tags: ["relay version:9.9.9"] + asserts: + - failedTemplate: {} + + - it: rejects a tag key with a trailing underscore + set: + image.tag: "1.2.3" + acceptance: + enabled: true + privateKeySecret: + name: buzz-acceptance-key + tags: ["env_:staging"] + asserts: + - failedTemplate: {} + + # Datadog collapses "__" to "_": relay__version would become relay_version. + - it: rejects a tag key with a double underscore that maps to a probe-owned key + set: + image.tag: "1.2.3" + acceptance: + enabled: true + privateKeySecret: + name: buzz-acceptance-key + tags: ["relay__version:x"] + asserts: + - failedTemplate: {} + + - it: rejects tag keys that collide once Datadog collapses "__" + set: + image.tag: "1.2.3" + acceptance: + enabled: true + privateKeySecret: + name: buzz-acceptance-key + tags: ["target_name:a", "target__name:b"] + asserts: + - failedTemplate: {} diff --git a/deploy/charts/buzz/values.schema.json b/deploy/charts/buzz/values.schema.json index 8162ed7d0d..5f9917f0f3 100644 --- a/deploy/charts/buzz/values.schema.json +++ b/deploy/charts/buzz/values.schema.json @@ -217,6 +217,38 @@ "secretKey": { "type": "string" } } }, + "acceptance": { + "type": "object", + "additionalProperties": false, + "properties": { + "enabled": { "type": "boolean" }, + "schedule": { "type": "string", "minLength": 1 }, + "activeDeadlineSeconds": { "type": "integer", "minimum": 1 }, + "successfulJobsHistoryLimit": { "type": "integer", "minimum": 0 }, + "failedJobsHistoryLimit": { "type": "integer", "minimum": 0 }, + "relayUrl": { "type": "string" }, + "stageTimeoutSeconds": { "type": "integer", "minimum": 1 }, + "privateKeySecret": { + "type": "object", + "additionalProperties": false, + "properties": { + "name": { "type": "string" }, + "key": { "type": "string", "minLength": 1 } + } + }, + "assertionFile": { "type": "string" }, + "statsdAddr": { "type": "string" }, + "metricPrefix": { "type": "string", "minLength": 1 }, + "tags": { "type": "array", "items": { "type": "string", "pattern": "^[a-z](_?[a-z0-9./-])*:.+$" } }, + "serviceAccountName": { "type": "string" }, + "podLabels": { "type": "object" }, + "podAnnotations": { "type": "object" }, + "extraInitContainers": { "type": "array", "items": { "type": "object" } }, + "extraVolumes": { "type": "array", "items": { "type": "object" } }, + "extraVolumeMounts": { "type": "array", "items": { "type": "object" } }, + "resources": { "type": "object" } + } + }, "storageAccounting": { "type": "object", "additionalProperties": false, diff --git a/deploy/charts/buzz/values.yaml b/deploy/charts/buzz/values.yaml index fbaa83d416..f475a6aeee 100644 --- a/deploy/charts/buzz/values.yaml +++ b/deploy/charts/buzz/values.yaml @@ -398,6 +398,59 @@ storageAccounting: cpu: "1" memory: 20Gi +# Relay acceptance probe: a CronJob that runs `buzz-acceptance` from the relay +# image, checks the relay's core jobs once per run, and exits (see README +# "Acceptance probe"). Requires image.tag or image.digest: the chart's default +# appVersion image does not include the probe. +acceptance: + enabled: false + schedule: "*/5 * * * *" + # Bounds the whole run, including init containers. backoffLimit is 0: a + # retry would hide a failed run. + activeDeadlineSeconds: 240 + successfulJobsHistoryLimit: 1 + failedJobsHistoryLimit: 3 + relayUrl: "" # empty → relayUrl + # A run has 13 serial stage timeouts of this length. Keep activeDeadlineSeconds + # above 13 × stageTimeoutSeconds + 30 s plus pull and init time: a run killed + # at the deadline sends no metrics. + stageTimeoutSeconds: 10 + # Secret holding the probe's key (hex or nsec). Required when enabled. On a + # members-only relay the key must be a relay member. + privateKeySecret: + name: "" + key: BUZZ_PRIVATE_KEY + # NIP-FI assertion path in the probe container. Pair with extraInitContainers, + # extraVolumes and extraVolumeMounts to mint it before the run. + assertionFile: "" + # DogStatsD address. `$(HOST_IP)` expands to the node IP, e.g. + # "$(HOST_IP):8125" for a node-local agent. Empty → no metrics. + statsdAddr: "" + metricPrefix: buzz.acceptance + # Extra `key:value` metric tags. Keys are lowercase [a-z0-9_./-], start with + # a letter, and have no `__` or trailing `_`. The chart always adds + # `probe_revision:`. The keys probe_revision, + # relay_version, check, stage and result are probe-owned and rejected here. + # Each key may appear once. + tags: [] + # Empty → the namespace default service account, not the relay's. The token + # is never mounted. + serviceAccountName: "" + # May not set app.kubernetes.io/name, /instance or /component. + # tags.datadoghq.com/version is chart-owned; see README "Datadog version label". + podLabels: {} + podAnnotations: {} + extraInitContainers: [] + extraVolumes: [] + extraVolumeMounts: [] + resources: + requests: + cpu: 50m + memory: 64Mi + limits: + cpu: 500m + memory: 256Mi + # Typed, one-shot operator jobs. The chart intentionally exposes no generic # command or environment registry: each job has a reviewed executable and # least-privilege environment contract.