Skip to content

Commit 7d7cc99

Browse files
browcodex
andcommitted
feat(push): require configured mobile and chart origins
Signed-off-by: Tom Brow <[email protected]> Co-authored-by: Codex <[email protected]> Ai-assisted: true
1 parent af33072 commit 7d7cc99

27 files changed

Lines changed: 428 additions & 121 deletions

‎.env.example‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,9 @@ RELAY_URL=ws://localhost:3000
7575
# BUZZ_WEB_DIR=./web/dist
7676

7777
# NIP-PL mobile push is an explicit deployment opt-in. A gateway URL alone
78-
# never enables it. When enabled and the URL is absent, the canonical
79-
# https://push.buzz.xyz/v1/deliveries/apns endpoint is used.
78+
# never enables it. When enabled, the exact HTTPS delivery URL is required.
8079
BUZZ_PUSH_ENABLED=false
81-
# BUZZ_PUSH_GATEWAY_DELIVERY_URL=https://push.buzz.xyz/v1/deliveries/apns
80+
BUZZ_PUSH_GATEWAY_DELIVERY_URL=https://push.buzz.xyz/v1/deliveries/apns
8281

8382
# -----------------------------------------------------------------------------
8483
# Admin Dashboard (private moderation surface)

‎.github/workflows/_ci-clients.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ jobs:
111111
- name: Analyze
112112
run: cd mobile && flutter analyze
113113
- name: Test
114-
run: cd mobile && flutter test
114+
run: cd mobile && flutter test --dart-define=BUZZ_PUSH_GATEWAY_URL=https://push.example
115115
- name: Build Android debug APK
116-
run: just mobile-build-android
116+
run: BUZZ_PUSH_GATEWAY_URL=https://push.example just mobile-build-android
117117

118118
mobile-swift:
119119
name: Mobile Swift
@@ -132,7 +132,7 @@ jobs:
132132
- name: Test
133133
run: swift test --package-path mobile/ios/BuzzPushKit
134134
- name: Build complete unsigned iOS release
135-
run: cd mobile && flutter build ios --release --no-codesign --no-pub
135+
run: cd mobile && flutter build ios --release --no-codesign --no-pub --dart-define=BUZZ_PUSH_GATEWAY_URL=https://push.example
136136

137137
results:
138138
name: Results

‎Justfile‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ mobile-check:
804804

805805
# Run mobile tests
806806
mobile-test:
807-
unset GIT_DIR GIT_WORK_TREE; cd {{mobile_dir}} && flutter test
807+
unset GIT_DIR GIT_WORK_TREE; cd {{mobile_dir}} && flutter test --dart-define=BUZZ_PUSH_GATEWAY_URL=https://push.example
808808

809809
# Regenerate the emoji dataset asset from desktop's emoji-mart install.
810810
# Output is committed — rerun after bumping @emoji-mart/data.
@@ -813,8 +813,9 @@ mobile-emoji-data:
813813

814814
# Compile an unsigned Android debug APK (worktree-aware debug identity)
815815
mobile-build-android:
816+
test -n "${BUZZ_PUSH_GATEWAY_URL:-}" || { echo "BUZZ_PUSH_GATEWAY_URL is required" >&2; exit 1; }
816817
./scripts/mobile-worktree-overrides.sh
817-
unset GIT_DIR GIT_WORK_TREE; cd {{mobile_dir}} && flutter build apk --debug --no-pub
818+
unset GIT_DIR GIT_WORK_TREE; cd {{mobile_dir}} && flutter build apk --debug --no-pub --dart-define="BUZZ_PUSH_GATEWAY_URL=${BUZZ_PUSH_GATEWAY_URL}"
818819

819820
# Run the mobile app on iOS simulator (worktree-aware debug identity)
820821
mobile-dev:
@@ -825,9 +826,10 @@ mobile-dev:
825826
sleep 3
826827
fi
827828
./scripts/mobile-worktree-overrides.sh
829+
test -n "${BUZZ_PUSH_GATEWAY_URL:-}" || { echo "BUZZ_PUSH_GATEWAY_URL is required" >&2; exit 1; }
828830
cd {{mobile_dir}}
829831
unset GIT_DIR GIT_WORK_TREE
830-
flutter run
832+
flutter run --dart-define="BUZZ_PUSH_GATEWAY_URL=${BUZZ_PUSH_GATEWAY_URL}"
831833
832834
# Uninstall stale worktree-suffixed Buzz debug installs (production apps kept)
833835
mobile-clean:

