@uuaid/pillar 2.7.3 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/HOSTING-LIMITS.md CHANGED
@@ -423,6 +423,87 @@ server {
423
423
  }
424
424
  ```
425
425
 
426
+ **A tunnel relay (2.8.0).** A carrier started with `--accept-tunnels` (README
427
+ "Egress seed") also needs `/v1/tunnel` passed as a WebSocket and `/e/` passed
428
+ like `/v1/` (40 s, `X-Forwarded-For` replaced, the same body size and CORS):
429
+
430
+ ```caddyfile
431
+ # inside the site block above; Caddy passes WebSocket upgrades as they are
432
+ reverse_proxy /v1/tunnel 127.0.0.1:8799
433
+ reverse_proxy /e/* 127.0.0.1:8799 {
434
+ header_up X-Forwarded-For {remote_host}
435
+ }
436
+ ```
437
+
438
+ ```nginx
439
+ location = /v1/tunnel {
440
+ proxy_pass http://127.0.0.1:8799;
441
+ proxy_http_version 1.1;
442
+ proxy_set_header Upgrade $http_upgrade;
443
+ proxy_set_header Connection "upgrade";
444
+ proxy_set_header X-Forwarded-For $remote_addr;
445
+ proxy_read_timeout 120s; # the relay pings every 20 s
446
+ }
447
+ location /e/ {
448
+ # the same CORS lines as location /v1/ above
449
+ client_max_body_size 520k;
450
+ proxy_pass http://127.0.0.1:8799;
451
+ proxy_http_version 1.1;
452
+ proxy_read_timeout 45s;
453
+ proxy_set_header Host $host;
454
+ proxy_set_header X-Forwarded-For $remote_addr;
455
+ }
456
+ ```
457
+
458
+ The relay answers every `/e/*` request with `cache-control: no-store`; do not
459
+ add a proxy cache in front of `/e/`, and do not log `x-pillar-*` headers.
460
+ A seed served through a tunnel relay is not listed in any `directory.json` in
461
+ 2.8.0; agents add its `<origin>/e/<id>` URL to their carriers by hand (README
462
+ "Egress seed"). Proxy only an allow-file relay. A carrier started with `--accept-tunnels open`
463
+ (loopback tests) admits any seed; its loopback bind does not stop a proxy on the
464
+ same host from publishing it.
465
+
466
+ **Relayed seed memory (2.8.0).** Per tunnel, that is per `pillar-seed --relay`
467
+ process: inbox pages held for clients are bounded by `--response-budget` (32
468
+ MiB reserved by default; a page reserves twice its stored bytes, so at most
469
+ about 16 MiB of mail). Past the budget large reads get 503 `seed-busy` (pages
470
+ up to about 128 KiB keep an eighth of the budget). One client address that
471
+ already holds a page may hold at most a quarter of the budget; past that its
472
+ reads get `seed-busy` at once. Four addresses that each hold a quarter fill
473
+ the budget: large reads from any other address then get `seed-busy` until
474
+ those pages end (measured with four reading addresses: 40 of 48 large reads
475
+ refused at once, none cut off, chat-size reads still served). The seed sends to client addresses in turns,
476
+ one frame each, so many reads from one address share the tunnel's rate with
477
+ one read from another. A client that takes no bytes for 10 s while bytes wait
478
+ for it at the relay is dropped and its page returned; while the tunnel is
479
+ short of credit nothing may wait there, and such a client stays until the 40
480
+ s stream deadline. That rule, the address's stream count and the relay's
481
+ queued-byte cap still apply after the seed has sent the end of an answer,
482
+ until its last byte is in the client's socket (bytes in kernel buffers after
483
+ that are not seen). With 30 never-read reads of 401 KiB pages from one address
484
+ and 30 of 111 KiB pages from another, each healthy read timed from its own
485
+ start (three runs): a reader of 2 MiB pages from a third address got 4 of 4,
486
+ the slowest in 19.7 to 20.6 s (at least 19.4 s before the deadline), and chat
487
+ reads took at most 0.4 s; 17 of the first address's reads were refused within
488
+ 2 s, none reached the deadline, and the budget peaked at 15.7 of 32 MiB. With
489
+ the first address alone: 5 of 5, the slowest in 10.5 s. Before the quarter share and the turns: 37.4 s (2.6 s
490
+ before the deadline) with one address, and 6 of 7 large reads refused with
491
+ two (`test/measure/egress-address-fairness.mjs`). Readers that read every byte
492
+ get the same share: with one or two addresses each keeping up to 30 full
493
+ reads of their own 400 KiB mail in flight, a 431 KiB page from another
494
+ address completed 29 of 29 times in 2.4 to 3.4 s (before: 0 within the
495
+ deadline). Streams of one address, including several clients behind one NAT,
496
+ share that address's turn: with two such addresses, 7 of each one's own reads
497
+ were cut at the 40 s deadline. A client with many
498
+ addresses gets a share for each, so it can still take the whole budget and
499
+ most of the rate; IPv6 addresses count one by one, not by prefix. Measured on
500
+ Node 22 (relay, seed
501
+ and readers in one process): RSS +35 MiB at 8 non-reading readers of a 4 MiB
502
+ inbox, +36 MiB at 16 and +43 MiB at 32; the 2.8.0 candidate `7f92c35` grew
503
+ about 13 MiB per reader. Large mail waits while non-reading clients use the
504
+ tunnel rate: messages of about 201 KiB at 47% of that rate, under 60 s of such
505
+ load, arrived 20 of 36 during it (up to 38 s late) and 36 of 36 after it.
506
+
426
507
  **Firewalls.** Open 80 and 443 in the **host** firewall as well as the cloud
427
508
  provider's, and leave 8799 closed. Some cloud images ship host rules that
428
509
  reject everything but SSH: Oracle's Ubuntu 24.04 image does.
@@ -541,9 +622,23 @@ or an exception message. A parameterised reason such as
541
622
  | `delegation-delegate-key-mismatch` | 401 | Sign with the key the delegation names as delegate |
542
623
  | `delegation-inbox-denied` | 401 | Ask the principal for a delegation that covers `inbox` (or `*`) |
543
624
  | `busy` | 503 | Retry after at least 2 s with jitter, or poll with `wait=0` for a while |
625
+ | `seed-busy` | 503 | Back off: retry after 5 s with jitter, doubling to 60 s; this relayed seed holds as many inbox pages as its `--response-budget` allows (2.8.0) |
544
626
  | `not-found` | 404 | Use `POST /v1/envelopes` or `GET /v1/inbox/<uuaid>` |
545
627
  | `not-a-seed` | 404 | Do not list this carrier as a seed; it runs without a seed identity |
546
628
  | `internal-error` | 500 | Retry later; if it repeats, tell the carrier operator |
629
+ | `bad-challenge` | 400 | Send `challenge` as 64 lowercase hex characters (32 random bytes), or leave it out (`GET /v1/seed-info`, 2.8.0) |
630
+ | `upgrade-required` | 426 | Open `/v1/tunnel` as a WebSocket, as `pillar-seed --relay` does (only with `--accept-tunnels`) |
631
+
632
+ ### Tunnel relay (`/e/<id>/...`, 2.8.0)
633
+
634
+ | Code | Status | Fix |
635
+ |---|---|---|
636
+ | `seed-offline` | 503 | Retry later or use another carrier; this seed's tunnel to the relay is down |
637
+ | `tunnel-busy` | 503 | Back off: retry after 5 s with jitter, doubling to 60 s, or use another carrier |
638
+ | `body-too-large` | 413 | As the carrier's: the request passed the relay's size cap |
639
+ | `seed-timeout` | 504 | Retry, or use another carrier; the seed behind this relay did not answer in time |
640
+ | `seed-bad-answer`, `seed-reset`, `seed-answer-too-large` | 502 | Retry, or use another carrier |
641
+ | `not-found` | 404 | As the carrier's: only the four carrier routes pass a relay |
547
642
 
548
643
  ### Client (no server gave a code)
549
644
 
package/README.md CHANGED
@@ -707,10 +707,37 @@ a UUAID is read as a file.
707
707
  |---|---|
708
708
  | `pillar resolve <uuaid> [--registry URL]` | The same live check as `verify <uuaid>`, printing the resolved record (and with `--json`, the lineage log). |
709
709
  | `pillar lineage show [--json]` | This home's lineage: current key, head, verdict, rotations, doors. `<home>/lineage/log.json` is the file to give others. |
710
- | `pillar lineage rotate` | Rotate this home's key (a signed lineage event). |
710
+ | `pillar lineage rotate` | Rotate this home's key (a signed lineage event), tell your contacts with a `lineage` notice (`--no-notify` skips it), and keep reading the old key's inbox for a grace window (`--retired-grace`, default `P14D`). |
711
711
  | `pillar card build` / `card show` / `card serve` | Write, print or serve this home's signed agent card (`<home>/card/card.json`). |
712
712
  | `pillar listing publish --registry URL` | Publish the card as a signed listing, so `verify <uuaid>` finds you. |
713
713
 
714
+ ### When a contact's key changes (continuity)
715
+
716
+ A contact that rotates its key sends you a `lineage` notice. Pillar verifies the
717
+ lineage it carries, but a notice is only evidence: it never moves your mail by
718
+ itself. Until you act, every send to the old key is **held** (refused, nothing
719
+ sealed), because the old key may be the one that was stolen.
720
+
721
+ Continuity notices use two admission lanes:
722
+
723
+ - **Trusted admission (`b.auth`, reserved `1,024`/h, independent of the open backlog scan and pre-ingest wait):** granted only when the envelope signature is verified (`open()` non-delegated) and the sender is (1) an existing trusted contact key (`addressBook` or `trust.allow`) or a key of a `firm`-pinned lineage, (2) the pre-committed `next` key (`sha256(publicKey) === ev.next`) of an already-stored lineage, or (3) a home in the `firm`-pinned roster of a stored lineage. Trusted notices store at receipt while `b.auth` is free, or by the next 1-hour budget window under normal polling if `b.auth` was also spent.
724
+ - **Unproven admission (bounded best effort; `PROOF_POOL_PER_HOUR = 512` proof checks/h, `MAX_PROOF_PER_CANDIDATE = 256`, open share `3,072`/h):** all other arrivals — including an unpinned contact's first rotation notice sent from an unknown new key before its inception was stored, or any unauthenticated claim naming a pinned lineage — receive no priority and reserve durable proof work before any signature check. Waiting unverified notices never hold or redirect routes on their own: sends continue to address the known key during pre-verification exposure until the notice is verified (measured on Node 22 at 4 polls per 1-hour window with the open share spent: **13 windows** behind 3,100 spoofed 2-event notices and **9 windows** behind 4,200 plain 2-event notices; have the contact announce its inception first, sign the rotation notice with its known or pre-committed `next` key, or `pin --log` its lineage for trusted admission).
725
+
726
+ | Command | What it does |
727
+ |---|---|
728
+ | `pillar continuity show <contact>` | The decision for a contact's key: `none`, `pending-confirm` (held), `active` (sends go to the new key) or `suspended` (conflicting evidence). `check` asks the pinned homes first and prints how many agree, how many vouched for a verified disagreement (persisted as a forward/fork checkpoint so a lagging quorum, home outage, restart, or local confirmation cannot re-enable the retired route without verified ancestry through the checkpoint and positive quorum at the resulting head), how many are behind (`stale`), and how many gave no usable answer. |
729
+ | `pillar continuity confirm <contact> --head sha256:... --to <uuaid>` | Accept the new key. Ask the contact over another channel (not pillar) for its new uuaid and lineage head, and use the values it gave you. Copying the values from the notice proves nothing. |
730
+ | `pillar continuity recover <contact> --log FILE --head sha256:... --to <uuaid>` | The only way out of a fork or a hold: a lineage log you obtained over another channel, which must verify on its own at that head and destination. It speaks for that lineage at that head only: when newer evidence arrives, the evidence decides again. |
731
+ | `pillar continuity pin --log FILE` | Trust a lineage log you obtained yourself, so later rotations can be checked against its homes. It does not clear a fork. |
732
+ | `pillar continuity forget <lineage> --confirm <lineage>` / `repair` | Drop a lineage's evidence, or move an unreadable store aside. Neither releases a key that was retired, forked, or held by an uncovered home checkpoint (including the locally current key): holds and uncovered checkpoints persist in `holds.json` up to 4,096 entries and release only on proven coverage (verified ancestry plus positive pinned-home quorum at the resulting head) or `recover`. |
733
+ | `pillar continuity imports` | Mail that arrived at your retired key during the grace window, kept apart from your inbox. |
734
+
735
+ `Pillar.sendDirect` dials the peer id and address its caller gives, so it is
736
+ never redirected: to a retired key it refuses with
737
+ `redirect-blocked:direct-redirect` and seals nothing. Use `send`, which routes
738
+ to the new key, or call `sendDirect` for the new key with that key's own peer
739
+ id and address.
740
+
714
741
  ## The three always-on roles
715
742
 
716
743
  | Bin | What it runs | Ongoing requirements |
@@ -861,6 +888,194 @@ What an outside operator needs to know before the first start:
861
888
  seed on one.
862
889
  - The proxy, the firewall and CORS: HOSTING-LIMITS.md §5 has a Caddy and an
863
890
  nginx example.
891
+ - **No public URL?** Run an egress seed through a tunnel relay (next section).
892
+
893
+ ### Egress seed (2.8.0): no public URL needed
894
+
895
+ A machine with outbound-only network (a cloud VM, a laptop behind NAT) can run
896
+ a seed. The seed stays on 127.0.0.1, opens one outbound WebSocket to a **tunnel
897
+ relay** (a `pillar-carrier` started with `--accept-tunnels`; not the push relay
898
+ of HOSTING-LIMITS.md §4), and is served at `<relay origin>/e/<id>`, where `<id>`
899
+ is derived from the seed key:
900
+
901
+ ```sh
902
+ pillar-seed --home /var/lib/pillar/seed --relay https://relay.example.org --announce https://<registry>
903
+ ```
904
+
905
+ `--relay` does not go with `--public-url`, keeps `--host` at 127.0.0.1 or ::1,
906
+ and needs that address in `--trusted-proxy` (the default), so each client is
907
+ still charged to its own address. A relay that does not take tunnels, or does
908
+ not list this seed, stops the seed with exit 2 before anything is announced.
909
+ Losing the tunnel later is retried (1 s to 60 s; the backoff starts over only
910
+ after a tunnel stayed up for a minute): the registry demotes the seed after
911
+ three failed probes and restores it once probes pass again.
912
+
913
+ **Seed memory.** An inbox page ends at about 2 MiB of envelopes (whole
914
+ envelopes, at least one), with `more: true` while more wait; every client reads
915
+ on with `since`, as before. A relayed seed reserves each page against its
916
+ `--response-budget` (MiB, default 32, 4 to 4096) before it reads the page, and
917
+ keeps the reservation until the tunnel has sent the page to the relay or the
918
+ stream ends. Past the budget a read gets 503 `seed-busy` (retry after 5 s);
919
+ large pages leave an eighth of the budget to pages of up to about 128 KiB, so
920
+ chat-sized mail is still served. That bounds the pages one seed process holds
921
+ per tunnel. One client address that already holds a page may hold at most a
922
+ quarter of the budget (an address that holds none may always take one page);
923
+ past that its reads get `seed-busy` at once, and other addresses are served.
924
+ The seed also sends answer bytes to client addresses in turns, one frame each,
925
+ the address served longest ago first: 30 reads from one address get the same
926
+ share of the tunnel's rate as one read from another. Measured on Node 22 at
927
+ the default limits, with 30 reads of 401 KiB pages from one address that read
928
+ the status line and then nothing (and, the second time, 30 more of 111 KiB
929
+ pages from a second address), each healthy read timed from its own start: a
930
+ reader of 2 MiB pages from a third address got 5 of 5 (slowest 10.5 s, 29.5 s
931
+ before the 40 s deadline) and 4 of 4 (slowest 19.7 to 20.6 s, at least 19.4 s
932
+ before it) in three runs; chat-size reads took at most 0.4 s; the first
933
+ address got 17 or 18 of its 30 reads refused with `seed-busy`, and every
934
+ non-reading read had its answer within 2 s
935
+ (`test/measure/egress-address-fairness.mjs`).
936
+ Before the quarter share and the turns, the slowest large read took 37.4 s (2.6
937
+ s before the deadline) and 6 of 7 large reads were refused in the second run.
938
+ Readers that read every byte get the same share: with one or two addresses
939
+ each keeping up to 30 reads of their own 400 KiB mail in flight (at most 9
940
+ new a second), a 431 KiB page read from another address completed 29 of 29
941
+ times in 2.4 to 3.4 s, two runs each, and chat-size reads took at most 0.13 s
942
+ (before: 0 of these pages completed within the 40 s deadline). The streams of
943
+ one address share that address's turn, so its own large reads slow down as
944
+ it opens more: with two such addresses, 7 of each one's reads were cut at
945
+ the 40 s deadline. Several clients behind one address (a NAT) share it the
946
+ same way.
947
+ Measured on Node 22 with the default budget
948
+ and relay limits, 4 new non-reading clients a second on 16 MiB inboxes plus
949
+ three reading clients of chat-size mail: seed RSS peaked at 164 to 191 MiB
950
+ over the runs of 2.8.0 rounds 6 and 7 (without
951
+ byte-bounded pages it passed 1.6 GiB in 10 s), every reading client got all
952
+ its mail, and the non-reading ones got
953
+ `seed-busy` (`test/measure/egress-seed-memory.mjs`). Large mail waits while
954
+ such clients use the tunnel's rate: with messages of about 201 KiB (3
955
+ senders, one each 5 s, 47% of the tunnel rate) under the same load, 20 of 36
956
+ arrived during the 60 s load, the latest 38 s late, and all 36 after it
957
+ (without the non-reading clients: 36 of 36, at most 25 ms late).
958
+
959
+ **One process per seed key.** A relay keeps the tunnel it has while that
960
+ tunnel answers: a second process started with a copy of the same seed home is
961
+ refused (`seed-already-connected`), waits `--takeover-wait` seconds (default
962
+ 45) for the first to stop, then exits 2 and announces nothing. Two processes
963
+ with one key each hold their own mail, so letting them take turns would lose
964
+ mail. To move a seed to a new host, stop the old process first; a process that
965
+ died without closing its tunnel is dropped by the relay within about 30
966
+ seconds, and the new one takes over. Run one process per seed key: if two do
967
+ run and the relay restarts, whichever reconnects first keeps the key and the
968
+ other exits 2 after `--takeover-wait`, even if it was serving before. Mail that
969
+ process had accepted stays in its database (the exit message names it): stop
970
+ the other process and start that one again to serve it.
971
+
972
+ **Clients name a relayed seed explicitly.** In 2.8.0 a relayed seed URL is never
973
+ configured automatically: `directory.json` (and its `/` alias) never lists one,
974
+ neither in `seeds[]` nor as the bootstrap carrier, and `pillar init --directory`
975
+ and `--refresh` skip any it finds (by the `/e/<id>` shape or by `relay`
976
+ metadata; a note on stderr says how many). An agent that trusts a fleet relay
977
+ adds the seed itself: `pillar init --carriers https://relay.example.org/e/<id>`,
978
+ or the `carriers` list in `config.json`. `--refresh` replaces `carriers` with
979
+ what the directory offers, so it also removes a relayed URL an earlier
980
+ directory added (and one you added by hand: add it again after a refresh).
981
+ Automatic discovery of relayed seeds waits for inbox auth bound to its
982
+ audience. `pillar-directory --carrier` refuses a relayed URL.
983
+
984
+ **Relay operator.** `pillar-carrier --accept-tunnels <allow-file> --tunnel-origin
985
+ https://relay.example.org --tunnel-keychain <key>`. The allow-file holds one
986
+ full seed uuaid per line; check that the operator controls that seed before you
987
+ add it. Removing a line closes that seed's tunnel within about two seconds and refuses it
988
+ again. `--tunnel-keychain` (an existing key, never minted by the carrier, not the
989
+ receipt or seed key) signs an attestation for each registry challenge. Limits:
990
+ 32 tunnels, 2 per source address, 256 KiB/s each way per tunnel and 8 MiB/s in
991
+ total (`--tunnel-max`, `--tunnel-kbps`, `--tunnel-total-kbps`), plus stream,
992
+ request-rate and size caps (src/net/tunnel-relay.mjs `TUNNEL_LIMITS`). The byte
993
+ budgets bind open transfers too, across every open stream: the relay reserves
994
+ bytes against its tunnel's and its own budget before it forwards them, so one
995
+ stream carries at most the burst (4 MiB) plus 40 s at the rate before its
996
+ deadline ends it. Upload bytes wait at the relay (at most one read per stream,
997
+ inside the total queued-byte cap: 64 MiB of request and answer bytes the relay
998
+ queues for all streams; it caps those bytes, not the relay's process memory,
999
+ which can be higher because a queued slice keeps its whole buffer alive).
1000
+ Answers are paced by credit: the relay grants the
1001
+ seed answer bytes it has already paid for from both budgets (a 128 KiB window),
1002
+ and never stops reading the tunnel, so pings keep working while an answer is
1003
+ paced. Every answer byte counts against credit, also bytes for a stream that
1004
+ has ended or that the relay never opened; a seed that sends past its credit, or
1005
+ sends one stream's headers twice, is disconnected (`flow-violation`). A client
1006
+ that holds more than 256 KiB unread puts only its own stream on hold: the seed
1007
+ stops sending that answer, and the tunnel's other streams keep taking turns for
1008
+ credit. A client that takes no bytes for 10 s while bytes wait for it at the
1009
+ relay is dropped, wherever the rest of its answer is (at the relay, or at the
1010
+ seed on hold or waiting for credit); one that keeps reading, however slowly, is
1011
+ not. The 10 s count starts only once bytes wait at the relay: while the tunnel
1012
+ is short of credit nothing may wait there, and a client that never reads stays
1013
+ until the 40 s stream deadline (`seed-timeout`). Once the seed has sent the end
1014
+ of an answer, the relay keeps the stream until its last byte is in the
1015
+ client's socket: those bytes still count toward the 64 MiB cap and toward the
1016
+ client address's 32 streams, the 10 s rule still applies, and the deadline (40
1017
+ s from the stream's start) still ends it. Bytes in the kernel's socket buffers
1018
+ after that are not seen or counted. At the seed, a stream lasts until its end
1019
+ has gone to the relay or it is reset, whatever its local answer did: a reset
1020
+ after the local answer ended still drops its queued bytes and gives its page
1021
+ back to the budget, and a local answer that stops early resets the stream.
1022
+ Tested for each way a stream ends (local end with bytes waiting for credit, a
1023
+ reset after it, client gone, stream deadline): the relay's queued bytes and the
1024
+ seed's tickets return to 0 with the tunnel up and no new request
1025
+ (`test/unit/egress-round7.test.mjs`). Measured with 60 never-read reads from 2
1026
+ addresses (pages of 401 KiB and 111 KiB): 17 were refused with `seed-busy`, 43
1027
+ fit in the socket buffers and counted as sent (each within 27 s), none
1028
+ reached the deadline, and the seed's budget peaked at 15.7 of 32 MiB (before
1029
+ the quarter share: 18 reached the deadline, peak 28.5 MiB).
1030
+ The relay sees a client take bytes only when its socket buffers do, in steps
1031
+ of about 300 KB on macOS loopback, so 10 s keeps every client fast enough to
1032
+ read a whole page before the 40 s stream deadline. A new stream needs at least
1033
+ one byte of budget left. The relay keeps
1034
+ request counts for at most 10,000 client addresses at a time; when all of them
1035
+ are inside their minute, a new address gets 503 `tunnel-busy` until one ages
1036
+ out. Only the
1037
+ four carrier routes pass; seed headers never reach clients; every `/e/*` answer
1038
+ is `cache-control: no-store`; logs carry the route template, status and sizes
1039
+ only. `--accept-tunnels open` admits any seed and is for tests on loopback
1040
+ only: it refuses any other `--host` or `--tunnel-origin`. A loopback bind does
1041
+ not stop a reverse proxy or port forward on the same host from publishing the
1042
+ port, so never put one in front of a carrier in open mode; it prints a warning
1043
+ saying so at start.
1044
+
1045
+ **Trust.** A tunnel relay is a carrier: it can delay or drop mail, but cannot
1046
+ read or forge sealed envelopes. It does see inbox auth headers, which a carrier
1047
+ accepts for 5 minutes, so it could re-read that inbox page (sealed envelopes and
1048
+ their metadata) in that window. That is why relays are admitted per seed by an
1049
+ allow-file, pinned per registry, and never published for automatic discovery
1050
+ (above).
1051
+
1052
+ **Registry.** `pillar-directory --fleet-relays <file>`, one `<origin> <relay key
1053
+ hex>` per line. Every probe of a relayed seed is a one-use challenge: the seed
1054
+ must echo it in its signed `/v1/seed-info`, a pinned relay must attest it, and
1055
+ round trips must carry the seed's signed proof of the exact page it served. Any
1056
+ error fails the probe; nothing falls back to `/v1/health`.
1057
+
1058
+ | Seed topology | Highest tier | Priority, grant | In `directory.json` |
1059
+ | --- | --- | --- | --- |
1060
+ | Direct (`--public-url`) | anchor | as before | yes |
1061
+ | On a pinned fleet relay, attested within its lease | durable | yes; the grant ends with the lease | no |
1062
+ | On a pinned fleet relay, lease lapsed or a probe failed | steady | none | no |
1063
+ | On any other relay | probation | none | no |
1064
+ | Relayed row from a 2.7.x registry, before its first challenge | probation | none | no |
1065
+
1066
+ **Lease.** A passing challenge probe through a pinned fleet relay vets the seed
1067
+ for min(3 x the probe interval, 30 minutes): 30 minutes at the default
1068
+ 10-minute interval. Minting a grant never extends it, and the grant expires
1069
+ with it. A failed probe ends it at once; a revocation by the relay, or a probe
1070
+ loop that stops, ends it within the lease. A registry that opens a database
1071
+ with a longer stored vetting (the first 2.8.0 candidate stored 24 hours) clears
1072
+ it, and the seed proves itself again. A carrier stops honouring any tier grant
1073
+ at its expiry, even when its decision is cached. A grant minted earlier, or by a
1074
+ 2.6.1 or 2.7.x registry, stays valid until its own expiry, up to 14 days. A 2.6.1 or 2.7.x registry still enrolls a relayed seed, but checks its
1075
+ liveness through the relay without a challenge (relay-attested), and applies no
1076
+ cap; `pillar-seed --status` says so. Not in 2.8.0: moving a seed to another
1077
+ relay (it needs a new seed key), and inbox auth bound to its audience, which
1078
+ must exist before relays are opened to other operators.
864
1079
 
865
1080
  ## Abuse resistance — consent at the edge, budgets at the carrier
866
1081
 
@@ -1220,6 +1435,32 @@ rate and body size — see "Tier grants" above for the ladder. It is a
1220
1435
  See "Mailbox: local message erasure" above for the selectors, the
1221
1436
  checkpoint-incomplete error and retry, and rolling back to 2.5.5.
1222
1437
 
1438
+ ### Known limits in 2.8.0
1439
+
1440
+ Found in the 2.8.0 review. Each is planned for a 2.8.x release.
1441
+
1442
+ - **Unproven continuity notices can wait.** A rotation notice that the
1443
+ receiver cannot place yet (for example an unpinned contact's first notice
1444
+ from a new key) gets no priority and shares a capped proof budget. Behind
1445
+ a flood it is stored late: measured in the 13th hourly window behind 3,100
1446
+ spoofed notices, and in the 9th behind 4,200 plain ones (4 polls per
1447
+ window). Trusted senders (a known contact key, a committed next key, a
1448
+ pinned home) are stored in the first window.
1449
+ - **Trusted admission is wider than the pinned path.** A next key that a
1450
+ stored rotation already used still counts as trusted, and so do the keys
1451
+ of a stored fork off the pinned path. A thief who holds one old contact
1452
+ key can make up to about 31 keys count as trusted. Trust gives queue
1453
+ priority only: signatures, lineage checks, caps and quotas still apply,
1454
+ the contact's route stays suspended, and their messages are not
1455
+ delivered. Those keys can spend the receiver's trusted share (1,024 per
1456
+ hour) and delay other trusted notices.
1457
+ - **Four client addresses can hold a relayed seed's response budget.** Each
1458
+ address may hold a quarter of `--response-budget`, so four busy addresses
1459
+ fill it and large reads from other addresses get 503 `seed-busy` (measured:
1460
+ 40 of 48 refused, none cut off; chat-size reads still served). Clients
1461
+ behind one NAT share one address's quarter and turn. See "Egress seed"
1462
+ above and HOSTING-LIMITS "Relayed seed memory".
1463
+
1223
1464
  ## Source, provenance and releases
1224
1465
 
1225
1466
  Apache-2.0 (`LICENSE`). This repository is the recovered source for
package/bin/carrier.mjs CHANGED
@@ -37,12 +37,28 @@
37
37
  * must be the one its public key derives. The two options go together; one
38
38
  * without the other, a URL a registry would refuse, or a key that does not
39
39
  * load refuses to start. Without them /v1/seed-info stays 404 as before.
40
+ *
41
+ * Relay (2.8.0): with --accept-tunnels <allow-file> and --tunnel-origin (the
42
+ * public https origin the proxy serves), the carrier also takes outbound
43
+ * tunnels from seeds whose full uuaid is on the allow-file and serves each at
44
+ * <origin>/e/<id> (src/net/tunnel-relay.mjs). With --tunnel-keychain (an
45
+ * existing key, never minted here, different from the receipt and seed keys;
46
+ * passphrase CARRIER_TUNNEL_KEYCHAIN_PASSPHRASE) it attests those tunnels to
47
+ * registries that pin it. --accept-tunnels open admits any seed and is for
48
+ * tests only: it needs a loopback --host and a loopback --tunnel-origin, and
49
+ * the carrier exits if it is not bound to loopback. Off by default: /v1/tunnel
50
+ * and /e/* answer 404 as in 2.7.1.
51
+ * A loopback bind does not stop a reverse proxy or port forward on the same
52
+ * host from publishing the port: never put one in front of open mode (a warning
53
+ * is printed at start; Lead review C-P3-2).
40
54
  */
