From 388f992da9c39c68364631b09019cb76dbe69c01 Mon Sep 17 00:00:00 2001 From: Stelios Charmpalis Date: Thu, 12 Nov 2026 14:45:51 +0200 Subject: [PATCH 01/10] test(chart): assert the values the dashboard install command sets The dashboard will soon offer each new chart release to customers as soon as it is published, with no review of its own. Helm ignores values keys a chart does not read, so if the chart renamed or dropped one the dashboard sets, the install would still render and quietly lose the token, cluster name, netobs switch or a source. Each case sets the dashboard's keys and asserts the value reaches the rendered config, not only that the render succeeds. Refs: #27 Refs: NOFireAI/engineering#1983 Signed-off-by: Stelios Charmpalis --- tests/dashboard_install_test.yaml | 103 ++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 tests/dashboard_install_test.yaml diff --git a/tests/dashboard_install_test.yaml b/tests/dashboard_install_test.yaml new file mode 100644 index 0000000..a60b890 --- /dev/null +++ b/tests/dashboard_install_test.yaml @@ -0,0 +1,103 @@ +# The values the NOFire AI dashboard's install, sources and disconnect commands +# set (app/dashboard/activation/installCommand.ts in NOFireAI/dashboard). +# +# Once a chart release publishes edge/latest.json, the dashboard offers that +# version to customers with no review step of its own, so this suite is the +# gate. Helm ignores values keys a chart does not read, so a renamed or dropped +# key would still render cleanly: each case asserts the value comes out the +# other side, not only that the render succeeds. +# +# Change these together with the dashboard's command builders. +suite: dashboard install command +templates: + - templates/configmap.yaml + - templates/deployment.yaml + - templates/edge-proxy-configmap.yaml + - templates/edge-proxy-deployment.yaml +tests: + - it: install puts the token, cluster name and netobs switch in config.json + template: templates/configmap.yaml + set: + config.publisher.apiKey: dash-test-token + config.kube.clusterName: dash-test-cluster + config.netobs.enabled: true + asserts: + - matchRegex: + path: data["config.json"] + pattern: '"apiKey": "dash-test-token"' + - matchRegex: + path: data["config.json"] + pattern: '"clusterName": "dash-test-cluster"' + - matchRegex: + path: data["config.json"] + pattern: '"netobs": \{\s*"enabled": true' + + - it: a non-canonical origin sets the publisher graph URL + template: templates/configmap.yaml + set: + config.publisher.graph.url: https://dash-test.example/api/edge + asserts: + - matchRegex: + path: data["config.json"] + pattern: '"url": "https://dash-test.example/api/edge"' + + - it: the dnstap verify command can select the edge pod by name label + template: templates/deployment.yaml + asserts: + - equal: + path: spec.template.metadata.labels["app.kubernetes.io/name"] + value: nofire-edge + + - it: sources deploy edge-proxy with each connection + template: templates/edge-proxy-configmap.yaml + set: + config.publisher.apiKey: dash-test-token + config.kube.clusterName: dash-test-cluster + edgeProxy.enabled: true + onPremConnections: + prometheus: + type: prometheus + url: http://prometheus.monitoring:9090 + enabled: true + elasticsearch: + type: elasticsearch + url: http://es.logging:9200 + index: logs-* + enabled: true + asserts: + - matchRegex: + path: data["config.json"] + pattern: '"clusterName": "dash-test-cluster"' + - matchRegex: + path: data["config.json"] + pattern: '"prometheus": \{\s*"type": "prometheus",\s*"enabled": true' + - matchRegex: + path: data["config.json"] + pattern: '"url": "http://prometheus.monitoring:9090"' + - matchRegex: + path: data["config.json"] + pattern: '"index": "logs-\*"' + + - it: edgeProxy.enabled renders the edge-proxy deployment + template: templates/edge-proxy-deployment.yaml + set: + edgeProxy.enabled: true + asserts: + - hasDocuments: + count: 1 + - isKind: + of: Deployment + + - it: disconnect turns one connection off and keeps it listed + template: templates/edge-proxy-configmap.yaml + set: + edgeProxy.enabled: true + onPremConnections: + prometheus: + type: prometheus + url: http://prometheus.monitoring:9090 + enabled: false + asserts: + - matchRegex: + path: data["config.json"] + pattern: '"prometheus": \{\s*"type": "prometheus",\s*"enabled": false' From 41b535cb63e45f55d3bebd19de895e680b17996d Mon Sep 17 00:00:00 2001 From: Stelios Charmpalis Date: Thu, 12 Nov 2026 14:45:51 +0200 Subject: [PATCH 02/10] ci(release): publish Edge release metadata to releases.nofire.ai Write edge/.json and edge/latest.json after each release, so the dashboard can read the current chart version instead of pinning it. - The versioned file is written once, with If-None-Match. - latest.json only moves to a higher version and never to a pre-release. The current one is read from S3 directly, so a cached copy cannot hide a newer version. - The steps run on every run and each write is idempotent: a re-run changes nothing, and a manual run backfills a release made before this change. - latest.json waits until GitHub Pages serves an index.yaml that lists the version. Otherwise `helm repo update` could miss it. - Nothing runs until the RELEASE_METADATA_ROLE_ARN repository variable holds the role from NOFireAI/terraform#295. Refs: #27 Refs: NOFireAI/engineering#1983 Signed-off-by: Stelios Charmpalis --- .github/workflows/release.yml | 107 ++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1926ff4..82089b2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,6 +13,8 @@ jobs: runs-on: ubuntu-latest permissions: contents: write + # OIDC token for the release metadata role (NOFireAI/terraform#295). + id-token: write steps: - name: Checkout uses: actions/checkout@v4 @@ -103,3 +105,108 @@ jobs: git add . git commit -m "chore(release): ${{ steps.chart.outputs.name }}-${{ steps.chart.outputs.version }}" git push + + # Release metadata for the NOFire AI dashboard (NOFireAI/engineering#1983). + # The dashboard reads edge/latest.json at https://releases.nofire.ai to pick + # the chart version its install commands use, so writing it is what ships + # a chart release to customers. tests/dashboard_install_test.yaml is the + # gate for that. + # + # These steps run on every run, not only when a release was created, and + # each write is idempotent: a re-run changes nothing, and a manual run + # publishes a release that predates them. They are skipped until the + # RELEASE_METADATA_ROLE_ARN repository variable is set. + - name: Wait for the Helm repo index + if: vars.RELEASE_METADATA_ROLE_ARN != '' + env: + VERSION: ${{ steps.chart.outputs.version }} + NAME: ${{ steps.chart.outputs.name }} + run: | + # GitHub Pages deploys after the push. latest.json must not name a + # version `helm repo update` cannot find yet. + for _ in $(seq 1 40); do + if curl -sSfL https://nofireai.github.io/edge-helm-chart/index.yaml \ + | yq -e ".entries[\"$NAME\"][] | select(.version == \"$VERSION\")" >/dev/null 2>&1; then + echo "$NAME $VERSION is in the index" + exit 0 + fi + sleep 15 + done + echo "::error::$NAME $VERSION did not appear in index.yaml within 10 minutes" + exit 1 + + - name: Configure AWS credentials + if: vars.RELEASE_METADATA_ROLE_ARN != '' + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ vars.RELEASE_METADATA_ROLE_ARN }} + aws-region: us-east-1 + + - name: Publish release metadata + if: vars.RELEASE_METADATA_ROLE_ARN != '' + env: + GH_TOKEN: ${{ github.token }} + NAME: ${{ steps.chart.outputs.name }} + VERSION: ${{ steps.chart.outputs.version }} + BUCKET: releases.nofire.ai + run: | + set -euo pipefail + app_version="$(yq -r '.appVersion' Chart.yaml)" + tag="$(yq -r '.image.tag // ""' values.yaml)" + tag="${tag:-$app_version}" + proxy_tag="$(yq -r '.edgeProxy.image.tag // ""' values.yaml)" + proxy_tag="${proxy_tag:-$tag}" + release="$(gh release view "$NAME-$VERSION" --json publishedAt,url)" + + jq -n \ + --arg name "$NAME" \ + --arg version "$VERSION" \ + --arg appVersion "$app_version" \ + --arg edge "$(yq -r '.image.repository' values.yaml):$tag" \ + --arg edgeProxy "$(yq -r '.edgeProxy.image.repository' values.yaml):$proxy_tag" \ + --argjson release "$release" \ + '{ + schema: 1, + chart: {name: $name, version: $version, repo: "https://nofireai.github.io/edge-helm-chart"}, + edge: {version: $appVersion, images: {edge: $edge, edgeProxy: $edgeProxy}}, + releasedAt: $release.publishedAt, + releaseUrl: $release.url + }' > metadata.json + cat metadata.json + + # The versioned file is immutable: written once, never replaced. + if aws s3api put-object --bucket "$BUCKET" --key "edge/$VERSION.json" \ + --body metadata.json --content-type application/json \ + --cache-control 'public, max-age=31536000, immutable' \ + --if-none-match '*' >/dev/null 2>err.txt; then + echo "wrote edge/$VERSION.json" + elif grep -q PreconditionFailed err.txt; then + echo "edge/$VERSION.json already exists" + else + cat err.txt + exit 1 + fi + + # latest.json only moves forward, and never to a pre-release. Read it + # from S3 rather than through Cloudflare, so a cached copy cannot hide + # a newer version. A missing key is a 403: the bucket allows no listing. + case "$VERSION" in *-*) + echo "$VERSION is a pre-release, leaving latest.json alone" + exit 0 + esac + code="$(curl -sS -o latest.json -w '%{http_code}' \ + "https://s3.us-east-1.amazonaws.com/$BUCKET/edge/latest.json")" + case "$code" in + 200) current="$(jq -r '.chart.version' latest.json)" ;; + 403|404) current="" ;; + *) echo "::error::reading latest.json returned HTTP $code"; exit 1 ;; + esac + if [ -n "$current" ] && \ + [ "$(printf '%s\n%s\n' "$current" "$VERSION" | sort -V | tail -1)" = "$current" ]; then + echo "latest.json holds $current, not replacing it with $VERSION" + exit 0 + fi + aws s3api put-object --bucket "$BUCKET" --key edge/latest.json \ + --body metadata.json --content-type application/json \ + --cache-control 'public, max-age=300' >/dev/null + echo "latest.json now holds $VERSION (was ${current:-nothing})" From 9ca4bd21e0f75b37cfc7bf99831ab57e824ba522 Mon Sep 17 00:00:00 2001 From: Stelios Charmpalis Date: Thu, 12 Nov 2026 14:54:13 +0200 Subject: [PATCH 03/10] test(render): render a dashboard-made 0.9.0 release reused onto this chart The dashboard's step 5 and disconnect commands run `helm upgrade --reuse-values`, and once they follow the published chart version they render each new chart's templates against an older release's values. The new suite only covers fresh values. This case is 0.9.0's values.yaml plus what the dashboard set on that release (token, cluster name, netobs, edge-proxy and one source), and checks those still reach config.json. Refs: #27 Refs: NOFireAI/engineering#1983 Signed-off-by: Stelios Charmpalis --- .../dashboard-reuse-from-0.9.0/expect.jq | 3 + .../dashboard-reuse-from-0.9.0/replace-values | 0 .../dashboard-reuse-from-0.9.0/values.yaml | 530 ++++++++++++++++++ 3 files changed, 533 insertions(+) create mode 100644 tests/render/cases/dashboard-reuse-from-0.9.0/expect.jq create mode 100644 tests/render/cases/dashboard-reuse-from-0.9.0/replace-values create mode 100644 tests/render/cases/dashboard-reuse-from-0.9.0/values.yaml diff --git a/tests/render/cases/dashboard-reuse-from-0.9.0/expect.jq b/tests/render/cases/dashboard-reuse-from-0.9.0/expect.jq new file mode 100644 index 0000000..715e724 --- /dev/null +++ b/tests/render/cases/dashboard-reuse-from-0.9.0/expect.jq @@ -0,0 +1,3 @@ +.publisher.apiKey == "dash-test-token" +and .kube.clusterName == "dash-test-cluster" +and .netobs.enabled == true diff --git a/tests/render/cases/dashboard-reuse-from-0.9.0/replace-values b/tests/render/cases/dashboard-reuse-from-0.9.0/replace-values new file mode 100644 index 0000000..e69de29 diff --git a/tests/render/cases/dashboard-reuse-from-0.9.0/values.yaml b/tests/render/cases/dashboard-reuse-from-0.9.0/values.yaml new file mode 100644 index 0000000..d4febbb --- /dev/null +++ b/tests/render/cases/dashboard-reuse-from-0.9.0/values.yaml @@ -0,0 +1,530 @@ +# The 0.9.0 chart's values.yaml, verbatim except for what the dashboard set on +# that release (marked "dashboard:"): the step 4 install, then the step 5 +# sources. `helm upgrade --reuse-values` to a newer chart renders the new +# templates against exactly this, which is what the dashboard's step 5 and +# disconnect commands do once they follow the published chart version +# (NOFireAI/engineering#1983). +# Default values for nofire-edge. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +# Image configuration +image: + repository: nofireai/edge + pullPolicy: Always + # Overrides the image tag, which otherwise defaults to the chart appVersion. + # Released tags carry the "v" prefix (nofireai/edge:v3.9.0); a bare "3.9.0" + # does not exist in the registry. + tag: "v3.9.0" + +# Image pull secrets +imagePullSecrets: [] + +# Override name and fullname +nameOverride: "" +fullnameOverride: "" + +# Number of replicas +replicaCount: 1 + +# Deployment strategy +strategy: + type: RollingUpdate + rollingUpdate: + maxUnavailable: 1 + maxSurge: 1 + +# Service account configuration +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +# RBAC configuration +rbac: + # Specifies whether RBAC resources should be created + create: true + # Additional cluster role rules + extraRules: [] + +# Pod annotations +podAnnotations: {} + +# Pod labels +podLabels: {} + +# Pod security context +podSecurityContext: + {} + # fsGroup: 2000 + +# Security context for containers +securityContext: + {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +# Service configuration +service: + type: ClusterIP + # clusterIP: "" # Optional: Set a static ClusterIP + port: 8080 + dnstapPort: 6000 + targetPort: 8080 + annotations: {} + +# Ingress configuration +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: k8s-resource-graph-client.local + paths: + - path: / + pathType: Prefix + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +# Resource limits and requests +resources: + limits: + cpu: 200m + memory: 256Mi + requests: + cpu: 100m + memory: 128Mi + +# Horizontal Pod Autoscaler +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +# Node selector +nodeSelector: {} + +# Tolerations +tolerations: [] + +# Affinity +affinity: {} + +# Topology spread constraints +topologySpreadConstraints: [] + +# Pod disruption budget +podDisruptionBudget: + enabled: false + minAvailable: 1 + # maxUnavailable: 1 + +# Liveness probe configuration +livenessProbe: + httpGet: + path: /healthz + port: http + initialDelaySeconds: 30 + periodSeconds: 10 + timeoutSeconds: 5 + failureThreshold: 3 + +# Readiness probe configuration +readinessProbe: + httpGet: + path: /healthz + port: http + initialDelaySeconds: 5 + periodSeconds: 10 + timeoutSeconds: 5 + failureThreshold: 3 + +# Monitoring configuration +monitoring: + # Enable ServiceMonitor for Prometheus Operator + serviceMonitor: + enabled: false + namespace: "" + labels: + release: prometheus + annotations: {} + interval: 30s + path: /metrics + targetLabels: [] + metricRelabelings: [] + relabelings: [] + +# Client configuration +config: + # Logging configuration + logLevel: "info" + + # Server configuration + serverPort: 8080 + + # Sentry configuration + sentry: + dsn: "https://0d3d5e19f07e0173eaadeb930a405150@o4507775482789888.ingest.de.sentry.io/4510431321718864" + environment: "production" + release: "" + debug: false + sampleRate: 1.0 + tracesSampleRate: 0.2 + + + # Graph configuration + graph: + pruneInterval: "1h" + maxPruneAge: "24h" + + # Kubernetes configuration + kube: + configPath: "" + resyncInterval: "5m" + clusterName: "dash-test-cluster" # dashboard: config.kube.clusterName + resources: + - "pods" + - "nodes" + - "k8services" + - "endpoints" + - "configmaps" + - "secrets" + - "persistentvolumeclaims" + - "persistentvolumes" + - "deployments" + - "replicasets" + - "statefulsets" + - "daemonsets" + - "jobs" + - "ingresses" + - "ingressclasses" + - "gatewayclasses" + - "gateways" + - "httproutes" + - "grpcroutes" + - "tlsroutes" + - "tcproutes" + - "udproutes" + - "referencegrants" + - "ingressroutes" + - "ingressroutetcps" + - "ingressrouteudps" + - "traefikservices" + - "namespaces" + - "services" + # Opt-in kinds, off by default. The ClusterRole already grants get, list + # and watch on them. The three calico* kinds also need Calico's CRDs + # (crd.projectcalico.org/v1) installed in the cluster; the agent skips + # them otherwise, just as it skips the Gateway API + # (gateway.networking.k8s.io) and Traefik (traefik.io/v1alpha1 or + # traefik.containo.us/v1alpha1) routing kinds above when their CRDs are + # absent. + # - "cronjobs" + # - "priorityclasses" + # - "roles" + # - "clusterroles" + # - "rolebindings" + # - "clusterrolebindings" + # - "calicoippools" + # - "calicobgppeers" + # - "calicoipamconfigs" + # Restrict which namespaces enter the resource graph. Unset (or mode "none") + # means every namespace is graphed. The chart fails the render on invalid + # combinations, mirroring the Edge's own validation: + # - namespaces set with mode unset/""/"none" + # - mode "allow" or "deny" with an empty namespaces list + # - any other mode + # namespaceFilter: + # mode: allow # allow | deny | none + # namespaces: + # - production + # - staging + # Causal analysis configuration + enableCausalAnalysis: false + causal: + algorithm: "counterfactual" + interval: "15m" + + # Services configuration + services: + workers: 4 + # Keys you leave out use the Edge defaults shown below (set a key to override + # it; partial tls/compression/handshake objects are merged into the defaults). + # DNSTap listens on :6000 even when address is unset (matches service.dnstapPort). + # address: ":6000" + # maxConns: 100 + # readTimeout: "30s" + # writeTimeout: "10s" + # tls: + # enabled: false + # certFile: "/etc/nofire/certs/tls.crt" + # keyFile: "/etc/nofire/certs/tls.key" + # caFile: "/etc/nofire/certs/ca.crt" + # requireClientCert: false + # minVersion: "1.2" + # cipherSuites: # setting this replaces the default list + # - TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 + # - TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 + # - TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 + # - TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 + # compression: + # enabled: true + # type: "gzip" # none | gzip + # level: -1 + # handshake: + # timeout: "10s" + # contentType: "protobuf:dnstap.Dnstap" + + # Network observability — L7 dependency detection via Hubble, Istio, or Caretta. + # Auto-detects available source when source is empty (hubble > istio > caretta). + netobs: + enabled: true # dashboard: config.netobs.enabled + interval: "60s" + prometheusUrl: "" # empty = in-cluster discovery + source: "" # empty = auto-detect; or "hubble" | "istio" | "caretta" + prometheusTimeout: "10s" + # How long a network edge is kept after it stops being observed (Edge default: 2h). + # edgeExistenceTtl: "2h" + # Namespaces whose network flows are dropped before collection. Edge default: + # [kube-system, monitoring]. Setting this REPLACES the default, it does not + # append (use [] to exclude nothing). Namespaces listed in a deny-mode + # kube.namespaceFilter are added by the Edge on top of this list. + # excludeNamespaces: + # - kube-system + # - monitoring + + # Publishing configuration + enablePublishing: true + publisher: + # REQUIRED: API key for authentication (must be set to a valid value) + # apiKey: "your-api-key-here" + apiKey: "dash-test-token" # dashboard: config.publisher.apiKey + # Source the API key from an existing Secret (via the NOFIRE_API_KEY env var) + # instead of baking apiKey into the config.json ConfigMap in plaintext. When + # enabled the chart does NOT render templates/secret.yaml — the named Secret is + # expected to already exist (e.g. created by External Secrets Operator). + apiKeySecret: + enabled: false + name: nofire-credentials + key: api-key + timeout: "30s" + maxRetries: 3 + retryDelay: "5s" + enableCompression: true + graph: + url: "https://my.nofire.ai/api/edge" + interval: "5m" + heartbeat: + url: "" + interval: "10s" + + # ConfigMap value capture. Hash-by-default so raw customer configuration never + # leaves the cluster. Set clearText: true to send values verbatim (still + # subject to redactKeyPatterns and captureCap). + configMapCapture: + # false (default): every ConfigMap value is sent as a sha256 hash. + # true: values are sent in the clear, except keys matching redactKeyPatterns. + clearText: false + # In clear-text mode, ConfigMap data keys matching any of these regexes are + # hashed instead of sent verbatim (e.g. secrets embedded in a ConfigMap). + redactKeyPatterns: [] + # - "(?i)(password|passwd|secret|token|apikey|api_key|private_key)" + # Per-value byte cap for clear-text values. Values over the cap are trimmed + # (Brain is told the value was trimmed). Hashes always cover the full value. + # 0, negative or unset uses the Edge default of 4096. + captureCap: 4096 + + # Container env-var value capture. Hash-by-default so a plaintext credential in + # an env var never leaves the cluster. Same model as configMapCapture. + envCapture: + # false (default): every literal env value is sent as a sha256 hash. + # true: literal values are sent in the clear, except names matching redactKeyPatterns. + clearText: false + # In clear-text mode, env var names matching any of these regexes stay hashed. + redactKeyPatterns: [] + # - "(?i)(password|passwd|secret|token|apikey|api_key|private_key)" + # Per-value byte cap for clear-text values (over-cap values trimmed, flagged). + # 0, negative or unset uses the Edge default of 4096. + captureCap: 4096 + +# GODEBUG for the edge and edge-proxy containers. The default turns off the +# MPTCP listeners Go 1.24+ opens, the precondition for the CVE-2026-98432 +# exploit. "" omits it; a GODEBUG entry in env overrides it on edge. +godebug: "multipathtcp=0" + +# Environment variables +env: [] +# - name: NODE_NAME +# valueFrom: +# fieldRef: +# fieldPath: spec.nodeName + +# Additional volumes +extraVolumes: [] + +# Additional volume mounts +extraVolumeMounts: [] + +# Extra containers +extraContainers: [] + +# Init containers +initContainers: [] + +# Node name configuration (for DaemonSet-like behavior) +nodeName: + # Enable automatic node name injection + enabled: true + # Field path for node name + fieldPath: "spec.nodeName" + +# ============================================================================= +# Edge Proxy Configuration +# ============================================================================= +# The edge proxy connects to Brain via gRPC and proxies observability queries +# to on-prem data sources (Prometheus, Loki, Tempo, etc.). +# Set enabled: true to deploy the edge proxy alongside the main agent. + +edgeProxy: + enabled: true # dashboard: edgeProxy.enabled + + image: + repository: nofireai/edge-proxy + # tag: defaults to .Values.image.tag (shared version with main agent) + # pullPolicy: defaults to .Values.image.pullPolicy + + replicaCount: 1 + + resources: + requests: + memory: "128Mi" + cpu: "100m" + limits: + memory: "256Mi" + cpu: "500m" + + # Stream configuration (Brain gRPC connection) + stream: + serverAddress: "edge.nofire.ai:443" + useTLS: true + reconnectDelay: "1s" + maxReconnectDelay: "60s" + heartbeatInterval: "30s" + maxMessageSize: 16777216 # 16MB + maxConcurrent: 10 + keepaliveTime: "30s" + keepaliveTimeout: "10s" + protocolVersion: 1 + + # HTTP client settings for backend connections + http: + timeout: "30s" + maxIdleConns: 100 + retryMaxAttempts: 3 + + # PII redaction before data leaves customer infrastructure + redaction: + enabled: true + standardPII: true + + # Health/metrics HTTP server port + serverPort: 8081 + + # Base path for K8s secret volume mounts inside the pod + secretsPath: "/etc/nofire/secrets" + + # Service configuration + service: + type: ClusterIP + port: 8081 + annotations: {} + + # Probes + livenessProbe: + httpGet: + path: /healthz + port: 8081 + initialDelaySeconds: 15 + periodSeconds: 10 + readinessProbe: + httpGet: + path: /healthz + port: 8081 + initialDelaySeconds: 5 + periodSeconds: 5 + +# On-premises connections map (used when edgeProxy.enabled: true) +# +# Supported types: prometheus, loki, tempo, grafana, elasticsearch, +# open_search, mongodb_atlas, datadog, cloudwatch, google_cloud_logs, +# jaeger, alertmanager, github, gitlab, bitbucket, slack, custom_http, postgres +# +# Each connection supports: +# type: (required) backend type from list above +# enabled: (optional, default: true) whether connection is active +# name: (optional, default: key name) human-friendly display name +# secretName: (optional) K8s secret name for credentials (username/password/token) +# url: (required for most types) backend service base URL +# orgId: (optional) Loki multi-tenant org ID (X-Scope-OrgID header) +# index: (optional) Elasticsearch/OpenSearch index pattern +# datasourceUID: (optional) Tempo datasource UID +# tlsEnabled: (optional) enable TLS for backend connection +# tlsSkipVerify: (optional) skip backend TLS certificate verification +# caCertPath: (optional) path to CA cert for backend TLS verification +# +# Postgres connections use DB fields instead of url: +# dbHost: (required) database hostname +# dbPort: (optional, default: 5432) database port +# dbName: (required) database name +# dbSSLMode: (optional) sslmode (e.g. disable, require, verify-full) +# +# Example: +# onPremConnections: +# prod-prometheus: +# type: prometheus +# enabled: true +# name: "Production Prometheus" +# secretName: prometheus-creds +# url: "http://prometheus:9090" +# prod-loki: +# type: loki +# enabled: true +# name: "Production Loki" +# secretName: loki-creds +# url: "http://loki:3100" +# orgId: "tenant1" +# prod-postgres: +# type: postgres +# enabled: true +# name: "Production Postgres" +# secretName: postgres-creds +# dbHost: "postgres.default.svc.cluster.local" +# dbPort: 5432 +# dbName: "app" +# dbSSLMode: "require" +# internal-api: +# type: custom_http +# enabled: true +# name: "Internal API" +# secretName: internal-api-creds +# url: "https://api.internal.example.com" +# dashboard: onPremConnections.prometheus.* +onPremConnections: + prometheus: + type: prometheus + url: http://prometheus.monitoring:9090 + enabled: true From 2f9163cc503f0ce603d881dc06861ed067012872 Mon Sep 17 00:00:00 2001 From: Stelios Charmpalis Date: Fri, 13 Nov 2026 12:59:47 +0200 Subject: [PATCH 04/10] ci(release): read latest.json with the role and write it conditionally Review on #28 found two ways latest.json could go wrong without a failed step: - The anonymous read took any 403 as "no latest.json yet". S3 also answers 403 when the file exists but cannot be read, so a backfill could replace a newer version with an older one. The role now reads it from S3 and can list the bucket, so only NoSuchKey means absent and any other error fails the step. - Two releases close together both read the same latest.json and the last writer won, even when it was the older version. The write now carries the ETag it read (or If-None-Match when there was none); the loser of a race reads again and compares again, up to five times. Also install yq pinned as ci.yaml does instead of relying on the runner image, keep scratch files in RUNNER_TEMP so they can never be packaged, treat a latest.json without chart.version as empty, and name the render case alongside the unit suite as the gate. Needs s3:GetObject and s3:ListBucket on the role (NOFireAI/terraform#301). Refs: #27 Signed-off-by: Stelios Charmpalis --- .github/workflows/release.yml | 86 ++++++++++++++++++++++++----------- 1 file changed, 59 insertions(+), 27 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 82089b2..5522c8d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -109,13 +109,19 @@ jobs: # Release metadata for the NOFire AI dashboard (NOFireAI/engineering#1983). # The dashboard reads edge/latest.json at https://releases.nofire.ai to pick # the chart version its install commands use, so writing it is what ships - # a chart release to customers. tests/dashboard_install_test.yaml is the - # gate for that. + # a chart release to customers. tests/dashboard_install_test.yaml and the + # dashboard-reuse-from-0.9.0 render case, run by ci.yaml, are the gate. # # These steps run on every run, not only when a release was created, and # each write is idempotent: a re-run changes nothing, and a manual run # publishes a release that predates them. They are skipped until the # RELEASE_METADATA_ROLE_ARN repository variable is set. + - name: Install yq + if: vars.RELEASE_METADATA_ROLE_ARN != '' + run: | + sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/v4.44.3/yq_linux_amd64 + sudo chmod +x /usr/local/bin/yq + - name: Wait for the Helm repo index if: vars.RELEASE_METADATA_ROLE_ARN != '' env: @@ -151,6 +157,10 @@ jobs: BUCKET: releases.nofire.ai run: | set -euo pipefail + # Scratch files live outside the checkout, so nothing here can end up in a + # chart package. + work="$RUNNER_TEMP/release-metadata" + mkdir -p "$work" app_version="$(yq -r '.appVersion' Chart.yaml)" tag="$(yq -r '.image.tag // ""' values.yaml)" tag="${tag:-$app_version}" @@ -171,42 +181,64 @@ jobs: edge: {version: $appVersion, images: {edge: $edge, edgeProxy: $edgeProxy}}, releasedAt: $release.publishedAt, releaseUrl: $release.url - }' > metadata.json - cat metadata.json + }' > "$work/metadata.json" + cat "$work/metadata.json" # The versioned file is immutable: written once, never replaced. if aws s3api put-object --bucket "$BUCKET" --key "edge/$VERSION.json" \ - --body metadata.json --content-type application/json \ + --body "$work/metadata.json" --content-type application/json \ --cache-control 'public, max-age=31536000, immutable' \ - --if-none-match '*' >/dev/null 2>err.txt; then + --if-none-match '*' >/dev/null 2>"$work/err.txt"; then echo "wrote edge/$VERSION.json" - elif grep -q PreconditionFailed err.txt; then + elif grep -q PreconditionFailed "$work/err.txt"; then echo "edge/$VERSION.json already exists" else - cat err.txt + cat "$work/err.txt" exit 1 fi - # latest.json only moves forward, and never to a pre-release. Read it - # from S3 rather than through Cloudflare, so a cached copy cannot hide - # a newer version. A missing key is a 403: the bucket allows no listing. + # latest.json only moves forward, and never to a pre-release. case "$VERSION" in *-*) echo "$VERSION is a pre-release, leaving latest.json alone" exit 0 esac - code="$(curl -sS -o latest.json -w '%{http_code}' \ - "https://s3.us-east-1.amazonaws.com/$BUCKET/edge/latest.json")" - case "$code" in - 200) current="$(jq -r '.chart.version' latest.json)" ;; - 403|404) current="" ;; - *) echo "::error::reading latest.json returned HTTP $code"; exit 1 ;; - esac - if [ -n "$current" ] && \ - [ "$(printf '%s\n%s\n' "$current" "$VERSION" | sort -V | tail -1)" = "$current" ]; then - echo "latest.json holds $current, not replacing it with $VERSION" - exit 0 - fi - aws s3api put-object --bucket "$BUCKET" --key edge/latest.json \ - --body metadata.json --content-type application/json \ - --cache-control 'public, max-age=300' >/dev/null - echo "latest.json now holds $VERSION (was ${current:-nothing})" + + # Read it with the role, from S3 rather than through Cloudflare, so a cached + # copy cannot hide a newer version. The role can list the bucket, so a missing + # key is NoSuchKey; any other error, AccessDenied included, fails the step + # instead of passing for "no latest.json yet". The write only lands if + # latest.json still holds what was read (its ETag, or nothing), so of two + # releases racing, the one that loses reads again and compares again. + for _ in 1 2 3 4 5; do + if aws s3api get-object --bucket "$BUCKET" --key edge/latest.json \ + "$work/latest.json" >"$work/get.json" 2>"$work/err.txt"; then + current="$(jq -r '.chart.version // ""' "$work/latest.json")" + condition=(--if-match "$(jq -r '.ETag' "$work/get.json")") + elif grep -q NoSuchKey "$work/err.txt"; then + current="" + condition=(--if-none-match '*') + else + cat "$work/err.txt" + exit 1 + fi + if [ -n "$current" ] && \ + [ "$(printf '%s\n%s\n' "$current" "$VERSION" | sort -V | tail -1)" = "$current" ]; then + echo "latest.json holds $current, not replacing it with $VERSION" + exit 0 + fi + if aws s3api put-object --bucket "$BUCKET" --key edge/latest.json \ + --body "$work/metadata.json" --content-type application/json \ + --cache-control 'public, max-age=300' "${condition[@]}" \ + >/dev/null 2>"$work/err.txt"; then + echo "latest.json now holds $VERSION (was ${current:-nothing})" + exit 0 + fi + if ! grep -Eq 'PreconditionFailed|ConditionalRequestConflict' "$work/err.txt"; then + cat "$work/err.txt" + exit 1 + fi + echo "latest.json changed while this run read it, reading it again" + sleep 3 + done + echo "::error::latest.json kept changing, gave up after 5 attempts" + exit 1 From a3d886cc775f0a5236f2691a820685aaa464169d Mon Sep 17 00:00:00 2001 From: Stelios Charmpalis Date: Fri, 13 Nov 2026 12:59:47 +0200 Subject: [PATCH 05/10] test(render): say what the dashboard reuse case does and does not assert expect.jq checks config.json only; the edge-proxy values in the case prove those templates render, and the unit suite asserts their content. Refs: #27 Signed-off-by: Stelios Charmpalis --- tests/render/cases/dashboard-reuse-from-0.9.0/values.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/render/cases/dashboard-reuse-from-0.9.0/values.yaml b/tests/render/cases/dashboard-reuse-from-0.9.0/values.yaml index d4febbb..93f5bcf 100644 --- a/tests/render/cases/dashboard-reuse-from-0.9.0/values.yaml +++ b/tests/render/cases/dashboard-reuse-from-0.9.0/values.yaml @@ -4,6 +4,10 @@ # templates against exactly this, which is what the dashboard's step 5 and # disconnect commands do once they follow the published chart version # (NOFireAI/engineering#1983). +# +# expect.jq checks config.json only. The edgeProxy and onPremConnections values +# below prove the edge-proxy templates still render against them (a render error +# fails this case); tests/dashboard_install_test.yaml asserts what they render. # Default values for nofire-edge. # This is a YAML-formatted file. # Declare variables to be passed into your templates. From e81e47b8428bac6bbb866b2079f64f6bd11063ab Mon Sep 17 00:00:00 2001 From: Stelios Charmpalis Date: Fri, 13 Nov 2026 13:22:16 +0200 Subject: [PATCH 06/10] ci(release): treat a conflicting versioned write like an existing one S3 answers a concurrent conditional write with 409 ConditionalRequestConflict rather than 412. The latest.json write already accepted both; the versioned write failed the run on 409 and never reached latest.json. Refs: #27 Signed-off-by: Stelios Charmpalis --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5522c8d..a1e6d51 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -190,8 +190,8 @@ jobs: --cache-control 'public, max-age=31536000, immutable' \ --if-none-match '*' >/dev/null 2>"$work/err.txt"; then echo "wrote edge/$VERSION.json" - elif grep -q PreconditionFailed "$work/err.txt"; then - echo "edge/$VERSION.json already exists" + elif grep -Eq 'PreconditionFailed|ConditionalRequestConflict' "$work/err.txt"; then + echo "edge/$VERSION.json already exists, or another run is writing it" else cat "$work/err.txt" exit 1 From e7d903ac2be88a15ed7dae2f923d400fb5b0e30a Mon Sep 17 00:00:00 2001 From: Stelios Charmpalis Date: Fri, 13 Nov 2026 13:42:00 +0200 Subject: [PATCH 07/10] ci(release): fail before publishing metadata with a missing field edge/.json is written once and never replaced. Without a guard, a values.yaml missing an image repository would publish "null:" into it for good. Read appVersion and both repositories with `// ""` and fail the step before any write if one is empty. Refs: #27 Signed-off-by: Stelios Charmpalis --- .github/workflows/release.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a1e6d51..8792f7f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -161,19 +161,29 @@ jobs: # chart package. work="$RUNNER_TEMP/release-metadata" mkdir -p "$work" - app_version="$(yq -r '.appVersion' Chart.yaml)" + app_version="$(yq -r '.appVersion // ""' Chart.yaml)" tag="$(yq -r '.image.tag // ""' values.yaml)" tag="${tag:-$app_version}" proxy_tag="$(yq -r '.edgeProxy.image.tag // ""' values.yaml)" proxy_tag="${proxy_tag:-$tag}" + edge_repo="$(yq -r '.image.repository // ""' values.yaml)" + proxy_repo="$(yq -r '.edgeProxy.image.repository // ""' values.yaml)" + # edge/.json is written once and never replaced, so a missing + # field fails here rather than shipping as an empty or "null" image. + for field in "$app_version" "$tag" "$edge_repo" "$proxy_repo"; do + if [ -z "$field" ]; then + echo "::error::Chart.yaml appVersion or an image repository is missing" + exit 1 + fi + done release="$(gh release view "$NAME-$VERSION" --json publishedAt,url)" jq -n \ --arg name "$NAME" \ --arg version "$VERSION" \ --arg appVersion "$app_version" \ - --arg edge "$(yq -r '.image.repository' values.yaml):$tag" \ - --arg edgeProxy "$(yq -r '.edgeProxy.image.repository' values.yaml):$proxy_tag" \ + --arg edge "$edge_repo:$tag" \ + --arg edgeProxy "$proxy_repo:$proxy_tag" \ --argjson release "$release" \ '{ schema: 1, From a4cfaa9a93958064c5c5d3a1d4c1e23334e48572 Mon Sep 17 00:00:00 2001 From: Stelios Charmpalis Date: Fri, 13 Nov 2026 13:59:48 +0200 Subject: [PATCH 08/10] ci(release): publish release metadata from its own job, with no downloads Review on #28: the job downloaded an unpinned yq binary next to a write token, and the publishing logic was some 70 lines of escaped shell in the workflow. - The release job is back to what it is on main. A new publish-metadata job, after it, holds the only id-token: write and has contents: read, so the AWS role's token never shares a job with the release's write token. configure-aws-credentials is pinned to a commit. - The logic moves into .github/scripts/publish_release_metadata.py, standard library only, calling tools the runner image already ships (aws, gh, helm). It reads the chart name, version and appVersion from Chart.yaml, and waits for the version with `helm show chart --version`, the lookup a customer's `helm repo update` makes. - The metadata drops the image names: the dashboard reads only chart.version, and from 0.6.0 the images follow appVersion. Behaviour is otherwise unchanged: edge/.json written once, latest.json read with the role and written conditionally on its ETag, only forward, never to a pre-release. Refs: #27 Signed-off-by: Stelios Charmpalis --- .github/scripts/publish_release_metadata.py | 142 +++++++++++++++++ .github/workflows/release.yml | 160 +++----------------- 2 files changed, 163 insertions(+), 139 deletions(-) create mode 100755 .github/scripts/publish_release_metadata.py diff --git a/.github/scripts/publish_release_metadata.py b/.github/scripts/publish_release_metadata.py new file mode 100755 index 0000000..5e1224d --- /dev/null +++ b/.github/scripts/publish_release_metadata.py @@ -0,0 +1,142 @@ +#!/usr/bin/env python3 +"""Publish Edge release metadata to releases.nofire.ai (NOFireAI/engineering#1983). + +The NOFire AI dashboard reads edge/latest.json to pick the chart version its +install commands use. For the chart version in Chart.yaml this: + +1. waits until the Helm repo serves it, so latest.json never names a version + `helm repo update` cannot find yet; +2. writes edge/.json once (never replaced); +3. moves edge/latest.json to , unless it already names the same or a + newer version, or is a pre-release. + +Safe to re-run. Uses only the standard library and the tools on the runner: +the AWS CLI (credentials for the release metadata role), gh and helm. + +Run from the chart's root: python3 .github/scripts/publish_release_metadata.py +""" + +import json +import subprocess +import sys +import tempfile +import time +from pathlib import Path + +BUCKET = "releases.nofire.ai" +CHART_REPO = "https://nofireai.github.io/edge-helm-chart" + + +def run(*cmd): + return subprocess.run(cmd, capture_output=True, text=True) + + +def fail(message, result=None): + sys.exit(f"::error::{message}" + (f"\n{result.stderr}" if result else "")) + + +def chart_field(key): + """A top-level scalar from Chart.yaml, e.g. appVersion.""" + for line in Path("Chart.yaml").read_text().splitlines(): + name, _, value = line.partition(":") + if name == key and value.strip(): + return value.strip().strip("\"'") + fail(f"Chart.yaml has no {key}") + + +def parse_version(version): + """(major, minor, patch) for a plain x.y.z, else None.""" + parts = version.split(".") if isinstance(version, str) else [] + if len(parts) != 3 or not all(p.isdigit() for p in parts): + return None + return tuple(int(p) for p in parts) + + +def wait_for_helm_repo(name, version): + # GitHub Pages deploys after the gh-pages push; give it 10 minutes. + run("helm", "repo", "add", "--force-update", "nofire", CHART_REPO) + for _ in range(40): + run("helm", "repo", "update", "nofire") + if run("helm", "show", "chart", f"nofire/{name}", "--version", version).returncode == 0: + return + time.sleep(15) + fail(f"{name} {version} is not in the Helm repo after 10 minutes") + + +def s3(*args): + return run("aws", "s3api", *args, "--bucket", BUCKET) + + +def put(key, body, cache_control, *condition): + return s3("put-object", "--key", key, "--body", body, + "--content-type", "application/json", + "--cache-control", cache_control, *condition) + + +def lost_race(result): + # S3's answer when a conditional write's condition no longer holds. + return "PreconditionFailed" in result.stderr or "ConditionalRequestConflict" in result.stderr + + +def main(): + name, version = chart_field("name"), chart_field("version") + wait_for_helm_repo(name, version) + + release = run("gh", "release", "view", f"{name}-{version}", "--json", "publishedAt,url") + if release.returncode != 0: + fail(f"no GitHub release {name}-{version}", release) + release = json.loads(release.stdout) + + work = Path(tempfile.mkdtemp()) + body = work / "metadata.json" + body.write_text(json.dumps({ + "schema": 1, + "chart": {"name": name, "version": version, "repo": CHART_REPO}, + "edge": {"version": chart_field("appVersion")}, + "releasedAt": release["publishedAt"], + "releaseUrl": release["url"], + }, indent=2) + "\n") + print(body.read_text()) + + result = put(f"edge/{version}.json", str(body), + "public, max-age=31536000, immutable", "--if-none-match", "*") + if result.returncode != 0 and not lost_race(result): + fail(f"writing edge/{version}.json failed", result) + print(f"edge/{version}.json is published") + + new = parse_version(version) + if new is None: + print(f"{version} is not a plain release, leaving latest.json alone") + return + + # Read with the role, from S3 rather than through Cloudflare's cache. Only + # NoSuchKey means there is no latest.json; any other error stops here. The + # write only lands if latest.json still holds what was read, so of two + # releases racing, the loser reads again and compares again. + current_file = work / "latest.json" + for _ in range(5): + result = s3("get-object", "--key", "edge/latest.json", str(current_file)) + if result.returncode == 0: + current = json.loads(current_file.read_text()).get("chart", {}).get("version") + condition = ("--if-match", json.loads(result.stdout)["ETag"]) + elif "NoSuchKey" in result.stderr: + current, condition = None, ("--if-none-match", "*") + else: + fail("reading edge/latest.json failed", result) + + held = parse_version(current) + if held is not None and held >= new: + print(f"latest.json holds {current}, leaving it") + return + result = put("edge/latest.json", str(body), "public, max-age=300", *condition) + if result.returncode == 0: + print(f"latest.json now holds {version} (was {current or 'nothing'})") + return + if not lost_race(result): + fail("writing edge/latest.json failed", result) + print("latest.json changed while this ran, reading it again") + fail("latest.json kept changing, gave up after 5 attempts") + + +if __name__ == "__main__": + main() diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8792f7f..babe4c1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,8 +13,6 @@ jobs: runs-on: ubuntu-latest permissions: contents: write - # OIDC token for the release metadata role (NOFireAI/terraform#295). - id-token: write steps: - name: Checkout uses: actions/checkout@v4 @@ -106,149 +104,33 @@ jobs: git commit -m "chore(release): ${{ steps.chart.outputs.name }}-${{ steps.chart.outputs.version }}" git push - # Release metadata for the NOFire AI dashboard (NOFireAI/engineering#1983). - # The dashboard reads edge/latest.json at https://releases.nofire.ai to pick - # the chart version its install commands use, so writing it is what ships - # a chart release to customers. tests/dashboard_install_test.yaml and the - # dashboard-reuse-from-0.9.0 render case, run by ci.yaml, are the gate. - # - # These steps run on every run, not only when a release was created, and - # each write is idempotent: a re-run changes nothing, and a manual run - # publishes a release that predates them. They are skipped until the - # RELEASE_METADATA_ROLE_ARN repository variable is set. - - name: Install yq - if: vars.RELEASE_METADATA_ROLE_ARN != '' - run: | - sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/v4.44.3/yq_linux_amd64 - sudo chmod +x /usr/local/bin/yq - - - name: Wait for the Helm repo index - if: vars.RELEASE_METADATA_ROLE_ARN != '' - env: - VERSION: ${{ steps.chart.outputs.version }} - NAME: ${{ steps.chart.outputs.name }} - run: | - # GitHub Pages deploys after the push. latest.json must not name a - # version `helm repo update` cannot find yet. - for _ in $(seq 1 40); do - if curl -sSfL https://nofireai.github.io/edge-helm-chart/index.yaml \ - | yq -e ".entries[\"$NAME\"][] | select(.version == \"$VERSION\")" >/dev/null 2>&1; then - echo "$NAME $VERSION is in the index" - exit 0 - fi - sleep 15 - done - echo "::error::$NAME $VERSION did not appear in index.yaml within 10 minutes" - exit 1 + # Release metadata for the NOFire AI dashboard (NOFireAI/engineering#1983): it + # reads edge/latest.json at https://releases.nofire.ai to pick the chart + # version customers install, and tests/dashboard_install_test.yaml is the gate. + # A job of its own, so the AWS role's OIDC token never shares a job with the + # release's write token. Runs on every run (each write is idempotent); skipped + # until the RELEASE_METADATA_ROLE_ARN repository variable is set. aws, gh, helm + # and python3 come with the runner image. + publish-metadata: + needs: release + if: vars.RELEASE_METADATA_ROLE_ARN != '' + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + persist-credentials: false - name: Configure AWS credentials - if: vars.RELEASE_METADATA_ROLE_ARN != '' - uses: aws-actions/configure-aws-credentials@v4 + uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a # v4.3.1 with: role-to-assume: ${{ vars.RELEASE_METADATA_ROLE_ARN }} aws-region: us-east-1 - name: Publish release metadata - if: vars.RELEASE_METADATA_ROLE_ARN != '' env: GH_TOKEN: ${{ github.token }} - NAME: ${{ steps.chart.outputs.name }} - VERSION: ${{ steps.chart.outputs.version }} - BUCKET: releases.nofire.ai - run: | - set -euo pipefail - # Scratch files live outside the checkout, so nothing here can end up in a - # chart package. - work="$RUNNER_TEMP/release-metadata" - mkdir -p "$work" - app_version="$(yq -r '.appVersion // ""' Chart.yaml)" - tag="$(yq -r '.image.tag // ""' values.yaml)" - tag="${tag:-$app_version}" - proxy_tag="$(yq -r '.edgeProxy.image.tag // ""' values.yaml)" - proxy_tag="${proxy_tag:-$tag}" - edge_repo="$(yq -r '.image.repository // ""' values.yaml)" - proxy_repo="$(yq -r '.edgeProxy.image.repository // ""' values.yaml)" - # edge/.json is written once and never replaced, so a missing - # field fails here rather than shipping as an empty or "null" image. - for field in "$app_version" "$tag" "$edge_repo" "$proxy_repo"; do - if [ -z "$field" ]; then - echo "::error::Chart.yaml appVersion or an image repository is missing" - exit 1 - fi - done - release="$(gh release view "$NAME-$VERSION" --json publishedAt,url)" - - jq -n \ - --arg name "$NAME" \ - --arg version "$VERSION" \ - --arg appVersion "$app_version" \ - --arg edge "$edge_repo:$tag" \ - --arg edgeProxy "$proxy_repo:$proxy_tag" \ - --argjson release "$release" \ - '{ - schema: 1, - chart: {name: $name, version: $version, repo: "https://nofireai.github.io/edge-helm-chart"}, - edge: {version: $appVersion, images: {edge: $edge, edgeProxy: $edgeProxy}}, - releasedAt: $release.publishedAt, - releaseUrl: $release.url - }' > "$work/metadata.json" - cat "$work/metadata.json" - - # The versioned file is immutable: written once, never replaced. - if aws s3api put-object --bucket "$BUCKET" --key "edge/$VERSION.json" \ - --body "$work/metadata.json" --content-type application/json \ - --cache-control 'public, max-age=31536000, immutable' \ - --if-none-match '*' >/dev/null 2>"$work/err.txt"; then - echo "wrote edge/$VERSION.json" - elif grep -Eq 'PreconditionFailed|ConditionalRequestConflict' "$work/err.txt"; then - echo "edge/$VERSION.json already exists, or another run is writing it" - else - cat "$work/err.txt" - exit 1 - fi - - # latest.json only moves forward, and never to a pre-release. - case "$VERSION" in *-*) - echo "$VERSION is a pre-release, leaving latest.json alone" - exit 0 - esac - - # Read it with the role, from S3 rather than through Cloudflare, so a cached - # copy cannot hide a newer version. The role can list the bucket, so a missing - # key is NoSuchKey; any other error, AccessDenied included, fails the step - # instead of passing for "no latest.json yet". The write only lands if - # latest.json still holds what was read (its ETag, or nothing), so of two - # releases racing, the one that loses reads again and compares again. - for _ in 1 2 3 4 5; do - if aws s3api get-object --bucket "$BUCKET" --key edge/latest.json \ - "$work/latest.json" >"$work/get.json" 2>"$work/err.txt"; then - current="$(jq -r '.chart.version // ""' "$work/latest.json")" - condition=(--if-match "$(jq -r '.ETag' "$work/get.json")") - elif grep -q NoSuchKey "$work/err.txt"; then - current="" - condition=(--if-none-match '*') - else - cat "$work/err.txt" - exit 1 - fi - if [ -n "$current" ] && \ - [ "$(printf '%s\n%s\n' "$current" "$VERSION" | sort -V | tail -1)" = "$current" ]; then - echo "latest.json holds $current, not replacing it with $VERSION" - exit 0 - fi - if aws s3api put-object --bucket "$BUCKET" --key edge/latest.json \ - --body "$work/metadata.json" --content-type application/json \ - --cache-control 'public, max-age=300' "${condition[@]}" \ - >/dev/null 2>"$work/err.txt"; then - echo "latest.json now holds $VERSION (was ${current:-nothing})" - exit 0 - fi - if ! grep -Eq 'PreconditionFailed|ConditionalRequestConflict' "$work/err.txt"; then - cat "$work/err.txt" - exit 1 - fi - echo "latest.json changed while this run read it, reading it again" - sleep 3 - done - echo "::error::latest.json kept changing, gave up after 5 attempts" - exit 1 + run: python3 -u .github/scripts/publish_release_metadata.py From 2f68deff194fd2422a87519888bc8176bd29374b Mon Sep 17 00:00:00 2001 From: Stelios Charmpalis Date: Fri, 13 Nov 2026 13:59:48 +0200 Subject: [PATCH 09/10] test(render): drop the dashboard reuse case It copied 0.9.0's values.yaml to show that a --reuse-values upgrade still renders, but its expect.jq only re-checked config.json, which tests/dashboard_install_test.yaml already asserts. It would also need a new copy for every chart version worth testing from. Refs: #27 Signed-off-by: Stelios Charmpalis --- .../dashboard-reuse-from-0.9.0/expect.jq | 3 - .../dashboard-reuse-from-0.9.0/replace-values | 0 .../dashboard-reuse-from-0.9.0/values.yaml | 534 ------------------ 3 files changed, 537 deletions(-) delete mode 100644 tests/render/cases/dashboard-reuse-from-0.9.0/expect.jq delete mode 100644 tests/render/cases/dashboard-reuse-from-0.9.0/replace-values delete mode 100644 tests/render/cases/dashboard-reuse-from-0.9.0/values.yaml diff --git a/tests/render/cases/dashboard-reuse-from-0.9.0/expect.jq b/tests/render/cases/dashboard-reuse-from-0.9.0/expect.jq deleted file mode 100644 index 715e724..0000000 --- a/tests/render/cases/dashboard-reuse-from-0.9.0/expect.jq +++ /dev/null @@ -1,3 +0,0 @@ -.publisher.apiKey == "dash-test-token" -and .kube.clusterName == "dash-test-cluster" -and .netobs.enabled == true diff --git a/tests/render/cases/dashboard-reuse-from-0.9.0/replace-values b/tests/render/cases/dashboard-reuse-from-0.9.0/replace-values deleted file mode 100644 index e69de29..0000000 diff --git a/tests/render/cases/dashboard-reuse-from-0.9.0/values.yaml b/tests/render/cases/dashboard-reuse-from-0.9.0/values.yaml deleted file mode 100644 index 93f5bcf..0000000 --- a/tests/render/cases/dashboard-reuse-from-0.9.0/values.yaml +++ /dev/null @@ -1,534 +0,0 @@ -# The 0.9.0 chart's values.yaml, verbatim except for what the dashboard set on -# that release (marked "dashboard:"): the step 4 install, then the step 5 -# sources. `helm upgrade --reuse-values` to a newer chart renders the new -# templates against exactly this, which is what the dashboard's step 5 and -# disconnect commands do once they follow the published chart version -# (NOFireAI/engineering#1983). -# -# expect.jq checks config.json only. The edgeProxy and onPremConnections values -# below prove the edge-proxy templates still render against them (a render error -# fails this case); tests/dashboard_install_test.yaml asserts what they render. -# Default values for nofire-edge. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -# Image configuration -image: - repository: nofireai/edge - pullPolicy: Always - # Overrides the image tag, which otherwise defaults to the chart appVersion. - # Released tags carry the "v" prefix (nofireai/edge:v3.9.0); a bare "3.9.0" - # does not exist in the registry. - tag: "v3.9.0" - -# Image pull secrets -imagePullSecrets: [] - -# Override name and fullname -nameOverride: "" -fullnameOverride: "" - -# Number of replicas -replicaCount: 1 - -# Deployment strategy -strategy: - type: RollingUpdate - rollingUpdate: - maxUnavailable: 1 - maxSurge: 1 - -# Service account configuration -serviceAccount: - # Specifies whether a service account should be created - create: true - # Annotations to add to the service account - annotations: {} - # The name of the service account to use. - # If not set and create is true, a name is generated using the fullname template - name: "" - -# RBAC configuration -rbac: - # Specifies whether RBAC resources should be created - create: true - # Additional cluster role rules - extraRules: [] - -# Pod annotations -podAnnotations: {} - -# Pod labels -podLabels: {} - -# Pod security context -podSecurityContext: - {} - # fsGroup: 2000 - -# Security context for containers -securityContext: - {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -# Service configuration -service: - type: ClusterIP - # clusterIP: "" # Optional: Set a static ClusterIP - port: 8080 - dnstapPort: 6000 - targetPort: 8080 - annotations: {} - -# Ingress configuration -ingress: - enabled: false - className: "" - annotations: {} - # kubernetes.io/ingress.class: nginx - # kubernetes.io/tls-acme: "true" - hosts: - - host: k8s-resource-graph-client.local - paths: - - path: / - pathType: Prefix - tls: [] - # - secretName: chart-example-tls - # hosts: - # - chart-example.local - -# Resource limits and requests -resources: - limits: - cpu: 200m - memory: 256Mi - requests: - cpu: 100m - memory: 128Mi - -# Horizontal Pod Autoscaler -autoscaling: - enabled: false - minReplicas: 1 - maxReplicas: 100 - targetCPUUtilizationPercentage: 80 - # targetMemoryUtilizationPercentage: 80 - -# Node selector -nodeSelector: {} - -# Tolerations -tolerations: [] - -# Affinity -affinity: {} - -# Topology spread constraints -topologySpreadConstraints: [] - -# Pod disruption budget -podDisruptionBudget: - enabled: false - minAvailable: 1 - # maxUnavailable: 1 - -# Liveness probe configuration -livenessProbe: - httpGet: - path: /healthz - port: http - initialDelaySeconds: 30 - periodSeconds: 10 - timeoutSeconds: 5 - failureThreshold: 3 - -# Readiness probe configuration -readinessProbe: - httpGet: - path: /healthz - port: http - initialDelaySeconds: 5 - periodSeconds: 10 - timeoutSeconds: 5 - failureThreshold: 3 - -# Monitoring configuration -monitoring: - # Enable ServiceMonitor for Prometheus Operator - serviceMonitor: - enabled: false - namespace: "" - labels: - release: prometheus - annotations: {} - interval: 30s - path: /metrics - targetLabels: [] - metricRelabelings: [] - relabelings: [] - -# Client configuration -config: - # Logging configuration - logLevel: "info" - - # Server configuration - serverPort: 8080 - - # Sentry configuration - sentry: - dsn: "https://0d3d5e19f07e0173eaadeb930a405150@o4507775482789888.ingest.de.sentry.io/4510431321718864" - environment: "production" - release: "" - debug: false - sampleRate: 1.0 - tracesSampleRate: 0.2 - - - # Graph configuration - graph: - pruneInterval: "1h" - maxPruneAge: "24h" - - # Kubernetes configuration - kube: - configPath: "" - resyncInterval: "5m" - clusterName: "dash-test-cluster" # dashboard: config.kube.clusterName - resources: - - "pods" - - "nodes" - - "k8services" - - "endpoints" - - "configmaps" - - "secrets" - - "persistentvolumeclaims" - - "persistentvolumes" - - "deployments" - - "replicasets" - - "statefulsets" - - "daemonsets" - - "jobs" - - "ingresses" - - "ingressclasses" - - "gatewayclasses" - - "gateways" - - "httproutes" - - "grpcroutes" - - "tlsroutes" - - "tcproutes" - - "udproutes" - - "referencegrants" - - "ingressroutes" - - "ingressroutetcps" - - "ingressrouteudps" - - "traefikservices" - - "namespaces" - - "services" - # Opt-in kinds, off by default. The ClusterRole already grants get, list - # and watch on them. The three calico* kinds also need Calico's CRDs - # (crd.projectcalico.org/v1) installed in the cluster; the agent skips - # them otherwise, just as it skips the Gateway API - # (gateway.networking.k8s.io) and Traefik (traefik.io/v1alpha1 or - # traefik.containo.us/v1alpha1) routing kinds above when their CRDs are - # absent. - # - "cronjobs" - # - "priorityclasses" - # - "roles" - # - "clusterroles" - # - "rolebindings" - # - "clusterrolebindings" - # - "calicoippools" - # - "calicobgppeers" - # - "calicoipamconfigs" - # Restrict which namespaces enter the resource graph. Unset (or mode "none") - # means every namespace is graphed. The chart fails the render on invalid - # combinations, mirroring the Edge's own validation: - # - namespaces set with mode unset/""/"none" - # - mode "allow" or "deny" with an empty namespaces list - # - any other mode - # namespaceFilter: - # mode: allow # allow | deny | none - # namespaces: - # - production - # - staging - # Causal analysis configuration - enableCausalAnalysis: false - causal: - algorithm: "counterfactual" - interval: "15m" - - # Services configuration - services: - workers: 4 - # Keys you leave out use the Edge defaults shown below (set a key to override - # it; partial tls/compression/handshake objects are merged into the defaults). - # DNSTap listens on :6000 even when address is unset (matches service.dnstapPort). - # address: ":6000" - # maxConns: 100 - # readTimeout: "30s" - # writeTimeout: "10s" - # tls: - # enabled: false - # certFile: "/etc/nofire/certs/tls.crt" - # keyFile: "/etc/nofire/certs/tls.key" - # caFile: "/etc/nofire/certs/ca.crt" - # requireClientCert: false - # minVersion: "1.2" - # cipherSuites: # setting this replaces the default list - # - TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 - # - TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 - # - TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 - # - TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 - # compression: - # enabled: true - # type: "gzip" # none | gzip - # level: -1 - # handshake: - # timeout: "10s" - # contentType: "protobuf:dnstap.Dnstap" - - # Network observability — L7 dependency detection via Hubble, Istio, or Caretta. - # Auto-detects available source when source is empty (hubble > istio > caretta). - netobs: - enabled: true # dashboard: config.netobs.enabled - interval: "60s" - prometheusUrl: "" # empty = in-cluster discovery - source: "" # empty = auto-detect; or "hubble" | "istio" | "caretta" - prometheusTimeout: "10s" - # How long a network edge is kept after it stops being observed (Edge default: 2h). - # edgeExistenceTtl: "2h" - # Namespaces whose network flows are dropped before collection. Edge default: - # [kube-system, monitoring]. Setting this REPLACES the default, it does not - # append (use [] to exclude nothing). Namespaces listed in a deny-mode - # kube.namespaceFilter are added by the Edge on top of this list. - # excludeNamespaces: - # - kube-system - # - monitoring - - # Publishing configuration - enablePublishing: true - publisher: - # REQUIRED: API key for authentication (must be set to a valid value) - # apiKey: "your-api-key-here" - apiKey: "dash-test-token" # dashboard: config.publisher.apiKey - # Source the API key from an existing Secret (via the NOFIRE_API_KEY env var) - # instead of baking apiKey into the config.json ConfigMap in plaintext. When - # enabled the chart does NOT render templates/secret.yaml — the named Secret is - # expected to already exist (e.g. created by External Secrets Operator). - apiKeySecret: - enabled: false - name: nofire-credentials - key: api-key - timeout: "30s" - maxRetries: 3 - retryDelay: "5s" - enableCompression: true - graph: - url: "https://my.nofire.ai/api/edge" - interval: "5m" - heartbeat: - url: "" - interval: "10s" - - # ConfigMap value capture. Hash-by-default so raw customer configuration never - # leaves the cluster. Set clearText: true to send values verbatim (still - # subject to redactKeyPatterns and captureCap). - configMapCapture: - # false (default): every ConfigMap value is sent as a sha256 hash. - # true: values are sent in the clear, except keys matching redactKeyPatterns. - clearText: false - # In clear-text mode, ConfigMap data keys matching any of these regexes are - # hashed instead of sent verbatim (e.g. secrets embedded in a ConfigMap). - redactKeyPatterns: [] - # - "(?i)(password|passwd|secret|token|apikey|api_key|private_key)" - # Per-value byte cap for clear-text values. Values over the cap are trimmed - # (Brain is told the value was trimmed). Hashes always cover the full value. - # 0, negative or unset uses the Edge default of 4096. - captureCap: 4096 - - # Container env-var value capture. Hash-by-default so a plaintext credential in - # an env var never leaves the cluster. Same model as configMapCapture. - envCapture: - # false (default): every literal env value is sent as a sha256 hash. - # true: literal values are sent in the clear, except names matching redactKeyPatterns. - clearText: false - # In clear-text mode, env var names matching any of these regexes stay hashed. - redactKeyPatterns: [] - # - "(?i)(password|passwd|secret|token|apikey|api_key|private_key)" - # Per-value byte cap for clear-text values (over-cap values trimmed, flagged). - # 0, negative or unset uses the Edge default of 4096. - captureCap: 4096 - -# GODEBUG for the edge and edge-proxy containers. The default turns off the -# MPTCP listeners Go 1.24+ opens, the precondition for the CVE-2026-98432 -# exploit. "" omits it; a GODEBUG entry in env overrides it on edge. -godebug: "multipathtcp=0" - -# Environment variables -env: [] -# - name: NODE_NAME -# valueFrom: -# fieldRef: -# fieldPath: spec.nodeName - -# Additional volumes -extraVolumes: [] - -# Additional volume mounts -extraVolumeMounts: [] - -# Extra containers -extraContainers: [] - -# Init containers -initContainers: [] - -# Node name configuration (for DaemonSet-like behavior) -nodeName: - # Enable automatic node name injection - enabled: true - # Field path for node name - fieldPath: "spec.nodeName" - -# ============================================================================= -# Edge Proxy Configuration -# ============================================================================= -# The edge proxy connects to Brain via gRPC and proxies observability queries -# to on-prem data sources (Prometheus, Loki, Tempo, etc.). -# Set enabled: true to deploy the edge proxy alongside the main agent. - -edgeProxy: - enabled: true # dashboard: edgeProxy.enabled - - image: - repository: nofireai/edge-proxy - # tag: defaults to .Values.image.tag (shared version with main agent) - # pullPolicy: defaults to .Values.image.pullPolicy - - replicaCount: 1 - - resources: - requests: - memory: "128Mi" - cpu: "100m" - limits: - memory: "256Mi" - cpu: "500m" - - # Stream configuration (Brain gRPC connection) - stream: - serverAddress: "edge.nofire.ai:443" - useTLS: true - reconnectDelay: "1s" - maxReconnectDelay: "60s" - heartbeatInterval: "30s" - maxMessageSize: 16777216 # 16MB - maxConcurrent: 10 - keepaliveTime: "30s" - keepaliveTimeout: "10s" - protocolVersion: 1 - - # HTTP client settings for backend connections - http: - timeout: "30s" - maxIdleConns: 100 - retryMaxAttempts: 3 - - # PII redaction before data leaves customer infrastructure - redaction: - enabled: true - standardPII: true - - # Health/metrics HTTP server port - serverPort: 8081 - - # Base path for K8s secret volume mounts inside the pod - secretsPath: "/etc/nofire/secrets" - - # Service configuration - service: - type: ClusterIP - port: 8081 - annotations: {} - - # Probes - livenessProbe: - httpGet: - path: /healthz - port: 8081 - initialDelaySeconds: 15 - periodSeconds: 10 - readinessProbe: - httpGet: - path: /healthz - port: 8081 - initialDelaySeconds: 5 - periodSeconds: 5 - -# On-premises connections map (used when edgeProxy.enabled: true) -# -# Supported types: prometheus, loki, tempo, grafana, elasticsearch, -# open_search, mongodb_atlas, datadog, cloudwatch, google_cloud_logs, -# jaeger, alertmanager, github, gitlab, bitbucket, slack, custom_http, postgres -# -# Each connection supports: -# type: (required) backend type from list above -# enabled: (optional, default: true) whether connection is active -# name: (optional, default: key name) human-friendly display name -# secretName: (optional) K8s secret name for credentials (username/password/token) -# url: (required for most types) backend service base URL -# orgId: (optional) Loki multi-tenant org ID (X-Scope-OrgID header) -# index: (optional) Elasticsearch/OpenSearch index pattern -# datasourceUID: (optional) Tempo datasource UID -# tlsEnabled: (optional) enable TLS for backend connection -# tlsSkipVerify: (optional) skip backend TLS certificate verification -# caCertPath: (optional) path to CA cert for backend TLS verification -# -# Postgres connections use DB fields instead of url: -# dbHost: (required) database hostname -# dbPort: (optional, default: 5432) database port -# dbName: (required) database name -# dbSSLMode: (optional) sslmode (e.g. disable, require, verify-full) -# -# Example: -# onPremConnections: -# prod-prometheus: -# type: prometheus -# enabled: true -# name: "Production Prometheus" -# secretName: prometheus-creds -# url: "http://prometheus:9090" -# prod-loki: -# type: loki -# enabled: true -# name: "Production Loki" -# secretName: loki-creds -# url: "http://loki:3100" -# orgId: "tenant1" -# prod-postgres: -# type: postgres -# enabled: true -# name: "Production Postgres" -# secretName: postgres-creds -# dbHost: "postgres.default.svc.cluster.local" -# dbPort: 5432 -# dbName: "app" -# dbSSLMode: "require" -# internal-api: -# type: custom_http -# enabled: true -# name: "Internal API" -# secretName: internal-api-creds -# url: "https://api.internal.example.com" -# dashboard: onPremConnections.prometheus.* -onPremConnections: - prometheus: - type: prometheus - url: http://prometheus.monitoring:9090 - enabled: true From 0db32f1763dc682aeab855c9e9118d5a291c3684 Mon Sep 17 00:00:00 2001 From: Stelios Charmpalis Date: Fri, 13 Nov 2026 15:43:36 +0200 Subject: [PATCH 10/10] ci(release): port the metadata publisher from Python to Go The chart repo's tooling is shell and Go (tests/render/edgecheck), and the backend is Go; nothing here uses Python. Same logic, standard library only, still calling the runner's aws, gh and helm, so nothing is downloaded at build time. setup-go is pinned to a commit and uses the Go the runner image caches. Refs: #27 Signed-off-by: Stelios Charmpalis --- .../scripts/publish-release-metadata/main.go | 212 ++++++++++++++++++ .github/scripts/publish_release_metadata.py | 142 ------------ .github/workflows/release.yml | 12 +- 3 files changed, 221 insertions(+), 145 deletions(-) create mode 100644 .github/scripts/publish-release-metadata/main.go delete mode 100755 .github/scripts/publish_release_metadata.py diff --git a/.github/scripts/publish-release-metadata/main.go b/.github/scripts/publish-release-metadata/main.go new file mode 100644 index 0000000..82d6333 --- /dev/null +++ b/.github/scripts/publish-release-metadata/main.go @@ -0,0 +1,212 @@ +// publish-release-metadata publishes Edge release metadata to releases.nofire.ai +// (NOFireAI/engineering#1983). +// +// The NOFire AI dashboard reads edge/latest.json to pick the chart version its +// install commands use. For the chart version in Chart.yaml this: +// +// 1. waits until the Helm repo serves it, so latest.json never names a version +// `helm repo update` cannot find yet; +// 2. writes edge/.json once (never replaced); +// 3. moves edge/latest.json to , unless it already names the same or a +// newer version, or is a pre-release. +// +// Safe to re-run. Standard library only; it calls the tools on the runner: the +// AWS CLI (credentials for the release metadata role), gh and helm. +// +// Run from the chart's root: go run ./.github/scripts/publish-release-metadata +package main + +import ( + "bytes" + "encoding/json" + "fmt" + "os" + "os/exec" + "path/filepath" + "strconv" + "strings" + "time" +) + +const ( + bucket = "releases.nofire.ai" + chartRepo = "https://nofireai.github.io/edge-helm-chart" +) + +type result struct { + ok bool + stdout, stderr string +} + +func run(name string, args ...string) result { + var stdout, stderr bytes.Buffer + cmd := exec.Command(name, args...) + cmd.Stdout, cmd.Stderr = &stdout, &stderr + err := cmd.Run() + return result{err == nil, stdout.String(), stderr.String()} +} + +func fail(format string, args ...any) { + fmt.Fprintf(os.Stderr, "::error::"+format+"\n", args...) + os.Exit(1) +} + +// chartField reads a top-level scalar from Chart.yaml, e.g. appVersion. +func chartField(key string) string { + data, err := os.ReadFile("Chart.yaml") + if err != nil { + fail("reading Chart.yaml: %v", err) + } + for _, line := range strings.Split(string(data), "\n") { + name, value, found := strings.Cut(line, ":") + if found && name == key && strings.TrimSpace(value) != "" { + return strings.Trim(strings.TrimSpace(value), `"'`) + } + } + fail("Chart.yaml has no %s", key) + return "" +} + +// parseVersion returns major, minor and patch for a plain x.y.z, else nil. +func parseVersion(version string) []int { + parts := strings.Split(version, ".") + if len(parts) != 3 { + return nil + } + nums := make([]int, 3) + for i, part := range parts { + n, err := strconv.Atoi(part) + if err != nil || n < 0 || strconv.Itoa(n) != part { + return nil + } + nums[i] = n + } + return nums +} + +// atLeast reports whether version a >= version b. +func atLeast(a, b []int) bool { + for i := range a { + if a[i] != b[i] { + return a[i] > b[i] + } + } + return true +} + +func waitForHelmRepo(name, version string) { + // GitHub Pages deploys after the gh-pages push; give it 10 minutes. + run("helm", "repo", "add", "--force-update", "nofire", chartRepo) + for range 40 { + run("helm", "repo", "update", "nofire") + if run("helm", "show", "chart", "nofire/"+name, "--version", version).ok { + return + } + time.Sleep(15 * time.Second) + } + fail("%s %s is not in the Helm repo after 10 minutes", name, version) +} + +func s3(args ...string) result { + return run("aws", append(append([]string{"s3api"}, args...), "--bucket", bucket)...) +} + +func put(key, body, cacheControl string, condition ...string) result { + args := []string{"put-object", "--key", key, "--body", body, + "--content-type", "application/json", "--cache-control", cacheControl} + return s3(append(args, condition...)...) +} + +// lostRace reports S3's answer when a conditional write's condition no longer holds. +func lostRace(r result) bool { + return strings.Contains(r.stderr, "PreconditionFailed") || + strings.Contains(r.stderr, "ConditionalRequestConflict") +} + +func main() { + name, version := chartField("name"), chartField("version") + waitForHelmRepo(name, version) + + release := run("gh", "release", "view", name+"-"+version, "--json", "publishedAt,url") + if !release.ok { + fail("no GitHub release %s-%s\n%s", name, version, release.stderr) + } + var published struct{ PublishedAt, URL string } + if err := json.Unmarshal([]byte(release.stdout), &published); err != nil { + fail("reading gh release output: %v", err) + } + + work, err := os.MkdirTemp("", "release-metadata") + if err != nil { + fail("%v", err) + } + metadata, _ := json.MarshalIndent(map[string]any{ + "schema": 1, + "chart": map[string]string{"name": name, "version": version, "repo": chartRepo}, + "edge": map[string]string{"version": chartField("appVersion")}, + "releasedAt": published.PublishedAt, + "releaseUrl": published.URL, + }, "", " ") + body := filepath.Join(work, "metadata.json") + if err := os.WriteFile(body, append(metadata, '\n'), 0o644); err != nil { + fail("%v", err) + } + fmt.Println(string(metadata)) + + r := put("edge/"+version+".json", body, "public, max-age=31536000, immutable", "--if-none-match", "*") + if !r.ok && !lostRace(r) { + fail("writing edge/%s.json failed\n%s", version, r.stderr) + } + fmt.Printf("edge/%s.json is published\n", version) + + next := parseVersion(version) + if next == nil { + fmt.Printf("%s is not a plain release, leaving latest.json alone\n", version) + return + } + + // Read with the role, from S3 rather than through Cloudflare's cache. Only + // NoSuchKey means there is no latest.json; any other error stops here. The + // write only lands if latest.json still holds what was read, so of two + // releases racing, the loser reads again and compares again. + currentFile := filepath.Join(work, "latest.json") + for range 5 { + var current string + var condition []string + r := s3("get-object", "--key", "edge/latest.json", currentFile) + switch { + case r.ok: + var doc struct{ Chart struct{ Version string } } + if data, err := os.ReadFile(currentFile); err == nil { + _ = json.Unmarshal(data, &doc) // a malformed file is replaced + } + var head struct{ ETag string } + if err := json.Unmarshal([]byte(r.stdout), &head); err != nil || head.ETag == "" { + fail("no ETag reading edge/latest.json\n%s", r.stdout) + } + current, condition = doc.Chart.Version, []string{"--if-match", head.ETag} + case strings.Contains(r.stderr, "NoSuchKey"): + condition = []string{"--if-none-match", "*"} + default: + fail("reading edge/latest.json failed\n%s", r.stderr) + } + + if held := parseVersion(current); held != nil && atLeast(held, next) { + fmt.Printf("latest.json holds %s, leaving it\n", current) + return + } + r = put("edge/latest.json", body, "public, max-age=300", condition...) + if r.ok { + if current == "" { + current = "nothing" + } + fmt.Printf("latest.json now holds %s (was %s)\n", version, current) + return + } + if !lostRace(r) { + fail("writing edge/latest.json failed\n%s", r.stderr) + } + fmt.Println("latest.json changed while this ran, reading it again") + } + fail("latest.json kept changing, gave up after 5 attempts") +} diff --git a/.github/scripts/publish_release_metadata.py b/.github/scripts/publish_release_metadata.py deleted file mode 100755 index 5e1224d..0000000 --- a/.github/scripts/publish_release_metadata.py +++ /dev/null @@ -1,142 +0,0 @@ -#!/usr/bin/env python3 -"""Publish Edge release metadata to releases.nofire.ai (NOFireAI/engineering#1983). - -The NOFire AI dashboard reads edge/latest.json to pick the chart version its -install commands use. For the chart version in Chart.yaml this: - -1. waits until the Helm repo serves it, so latest.json never names a version - `helm repo update` cannot find yet; -2. writes edge/.json once (never replaced); -3. moves edge/latest.json to , unless it already names the same or a - newer version, or is a pre-release. - -Safe to re-run. Uses only the standard library and the tools on the runner: -the AWS CLI (credentials for the release metadata role), gh and helm. - -Run from the chart's root: python3 .github/scripts/publish_release_metadata.py -""" - -import json -import subprocess -import sys -import tempfile -import time -from pathlib import Path - -BUCKET = "releases.nofire.ai" -CHART_REPO = "https://nofireai.github.io/edge-helm-chart" - - -def run(*cmd): - return subprocess.run(cmd, capture_output=True, text=True) - - -def fail(message, result=None): - sys.exit(f"::error::{message}" + (f"\n{result.stderr}" if result else "")) - - -def chart_field(key): - """A top-level scalar from Chart.yaml, e.g. appVersion.""" - for line in Path("Chart.yaml").read_text().splitlines(): - name, _, value = line.partition(":") - if name == key and value.strip(): - return value.strip().strip("\"'") - fail(f"Chart.yaml has no {key}") - - -def parse_version(version): - """(major, minor, patch) for a plain x.y.z, else None.""" - parts = version.split(".") if isinstance(version, str) else [] - if len(parts) != 3 or not all(p.isdigit() for p in parts): - return None - return tuple(int(p) for p in parts) - - -def wait_for_helm_repo(name, version): - # GitHub Pages deploys after the gh-pages push; give it 10 minutes. - run("helm", "repo", "add", "--force-update", "nofire", CHART_REPO) - for _ in range(40): - run("helm", "repo", "update", "nofire") - if run("helm", "show", "chart", f"nofire/{name}", "--version", version).returncode == 0: - return - time.sleep(15) - fail(f"{name} {version} is not in the Helm repo after 10 minutes") - - -def s3(*args): - return run("aws", "s3api", *args, "--bucket", BUCKET) - - -def put(key, body, cache_control, *condition): - return s3("put-object", "--key", key, "--body", body, - "--content-type", "application/json", - "--cache-control", cache_control, *condition) - - -def lost_race(result): - # S3's answer when a conditional write's condition no longer holds. - return "PreconditionFailed" in result.stderr or "ConditionalRequestConflict" in result.stderr - - -def main(): - name, version = chart_field("name"), chart_field("version") - wait_for_helm_repo(name, version) - - release = run("gh", "release", "view", f"{name}-{version}", "--json", "publishedAt,url") - if release.returncode != 0: - fail(f"no GitHub release {name}-{version}", release) - release = json.loads(release.stdout) - - work = Path(tempfile.mkdtemp()) - body = work / "metadata.json" - body.write_text(json.dumps({ - "schema": 1, - "chart": {"name": name, "version": version, "repo": CHART_REPO}, - "edge": {"version": chart_field("appVersion")}, - "releasedAt": release["publishedAt"], - "releaseUrl": release["url"], - }, indent=2) + "\n") - print(body.read_text()) - - result = put(f"edge/{version}.json", str(body), - "public, max-age=31536000, immutable", "--if-none-match", "*") - if result.returncode != 0 and not lost_race(result): - fail(f"writing edge/{version}.json failed", result) - print(f"edge/{version}.json is published") - - new = parse_version(version) - if new is None: - print(f"{version} is not a plain release, leaving latest.json alone") - return - - # Read with the role, from S3 rather than through Cloudflare's cache. Only - # NoSuchKey means there is no latest.json; any other error stops here. The - # write only lands if latest.json still holds what was read, so of two - # releases racing, the loser reads again and compares again. - current_file = work / "latest.json" - for _ in range(5): - result = s3("get-object", "--key", "edge/latest.json", str(current_file)) - if result.returncode == 0: - current = json.loads(current_file.read_text()).get("chart", {}).get("version") - condition = ("--if-match", json.loads(result.stdout)["ETag"]) - elif "NoSuchKey" in result.stderr: - current, condition = None, ("--if-none-match", "*") - else: - fail("reading edge/latest.json failed", result) - - held = parse_version(current) - if held is not None and held >= new: - print(f"latest.json holds {current}, leaving it") - return - result = put("edge/latest.json", str(body), "public, max-age=300", *condition) - if result.returncode == 0: - print(f"latest.json now holds {version} (was {current or 'nothing'})") - return - if not lost_race(result): - fail("writing edge/latest.json failed", result) - print("latest.json changed while this ran, reading it again") - fail("latest.json kept changing, gave up after 5 attempts") - - -if __name__ == "__main__": - main() diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index babe4c1..1de940f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -109,8 +109,8 @@ jobs: # version customers install, and tests/dashboard_install_test.yaml is the gate. # A job of its own, so the AWS role's OIDC token never shares a job with the # release's write token. Runs on every run (each write is idempotent); skipped - # until the RELEASE_METADATA_ROLE_ARN repository variable is set. aws, gh, helm - # and python3 come with the runner image. + # until the RELEASE_METADATA_ROLE_ARN repository variable is set. aws, gh and + # helm come with the runner image; setup-go uses the Go it already caches. publish-metadata: needs: release if: vars.RELEASE_METADATA_ROLE_ARN != '' @@ -124,6 +124,12 @@ jobs: with: persist-credentials: false + - name: Set up Go + uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 + with: + go-version: '1.26' + cache: false + - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a # v4.3.1 with: @@ -133,4 +139,4 @@ jobs: - name: Publish release metadata env: GH_TOKEN: ${{ github.token }} - run: python3 -u .github/scripts/publish_release_metadata.py + run: go run .github/scripts/publish-release-metadata/main.go