No description
  • Erlang 54%
  • Shell 20.2%
  • Python 19.9%
  • Dockerfile 5.9%
Find a file
2026-11-24 01:13:04 +01:00
.github No crew member or lab box names in a public tree 2026-11-23 21:24:29 +01:00
apps/mcl_turn_credentials The Erlang cookie stays on the box; distribution and epmd on loopback (PR 1 squashed) 2026-11-23 21:21:13 +01:00
architecture c4: name both open procedures and the one capability the service declares 2026-10-23 04:31:03 +02:00
assets c4: name both open procedures and the one capability the service declares 2026-10-23 04:31:03 +02:00
config The Erlang cookie stays on the box; distribution and epmd on loopback (PR 1 squashed) 2026-11-23 21:21:13 +01:00
deploy The Erlang cookie stays on the box; distribution and epmd on loopback (PR 1 squashed) 2026-11-23 21:21:13 +01:00
scripts The Erlang cookie stays on the box; distribution and epmd on loopback (PR 1 squashed) 2026-11-23 21:21:13 +01:00
.gitignore scaffold: rebar3 new mcl_service from mcl_om 3f76daf 2026-09-23 23:05:38 +02:00
.tool-versions scaffold: rebar3 new mcl_service from mcl_om 3f76daf 2026-09-23 23:05:38 +02:00
CHANGELOG.md advisories: refuse a dependency with a published advisory before the image ships (#12) 2026-11-02 22:03:16 +01:00
Containerfile The Erlang cookie stays on the box; distribution and epmd on loopback (PR 1 squashed) 2026-11-23 21:21:13 +01:00
LICENSE scaffold: rebar3 new mcl_service from mcl_om 3f76daf 2026-09-23 23:05:38 +02:00
README.md README: drop the GitHub Sponsors badge 2026-11-23 22:20:51 +00:00
rebar.config docs: the floor statements say 16, and the tests hold it 2026-10-22 03:35:13 +02:00
SECURITY.md SECURITY.md: response times, attachment and identity rules, drills (macula-io/macula#174) 2026-10-31 02:59:49 +01:00

mcl-turn-credentials

CI License ghcr.io BEAM Buy Me a Coffee

Macula

Mints short-lived TURN credentials over the mesh, keeping the master secret out of client apps


Built on macula 16 through mcl_om 1.4 (wire 1.0), the wire the live fleet runs.

What it does

mcl-turn-credentials/mint_credential is the service's own procedure, and the only one. The service also answers /health on 8485. mcl_om adds mcl-turn-credentials/info and mcl-turn-credentials/get_limits to every service, open to any caller; capabilities/0 is the list.

A call returns one TURN credential in coturn's use-auth-secret (REST API) scheme: the username is a unix expiry timestamp and the password is base64(HMAC-SHA1(secret, username)). coturn derives the same pair from the same secret when the client allocates, so the service never talks to coturn, and the master secret never ships inside a client app.

#{username    => {text, <<"1790000000">>},
  credential  => {text, <<"base64 HMAC">>},
  ttl_seconds => 3600,
  urls        => [{text, <<"turn:turn.macula.io:3478?transport=udp">>}]}

Every string in the reply is tagged text. A bare binary would reach non-BEAM callers as 0x-hex, and a hex username is useless to an ICE agent.

mint_credential is open: any peer that reaches it gets a credential. The service keeps the secret out of public clients; it does not decide who may place a call. It asks the realm for no pubsub authority, because it publishes and subscribes to nothing.

/health is down while TURN_SHARED_SECRET is unset or empty, because every mint call would fail. A dark mesh is not a health failure.

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-turn-credentials -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. An 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 a production 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.
TURN_SHARED_SECRET required coturn's static-auth-secret, byte for byte. A secret: supply it from the host, never commit it. Without it /health is down and a mint answers turn_shared_secret_not_configured.
MCL_SERVICE_NAME mcl-turn-credentials 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_HEALTH_PORT 8485 Health endpoint, assigned in macula-fleet PORTS.md. Host networking makes a collision a silent bind failure, so take a new one from there rather than picking one.
MCL_NODE_NAME mcl_turn_credentials 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-turn-credentials /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

The image has two channels. A push to main publishes ghcr.io/macula-services/mcl-turn-credentials:main and :<sha>, the tip, for trying; nothing follows it. A v* tag publishes :<semver> and, once attest has signed that digest, moves :latest onto it; a host installs the release it wants and the semver tags stay published as the rollback archive. A push that changes only documentation builds no image (scripts/is_image_push.sh).

The service's org, the <org> prefix on its own procedure's name (<org>/<name>), is this repository's name, fixed in config/sys.config.src. The realm's grant names it; a node without an org refuses to boot.

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, the station seeds with their matching node ids, and TURN_SHARED_SECRET supplied from somewhere they are not committed.

The service contract

Six callbacks in mcl_turn_credentials_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-turn-credentials system context

Licence

Apache-2.0.