Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -179,10 +183,12 @@ 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.
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
97 changes: 97 additions & 0 deletions deploy/charts/buzz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` (`<prefix>.runs`, `<prefix>.run.seconds`,
`<prefix>.check.runs`, `<prefix>.check.seconds`, `<prefix>.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
Expand Down
26 changes: 26 additions & 0 deletions deploy/charts/buzz/templates/_validate.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
103 changes: 103 additions & 0 deletions deploy/charts/buzz/templates/acceptance-cronjob.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
Loading
Loading