Skip to content

feat(lab): publish the season list as signed text - #167

Merged
TN019 merged 8 commits into
mainfrom
feat/signed-season-publication
Dec 1, 2026
Merged

TN019 merged 8 commits into
mainfrom
feat/signed-season-publication

Conversation

@TN019

@TN019 TN019 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Why

The data-centre stub only published the binary list, whose 32-byte records cannot hold a signed barcode of about 159 characters. Gates need a season-scale list in their signed text format.

What changed

  • lab/stub.py gains --season-key, --season-count and --season-signer: at startup it signs event7 tickets with key id season1 and serves them at /season.txt on both ports with ETag, If-None-Match and byte ranges, logging the count, size and signing time. /tickets.gpb and the hub's sync are unchanged.
  • lab/compose.yaml publishes 20000 tickets from dc and dc2 and mounts the signing key into those two services only.
  • Add tests/ticket_list_verify.c, a small verifier built on the gate's gated/verify.c, and tests/test_season_publish.py (ctest season_publish).

How to verify

On Linux with the build dependencies listed in Dockerfile.build, run from the repository root:

cmake --preset debug
cmake --build --preset debug
ctest --preset debug -R '^(season_publish)$' --output-on-failure

The test publishes 2,000 tickets, verifies them all with the gate verifier, checks that the first line matches a direct signing of the first ticket, and expects signature_invalid after tampering with a signature, ticket id or event. It also checks 304, 206 and 416 replies, the TLS port, the unchanged binary endpoints, a stub without a key (404 on /season.txt) and a missing key file. The venue default is 20,000 tickets; publishing the list does not change hub admission.


背景

数据中心测试服务原来只发布二进制票单,它每条记录只有 32 字节,放不下约 159 个字符的签名条码。闸机需要一份赛季规模、采用其签名文本格式的票单。

改动

  • lab/stub.py 新增 --season-key、--season-count 和 --season-signer:启动时用密钥编号 season1 签发 event7 门票,在两个端口的 /season.txt 上提供,支持 ETag、If-None-Match 和字节范围,并记录票数、大小和签名耗时。/tickets.gpb 和 hub 的同步都不变。
  • lab/compose.yaml 让 dc 和 dc2 发布 20000 张票,签名密钥只挂载到这两个服务。
  • 新增基于闸机 gated/verify.c 的小工具 tests/ticket_list_verify.c,以及测试 tests/test_season_publish.py(ctest 名 season_publish)。

怎么验证

在 Linux 环境安装 Dockerfile.build 列出的构建依赖后,从仓库根目录运行:

cmake --preset debug
cmake --build --preset debug
ctest --preset debug -R '^(season_publish)$' --output-on-failure

测试发布 2,000 张票,用闸机的验证逻辑逐张核验,确认第一行与单独签发第一张票的结果相同;篡改签名、票号或场次后,都应得到 signature_invalid。测试还检查 304、206 和 416 响应、TLS 端口、未改动的二进制端点、未配置密钥时 /season.txt 返回 404,以及密钥文件缺失时启动失败。场馆默认规模是 20,000 张;仅发布这份票单不改变 hub 的入场判断。

Ben Carter and others added 8 commits October 27, 2026 16:30
Serve a large ticket list, shrink the client's receive buffer, read
only the response headers, then reset the connection during the body.

The complete download should add one tickets/200 count, and the
aborted download should add one tickets/incomplete count. Today both
are counted as 200. CTest accepts this run only when it fails that way.
A body write that failed part-way still counted as 200, so aborted
transfers never appeared in the ticket request metric. Count those
replies, and replies whose headers could not be written, once as
status="incomplete" on the tickets route.

The header-write path is not covered by the test: headers are too
small to make that write fail reliably.
…s heartbeat

The hub could not tell which list each gate had installed. List age
based on file time also kept growing through 304 confirmations.

Keep the verified SHA-256 and monotonic confirmation time at each gate.
Send the installed version and time since confirmation in CONFIG, then
compare it with the list the hub currently serves. Gates reporting no
version have unknown status, which is not an error. A gate retries an
empty CONFIG on the same connection for a hub not yet upgraded.