‎deploy/charts/buzz-push-gateway/templates/deployment.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ spec:
3232
env:
3333
- { name: BUZZ_PUSH_BIND_ADDR, value: "0.0.0.0:8080" }
3434
- { name: BUZZ_PUSH_HEALTH_ADDR, value: "0.0.0.0:8081" }
35-
- { name: BUZZ_PUSH_PUBLIC_DELIVERY_URL, value: {{ .Values.publicDeliveryUrl | quote }} }
35+
- { name: BUZZ_PUSH_GATEWAY_ORIGIN, value: {{ required "gatewayOrigin is required" .Values.gatewayOrigin | quote }} }
3636
- { name: BUZZ_PUSH_MAX_GRANT_LIFETIME_SECONDS, value: {{ .Values.maxGrantLifetimeSeconds | quote }} }
3737
- { name: BUZZ_PUSH_APP_ATTEST_ROOT_CERT_PATH, value: /run/buzz/app-attest/root.pem }
3838
- { name: BUZZ_PUSH_DOGFOOD_APP_ATTEST_APP_ID, value: {{ .Values.profiles.dogfood.appAttestAppId | quote }} }

‎deploy/charts/buzz-push-gateway/templates/httproute.yaml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{{- if .Values.httpRoute.enabled }}
2+
{{- $gatewayURL := urlParse (required "gatewayOrigin is required" .Values.gatewayOrigin) }}
23
apiVersion: gateway.networking.k8s.io/v1
34
kind: HTTPRoute
45
metadata:
56
name: {{ include "push.name" . }}
67
spec:
78
parentRefs: {{- toYaml .Values.httpRoute.parentRefs | nindent 4 }}
8-
hostnames: {{- toYaml .Values.httpRoute.hostnames | nindent 4 }}
9+
hostnames:
10+
- {{ required "gatewayOrigin must include a hostname" $gatewayURL.host | quote }}
911
rules:
1012
- matches:
1113
- path: { type: PathPrefix, value: / }

‎deploy/charts/buzz-push-gateway/tests/render.sh‎

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
set -euo pipefail
33
out=$(mktemp); production_out=$(mktemp); route_out=$(mktemp); datadog_out=$(mktemp)
44
trap 'rm -f "$out" "$production_out" "$route_out" "$datadog_out" "${monitoring_out:-}"' EXIT
5+
gateway_origin_arg=(--set 'gatewayOrigin=https://push.example')
56

