- Go 81.7%
- Makefile 4.8%
- Objective-C 4.8%
- Shell 4.5%
- PowerShell 2.7%
- Other 1.5%
On nvb the hoster and the pushgateway each run under their own hostname, so connecting to /push/v1 on the hoster's basisUrl gave a 404 and no seintje arrived. The app now hands the pushgateway over separately; an entry without it keeps using the shared hostname. |
||
|---|---|---|
| .forgejo/workflows | ||
| cmd/mailbox-app-push-agent | ||
| internal | ||
| packaging | ||
| .dockerignore | ||
| .gitignore | ||
| Dockerfile | ||
| go.mod | ||
| go.sum | ||
| LICENSE | ||
| Makefile | ||
| README.md | ||
mailbox-app-push-agent
Background service of the mailbox-app on the desktop. It keeps the WebSocket to
mailbox-app-push-gateway open while the citizen is logged in, registers it at the hoster, and shows
"Er is post" when a seintje arrives, also when the app itself is closed. That way a desktop needs no
push service of Apple, Google or Microsoft (ADR 0003 in getting-started).
Part of the Notificatie voor Burgers walking skeleton. Vocabulary follows the shared glossary.
| Linux | macOS | Windows | |
|---|---|---|---|
| Notification | org.freedesktop.Notifications (D-Bus) |
UNUserNotificationCenter, inside a helper bundle |
toast under the app's AppUserModelID |
| Click | starts mailbox_app |
open -b nl.overheid.digitaledienst.mailboxApp |
opens the app behind the AppUserModelID |
| Keyring | Secret Service | Keychain | Credential Manager |
| State | $XDG_STATE_HOME/mailbox-app-push-agent |
~/Library/Application Support/mailbox-app-push-agent |
%LOCALAPPDATA%\mailbox-app-push-agent |
| Started at login (development route) | systemd user unit | LaunchAgent | HKCU\…\Run |
| Verified | tests and e2e; desktop on a Linux machine still open | on a Mac (see below) | unverified until there is a Windows machine or runner |
The code that talks to the gateway and the hoster has no platform dependency; only the notifier, the
defaults and the packaging differ per operating system (build tags and _linux/_darwin/_windows
files). On every operating system the agent registers only the pushtoken the gateway gave it: the
gateway sealed its kanaal inside, so the hoster never learns how the agent is reached, and nobody
learns the operating system.
Behaviour
- Take the lock
agent.lockin the state directory. One agent runs per citizen: a second one, started by hand or by macOS to hand it a click on a notification, logs "already running" and stops with exit code 0, so launchd (KeepAliveSuccessfulExitfalse) and systemd (Restart=on-failure) leave it stopped. On macOS it first sets up the notifications for 5 s, so a click that started it still opens the app. The operating system lets go of the lock when the agent ends, also after a crash. - Read the brievenbus from the keyring (see below). It is read again for every connection, and every 10 s while connected (locally, nothing goes over the network): when the app replaced the brievenbus the agent connects again for the new one; when the app removed it the agent closes the connection and waits, without notifications, until the app writes one again.
- Connect to
GET /push/v1/verbinding. The first message carries a pushtoken. - Register that pushtoken at the hoster:
PUT /hoster/v1/brievenbussen/{functioneelAdres}/apparaten/{apparaatId}with body{pushtoken}. The apparaatId is the agent's own (<random>-agent), kept in its state, so the hoster sees the agent apart from the app's own registrations. The pushtoken changes with every connection (C9 in the design). - Catch up once: fetch the signals and show one "Er is post" if any arrived since the agent last looked. Seintjes sent while the agent was away were refused by the gateway with 410. On the very first run nothing is announced.
- Show "Er is post" for every seintje. Reading the connection answers the gateway's pings.
- When the connection ends, reconnect with back-off: a random delay below a ceiling that doubles from 1 s to 5 min, reset after every successful registration.
Only the first read after the start may make the operating system ask the citizen to unlock the keyring. Later reads are quiet: on Linux the agent first asks Secret Service whether the login collection is locked, which never prompts. While it is locked the agent keeps its connection and reconnects for the brievenbus it read last, and notices a replaced brievenbus once it is unlocked.
A notification never shows a sender, subject or text. The state file holds no burgerenveloppen, only their SHA-256 fingerprints, to tell new signals from announced ones, and the fingerprint of the brievenbus they belong to: after the app replaced the brievenbus, the mail already in the new one is not announced, as on a first start.
Handover from the app
The app owns the brievenbus; the agent only reads it. The app writes one keyring entry:
| Service | nl.overheid.digitaledienst.mailbox_app (the app's application id) |
| User | brievenbus |
| Secret | {"basisUrl":"https://mijnbo.cluster-a.fieldlab2026.nl","pushgatewayUrl":"…","functioneelAdres":"…","toegangstoken":"…"} |
basisUrl is the hoster, pushgatewayUrl the app-uitgever's pushgateway. Where every public API
shares one hostname, as on mijnbo, both are the same; pushgatewayUrl may then be left out.
On Linux that is a Secret Service item in the default collection with the attributes
service=nl.overheid.digitaledienst.mailbox_app and username=brievenbus, as
go-keyring reads it. By hand:
secret-tool store --label='Notificatie voor Burgers' service nl.overheid.digitaledienst.mailbox_app username brievenbus
On macOS it is a generic password in the login Keychain with service and account as above. By hand:
security add-generic-password -U -s nl.overheid.digitaledienst.mailbox_app -a brievenbus -w '{"basisUrl":"…","functioneelAdres":"…","toegangstoken":"…"}'
go-keyring reads it through /usr/bin/security, so an item the app writes through the Keychain API
must allow that tool access, or macOS asks the citizen. On Windows it is a generic credential with
target name nl.overheid.digitaledienst.mailbox_app:brievenbus and the JSON as UTF-8 blob.
The mailbox-app writes this entry on every start and for every new brievenbus while "Meldingen op de
achtergrond" is on (the default on desktops), and then opens no WebSocket of its own, so no
notification comes twice. Turned off, it deletes the entry and connects live itself. It runs as a
single instance, so a click on a notification brings the open window forward. The installers in
mailbox-app-installer start the agent at login; the app itself does not.
Running
mailbox-app-push-agent # keyring and desktop notifications
mailbox-app-push-agent --credentials-file brievenbus.json --notifier log # containers and tests
| Option | Environment | Default |
|---|---|---|
--credentials-file |
CREDENTIALS_FILE |
the keyring |
--notifier (desktop, log) |
NOTIFIER |
desktop |
--app-command |
APP_COMMAND |
what a click opens: a command on Linux (mailbox_app) and macOS (/usr/bin/open -b nl.overheid.digitaledienst.mailboxApp), the AppUserModelID on Windows (nl.overheid.digitaledienst.mailboxApp) |
--state-directory |
STATE_DIRECTORY |
per operating system, see the table above; systemd sets it on Linux |
--log-file |
LOG_FILE |
stderr; the Windows build has no console, so its install script sets a file |
--reconnect-initial / --reconnect-maximum |
RECONNECT_INITIAL / RECONNECT_MAXIMUM |
1s / 5m |
--credentials-check |
CREDENTIALS_CHECK |
10s: how often the keyring is read again to notice a replaced or removed brievenbus |
The desktop notifier uses org.freedesktop.Notifications on the session bus; clicking a notification
of the agent starts the app command.
macOS
macOS ties notification permission to a bundle identifier, so the agent runs inside a small helper
bundle (packaging/macos): MailboxAppPushAgent.app, bundle identifier
nl.overheid.digitaledienst.mailboxApp.pushAgent (MACOS_BUNDLE_IDENTIFIER), shown as "Notificatie
voor Burgers – meldingen", LSUIElement so it has no Dock icon. The notifier is Objective-C through
cgo, so the macOS build happens on a Mac, not on the CI runners. On first start macOS asks the citizen
to allow its notifications.
System Settings > Notifications lists the app and this helper as two entries; only the helper's, the
one ending in "– meldingen", decides whether notifications show. Without it macOS accepts every
notification and shows none. The agent therefore reads the permission before every notification and
every 30 seconds, logs a warning once per change, and reports each change to the app in the login
keychain, the reverse of the handover: user meldingen under the same service, secret
{"meldingenToegestaan":false,"sinds":"2026-11-24T14:00:00Z"}, which go-keyring stores on macOS as
go-keyring-base64: plus base64. A sandboxed app cannot read the agent's
state directory, but both reach that keychain through /usr/bin/security without asking the citizen.
The app then tells the citizen which entry to switch on.
make bundle-macos # build for this Mac and sign the bundle ad hoc
make dist-macos # universal (arm64 + amd64) bundle, zipped
make install-agent # development route: bundle in ~/Applications, LaunchAgent in ~/Library/LaunchAgents
make uninstall-agent
tail -f ~/Library/Logs/mailbox-app-push-agent.log
The ad hoc signature is enough on the Mac that built it. Other Macs need a Developer ID signature and
notarization (CODESIGN_IDENTITY), which wait for an Apple Developer ID (ADR 0003).
Verified on a Mac (macOS 26, Apple silicon): installed with make install-agent, the agent read a
brievenbus of the local k3d cluster from the Keychain, registered at the hoster, received the seintje
for a bericht from the bronorganisatie and handed "Er is post" to the Notification Center, which
stored it under "Notificatie voor Burgers" and asked for permission to show banners. Still to check by
hand: the banner once allowed, and that a click opens the app.
Windows
Built, not verified: there is no Windows machine or runner yet. The binaries are pure Go and
cross-compile from any machine (make dist-windows, a zip per architecture with a windowless exe and
the scripts in packaging/windows).
- The toast goes through the WinRT notification API via PowerShell, with the texts and the
AppUserModelID passed in the environment. Windows only shows toasts for an AppUserModelID it knows:
the development script declares it in
HKCU\Software\Classes\AppUserModelId; the installer gives the app's Start menu shortcut that ID. Whether a click opens the app without a COM activator is unknown. - Started at login through
HKCU\Software\Microsoft\Windows\CurrentVersion\Run, in the citizen's own session; a Windows Service runs in session 0 and cannot show toasts. install.ps1/uninstall.ps1are the development route, without administrator rights: the exe in%LOCALAPPDATA%\Programs\mailbox-app-push-agent, the log in%LOCALAPPDATA%\mailbox-app-push-agent.
One installer with the app
The agent ships together with the mailbox-app in one installer per operating system (ADR 0003),
built in mailbox-app-installer. Nothing in the agent assumes where it is installed: what a click opens, the state
directory, the log and the bundle identifier are options or build variables, and the development
install scripts above are only that.
- Linux: the deb/rpm installs the binary as
/usr/bin/mailbox-app-push-agentand the systemd user unit in/usr/lib/systemd/user, enabled per user (systemctl --global enable). - macOS: the helper bundle goes into the app at
Contents/Library/LoginItems/MailboxAppPushAgent.app, with a LaunchAgent plist inContents/Library/LaunchAgentswhoseBundleProgramisContents/Library/LoginItems/MailboxAppPushAgent.app/Contents/MacOS/mailbox-app-push-agent. For now the package's postinstall writes a LaunchAgent that starts it; once the app registers it withSMAppService.agent(plistName:), that goes. Notarizing the whole app waits for a Developer ID. - Windows (scaffolded, never built): the installer puts
mailbox-app-push-agent.exenext to the app, gives the app's Start menu shortcut the AppUserModelIDnl.overheid.digitaledienst.mailboxApp, and registers the agent to start at login (Runkey or a logon task) with--app-commandset to that ID.
Installing on Linux
Per user, no root, with a systemd user unit (packaging/linux):
make install-agent # build, copy to ~/.local/bin, enable and start the user unit
make uninstall-agent
journalctl --user -u mailbox-app-push-agent -f
make dist builds a tarball per architecture (linux-amd64, linux-arm64) with the binary, the unit
and install.sh/uninstall.sh; unpack it and run ./install.sh. Citizens get the deb or rpm of
mailbox-app-installer instead (see "One installer with the app").
Development
make test
make lint
make build
docker build --target production -t code.digitaledienst.overheid.nl/mijn-betaaloverzicht/mailbox-app-push-agent:dev .
The Linux and Windows binaries are pure Go (CGO_ENABLED=0) and cross-compile from any machine; the
macOS build needs cgo and a Mac. make lint lints for this machine, Linux and Windows. The tests run the
agent with its real gateway and hoster clients against a fake gateway and hoster (httptest).
Desktop notifications, the click and systemd can only be verified on a Linux desktop.
The image exists for the end-to-end test in getting-started, which runs the agent in the cluster with
--credentials-file and --notifier log. Citizens use the installers.
CI
.forgejo/workflows/ci.yml vets, tests, lints (Linux and Windows) and cross-compiles for linux and
windows on amd64 and arm64 on every push and pull request. macOS is not built in CI: the runners are
Linux and the notifier needs cgo with the macOS SDK, so make dist-macos runs on a Mac. On main it pushes the image
code.digitaledienst.overheid.nl/mijn-betaaloverzicht/mailbox-app-push-agent:<commit>.
License
EUPL-1.2, see LICENSE.