Skip to content

Commit 9175336

Browse files
committed
fix(push): render grant lifetimes as decimal seconds
Signed-off-by: Tom Brow <[email protected]>
1 parent 26ede6d commit 9175336

7 files changed

Lines changed: 84 additions & 4 deletions

File tree

‎.github/workflows/push-gateway-helm-chart.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ on:
1414
pull_request:
1515
paths:
1616
- "deploy/charts/buzz-push-gateway/**"
17+
- "crates/buzz-push-gateway/src/config.rs"
1718
- ".github/workflows/push-gateway-helm-chart.yml"
1819
permissions: {}
1920
env:
@@ -27,6 +28,7 @@ jobs:
2728
with:
2829
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.ref || '' }}
2930
fetch-depth: 0
31+
- uses: cashapp/activate-hermit@cea9af7913204a965fd488637a8d1811bba2e616 # v1
3032
- uses: azure/setup-helm@1a275c3b69536ee54be43f2070a358922e12c8d4
3133
with: { version: v3.16.4 }
3234
- run: deploy/charts/buzz-push-gateway/tests/render.sh

‎crates/buzz-push-gateway/src/config.rs‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@ mod tests {
386386
("BUZZ_PUSH_DOGFOOD_APNS_ENVIRONMENT", "staging"),
387387
("BUZZ_PUSH_MAX_GRANT_LIFETIME_SECONDS", "0"),
388388
("BUZZ_PUSH_MAX_GRANT_LIFETIME_SECONDS", "31536001"),
389+
("BUZZ_PUSH_MAX_GRANT_LIFETIME_SECONDS", "2.592e+06"),
390+
("BUZZ_PUSH_MAX_GRANT_LIFETIME_SECONDS", "2592000.5"),
389391
("BUZZ_PUSH_MAX_INSTALLATION_LIFETIME_SECONDS", "0"),
390392
] {
391393
let mut env = base();
@@ -394,6 +396,28 @@ mod tests {
394396
}
395397
}
396398

399+
// The chart test supplies actual Helm-rendered environment values. Keep this
400+
// separate from ordinary unit tests, which do not require Helm or fixtures.
401+
#[test]
402+
#[ignore = "run deploy/charts/buzz-push-gateway/tests/grant-lifetime.sh"]
403+
fn helm_rendered_grant_lifetimes() {
404+
let path = std::env::var("BUZZ_TEST_HELM_ENV_FILE").unwrap();
405+
let cases: Vec<(String, i64, HashMap<String, String>)> =
406+
serde_json::from_str(&std::fs::read_to_string(path).unwrap()).unwrap();
407+
assert_eq!(cases.len(), 9);
408+
for (label, expected, rendered) in cases {
409+
let mut env = base();
410+
env.extend(rendered);
411+
let config = Config::from_map(&env).unwrap_or_else(|error| panic!("{label}: {error}"));
412+
assert_eq!(config.max_grant_lifetime_seconds, expected, "{label}");
413+
assert_eq!(
414+
env["BUZZ_PUSH_MAX_GRANT_LIFETIME_SECONDS"],
415+
expected.to_string(),
416+
"{label} must render decimal integer text"
417+
);
418+
}
419+
}
420+
397421
#[test]
398422
fn cross_keyring_id_or_material_reuse_fails_startup() {
399423
for token_keys in [

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ apiVersion: v2
33
# branches (see docs/push-gateway-deployment.md, "Gateway chart release").
44
name: buzz-push-gateway
55
description: Public capability-gated APNs last-hop gateway for Buzz
6-
version: 0.3.1
6+
version: 0.3.2
77
appVersion: "0.1.0"
88
type: application

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ spec:
3333
- { name: BUZZ_PUSH_BIND_ADDR, value: "0.0.0.0:8080" }
3434
- { name: BUZZ_PUSH_HEALTH_ADDR, value: "0.0.0.0:8081" }
3535
- { name: BUZZ_PUSH_GATEWAY_ORIGIN, value: {{ required "gatewayOrigin is required" .Values.gatewayOrigin | quote }} }
36-
- { name: BUZZ_PUSH_MAX_GRANT_LIFETIME_SECONDS, value: {{ .Values.maxGrantLifetimeSeconds | quote }} }
36+
{{/* Schema bounds this integer; normalize YAML numbers before quote can emit scientific notation. */}}
37+
- { name: BUZZ_PUSH_MAX_GRANT_LIFETIME_SECONDS, value: {{ .Values.maxGrantLifetimeSeconds | int64 | quote }} }
3738
- { name: BUZZ_PUSH_APP_ATTEST_ROOT_CERT_PATH, value: /run/buzz/app-attest/root.pem }
3839
- { name: BUZZ_PUSH_DOGFOOD_APP_ATTEST_APP_ID, value: {{ .Values.profiles.dogfood.appAttestAppId | quote }} }
3940
- { name: BUZZ_PUSH_DOGFOOD_APNS_TOPIC, value: {{ .Values.profiles.dogfood.apnsTopic | quote }} }
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
fixture=$(mktemp)
4+
trap 'rm -f "$fixture"' EXIT
5+
6+
# Use real Helm renders, including YAML values (not just --set, which can
7+
# preserve a different numeric type). No deployment or real secrets are needed.
8+
env -u GEM_HOME -u GEM_PATH -u RUBYLIB -u RUBYOPT ruby -rjson -ryaml -ropen3 \
9+
- "$fixture" <<'RUBY'
10+
chart = 'deploy/charts/buzz-push-gateway'
11+
command = ['helm', 'template', 'push', chart, '--set', 'gatewayOrigin=https://push.example']
12+
cases = []
13+
render = lambda do |label, expected, args, values|
14+
output, error, status = Open3.capture3(*command, *args, stdin_data: values)
15+
raise "#{label}: Helm failed: #{error}" unless status.success?
16+
deployment = YAML.load_stream(output).compact.find { |x| x['kind'] == 'Deployment' }
17+
entries = deployment.fetch('spec').fetch('template').fetch('spec').fetch('containers')[0].fetch('env')
18+
# Secret references are intentionally excluded; Config's fixture supplies
19+
# synthetic keyrings and database configuration in memory.
20+
literal_env = entries.select { |entry| entry.key?('value') }.to_h do |entry|
21+
value = entry.fetch('value')
22+
raise "#{label}: #{entry['name']} is not a string" unless value.is_a?(String)
23+
[entry.fetch('name'), value]
24+
end
25+
raise "#{label}: lifetime missing" unless literal_env.key?('BUZZ_PUSH_MAX_GRANT_LIFETIME_SECONDS')
26+
cases << [label, expected, literal_env]
27+
end
28+
render.call('default', 2592000, [], '')
29+
[1, 2592000, 2592001, 31536000].each do |seconds|
30+
render.call("values #{seconds}", seconds, ['-f', '-'], "maxGrantLifetimeSeconds: #{seconds}\n")
31+
render.call("set #{seconds}", seconds, ['--set', "maxGrantLifetimeSeconds=#{seconds}"], '')
32+
end
33+
34+
# Integer conversion must never hide invalid inputs. Helm's schema remains
35+
# authoritative, including rejecting strings that merely look numeric.
36+
['0', '-1', '31536001', '2592000.5', '"2592000"', 'true'].each do |value|
37+
_, error, status = Open3.capture3(*command, '-f', '-', stdin_data: "maxGrantLifetimeSeconds: #{value}\n")
38+
unless !status.success? && error.include?('maxGrantLifetimeSeconds')
39+
raise "expected schema rejection for #{value}: #{error}"
40+
end
41+
end
42+
File.write(ARGV.fetch(0), JSON.generate(cases))
43+
RUBY
44+
45+
BUZZ_TEST_HELM_ENV_FILE="$fixture" cargo test -p buzz-push-gateway --lib \
46+
config::tests::helm_rendered_grant_lifetimes -- --ignored --exact

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
3+
bash deploy/charts/buzz-push-gateway/tests/grant-lifetime.sh
34
out=$(mktemp); production_out=$(mktemp); route_out=$(mktemp); datadog_out=$(mktemp)
45
trap 'rm -f "$out" "$production_out" "$route_out" "$datadog_out" "${monitoring_out:-}"' EXIT
56
gateway_origin_arg=(--set 'gatewayOrigin=https://push.example')

‎docs/push-gateway-deployment.md‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,14 @@ Kubernetes does not restart pods when referenced Secret bytes change. AEAD or AP
263263
The gateway chart has a collision-free release lane separate from the main
264264
`buzz` chart. To publish chart version `X.Y.Z`, update `version` in
265265
`deploy/charts/buzz-push-gateway/Chart.yaml` and keep `appVersion` equal to the
266-
gateway binary's workspace package version. Validate the chart, then open a
267-
same-repository PR whose branch is exactly `push-chart-release/X.Y.Z`:
266+
gateway binary's workspace package version.
267+
268+
The render tests require Helm, Ruby, and the repository's Rust toolchain. They
269+
pass rendered environment values into the gateway's configuration parser with
270+
synthetic credentials; no running gateway or database is needed.
271+
272+
Validate the chart, then open a same-repository PR whose branch is exactly
273+
`push-chart-release/X.Y.Z`:
268274

269275
```bash
270276
deploy/charts/buzz-push-gateway/tests/render.sh

0 commit comments

Comments
 (0)