6-
# Defaults must lint and render without parameter injection.
7-
helm lint deploy/charts/buzz-push-gateway >/dev/null
8-
helm template push deploy/charts/buzz-push-gateway >"$out"
7+
# Generic values require the deployment-owned gateway origin.
8+
helm lint deploy/charts/buzz-push-gateway "${gateway_origin_arg[@]}" >/dev/null
9+
helm template push deploy/charts/buzz-push-gateway "${gateway_origin_arg[@]}" >"$out"
910
# Production values support a platform-owned ingress without rendering an
1011
# HTTPRoute. The environment-owned inputs remain mandatory.
1112
production_args=(
1213
-f deploy/charts/buzz-push-gateway/values-production.yaml
1314
--set 'image.digest=sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
15+
--set 'gatewayOrigin=https://push.example'
1416
--set 'profiles.dogfood.appAttestAppId=REALTEAM.xyz.block.buzz.dogfood.mobile'
1517
--set 'networkPolicy.postgresEgressCidrs[0]=10.42.0.0/16'
1618
)
@@ -20,6 +22,7 @@ helm template push deploy/charts/buzz-push-gateway "${production_args[@]}" >"$pr
2022
# Gateway API remains an explicit supported ingress mode when an operator opts
2123
# in and supplies the environment-owned parent.
2224
helm template push deploy/charts/buzz-push-gateway \
25+
"${gateway_origin_arg[@]}" \
2326
--set httpRoute.enabled=true \
2427
--set 'httpRoute.parentRefs[0].name=production-gateway' \
2528
--set 'httpRoute.parentRefs[0].namespace=gateway-system' \
@@ -63,8 +66,12 @@ required = Set.new(%w[
6366
DATABASE_URL BUZZ_PUSH_DOGFOOD_APNS_CERT_PATH
6467
BUZZ_PUSH_DOGFOOD_APNS_TOPIC BUZZ_PUSH_DOGFOOD_APP_ATTEST_APP_ID
6568
BUZZ_PUSH_GRANT_KEYS BUZZ_PUSH_TOKEN_KEYS BUZZ_PUSH_MAX_GRANT_LIFETIME_SECONDS
69+
BUZZ_PUSH_GATEWAY_ORIGIN
6670
])
6771
assert!(required.subset?(env_names))
72+
gateway_origin = d.dig("spec", "template", "spec", "containers", 0, "env")
73+
.find { |entry| entry["name"] == "BUZZ_PUSH_GATEWAY_ORIGIN" }
74+
assert!(gateway_origin["value"] == "https://push.example")
6875
assert!(!env_names.any? { |name| name.include?("APP_STORE") })
6976
apns_volume = d.dig("spec", "template", "spec", "volumes").find { |volume| volume["name"] == "apns-dogfood" }
7077
assert!(apns_volume.dig("secret", "defaultMode") == 0o400, apns_volume.inspect)
@@ -100,20 +107,34 @@ production_image = production_deployment.dig("spec", "template", "spec", "contai
100107
assert!(production_image == "ghcr.io/block/buzz-push-gateway@sha256:#{"a" * 64}", production_image.inspect)
101108
route = YAML.load_stream(File.read(ARGV[2])).compact.find { |x| x["kind"] == "HTTPRoute" }
102109
assert!(!route.dig("spec", "parentRefs").empty?)
103-
assert!(route.dig("spec", "hostnames").include?("push.buzz.xyz"))
110+
assert!(route.dig("spec", "hostnames") == ["push.example"])
104111
RUBY
105112

113+
# A gateway origin is a required deployment input, even when HTTPRoute is off.
114+
if helm template push deploy/charts/buzz-push-gateway >/dev/null 2>&1; then
115+
echo 'expected missing gatewayOrigin to fail' >&2
116+
exit 1
117+
fi
118+
for invalid_origin in 'http://push.example' 'https://push.example:8443' 'https://push.example/base'; do
119+
if helm template push deploy/charts/buzz-push-gateway \
120+
--set "gatewayOrigin=$invalid_origin" >/dev/null 2>&1; then
121+
echo "expected malformed gatewayOrigin $invalid_origin to fail" >&2
122+
exit 1
123+
fi
124+
done
125+
106126
# Legacy token-auth values must fail rather than silently selecting the default
107127
# certificate Secret.
108128
if helm template push deploy/charts/buzz-push-gateway \
129+
"${gateway_origin_arg[@]}" \
109130
--set apnsKey.secretName=legacy-apns-secret \
110131
--set apnsKey.secretKey=legacy-provider.p8 >/dev/null 2>&1; then
111132
echo 'expected legacy apnsKey values to fail schema validation' >&2
112133
exit 1
113134
fi
114135

115136
# Enabling a route without a Gateway attachment must fail schema validation.
116-
if helm template push deploy/charts/buzz-push-gateway --set httpRoute.enabled=true >/dev/null 2>&1; then
137+
if helm template push deploy/charts/buzz-push-gateway "${gateway_origin_arg[@]}" --set httpRoute.enabled=true >/dev/null 2>&1; then
117138
echo 'expected httpRoute.enabled=true without parentRefs to fail' >&2
118139
exit 1
119140
fi
@@ -129,6 +150,7 @@ fi
129150
# keyed to the named monitoring source — never a blanket 8081 rule.
130151
monitoring_out=$(mktemp)
131152
helm template push deploy/charts/buzz-push-gateway \
153+
"${gateway_origin_arg[@]}" \
132154
--set podMonitor.enabled=true \
133155
--set prometheusRule.enabled=true \
134156
--set networkPolicy.monitoring.enabled=true \
@@ -162,9 +184,11 @@ RUBY
162184
# Datadog discovers the same private endpoint from pod annotations and needs no
163185
# prometheus-operator CRDs. Its agent ingress remains selector-scoped.
164186
helm lint deploy/charts/buzz-push-gateway \
165-
-f deploy/charts/buzz-push-gateway/tests/datadog-values.yaml >/dev/null
187+
-f deploy/charts/buzz-push-gateway/tests/datadog-values.yaml \
188+
"${gateway_origin_arg[@]}" >/dev/null
166189
helm template push deploy/charts/buzz-push-gateway \
167190
-f deploy/charts/buzz-push-gateway/tests/datadog-values.yaml \
191+
"${gateway_origin_arg[@]}" \
168192
>"$datadog_out"
169193

170194
env -u GEM_HOME -u GEM_PATH -u RUBYLIB -u RUBYOPT ruby -rjson -ryaml -rset \
@@ -200,6 +224,7 @@ RUBY
200224
# Negative: monitoring enabled with default empty selectors must fail (would
201225
# otherwise render a blanket 8081 rule matching all namespaces/pods).
202226
if helm template push deploy/charts/buzz-push-gateway \
227+
"${gateway_origin_arg[@]}" \
203228
--set podMonitor.enabled=true \
204229
--set networkPolicy.monitoring.enabled=true >/dev/null 2>&1; then
205230
echo 'expected monitoring.enabled with empty selectors to fail' >&2
@@ -209,6 +234,7 @@ fi
209234
# Negative: PodMonitor without ingress is an unreachable scraper and must fail.
210235
# Scoped ingress without PodMonitor is valid for annotation-discovered agents.
211236
if helm template push deploy/charts/buzz-push-gateway \
237+
"${gateway_origin_arg[@]}" \
212238
--set podMonitor.enabled=true \
213239
--set 'networkPolicy.monitoring.namespaceSelector.kubernetes\.io/metadata\.name=monitoring' \
214240
--set 'networkPolicy.monitoring.podSelector.app\.kubernetes\.io/name=prometheus' \
@@ -219,6 +245,7 @@ fi
219245

220246
# Negative: retry-ratio threshold is a fraction; a value > 1 must fail schema.
221247
if helm template push deploy/charts/buzz-push-gateway \
248+
"${gateway_origin_arg[@]}" \
222249
--set prometheusRule.enabled=true \
223250
--set prometheusRule.apnsRetryRatioThreshold=2 >/dev/null 2>&1; then
224251
echo 'expected apnsRetryRatioThreshold=2 to fail' >&2

‎deploy/charts/buzz-push-gateway/values-production.yaml‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
image:
44
tag: ""
55
digest: ""
6+
gatewayOrigin: ""
67
profiles:
78
dogfood:
89
appAttestAppId: ""
910
httpRoute:
10-
# Keep disabled when the platform already routes push.buzz.xyz to this
11-
# Service. Gateway API users enable it and inject an explicit parentRef.
11+
# Keep disabled when the platform already routes the configured gateway
12+
# origin to this Service. Gateway API users enable it and inject a parentRef.
1213
enabled: false
1314
parentRefs: []
14-
hostnames:
15-
- push.buzz.xyz
1615
networkPolicy:
1716
apnsEgressCidrs:
1817
- 0.0.0.0/0

‎deploy/charts/buzz-push-gateway/values.schema.json‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
"type": "string",
1212
"minLength": 1
1313
},
14-
"publicDeliveryUrl": {
15-
"const": "https://push.buzz.xyz/v1/deliveries/apns"
14+
"gatewayOrigin": {
15+
"type": "string",
16+
"format": "uri",
17+
"pattern": "^https://[^/?#@:]+/?$"
1618
},
1719
"maxGrantLifetimeSeconds": {
1820
"type": "integer",
@@ -40,23 +42,17 @@
4042
},
4143
"httpRoute": {
4244
"type": "object",
45+
"additionalProperties": false,
4346
"required": [
4447
"enabled",
45-
"parentRefs",
46-
"hostnames"
48+
"parentRefs"
4749
],
4850
"properties": {
4951
"enabled": {
5052
"type": "boolean"
5153
},
5254
"parentRefs": {
5355
"type": "array"
54-
},
55-
"hostnames": {
56-
"type": "array",
57-
"contains": {
58-
"const": "push.buzz.xyz"
59-
}
6056
}
6157
},
6258
"allOf": [
@@ -310,7 +306,7 @@
310306
"required": [
311307
"replicaCount",
312308
"existingSecret",
313-
"publicDeliveryUrl",
309+
"gatewayOrigin",
314310
"maxGrantLifetimeSeconds",
315311
"profiles",
316312
"httpRoute",

‎deploy/charts/buzz-push-gateway/values.yaml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ migration:
1818
resources:
1919
requests: {cpu: 50m, memory: 64Mi}
2020
limits: {cpu: 250m, memory: 128Mi}
21-
publicDeliveryUrl: https://push.buzz.xyz/v1/deliveries/apns
21+
# Exact externally reachable HTTPS origin. The gateway derives every protocol
22+
# route and App Attest audience from this one value.
23+
gatewayOrigin: ""
2224
maxGrantLifetimeSeconds: 2592000
2325
profiles:
2426
dogfood:
@@ -41,7 +43,6 @@ httpRoute:
4143
# existing ingress or service mesh route should keep this disabled.
4244
enabled: false
4345
parentRefs: []
44-
hostnames: [push.buzz.xyz]
4546
resources:
4647
requests: {cpu: 100m, memory: 128Mi}
4748
limits: {cpu: "1", memory: 512Mi}

‎deploy/compose/.env.example‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ BUZZ_REQUIRE_RELAY_MEMBERSHIP=true
1818
BUZZ_ALLOW_NIP_OA_AUTH=true
1919
BUZZ_AUTO_MIGRATE=true
2020
BUZZ_GIT_CONFORMANCE_PROBE=true
21+
# Push stays disabled unless explicitly enabled. Keep the delivery endpoint
22+
# explicit so enabling it never depends on an in-code deployment fallback.
23+
BUZZ_PUSH_ENABLED=false
24+
BUZZ_PUSH_GATEWAY_DELIVERY_URL=https://push.buzz.xyz/v1/deliveries/apns
2125
RUST_LOG=buzz_relay=info,buzz_db=info,buzz_auth=info,buzz_pubsub=info,tower_http=info
2226

2327
# Owner identity. Set to a 64-character hex Nostr pubkey.

0 commit comments

Comments
 (0)