The hub trusts the reported list state as sent: CONFIG has no MAC, so
whoever holds a gate's certificate can report a false state for that
gate.

Co-authored-by: Ben Carter <ben.carter@elsworne.example>
On-call staff could only read raw /metrics. Provision a dashboard for
the existing hub series: incomplete ticket replies, TLS handshake
failures, and per-gate list status.

Use a separate Compose file so the venue lab and its drills need no
Grafana password. Pin both images by tag and digest.

Keep the earlier sync-metrics regression test for the existing sync
accounting fix, and check dashboard metrics against the hub.

Co-authored-by: Yuki Tanaka <yuki.tanaka@elsworne.example>
The hub recorded connections that had not identified themselves under
the name "unknown". Writing list status for every record made that
pseudo-gate look like a gate reporting no version.

Write list status only for gates that identified themselves and sent
a heartbeat. A CONFIG from an unidentified connection records nothing.
… the uplink watcher has stopped

Cut both data-centre exits, restore them, then kill the hub's uplink
watcher. Compare Mailpit message IDs across each separate fault.

Each case expects exactly one mail to manager@elsworne.example from
alerts@elsworne.example through the venue's own mail server, which
remains available without the data-centre link. The subjects are
"Data centre unreachable" and "Uplink watcher stopped". Allow 20 s:
5 s for the probe, 10 s for the alert threshold, 1 s for the alert
loop, and 4 s for mail submission; the watcher checks every second.

Today neither mail is sent, so both judgements fail. Exit 0 means both
pass, 1 means a judgement fails, and 2 means an environment or cleanup
failure.
…he uplink watcher stops

The hub logged data-centre failures, and the uplink watcher could exit
without notifying the venue.

Submit mail after the shared alert threshold, once per incident. Keep
sent incidents in the atomic state file across hub restarts, and re-arm
each alert when its condition recovers without sending recovery mail.

Have the watcher update a heartbeat file each loop. Its modification
time uses the clock shared with the hub, since a shell cannot portably
read a monotonic clock. Give restarted hubs a fresh threshold of grace.

Add a CI test for transient and repeated faults, recovery, mail headers,
restart persistence, and the watcher grace period.

Co-authored-by: Yuki Tanaka <yuki.tanaka@elsworne.example>
A signed barcode of about 159 characters does not fit the binary
list's 32-byte record. Publish a 20000-ticket signed text list at
/season.txt from both data-centre services at lab scale. Keep the
signing key in dc and dc2 only. Leave /tickets.gpb and the hub
unchanged. Test publication with the gates' signature verifier,
HTTP and TLS responses, caching, ranges, and tampering.
@TN019

TN019 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Ben Carter · reviewer

Does the hub now hold the issuing secret to verify these tickets?


hub 现在要持有签发私钥才能验证这些票吗?

@TN019

TN019 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Wang Hao · author

No. The secret is mounted only into dc and dc2. The hub does not use /season.txt yet; this change only publishes it and tests it with the gate's verifier.


不用。私钥只挂载到 dc 和 dc2。hub 目前还不使用 /season.txt,这次只负责发布,并用闸机的验证逻辑测试。

@TN019

TN019 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Mateo Rossi · reviewer

Does the verifier also check the event, or only the signature?


这个验证工具也检查场次吗,还是只看签名?

@TN019

TN019 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Wang Hao · author

Both. ticket_list_verify takes the keyring, the expected event and the list, and stops at the first line with malformed, signature_invalid or event_mismatch. Changing the event name breaks the signature first, so the tamper cases expect signature_invalid on line 38.


都检查。ticket_list_verify 接收密钥表、预期场次和票单,遇到第一行出问题就停下,报告 malformed、signature_invalid 或 event_mismatch。改动场次名会先破坏签名,所以篡改用例都要求第 38 行报 signature_invalid。

@TN019
TN019 merged commit 289686e into main Dec 1, 2026
5 checks passed
@TN019
TN019 deleted the feat/signed-season-publication branch December 1, 2026 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant