- Go 97.3%
- Makefile 1.4%
- Dockerfile 0.9%
- Go Template 0.4%
| .forgejo/workflows | ||
| api | ||
| cmd/mailbox-app-push-gateway | ||
| helm | ||
| internal | ||
| .dockerignore | ||
| Dockerfile | ||
| go.mod | ||
| go.sum | ||
| LICENSE | ||
| Makefile | ||
| README.md | ||
mailbox-app-push-gateway
Pushgateway: the component of the app publisher that turns a nudge from a hoster into a push through the right push provider. A hoster holds no push credentials, so a self-hosted mailbox can wake the official app too (R5).
Part of the Notificatie voor Burgers walking skeleton. It stores nothing: open WebSockets live in memory, everything else is sealed in the pushtoken. Vocabulary follows the shared glossary.
Providers
| Kanaal | Provider |
|---|---|
web |
Web Push through the browser's push service, signed with the publisher's VAPID keys. Sent without payload, so the push service of Google, Mozilla or Apple learns nothing; the service worker always shows "Er is post". |
websocket |
A WebSocket to this gateway, kept open by the app while it runs or by the background service mailbox-app-push-agent on every desktop (ADR 0003 in getting-started). |
fcm |
Firebase Cloud Messaging to the mobile app, which reaches Android itself and iOS through APNs. The message only says "Er is post". Signs in with the service account in FCM_SERVICE_ACCOUNT; without it the gateway serves no fcm. |
The kanaal is the channel that reaches a device, not its operating system. Only this gateway knows it:
every pushtoken seals the kanaal and what reaches the device through it (the WebSocket's connection id,
the Web Push subscription, or the Firebase Installation ID) with AES-256-GCM under PUSHTOKEN_KEY, padded to one fixed length. The
hoster stores and returns the pushtoken without learning how a device is reached, and the gateway needs
no storage. A token it cannot open (forged, altered, or sealed under an earlier key) answers 410.
APNs-direct and WNS get their own provider behind the same interface later.
API
The contract is api/openapi.yaml (OAS 3.1, Dutch, NL API Design Rules). Like in blauwe knop it is
committed together with a generated api/openapi.json; CI checks they match, the image carries both in
/api/, and every listener serves them. Every response carries API-Version: 1.0.0; errors are
application/problem+json.
Public, routed at /push (prefix /push/v1):
GET /push/v1/vapid-sleutel→{publiekeSleutel}, for the browser'sPushManager.subscribePOST /push/v1/pushtokens{kanaal: "web", webPushAbonnement}or{kanaal: "fcm", fid}→201 {pushtoken}: exchanges a browser's subscription, or the mobile app's Firebase Installation ID, for a pushtoken;422for a kanaal this gateway does not serve hereGET /push/v1/verbindingWebSocket: first{"soort":"pushtoken","pushtoken":"…"}, then{"soort":"seintje"}per seintje. The pushtoken is valid only while the connection lives. The gateway pings every connection; after two unanswered pings in a row it closes the connection (1001) and forgets the pushtoken.GET /push/v1/openapi.jsonand/push/v1/openapi.yaml
Internal, on its own listener (INTERNAL_LISTEN_ADDRESS, default :8081) and Service
<release>-internal, never routed, so nobody outside the cluster can make devices buzz:
POST /v1/seintjes{pushtoken}→202sent,410the pushtoken no longer reaches a device (the hoster then forgets it),502the push provider refusedGET /v1/openapi.jsonand/v1/openapi.yaml
Management, on its own listener (MANAGEMENT_LISTEN_ADDRESS, default :8082) and Service
<release>-management, never routed; only mailbox-app-push-gateway-management-ui reads it:
GET /v1/overzicht→ per kanaal whether it is served, the devices connected now (websocket), the pushtokens issued and the seintjes sent and failed, the failures per reason, and the latest events (newest first). A pushtoken appears only as its pseudonym, the first 8 hex characters of its SHA-256. The counts live in memory: a restart starts from zero. The gateway does not know which hoster asked for a seintje or who the burger is.GET /v1/openapi.jsonand/v1/openapi.yaml
Configuration
VAPID_PUBLIC_KEY,VAPID_PRIVATE_KEY: from the Secret invapid.existingSecretVAPID_SUBJECT: contact URL ormailto:that push services requirePUSHTOKEN_KEY: base64 of 32 random bytes that seal every pushtoken, from the Secret inpushtokenKey.existingSecret; a new key makes every registered pushtoken goneFCM_SERVICE_ACCOUNT: optional, the JSON of the Firebase service account, from the Secret infcm.existingSecret; without it the gateway serves no fcmALLOWED_ORIGINS: comma-separated CORS and WebSocket origins, defaults to*INTERNAL_LISTEN_ADDRESS: listener of the seintjes API, defaults to:8081MANAGEMENT_LISTEN_ADDRESS: listener of the management API, defaults to:8082VERSION: the release shown on the operator screen; the chart sets it to its appVersionRECENT_EVENTS: how many of the latest events the overview keeps, defaults to100PING_INTERVAL: how often every WebSocket is pinged, defaults to30sMISSED_PONGS: unanswered pings in a row after which a WebSocket is closed, defaults to2
Generate a key pair with mailbox-app-push-gateway generate-vapid-keys and a pushtoken key with
mailbox-app-push-gateway generate-pushtoken-key (or docker run --rm <image> …).
Development
go test ./...
golangci-lint run ./...
docker build --target production -t code.digitaledienst.overheid.nl/mijn-betaaloverzicht/mailbox-app-push-gateway:0.1.0 .
helm upgrade --install mailbox-app-push-gateway helm
CI
.forgejo/workflows/ci.yml tests and lints every push and pull request. On main it pushes the image code.digitaledienst.overheid.nl/mijn-betaaloverzicht/mailbox-app-push-gateway:<commit>.
Release
make release VERSION=1.2.3 # on an up-to-date main: writes helm/Chart.yaml, commits, tags v1.2.3
git push --follow-tags
The tag pipeline tags the image 1.2.3 and v1.2.3 and publishes the chart at 1.2.3 to the
Forgejo Helm registry (see the charts repository). The environments repository pins that
version.
License
EUPL-1.2, see LICENSE.