ADR-0012: Deploy the backend with Juju charms on Kubernetes¶
Status: accepted
Date: 2026-11-09
Context¶
Operators need to deploy, configure, relate and upgrade the backend (API, bridge, ingest, broker) together with PostgreSQL and Kafka, without copying connection strings and passwords between systems. On Kubernetes each service runs in its own pod, so two things the Compose stack gets from a shared host are missing: a keyring directory that the API and ingest both read, and a CRL file that the API writes and Mosquitto reads.
Charmed PostgreSQL also shapes the database access. A plain relation user
is switched to the database’s owner role at login (a login hook runs
SET ROLE charmed_<database>_owner), so a service that connected with it
would own the tables and could disable row-level security. And relation
users cannot create roles: on a live Charmed PostgreSQL 16 the relation user
has no CREATEROLE, and the charm accepts only charmed_stats,
charmed_read, charmed_dml, charmed_admin or superuser as extra user
roles.
Decision¶
Four sidecar charms written with
ops:fleetwire-api-k8s,fleetwire-ingest-k8s,fleetwire-bridge-k8sandmosquitto-k8s. Each reconciles on every event: it reads its config, its secret and its relations, writes the files and the Pebble layer, andreplanrestarts the workload only when the layer changed. Statuses come from collect-status:blockednames the missing relation or secret and the command that fixes it,waitingmeans relation data or the workload is not ready,activemeans the workload’s own/readyz(or the broker’s port) answers.Canonical’s charms for the data stores:
postgresql-k8s16/stable overpostgresql_client,kafka-k8s4/stable (KRaft) overkafka_client, both throughdata_platform_libs. Kafka requires SASL/SCRAM-SHA-512, and TLS when it is related to a certificates provider; bridge and ingest take both from the relation. The bridge asks for producer rights onfleetwire.uplink.v1; ingest asks for consumer and producer rights onfleetwire.*(the uplink and dead-letter topics, and CREATE forensure-topics) and uses the granted consumer-group prefix.Two kinds of database login. The API’s
databaserelation (no extra roles) is the schema owner; the leader uses it only to runfleetwire-api migrateandcreate-operator-tokenin its workload container. The services log in through their own relations requested with the extra user rolecharmed_dml: the API’sruntime-databaseand ingest’sdatabase. Those users are not admins of the database, so the login hook leaves them as they are, and they cannot switch to the owner. Migrate runs withFLEETWIRE_DATABASE_RUNTIME_ROLE=charmed_dml, so the policies and grants name the group the runtime users belong to (ADR-0006). Ingest never sees the owner’s credentials, and it starts only once the API says, over theingestrelation, that the schema exists. A brokenruntime-databaserelation stops the API; a brokendatabaserelation makes the leader migrate again when one returns.The KEKs stay with the API. The local keyring lives on the API unit’s storage. Ingest uses the remote keyring backend: the API serves wrap and unwrap on an internal listener (
:8445), mutual TLS with service certificates, and admits onlyfleetwire-ingest. Data keys cross the wire; KEKs never do. With one keyring directory, the API application runs one unit, and the charm blocks with the reason if it is scaled up.The broker fetches the CRL. The API serves its latest CRL at
GET /v1/crlon the device listener. The Mosquitto charm gets that URL over thecrlrelation, fetches it over TLS verified against the CA bundle on every update-status hook and relation change, writes it only when it changed, and sends SIGHUP through Pebble.Own interfaces for what only fleetwire needs:
fleetwire_mqtt(Mosquitto publishes its service listener URL),fleetwire_ingest(keyring URL and schema readiness) andfleetwire_crl(CRL URL).PostgreSQL settings: the bundle enables the charm’s
btree_gistplugin (the chunk exclusion constraint needs it) and gives fleetwire a PostgreSQL of its own, becausecharmed_dmlreads and writes every database of the cluster that its members can connect to.Secrets: CA keys, the keyring root key and service certificates are Juju user secrets, one per application with only what that workload needs; charm config holds the secret ID. Files land in the workload owned by the workload’s user, mode 0600.
Operator bootstrap: the API charm’s
create-operator-tokenaction runs the command with the owner credentials only the charm holds.Tests:
ops.testingstate-transition unit tests for every charm, and a Jubilant integration test that deploys the bundle on MicroK8s, enrolls a real agent through port-forwards and checks that every acknowledged reading is stored.
Alternatives considered¶
Helm charts. Templates without a model of relations: database and Kafka credentials would be copied by hand or through an external secret store.
Migrate creates a login role (
fleetwire_app) with a generated password. Built first, and refused by Charmed PostgreSQL: relation users have noCREATEROLE(permission denied to create role).Services log in as the owner relation user and
SET ROLEdown to a less privileged role. Row-level security would hold for correct code, but a compromised service couldRESET ROLEand act as the owner.Requesting
superuser. It would allow creating roles, and make every API pod a cluster superuser.Keyring files on a shared volume. Juju storage belongs to one unit; a ReadWriteMany volume outside Juju would hold every tenant’s KEK where both pods, and its backups, can read it.
One charm for API and ingest. One pod would share the directory, but the two scale and fail differently, so each has its own charm.
The API pushes the CRL into the relation data. It works for small lists but puts a growing blob in every relation change; a URL keeps the relation small and lets other brokers use the same endpoint.
A Vault Transit or cloud KMS keyring. The right production answer, because it also removes the one-unit limit; it is future work behind the same
Keyringinterface.
Consequences¶
charmed_dmlis wider than fleetwire’s own grants: it includespg_read_all_dataandpg_write_all_dataon every database its members can connect to. Row-level security still applies to fleetwire’s tables, but the runtime logins could read other applications’ databases on a shared PostgreSQL, hence a dedicated one.The API application is limited to one unit until a shared keyring backend exists. Its pod restarting delays ingest only once ingest’s cached data keys expire (5 minutes); batches wait and are retried, they are not dead-lettered.
Revocation at the broker lags by up to the update-status interval (5 minutes by default). Ingest drops a revoked device’s data from the moment of revocation (ADR-0010, layer 1), so nothing from it is stored in that window.
Devices outside the cluster need the broker’s device port and the API’s device port exposed (a LoadBalancer or NodePort service); the charms do not create those.
Charm code is Python, the rest is Go: two toolchains in CI.