No description
  • Erlang 81.7%
  • Python 11.7%
  • Shell 3.7%
  • Dockerfile 2.9%
Find a file
2026-11-24 01:10:50 +01:00
.github ci: call the C4 gate that reads the front page 2026-10-23 21:07:42 +02:00
apps/mcl_citizens The Erlang cookie stays on the box; distribution and epmd on loopback (PR 1 squashed) 2026-11-23 21:14:18 +01:00
architecture build: 0.5.0, macula 18 and mcl_om 1.6 (mcl-om#42) 2026-10-30 15:52:30 +01:00
assets build: 0.5.0, macula 18 and mcl_om 1.6 (mcl-om#42) 2026-10-30 15:52:30 +01:00
config The Erlang cookie stays on the box; distribution and epmd on loopback (PR 1 squashed) 2026-11-23 21:14:18 +01:00
deploy The Erlang cookie stays on the box; distribution and epmd on loopback (PR 1 squashed) 2026-11-23 21:14:18 +01:00
scripts The Erlang cookie stays on the box; distribution and epmd on loopback (PR 1 squashed) 2026-11-23 21:14:18 +01:00
.gitignore scaffold: rebar3 new mcl_service from mcl_om 3f76daf 2026-09-23 23:49:12 +02:00
.tool-versions scaffold: rebar3 new mcl_service from mcl_om 3f76daf 2026-09-23 23:49:12 +02:00
CHANGELOG.md Release 0.6.0 (#14) 2026-11-02 18:36:27 +01:00
Containerfile The Erlang cookie stays on the box; distribution and epmd on loopback (PR 1 squashed) 2026-11-23 21:14:18 +01:00
LICENSE scaffold: rebar3 new mcl_service from mcl_om 3f76daf 2026-09-23 23:49:12 +02:00
README.md README: drop the GitHub Sponsors badge 2026-11-23 22:19:57 +00:00
rebar.config Release 0.6.0 (#14) 2026-11-02 18:36:27 +01:00
SECURITY.md SECURITY.md: response times, attachment and identity rules, drills (macula-io/macula#174) 2026-10-31 02:59:02 +01:00

mcl-citizens

CI License ghcr.io BEAM Buy Me a Coffee

Macula

The citizens directory for the Macula mesh: who exists, federated across instances by mesh facts


Built on macula 18 and mcl_om 1.6.

What it does

A public phone book of who is on the mesh right now. register_presence, list_citizens and get_citizen are the service's own procedures, and the only ones; mcl_om adds <org>/info and <org>/get_limits to every service, both open, and capabilities/0 is the list. /health answers on the Unix socket /run/mcl/health.sock.

Procedure Payload Reply
mcl-citizens/register_presence optional citizen_kind (at most 32 bytes), display_name (at most 64 bytes), offers (at most 16, each at most 64 bytes), ttl_ms (default and maximum 20 minutes), and optionally citizen_did #{ok => 1, expires_at => Ms} or #{ok => 0, error => Text}
mcl-citizens/list_citizens optional limit (1 to 200, default 100) and after (a citizen_did, 64 hex text) #{ok => 1, citizens => [Citizen], next => Did}, next absent on the last page, or #{ok => 0, error => "invalid_page"}
mcl-citizens/get_citizen citizen_did, 64 hex text #{ok => 1, citizen => Citizen} or #{ok => 0, error => Text}: not_found, invalid_citizen_did or invalid_payload

A Citizen is citizen_did (lowercase hex text), citizen_kind, display_name, offers, registered_at and expires_at (milliseconds), absent fields omitted. Every string goes out as {text, Bin}, so callers outside the BEAM get strings and not hex.

One entry costs a bounded amount, and every entry is text. Each of display_name, citizen_kind and every offer must be non-empty UTF-8 with no control character, within the limits in the table; a registration that is not is refused and nothing is written. The reasons are display_name_too_long, invalid_display_name, citizen_kind_too_long, invalid_citizen_kind, too_many_offers, offer_too_long and invalid_offer. The same check runs on a presence fact heard from another instance. Without it, one name that is not valid UTF-8 made every list_citizens reply unsendable.

list_citizens answers a page. Entries come ordered by citizen_did. To read the whole directory, call again with after set to the next you got, until a reply carries no next. One reply holds at most 200 entries, whatever the directory holds.

A citizen registers itself and nobody else. macula signs every CALL with the caller's identity key and verifies it here before the handler runs, so the registration is the verified caller's own and no proof travels in the payload. A citizen_did sent anyway must be the caller's, or the call is refused with citizen_did_is_not_the_caller.

Entries expire. An entry lives for its ttl_ms from registered_at, at most twenty minutes; clients re-register about every five minutes. The latest registration wins, by registered_at.

The directory is soft state, empty after a restart for up to one republish interval. It is held in memory, not on disk: every entry expires within twenty minutes anyway, and client re-registrations and the other instances' facts refill it.

Instances federate. Each registration is published as the fact <realm>/mcl-citizens/citizens/directory/citizen_presence_registered_v1. An instance admits a fact only from a publisher whose signature macula verified and whose node id is in MCL_CITIZENS_PRESENCE_PUBLISHERS, and computes the expiry itself from the fact's registered_at and ttl_ms. A registration stamped more than a minute ahead of the receiving clock is refused.

/health is down without the directory and degraded while the federation subscription is not held, which includes a dark mesh.

Running it

rebar3 compile
rebar3 eunit
rebar3 lint
rebar3 dialyzer

scripts/health.sh                      # against a running node

The image builds in the team's macula-ci-otp image and runs on macula-pq-runtime, both pinned by dated tag and digest (the same pair every mcl service uses); the service tests hold the pins.

podman build -t mcl-citizens -f Containerfile .

Configuration

Variable Default Meaning
MCL_REALM required 64-hex realm tag, the sha256 of the realm's name. No default: a service that guesses its realm announces itself where nobody can attribute it.
MCL_REALM_KEY required The realm's public signing key, hex encoded: the trust anchor, not an identifier. Every org-namespaced advertisement is verified against it, so without it nothing resolves, the boot claim never reaches the realm, and the service stays green while unreachable. Public material, not a secret.
MACULA_STATION_SEEDS required Station hosts to dial, host[:port], comma-separated. No default: naming a realm costs nothing, dialling somebody else's live station from every dev clone does.
MACULA_STATION_NODE_IDS required The matching 64-hex station node ids, comma-separated, index-paired with the seeds. The dial is pinned (D5): mcl_om refuses to boot a pool with an unpinned seed.
MCL_REALM_NAME required The realm's name, as the fact topic carries it. At start, sha256 of it must equal MCL_REALM or the node refuses to start.
MCL_CITIZENS_PRESENCE_PUBLISHERS required Node ids of the mcl-citizens instances to federate with, 64 hex each, comma separated. This instance's own id is added automatically; a single instance lists itself. Missing or malformed stops the node.
MCL_SERVICE_NAME mcl-citizens The service label on the claim the realm's operator sees at boot. Falls back to the service's own name.
MCL_BOX empty The host label on that claim: which box is asking. Set by whatever deploys the service.
MCL_NODE_NAME mcl_citizens Erlang node name.
MCL_NODE_HOST 127.0.0.1 Erlang node host.
MCL_COOKIE unset Erlang cookie. Unset, the image makes a random one on first start in the secrets volume (/etc/mcl/secrets/erlang.cookie, 0600) and keeps it. Distribution and epmd listen on 127.0.0.1 only. A remote shell: docker exec -it mcl-citizens /app/start.sh remote_console.

deploy/docker-compose.yml runs it, and carries what the service knows about itself. If you deploy through something else, let that carry placement: which host, which station, which realm, which secret store. Keeping the two apart is what stops a config table in a README and the real environment drifting.

Deployment

A v* tag publishes ghcr.io/macula-services/mcl-citizens:<version> and nothing else, signed by digest with its SBOM and provenance (macula-ci-images' attest-image.yml). A push to main publishes :main and :<sha>; no deployment takes them, and :latest does not move. The fleet runs a release by digest: macula-fleet's pin-releases workflow finds the signed release, verifies it was signed on its tag and pins <version>@sha256:<digest> (macula-fleet#14, #15), so a green v* tag is the deploy. To roll back, revert the pin and hold the image there. A push that changes only documentation builds no image (scripts/is_image_push.sh).

The service's org, the <org> that prefixes its own procedures (<org>/<name>), is this repository's name, fixed in config/sys.config.src. The realm's grant names it; without an org mcl_om refuses to boot, naming the setting.

Two things CI cannot do for you, both of which have bitten:

  1. The registry package may be created private, and the pull then fails on the host with a bare unauthorized that names nothing. Check it after the first build. On ghcr the org.opencontainers.image.source label in the Containerfile is what links the package to the repository.
  2. The host needs MCL_REALM, MCL_REALM_NAME, the instance list and MACULA_STATION_SEEDS plus MACULA_STATION_NODE_IDS, supplied from somewhere they are not committed.

The service contract

Six callbacks in mcl_citizens_service, all required, all resolved by name by mcl_om at startup on a live node. The -behaviour(mcl_om_service) attribute turns a missing one into a compile error rather than an undef where nobody is watching, and the eunit suite guards the attribute itself.

Adding a store later

This service has no reckon-db store, which is the right answer for most. The reckon-db applications run either way; what a store adds is a data directory, an open handle, and something written.

The cheapest way to get one is to scaffold again with store=1, which generates the callbacks, the config and the guards together.

⚠ By hand it is three things and not one, and the missing third crash-loops the node. Export store_id/0 and data_dir/0; add the evoq adapter block to config/sys.config.src, without which boot raises {not_configured, event_store_adapter} before any service code runs; and mount a volume in the compose file. A sibling service put two of three fleet nodes into a boot loop by doing the first and not the second.

Architecture

The C4 model is in architecture/README.md, with its diagrams drawn by architecture/c4_diagrams.py into assets/. Change the script, run it (python3 architecture/c4_diagrams.py), and look at the result before committing.

mcl-citizens system context

Licence

Apache-2.0.