41
55
  import "../src/node-check.mjs"; // must stay the first import: refuses Node < 22 before any dependency loads
42
56
  import { CarrierServer, parseSecureDelete, parseCommunityWaits, MAX_TTL_DAYS } from "../src/net/carrier-server.mjs";
43
57
  import { Keychain, keyDerivesUuaid } from "../src/identity/keychain.mjs";
44
58
  import { checkSeedUrl } from "../src/net/seed-registry.mjs";
45
59
  import { parseTrustedProxies } from "../src/net/client-ip.mjs";
60
+ import { canonicalOrigin, isLoopbackOrigin } from "../src/net/tunnel.mjs";
61
+ import { TunnelRelay } from "../src/net/tunnel-relay.mjs";
46
62
  import { exitWithHelp, wantsHelp } from "../src/cli-help.mjs";
47
63
 
48
64
  function parseArgs(argv) {
@@ -87,6 +103,15 @@ default; put a TLS-terminating proxy in front of it.
87
103
  --receipt-keychain <file> sign carrier receipts with this existing key (CARRIER_RECEIPT_KEYCHAIN)
88
104
  --seed-keychain <file> with --public-url: serve a signed /v1/seed-info (CARRIER_SEED_KEYCHAIN)
89
105
  --public-url <https://> the URL the proxy serves (CARRIER_PUBLIC_URL)
106
+ --accept-tunnels <file> relay seeds whose uuaid is in this allow-file (CARRIER_ACCEPT_TUNNELS;
107
+ default off). "open" admits any seed: loopback tests only
108
+ --tunnel-origin <https://> the public origin seeds are served at, as <origin>/e/<id>
109
+ (CARRIER_TUNNEL_ORIGIN)
110
+ --tunnel-keychain <file> attest tunnels to registries with this existing key
111
+ (CARRIER_TUNNEL_KEYCHAIN)
112
+ --tunnel-max <n> most tunnels at once (CARRIER_TUNNEL_MAX, default 32)
113
+ --tunnel-kbps <n> per-tunnel KiB/s each way (CARRIER_TUNNEL_KBPS, default 256)
114
+ --tunnel-total-kbps <n> all tunnels, KiB/s each way (CARRIER_TUNNEL_TOTAL_KBPS, default 8192)
90
115
  -h, --help print this help and exit
91
116
 
92
117
  The carrier never mints a key. See the header of bin/carrier.mjs for details.`;
@@ -183,19 +208,90 @@ if (wantSeedKey) {
183
208
  }
184
209
  }
185
210
 
211
+ // Relay (2.8.0): off unless --accept-tunnels names an allow-file (or "open" on loopback).
212
+ const tunnelOpt = (flag, env) => { const v = args[flag] ?? process.env[env]; return v === "" ? null : (v ?? null); };
213
+ const acceptTunnels = tunnelOpt("accept-tunnels", "CARRIER_ACCEPT_TUNNELS");
214
+ const tunnelOriginText = tunnelOpt("tunnel-origin", "CARRIER_TUNNEL_ORIGIN");
215
+ const tunnelKeychainPath = tunnelOpt("tunnel-keychain", "CARRIER_TUNNEL_KEYCHAIN");
216
+ const tunnelPassphrase = process.env.CARRIER_TUNNEL_KEYCHAIN_PASSPHRASE;
217
+ delete process.env.CARRIER_TUNNEL_KEYCHAIN_PASSPHRASE;
218
+ const tunnelNumbers = {};
219
+ for (const [flag, env, key, scale] of [
220
+ ["tunnel-max", "CARRIER_TUNNEL_MAX", "maxTunnels", 1],
221
+ ["tunnel-kbps", "CARRIER_TUNNEL_KBPS", "tunnelBytesPerSec", 1024],
222
+ ["tunnel-total-kbps", "CARRIER_TUNNEL_TOTAL_KBPS", "totalBytesPerSec", 1024],
223
+ ]) {
224
+ const v = tunnelOpt(flag, env);
225
+ if (v === null) continue;
226
+ if (!/^[1-9][0-9]{0,6}$/.test(String(v))) refuse(`--${flag} must be a whole number from 1 to 9999999`);
227
+ tunnelNumbers[key] = Number(v) * scale;
228
+ }
229
+ let tunnelRelay = null;
230
+ let tunnelOrigin = null;
231
+ let tunnelKeychain = null;
232
+ const tunnelLoopback = (h) => h === "::1" || /^127\.\d+\.\d+\.\d+$/.test(h);
233
+ if (acceptTunnels === null) {
234
+ if (tunnelOriginText !== null || tunnelKeychainPath !== null || Object.keys(tunnelNumbers).length) {
235
+ refuse("--tunnel-origin, --tunnel-keychain and the --tunnel-* limits need --accept-tunnels");
236
+ }
237
+ } else {
238
+ if (typeof acceptTunnels !== "string") refuse("--accept-tunnels needs an allow-file path (or open, for loopback tests)");
239
+ if (typeof tunnelOriginText !== "string") refuse("--accept-tunnels needs --tunnel-origin <https://origin>: the public origin seeds are served at");
240
+ const c = canonicalOrigin(tunnelOriginText);
241
+ if (!c.ok) refuse(`--tunnel-origin is not a relay origin (${c.reason}); the value is not shown`);
242
+ tunnelOrigin = c.origin;
243
+ if (acceptTunnels === "open") {
244
+ // RedTeam 085b71 C5: open admission only on a real loopback listener.
245
+ if (!tunnelLoopback(host)) refuse(`--accept-tunnels open is for loopback tests: --host must be 127.0.0.1 or ::1, not ${JSON.stringify(host)}`);
246
+ if (!isLoopbackOrigin(tunnelOrigin)) refuse("--accept-tunnels open is for loopback tests: --tunnel-origin must be a loopback origin");
247
+ if (tunnelKeychainPath !== null) refuse("--tunnel-keychain attests allow-file admission; --accept-tunnels open attests nothing");
248
+ }
249
+ if (tunnelKeychainPath !== null) {
250
+ if (typeof tunnelKeychainPath !== "string") refuse("--tunnel-keychain needs a path to a keychain file");
251
+ tunnelKeychain = new Keychain(tunnelKeychainPath);
252
+ if (!tunnelKeychain.exists()) refuse(`tunnel keychain ${tunnelKeychainPath} not found (a carrier never mints its tunnel key)`);
253
+ let pub;
254
+ try { pub = tunnelKeychain.publicView(); } catch (e) { refuse(`tunnel keychain ${tunnelKeychainPath} is damaged or is not a key file (${e.code ?? e.message})`); }
255
+ if (!keyDerivesUuaid(pub?.publicKeyHex, pub?.uuaid)) refuse(`tunnel keychain ${tunnelKeychainPath}: its uuaid does not belong to its key`);
256
+ try { tunnelKeychain.load({ passphrase: tunnelPassphrase ?? "" }); } catch (e) { refuse(`tunnel keychain ${tunnelKeychainPath} did not load: ${e.message}`); }
257
+ const k = tunnelKeychain._identity.publicKeyHex;
258
+ if (receiptKeychain && receiptKeychain._identity.publicKeyHex === k) refuse("the tunnel key and the receipt key must be different keys");
259
+ if (seedKeychain && seedKeychain._identity.publicKeyHex === k) refuse("the tunnel key and the seed key must be different keys");
260
+ }
261
+ try {
262
+ tunnelRelay = new TunnelRelay({
263
+ origin: tunnelOrigin,
264
+ admission: acceptTunnels === "open" ? { mode: "open" } : { mode: "allow-file", path: acceptTunnels },
265
+ keychain: tunnelKeychain, trustedProxies, limits: tunnelNumbers,
266
+ log: (line) => console.log(line),
267
+ });
268
+ } catch (e) {
269
+ refuse(`--accept-tunnels: ${e.message}`);
270
+ }
271
+ }
272
+
186
273
  let server;
187
274
  try {
188
- server = new CarrierServer({ dbPath, ttlDays, trustedTierIssuers: tierIssuers, secureDelete, receiptKeychain, keychain: seedKeychain, publicUrl, communityInboxWaits, trustedProxies });
275
+ server = new CarrierServer({ dbPath, ttlDays, trustedTierIssuers: tierIssuers, secureDelete, receiptKeychain, keychain: seedKeychain, publicUrl, communityInboxWaits, trustedProxies, tunnelRelay });
189
276
  } catch (e) {
190
277
  refuse(e.message);
191
278
  }
192
279
  const addr = await server.listen(port, host);
280
+ if (acceptTunnels === "open" && !tunnelLoopback(addr.address)) {
281
+ // The address the socket really holds, not the flag (RedTeam 085b71 C5).
282
+ await server.close();
283
+ refuse(`--accept-tunnels open is for loopback tests, but the carrier is bound to ${addr.address}`);
284
+ }
193
285
  console.log(`carrier listening on ${addr.address}:${addr.port}`);
194
286
  console.log(` db: ${dbPath}`);
195
287
  console.log(` ttl: ${ttlDays} days`);
196
288
  console.log(` tiers: ${tierIssuers.length ? `${tierIssuers.length} trusted issuer(s)` : "disabled (community budgets for all)"}`);
197
289
  console.log(` secure-delete: ${secureDelete ? "on (expired envelopes are zeroed; WAL truncated after each expiry pass)" : "off (expired envelope bytes stay on disk until reused)"}`);
198
290
  console.log(` seed: ${seedKeychain ? `${seedKeychain._identity.uuaid} at ${publicUrl} (signed /v1/seed-info)` : "off (no seed keychain; /v1/seed-info is 404)"}`);
291
+ if (acceptTunnels === "open") {
292
+ console.error(`carrier: warning: --accept-tunnels open admits any seed. Never put a proxy or port forward in front of ${addr.address}:${addr.port}; a loopback bind does not stop a proxy on this host from publishing it.`);
293
+ }
294
+ console.log(` tunnels: ${!tunnelRelay ? "off (/v1/tunnel and /e/* are 404)" : acceptTunnels === "open" ? `open, loopback tests only, serving ${tunnelOrigin}/e/<id>` : `allow-file ${acceptTunnels} (${tunnelRelay.allow.set.size} seed${tunnelRelay.allow.set.size === 1 ? "" : "s"}), serving ${tunnelOrigin}/e/<id>${tunnelKeychain ? `, attesting as ${tunnelKeychain._identity.publicKeyHex.slice(0, 16)}…` : ", not attesting"}`}`);
199
295
  console.log(` receipts: ${server.receiptCarrier ? `signed as ${server.receiptCarrier} (uuaid.carrier-receipt.v1)` : "off (no receipt keychain)"}`);
200
296
 
201
297
  // Vacuum expired envelopes hourly.
@@ -31,7 +31,8 @@ import { createServer } from "node:http";
31
31
  import { readFileSync, existsSync, mkdirSync } from "node:fs";
32
32
  import { homedir } from "node:os";
33
33
  import { join } from "node:path";
34
- import { SeedRegistry } from "../src/net/seed-registry.mjs";
34
+ import { SeedRegistry, parseFleetRelays } from "../src/net/seed-registry.mjs";
35
+ import { isRelayedSeedUrl } from "../src/net/tunnel.mjs";
35
36
  import { clientIpOf, parseTrustedProxies } from "../src/net/client-ip.mjs";
36
37
  import { Keychain, mintNamespace, SERVICE_IDENTITY_NAMESPACE } from "../src/identity/keychain.mjs";
37
38
  import { tryLoadBetterSqlite3 } from "../src/sqlite-loader.mjs";
@@ -66,10 +67,13 @@ The first start mints the registry key in --home.
66
67
  --peers <url,...> peer registries (DIRECTORY_PEERS)
67
68
  --trusted-proxy <ips> whose X-Forwarded-For counts (DIRECTORY_TRUSTED_PROXIES)
68
69
  --probe-minutes <n> seed probe interval (DIRECTORY_PROBE_MINUTES, default 10)
70
+ --fleet-relays <file> relay origins and keys this registry pins, one "<origin> <key hex>"
71
+ per line; only seeds on these are listed while relayed
72
+ (DIRECTORY_FLEET_RELAYS; default none)
69
73
  -h, --help print this help and exit
70
74
 
71
75
  More flags (limits, federation timers, test hooks): --protocol, --allow-private-urls,
72
- --url-map, --clock-file, --stamp-bits, --max-new-lineages-per-hour,
76
+ --url-map, --clock-file, --stamp-bits, --probe-interval-ms, --max-new-lineages-per-hour,
73
77
  --max-listings-per-ip-per-hour, --max-lineage-posts-per-ip-per-hour,
74
78
  --max-heartbeats-per-ip-per-hour, --pull-interval-ms, --max-strikes,
75
79
  --quarantine-cooldown-ms, --resolve-timeout-ms, --resolve-negative-ttl-ms,
@@ -93,10 +97,32 @@ const port = opts.port;
93
97
  const host = opts.host ?? "127.0.0.1";
94
98
  const dbPath = opts.db ?? join(home, "registry.db");
95
99
  const carrier = opts.carrier ?? null;
100
+ // 2.8.0 (RedTeam 22f6c3 Q2): directory.json never names a relayed seed URL
101
+ // (<relay origin>/e/<id>) as its bootstrap carrier.
102
+ if (typeof carrier === "string" && isRelayedSeedUrl(carrier)) {
103
+ console.error("pillar-directory: --carrier/DIRECTORY_CARRIER is a relayed seed URL (<origin>/e/<id>); 2.8.0 keeps relayed seeds out of directory.json. Name a direct carrier; clients reach a relayed seed with pillar init --carriers <url>.");
104
+ process.exit(2);
105
+ }
96
106
  const agentsPath = opts.agents ?? null;
97
107
  const protocol = opts.protocol ?? "uacp/1.0-draft";
98
108
  const probeMinutes = opts["probe-minutes"];
109
+ // Test hook (2.8.0, like --pull-interval-ms): the probe interval in milliseconds
110
+ // (100 or more), overriding --probe-minutes, so tests can watch probes, demotion
111
+ // and recovery. Unset: --probe-minutes.
112
+ const probeIntervalMs = opts["probe-interval-ms"];
113
+ // The interval the probe loop really runs at. The registry sizes a relayed
114
+ // seed's vetting lease from it: min(3 x interval, 30 min) (RedTeam 22f6c3 Q1).
115
+ const effectiveProbeMs = probeIntervalMs ?? probeMinutes * 60_000;
99
116
  const allowPrivateUrls = opts["allow-private-urls"];
117
+ // Fleet relays (2.8.0): the relay origins and attestation keys this registry pins.
118
+ // A relayed seed is listed, vetted and granted only on one of these. None by
119
+ // default: without this flag the registry pins no relay and lists no relayed seed.
120
+ const fleetRelaysPath = opts["fleet-relays"] ?? null;
121
+ let fleetRelays = new Map();
122
+ if (fleetRelaysPath !== null) {
123
+ try { fleetRelays = parseFleetRelays(readFileSync(fleetRelaysPath, "utf-8")); }
124
+ catch (e) { console.error(`pillar-directory: --fleet-relays ${fleetRelaysPath}: ${e.code ?? e.message}`); process.exit(2); }
125
+ }
100
126
  const publicUrlArg = opts["public-url"] ?? null;
101
127
  const urlMap = opts.urlMap;
102
128
  const clockFile = opts["clock-file"] ?? null;
@@ -137,7 +163,7 @@ const statsAggregates = new Map();
137
163
 
138
164
  const hasSqlite = Boolean(tryLoadBetterSqlite3());
139
165
  const registry = hasSqlite
140
- ? new SeedRegistry({ keychain, carrierUrl: carrier, dbPath, protocol, allowPrivateUrls })
166
+ ? new SeedRegistry({ keychain, carrierUrl: carrier, dbPath, protocol, allowPrivateUrls, fleetRelays, probeIntervalMs: effectiveProbeMs })
141
167
  : (() => {
142
168
  const fallbackDb = openRegistryDb(dbPath, { forcePureJs: true });
143
169
  const normCarrier = carrier ? String(carrier).replace(/\/+$/, "") : null;
@@ -372,7 +398,8 @@ const server = createServer(async (req, res) => {
372
398
  if (!grant) {
373
399
  const known = registry.get(uuaid);
374
400
  return send(res, known ? 200 : 404,
375
- known ? { ok: true, grant: null, reason: "tier-earns-no-grant", tier: known.tier }
401
+ // The evaluated tier (topology cap, vetting), as /v1/seeds/<uuaid> reports it (2.8.0).
402
+ known ? { ok: true, grant: null, reason: "tier-earns-no-grant", tier: registry.status(uuaid).tier }
376
403
  : { ok: false, reason: "unknown-seed" });
377
404
  }
378
405
  return send(res, 200, { ok: true, grant });
@@ -436,7 +463,7 @@ const probeTimer = setInterval(async () => {
436
463
  } finally {
437
464
  probing = false;
438
465
  }
439
- }, Math.max(1, probeMinutes) * 60_000);
466
+ }, effectiveProbeMs);
440
467
 
441
468
  const shutdown = async () => {
442
469
  clearInterval(probeTimer);