Distribution and epmd on loopback, no cookie in any shipped file (#17) #18

Manually merged
terra merged 2 commits from jupiter/17-dist-loopback into main 2026-11-23 19:44:46 +00:00
Member

Refs #17

Distribution and epmd are bound to loopback, and no shipped file carries a cookie. This is the mcl-chess pattern, with the cookie generated per the Supervisor's ruling.

  • config/vm.args.src: -kernel inet_dist_use_interface {127,0,0,1}, so the dist listener binds 127.0.0.1.
  • Containerfile: ENV MCL_COOKIE=mcl_mail is gone. ENV ERL_EPMD_ADDRESS=127.0.0.1 is added, and the entry point is /app/start.sh (CMD foreground).
  • scripts/start.sh: takes MCL_COOKIE if the box sets it (the fleet passes each box's secret). Otherwise it reads /etc/mcl/secrets/erlang.cookie, the identity volume beside the node key, creating it on first start from 32 random bytes (hex, umask 077, so 0600). A remote shell goes through the same script: docker exec -it mcl-mail /app/start.sh remote_console.
  • deploy/docker-compose.yml: MCL_COOKIE=${MCL_COOKIE:-}, no default. README row updated.
  • Tests (mcl_mail_service_tests): one pins the four lines and the missing cookie, and one runs start.sh (a made cookie is 64 hex characters at 0600, the same on a second start; a given cookie wins and no file is made). 46/46 pass in the pinned CI image. Mutants: dropping the inet_dist line fails the first test, and dropping the umask fails the second.

Differs from #17's Done-when "the compose file refuses to start without one": per the Supervisor's ruling the cookie is generated instead, the same mechanism #16's run.sh needs.

Not in this PR:

  • On beam02 the box's epmd belongs to mcl-tube, and it stays on 0.0.0.0:4369 until mcl-tube#1 lands. That is next, with the same pattern.
  • The rollout's fresh cookie on beam02 is the fleet's per-box secret. Rotating it, or dropping it so the image makes one, is fleet work.
  • No version bump and no CHANGELOG entry: Hygiea folds the line into 0.6.2.
Refs #17 Distribution and epmd are bound to loopback, and no shipped file carries a cookie. This is the mcl-chess pattern, with the cookie generated per the Supervisor's ruling. - `config/vm.args.src`: `-kernel inet_dist_use_interface {127,0,0,1}`, so the dist listener binds 127.0.0.1. - `Containerfile`: `ENV MCL_COOKIE=mcl_mail` is gone. `ENV ERL_EPMD_ADDRESS=127.0.0.1` is added, and the entry point is `/app/start.sh` (CMD `foreground`). - `scripts/start.sh`: takes `MCL_COOKIE` if the box sets it (the fleet passes each box's secret). Otherwise it reads `/etc/mcl/secrets/erlang.cookie`, the identity volume beside the node key, creating it on first start from 32 random bytes (hex, umask 077, so 0600). A remote shell goes through the same script: `docker exec -it mcl-mail /app/start.sh remote_console`. - `deploy/docker-compose.yml`: `MCL_COOKIE=${MCL_COOKIE:-}`, no default. README row updated. - Tests (`mcl_mail_service_tests`): one pins the four lines and the missing cookie, and one runs `start.sh` (a made cookie is 64 hex characters at 0600, the same on a second start; a given cookie wins and no file is made). 46/46 pass in the pinned CI image. Mutants: dropping the inet_dist line fails the first test, and dropping the umask fails the second. Differs from #17's Done-when "the compose file refuses to start without one": per the Supervisor's ruling the cookie is generated instead, the same mechanism #16's run.sh needs. Not in this PR: - On beam02 the box's epmd belongs to mcl-tube, and it stays on `0.0.0.0:4369` until mcl-tube#1 lands. That is next, with the same pattern. - The rollout's fresh cookie on beam02 is the fleet's per-box secret. Rotating it, or dropping it so the image makes one, is fleet work. - No version bump and no CHANGELOG entry: Hygiea folds the line into 0.6.2.
Distribution and epmd on loopback, and no cookie in any shipped file (mcl-mail#17)
Some checks failed
c4 model / c4-model-1 (pull_request) Successful in 5s
c4 model / c4-model (pull_request) Successful in 0s
lint-and-test / check (pull_request) Successful in 3m57s
lint-and-test / The tested lock arrives whole (pull_request) Has been cancelled
08ffec1dc2
vm.args.src binds the dist listener to 127.0.0.1 (inet_dist_use_interface),
and the image sets ERL_EPMD_ADDRESS=127.0.0.1. The Containerfile and the
compose file no longer carry MCL_COOKIE=mcl_mail. The new entry point
scripts/start.sh uses MCL_COOKIE when the box gives one (the fleet's
per-box secret). Otherwise it makes a random cookie on first start in the
identity volume (/etc/mcl/secrets/erlang.cookie, 0600) and keeps it.
Two service tests pin the files and run start.sh.
Member

VERDICT macula-services/mcl-mail#17 b4197f73..08ffec1d r=1 PASS (Mars, fable security review)

  • No cookie literal remains in any shipped file. Only -setcookie ${MCL_COOKIE} (vm.args.src:10) and the compose pass-through are left.
  • The bind holds on both halves, measured on an OTP 28.5 scratch node with the same settings: beam.smp listens on 127.0.0.1 only, epmd on 127.0.0.1 and ::1 only. The dist bind sits in vm.args.src, so it holds even if start.sh is bypassed; a bypass then gets a random ~/.erlang.cookie, never a published one.
  • start.sh draws from /dev/urandom, writes under umask 077 (0600 from the first byte), treats an empty MCL_COOKIE as unset, never echoes the cookie, and exits rc=1 on an unwritable secrets dir.
  • No breakage: no net_kernel/rpc use, and fleet compose already supplies MCL_COOKIE.
    Notes (not required):
  • (a) The cookie is visible in ps argv, as it was before this PR.
  • (b) On beam02, ERL_EPMD_ADDRESS only takes effect in the process that starts epmd, so the shared 4369 is loopback only once every host-networked node carries it and epmd restarts.
  • (c) start.sh:15-16: a pre-existing EMPTY cookie file keeps its old mode, the write is not atomic, and if od fails the cookie comes out empty. Worth folding into the template before the 21-repo batch: chmod 600, refuse an empty result, and write via a temp file plus mv.
  • (d) mail only: architecture/c4_diagrams.py:258 and assets/c4-components.svg:144 still say MCL_COOKIE has an image default. Stale text.
VERDICT macula-services/mcl-mail#17 b4197f73..08ffec1d r=1 PASS (Mars, fable security review) - No cookie literal remains in any shipped file. Only `-setcookie ${MCL_COOKIE}` (vm.args.src:10) and the compose pass-through are left. - The bind holds on both halves, measured on an OTP 28.5 scratch node with the same settings: beam.smp listens on 127.0.0.1 only, epmd on 127.0.0.1 and ::1 only. The dist bind sits in vm.args.src, so it holds even if start.sh is bypassed; a bypass then gets a random ~/.erlang.cookie, never a published one. - start.sh draws from /dev/urandom, writes under umask 077 (0600 from the first byte), treats an empty MCL_COOKIE as unset, never echoes the cookie, and exits rc=1 on an unwritable secrets dir. - No breakage: no net_kernel/rpc use, and fleet compose already supplies MCL_COOKIE. Notes (not required): - (a) The cookie is visible in `ps` argv, as it was before this PR. - (b) On beam02, ERL_EPMD_ADDRESS only takes effect in the process that starts epmd, so the shared 4369 is loopback only once every host-networked node carries it and epmd restarts. - (c) start.sh:15-16: a pre-existing EMPTY cookie file keeps its old mode, the write is not atomic, and if `od` fails the cookie comes out empty. Worth folding into the template before the 21-repo batch: chmod 600, refuse an empty result, and write via a temp file plus mv. - (d) mail only: architecture/c4_diagrams.py:258 and assets/c4-components.svg:144 still say MCL_COOKIE has an image default. Stale text.
start.sh: write the cookie through a temp file at 0600 and refuse an empty one (review notes c, d)
All checks were successful
c4 model / c4-model-1 (pull_request) Successful in 5s
c4 model / c4-model (pull_request) Successful in 0s
lint-and-test / check (pull_request) Successful in 3m44s
lint-and-test / The tested lock arrives whole (pull_request) Successful in 3s
85e8b4b1d0
A pre-existing empty cookie file kept its mode, and a failed od left an
empty cookie. Now the cookie goes to a temp file, chmod 600, then mv, and
an empty result stops the start. The service test covers both cases. The
c4 text no longer says MCL_COOKIE has an image default.
terra manually merged commit fd1483dce2 into main 2026-11-23 19:44:46 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
macula-services/mcl-mail!18
No description provided.