diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..95e5726 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,45 @@ +name: Release +on: + push: + tags: ['v*'] + workflow_dispatch: +permissions: + contents: read +concurrency: + group: release-${{ github.ref }} + cancel-in-progress: false +jobs: + packages-and-images: + runs-on: ubuntu-24.04 + timeout-minutes: 60 + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + - name: Build pinned tool image + run: docker build -f Dockerfile.build -t gatepost-build:current . + - name: Build, test and package + run: | + docker run --rm --security-opt seccomp=unconfined -v "$PWD:/src" -w /src gatepost-build:current sh -c ' + cmake --preset release && cmake --build --preset release && ctest --preset release --output-on-failure && + cmake --install build/release --prefix /tmp/gatepost-stage && + cpack --config build/release/CPackConfig.cmake -G DEB -B build/packages' + - name: Build lab image + run: docker build -f lab/Dockerfile -t gatepost-venue:release . + - name: Generate package SBOM with Syft 1.55.0 + run: | + docker run --rm -v "$PWD:/work" -w /work \ + ghcr.io/anchore/syft:v1.55.0@sha256:4cc92b64ca74ffca4c94d4c8fcc01f217731375300be14d0b6eeb2e82eaa110a \ + dir:build/packages -o spdx-json=/work/build/packages.spdx.json + - name: Scan build and lab images with Trivy 0.71.1 + run: | + for image in gatepost-build:current gatepost-venue:release; do + docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v "$PWD:/work" \ + ghcr.io/aquasecurity/trivy:0.71.1@sha256:53570e6911c2361ebe7995228088cf83a6b9b73e7f3cdca44bd8f8f425e80fa7 \ + image --scanners vuln --severity HIGH,CRITICAL --ignore-unfixed --exit-code 1 "$image" + done + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 + with: + name: gatepost-debian-and-sbom + path: | + build/packages/*.deb + build/packages.spdx.json + if-no-files-found: error diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..96d95a7 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,20 @@ +English | [简体中文](CHANGELOG.zh-CN.md) + +# Changelog + +## Unreleased + +### Fixed + +- `lab/monitoring-check.sh` no longer fails with "a monitored gate has not installed its ticket list" when `GATEPOST_GRAFANA_ADMIN_PASSWORD` is unset. The wait for each gate's ticket list ran `docker compose exec` through `lab/monitoring.yaml`, which requires the password, before the check generated its temporary one; it now uses the venue compose file only. + +## 1.0.0 - 2026-11-02 + +- Integrated local scanning, hub admission, offline journals and reports, and atomic ticket-list installation in one `gated` daemon. +- Verified Ed25519-signed event tickets on the gate before hub contact, with a per-gate HMAC on scans and offline reports. +- Moved TLS 1.3 mutual authentication into the C hub and gate clients; the gate certificate device ID must match its claimed ID. Hub-to-data-centre sync uses HTTPS with a client certificate. +- Reproduced the north-entrance PMTU fault and confirmed that a real gate installs the repaired list with a matching ETag and hash. +- Added a provisioned Venue entrance dashboard for scan traffic, rejections, p50/p95/p99 decision latency, gate heartbeats, seconds since ticket-list confirmation, and data-centre sync runs. +- Added separate Debian packages, hardened systemd units, release SBOM generation and pinned Trivy image scans. The build and lab images use digest-pinned third-party bases. + +Synthetic tickets and lab-issued keys remain test fixtures. See [security policy](SECURITY.md), [package setup](docs/operations/packages.md), and [logging compatibility](docs/operations/logging.md). diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md new file mode 100644 index 0000000..752ccac --- /dev/null +++ b/CHANGELOG.zh-CN.md @@ -0,0 +1,20 @@ +[English](CHANGELOG.md) | 简体中文 + +# 更新记录 + +## 未发布 + +### 修复 + +- 未设置 `GATEPOST_GRAFANA_ADMIN_PASSWORD` 时,`lab/monitoring-check.sh` 不再报"a monitored gate has not installed its ticket list"而失败。原来等待各闸机装好票单时,`docker compose exec` 带上了要求密码的 `lab/monitoring.yaml`,而检查要到这一步之后才生成临时密码;现在等待只用场馆的 compose 文件。 + +## 1.0.0 - 2026-11-02 + +- 在同一个 `gated` daemon 中整合本地扫描、hub 入场决定、离线日志和报告,以及票据列表的原子安装。 +- 闸机在联系 hub 前验证 Ed25519 签名的 event 门票;扫描和离线报告使用每台闸机独立的 HMAC。 +- 将 TLS 1.3 双向认证放入 C hub 与 gate 客户端;gate 证书设备 ID 必须与其声明的 ID 一致。hub 到数据中心的同步使用带客户端证书的 HTTPS。 +- 重现北入口 PMTU 故障,并确认真实闸机在修复后安装了 ETag 和哈希匹配的新列表。 +- 增加预配置的「Venue entrance」看板,展示扫描流量、拒绝情况、p50/p95/p99 决策延迟、闸机心跳、票单确认后经过的秒数,以及数据中心同步次数。 +- 增加独立的 Debian 软件包、加固的 systemd 单元、发布 SBOM 及固定版本的 Trivy 镜像扫描。构建和实验镜像的第三方基础镜像均固定 digest。 + +合成票据和实验室签发的密钥仍只是测试数据。参见[安全策略](SECURITY.zh-CN.md)、[软件包配置](docs/operations/packages.zh-CN.md)和[日志兼容性](docs/operations/logging.zh-CN.md)。 diff --git a/CMakeLists.txt b/CMakeLists.txt index d81c91a..e7e8fc6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,9 @@ cmake_minimum_required(VERSION 3.28) -project(gatepost VERSION 0.3.0 LANGUAGES C) +project(gatepost VERSION 1.1.0 LANGUAGES C) +# CMake project(VERSION) accepts numeric components only. +set(PROJECT_VERSION "1.1.0-dev") +set(gatepost_VERSION "${PROJECT_VERSION}") +message(STATUS "Gatepost ${PROJECT_VERSION}") set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_C_STANDARD 17) set(CMAKE_C_STANDARD_REQUIRED ON) @@ -288,3 +292,30 @@ add_test(NAME status_tls_workers COMMAND ${Python3_EXECUTABLE} set_tests_properties(status_tls_workers PROPERTIES TIMEOUT 120) set_tests_properties(gated_tls hub_tls device_tls second_hello tls_failure_reasons ticket_fetch_progress http_distribution ticket_reply_count offline_reports protocol_compat gate_list_version status_deadline status_tls_workers sync_metrics hub_season_reload hub_served_list hub_tickets_send_change monitoring_config dc_alerts PROPERTIES RESOURCE_LOCK status_ports) + +install(TARGETS gated RUNTIME DESTINATION usr/bin COMPONENT gate) +install(TARGETS gate-hub RUNTIME DESTINATION usr/bin COMPONENT hub) +install(PROGRAMS packaging/run-gated.sh DESTINATION usr/lib/gatepost RENAME run-gated COMPONENT gate) +install(PROGRAMS packaging/run-gate-hub.sh DESTINATION usr/lib/gatepost RENAME run-gate-hub COMPONENT hub) +install(FILES packaging/gated.service DESTINATION usr/lib/systemd/system COMPONENT gate) +install(FILES packaging/gate-hub.service DESTINATION usr/lib/systemd/system COMPONENT hub) +install(FILES config/gated.env.example DESTINATION etc/gatepost RENAME gated.env COMPONENT gate) +install(FILES config/gate-hub.env.example DESTINATION etc/gatepost RENAME gate-hub.env COMPONENT hub) +install(FILES config/hub.conf.example DESTINATION etc/gatepost RENAME hub.conf COMPONENT hub) + +set(CPACK_GENERATOR DEB) +set(CPACK_PACKAGING_INSTALL_PREFIX "/") +set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) +set(CPACK_PACKAGE_CONTACT "Gatepost maintainers ") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Gatepost venue admission services") +set(CPACK_DEB_COMPONENT_INSTALL ON) +set(CPACK_COMPONENTS_ALL gate hub) +set(CPACK_DEBIAN_GATE_PACKAGE_NAME gatepost-gated) +set(CPACK_DEBIAN_HUB_PACKAGE_NAME gatepost-gate-hub) +set(CPACK_DEBIAN_GATE_PACKAGE_DEPENDS "adduser, libc6, libcurl4, libssl3, libsodium23, libgpiod2, libsystemd0") +set(CPACK_DEBIAN_HUB_PACKAGE_DEPENDS "adduser, libc6, libcurl4, libssl3, libsodium23") +set(CPACK_DEBIAN_GATE_PACKAGE_CONTROL_EXTRA + "${CMAKE_SOURCE_DIR}/packaging/postinst;${CMAKE_SOURCE_DIR}/packaging/gate-control/conffiles") +set(CPACK_DEBIAN_HUB_PACKAGE_CONTROL_EXTRA + "${CMAKE_SOURCE_DIR}/packaging/postinst;${CMAKE_SOURCE_DIR}/packaging/hub-control/conffiles") +include(CPack) diff --git a/Dockerfile.build b/Dockerfile.build index 995eaba..461de07 100644 --- a/Dockerfile.build +++ b/Dockerfile.build @@ -2,12 +2,13 @@ FROM debian:12.12-slim@sha256:d5d3f9c23164ea16f31852f95bd5959aad1c5e854332fe00f7 ENV DEBIAN_FRONTEND=noninteractive RUN rm -f /etc/apt/sources.list.d/debian.sources && \ printf 'deb [check-valid-until=no] %s bookworm main\n' \ - 'http://snapshot.debian.org/archive/debian/20260115T000000Z' \ + 'http://snapshot.debian.org/archive/debian/20261030T000000Z' \ > /etc/apt/sources.list && \ printf 'deb [check-valid-until=no] %s bookworm-security main\n' \ - 'http://snapshot.debian.org/archive/debian-security/20260115T000000Z' \ + 'http://snapshot.debian.org/archive/debian-security/20261030T000000Z' \ >> /etc/apt/sources.list && \ - apt-get -o Acquire::Check-Valid-Until=false update && apt-get install -y --no-install-recommends \ + apt-get -o Acquire::Check-Valid-Until=false update && \ + apt-get install -y --no-install-recommends \ build-essential \ ninja-build \ clang \ @@ -38,3 +39,6 @@ RUN rm -f /etc/apt/sources.list.d/debian.sources && \ && rm -rf /var/lib/apt/lists/* \ && pip3 install --break-system-packages --no-cache-dir cmake==3.31.10 WORKDIR /src +RUN apt-get -o Acquire::Check-Valid-Until=false update && \ + apt-get upgrade -y && \ + rm -rf /var/lib/apt/lists/* diff --git a/README.md b/README.md index 04aa362..afb6eed 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ English | [简体中文](README.zh-CN.md) Gatepost is Elsworne's venue entry system. `gated` runs on a Linux gate device, reads barcodes and drives its lights and turnstile. It can use a local synthetic ticket list when the venue is offline. The venue hub will coordinate gates and distribute ticket lists. `libgate` owns the local ticket store. +The 1.0.0 release includes [offline ticket signatures](docs/security/ticket-signing.md), [device TLS](docs/adr/0019-authenticate-devices-with-mutual-tls.md), [two uplinks and NAT](docs/adr/0017-add-a-backup-exit.md), and the [north-entrance diagnosis](docs/adr/0020-keep-path-mtu-feedback-and-check-each-gate-list.md). Review [SECURITY.md](SECURITY.md) before deployment. + ## Quick start Install Docker. From the repository root, build the debug binaries and open the build container: @@ -40,6 +42,8 @@ time=1775170804236133 level=WARN event=hub_link gate=north state=offline reason= time=1775170804235739 level=INFO event=hub_link gate=south state=online ``` +For device installation, build the separate Debian packages with CPack and configure the hardened systemd units as described in [packages and device setup](docs/operations/packages.md). The release workflow builds packages, emits a Syft SBOM, and scans build and lab images with Trivy. [Logging compatibility](docs/operations/logging.md) explains the journal and admission records. + Exit the container with `exit`. For lights and turnstile movement, use the team's separate `gatepost-sim` repository with the [simulator protocol](docs/device/simulator-protocol.md). ## Build and test diff --git a/README.zh-CN.md b/README.zh-CN.md index 92dd3c0..0ef5162 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -6,6 +6,8 @@ Gatepost 是 Elsworne 的场馆入场系统。闸机上的 Linux 设备运行 `gated`,读取条码,控制指示灯和转闸。场馆断网时,它仍能根据本地票单放行。场馆的 `hub` 将负责协调各台闸机并分发票单;`libgate` 管理本地票单。 +1.0.0 版本包含[离线票据签名](docs/security/ticket-signing.zh-CN.md)、[设备 TLS](docs/adr/0019-authenticate-devices-with-mutual-tls.zh-CN.md)、[双上行与 NAT](docs/adr/0017-add-a-backup-exit.zh-CN.md)及[北入口诊断](docs/adr/0020-keep-path-mtu-feedback-and-check-each-gate-list.zh-CN.md)。部署前请阅读 [SECURITY.zh-CN.md](SECURITY.zh-CN.md)。 + ## 快速开始 安装 Docker。在仓库根目录编译调试版本,然后进入构建容器: @@ -38,6 +40,10 @@ time=1775170804236133 level=WARN event=hub_link gate=north state=offline reason= time=1775170804235739 level=INFO event=hub_link gate=south state=online ``` +设备安装可按[软件包与设备配置](docs/operations/packages.zh-CN.md)使用 CPack 构建独立的 Debian 软件包,并配置加固的 systemd 单元。发布工作流构建软件包、生成 Syft SBOM,并用 Trivy 扫描构建和实验镜像。[日志兼容性](docs/operations/logging.zh-CN.md)说明 journal 和入场记录。 + +## 扫描器监督与 systemd + 输入 `exit` 离开容器。要观察指示灯和转闸动作,可使用团队的独立仓库 `gatepost-sim`;通信格式见[模拟器协议](docs/device/simulator-protocol.zh-CN.md)。 ## 构建与测试 diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..e1db6a7 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,19 @@ +English | [简体中文](SECURITY.zh-CN.md) + +# Security policy + +## Supported versions + +Security fixes target the latest `1.0.x` release. Development versions are not deployment releases. + +## Reporting + +When this repository is published, use GitHub private vulnerability reporting for `codexary/gatepost`. Until then, contact the project owner through the agreed private channel. Do not publish exploit details, private keys, personal data or venue network addresses. We aim to acknowledge a report within two business days and coordinate disclosure after a fix is available. + +## Deployment boundaries + +The repository contains synthetic tickets and test-only key generation. Do not deploy `lab/tls/generated/`, `lab/tls/test-key.pem`, or keys generated for local tests. Keep the ticket-signing private key at the data centre. Provision public event keys, per-gate HMAC keys and device certificates through an authenticated channel. + +A hub-connected production gate requires `GATEPOST_PUBLIC_KEYS`, `GATEPOST_EVENT_ID`, per-gate HMAC keys, CA trust, a client certificate and its private key. The hub checks the TLS peer certificate and device ID. The data-centre sync uses HTTPS with hub credentials. `gated-test` and `gate-hub-test` permit plaintext only for local integration tests and are not packaged. Standalone offline use without a hub retains an unsigned compatibility path; deploy a hub-connected configuration for ticket issuance checks. + +The lab's UDP load generator is unauthenticated and is not an operational report channel. Configure deployment credentials and systemd access restrictions as in [package setup](docs/operations/packages.md). See [ticket signing](docs/security/ticket-signing.md), [device TLS](docs/adr/0019-authenticate-devices-with-mutual-tls.md), and the [certificate renewal runbook](docs/runbooks/renew-device-certificate.md). diff --git a/SECURITY.zh-CN.md b/SECURITY.zh-CN.md new file mode 100644 index 0000000..5ee61ce --- /dev/null +++ b/SECURITY.zh-CN.md @@ -0,0 +1,19 @@ +[English](SECURITY.md) | 简体中文 + +# 安全策略 + +## 支持版本 + +安全修复面向最新的 `1.0.x` 版本。开发版本不是部署版本。 + +## 报告方式 + +仓库发布后,请使用 `codexary/gatepost` 的 GitHub 私密漏洞报告;在此之前通过约定的私密渠道联系项目负责人。不要公开利用细节、私钥、个人数据或场馆网络地址。我们计划在两个工作日内确认报告,并在修复可用后协调披露。 + +## 部署边界 + +仓库包含合成票据和仅供测试的密钥生成工具。不要部署 `lab/tls/generated/`、`lab/tls/test-key.pem` 或本地测试密钥。票据签名私钥留在数据中心。通过经过认证的渠道配置 event 公钥、每台闸机的 HMAC 密钥和设备证书。 + +连接 hub 的生产闸机必须配置 `GATEPOST_PUBLIC_KEYS`、`GATEPOST_EVENT_ID`、每台闸机的 HMAC 密钥、受信任 CA、客户端证书和私钥。hub 核对 TLS 对端证书与设备 ID。数据中心同步使用带 hub 凭据的 HTTPS。`gated-test` 和 `gate-hub-test` 仅在本地集成测试中允许明文,不包含在软件包中。无 hub 的独立离线使用保留未签名兼容路径;部署时应使用连接 hub 的配置核对票据签发。 + +实验室 UDP 压测工具没有认证,不是运营报告渠道。按[软件包配置](docs/operations/packages.zh-CN.md)配置部署凭据和 systemd 访问限制。另见[票据签名](docs/security/ticket-signing.zh-CN.md)、[设备 TLS](docs/adr/0019-authenticate-devices-with-mutual-tls.zh-CN.md)和[证书续期手册](docs/runbooks/renew-device-certificate.zh-CN.md)。 diff --git a/config/gate-hub.env.example b/config/gate-hub.env.example new file mode 100644 index 0000000..c6fd1a6 --- /dev/null +++ b/config/gate-hub.env.example @@ -0,0 +1,7 @@ +GATEPOST_LISTEN_ALL=1 +GATEPOST_HUB_CONFIG=/etc/gatepost/hub.conf +GATEPOST_REPORT_FILE=/var/lib/gatepost/reports.log +GATEPOST_TICKETS=/var/lib/gatepost/tickets.txt +GATEPOST_LISTEN_PORT=7000 +GATEPOST_STATUS=1 +GATEPOST_SYNC=1 diff --git a/config/gated.env.example b/config/gated.env.example new file mode 100644 index 0000000..ea9c1dd --- /dev/null +++ b/config/gated.env.example @@ -0,0 +1,9 @@ +GATEPOST_ARP_INTERFACE=eth0 +GATEPOST_GATE_ID=gate-1 +GATEPOST_HUB=hub.example.invalid:7000 +GATEPOST_TLS_SERVER_NAME=hub.example.invalid +GATEPOST_PUBLIC_KEYS=/etc/gatepost/ticket-public.keys +GATEPOST_EVENT_ID=replace-with-event-id +GATEPOST_SCANNER=tty:/dev/ttyACM0 +GATEPOST_OUTPUTS=gpio:/dev/gpiochip0 +GATEPOST_TICKETS=/var/lib/gatepost/tickets.txt diff --git a/config/hub.conf.example b/config/hub.conf.example index 9560253..3e25d47 100644 --- a/config/hub.conf.example +++ b/config/hub.conf.example @@ -1,10 +1,10 @@ # Copy to /etc/gatepost/hub.conf and set paths for this host. smtp_url=smtp://mail.venue.lan:587 -smtp_ca=/etc/gatepost/mail-ca.pem +smtp_ca=/run/credentials/gate-hub.service/mail-ca.pem smtp_from=alerts@elsworne.example smtp_to=manager@elsworne.example smtp_user=gatepost -smtp_password_file=/etc/gatepost/smtp-password +smtp_password_file=/run/credentials/gate-hub.service/smtp-password state_file=/var/lib/gatepost/alerts.state alert_after_seconds=10 # Optional: the watcher's heartbeat file; its mtime uses the hub's shared wall clock. diff --git a/docs/adr/0020-keep-path-mtu-feedback-and-check-each-gate-list.md b/docs/adr/0020-keep-path-mtu-feedback-and-check-each-gate-list.md new file mode 100644 index 0000000..76e38e0 --- /dev/null +++ b/docs/adr/0020-keep-path-mtu-feedback-and-check-each-gate-list.md @@ -0,0 +1,41 @@ +English | [简体中文](0020-keep-path-mtu-feedback-and-check-each-gate-list.zh-CN.md) + +# ADR 0020: Keep path-MTU feedback and check each gate's ticket list + +- Status: Accepted +- Date: 2026-10-30 +- Decision makers: Ingrid Larsen, Yuki Tanaka, Ben Carter +- Consulted: Aisha Rahman (security review of the router change), Mateo Rossi (gate list version and download log), Noah Williams (drills), Wang Hao (season list), Fatima Zahra (venue) + +## Context + +[ADR 0019](0019-authenticate-devices-with-mutual-tls.md) put ticket lists on the mutual-TLS status port. The [north entrance review](../postmortems/2026-10-24-north-entrance-ticket-list.md) records the incident and lab measurements: an online gate could scan while the larger new list could not cross its path. On Monday, October 26, `feat(lab): add the north entrance segment` and `test(lab): show north gates keep their old list behind a path-MTU black hole` made that gap reproducible. + +On Tuesday, October 27, `fix(lab): let the venue router return fragmentation-needed to the hub` restored path-MTU feedback; `fix(gated): log the phase and bytes of a failed list download` and `test(gate-hub): show an aborted ticket reply is counted as 200` exposed gaps in diagnosis. On Wednesday, October 28, `fix(gate-hub): count only completed ticket replies` and `feat(gated,gate-hub): report each gate's installed list version in its heartbeat` made delivery and each gate's installed version visible. + +On Thursday, October 29, `feat(lab): publish the season list as signed text` supplied the larger list used in the drills. On Friday, October 30, `test(gate-hub): show a ticket only in the synced season list is rejected` and `fix(gate-hub): decide with and serve the verified season list` aligned admission with the served list; `test(lab): show a north gate behind a path-MTU black hole holds the TLS status port`, `test(gate-hub): show one stalled client holds the TLS status port for every gate`, and `fix(gate-hub): serve the TLS status port from four workers` addressed the shared listener. Ingrid, Yuki and Ben accepted this decision. + +## Decision + +1. Venue routers return ICMP “fragmentation needed” (type 3 code 4) to senders and continue dropping other destination-unreachable messages. Record the MTU of each routed segment in the network plan. +2. Each gate reports the version (ETag) of its installed list and when it last confirmed that list in its heartbeat. The hub shows and exports each gate as `current`, `stale` or `unknown`; no reported version means `unknown`, not an error. +3. Count a `/tickets` reply as 200 only after it has been sent completely; otherwise count `status="incomplete"`. A failed gate download logs its phase and bytes received. +4. Decide with and serve the same verified season list: its SHA-256 must equal its ETag, the whole list must load under the start-file rules, and the file and its directory must be synced. Keep a refused list out and try it again next round. The hub still leaves ticket-signature checks to gates, as in ADR 0018 and [ADR 0019](0019-authenticate-devices-with-mutual-tls.md), limit 6. +5. Serve port 8444 with four workers and a queue of 16. Close connections arriving beyond a full queue and count them in `gatepost_status_queue_full_total{listener="status"}`. Port 8081 remains one thread for staff. Deadlines remain 2 s per step and 10 s per connection. + +## Options considered + +- Clamp TCP MSS on the north link: this hides the path's real MTU and must be maintained on every path. Not chosen. +- Lower the hub or gate MTU: this changes every path to fix one. Not chosen. +- Judge a gate's list by file age: age keeps growing through 304 replies and does not say whether the list is newest. Comparing versions was chosen. +- Shorten the 8444 deadline for list replies or add jitter to gate fetch cycles: a shorter deadline ties the hub to the gates' 300 ms limit; jitter does not shorten a hold. Workers were chosen, while jitter remains an open action in the review. + +## Consequences and known limits + +1. Small replies can hide an interruption. The hub hands a reply to the kernel and counts it complete when every write returns. In the venue lab (Linux `7.0.14-linuxkit`, `net.ipv4.tcp_wmem` `4096 16384 4194304`), a gate that took nothing after its request and acknowledged nothing still had 30,750 bytes accepted by the kernel in 5 of 5 runs: 24,984 bytes at once and 5,766 more after the first 2 s step. `ss` showed `Send-Q` 30,750 and send buffer `tb46080`. Those bytes were a 342-byte header, three 8214-byte records and 5,766 bytes. Each 8214-byte record carries 8192 bytes of list, so the accepted data includes about 30 KB of list, roughly 175 to 180 lines of 170 to 174 characters. A list that small can be handed over whole and counted as 200 even when the gate has gone. The lab season list is much larger, about 3.5 MB (3,488,890 bytes), so `status="incomplete"` is meaningful for it. The threshold depends on the kernel and its settings. +2. `CONFIG` carries no MAC. The hub accepts the list version a gate reports. Anyone holding that gate's certificate and key can report a false list status for it; see [ADR 0019](0019-authenticate-devices-with-mutual-tls.md), limits 3 and 4. +3. A gate downloads its list synchronously in its scan loop with a 300 ms limit. Receiving the whole 3,488,890-byte list needs at least about 93 Mbit/s (3,488,890 × 8 / 0.3 s), more with the TLS handshake. On a slower link, a gate can only keep its old list through 304 replies. Moving the download out of the scan loop is Mateo Rossi's open action, not scheduled. +4. A stuck connection still holds one 8444 worker for up to 10 s; 4 to 6 s was measured for a client that stopped reading or lost power after its request. Four such connections make others wait, and a holder of gate certificates can do this deliberately. Port 8081 still has one thread. +5. Gates fetch on aligned 20 s cycles without jitter. +6. The router passes only type 3 code 4. A path elsewhere that drops it is again a black hole. Gate list status and the incomplete count reveal such a path; they do not repair it. +7. The hub decides with the verified season list but still does not check ticket signatures; the limit in ADR 0018 and [ADR 0019](0019-authenticate-devices-with-mutual-tls.md), limit 6, is unchanged. This ADR does not supersede any part of ADR 0019. diff --git a/docs/adr/0020-keep-path-mtu-feedback-and-check-each-gate-list.zh-CN.md b/docs/adr/0020-keep-path-mtu-feedback-and-check-each-gate-list.zh-CN.md new file mode 100644 index 0000000..5de9752 --- /dev/null +++ b/docs/adr/0020-keep-path-mtu-feedback-and-check-each-gate-list.zh-CN.md @@ -0,0 +1,41 @@ +[English](0020-keep-path-mtu-feedback-and-check-each-gate-list.md) | 简体中文 + +# ADR 0020:保留路径 MTU 反馈并核对每台闸机的票单 + +- 状态:已接受 +- 日期:2026-10-30 +- 决策者:Ingrid Larsen、Yuki Tanaka、Ben Carter +- 被咨询人:Aisha Rahman(路由器改动的安全审查)、Mateo Rossi(闸机票单版本与下载日志)、Noah Williams(演练)、Wang Hao(季票单)、Fatima Zahra(场馆) + +## 背景 + +[ADR 0019](0019-authenticate-devices-with-mutual-tls.zh-CN.md) 将票单放在双向 TLS 状态端口。[北入口事件复盘](../postmortems/2026-10-24-north-entrance-ticket-list.zh-CN.md) 记录了事件和实验室测量:闸机在线且能扫码,较大的新票单却过不了它所经的链路。10 月 26 日周一,`feat(lab): add the north entrance segment` 和 `test(lab): show north gates keep their old list behind a path-MTU black hole` 让这一差异可以复现。 + +10 月 27 日周二,`fix(lab): let the venue router return fragmentation-needed to the hub` 恢复路径 MTU 反馈;`fix(gated): log the phase and bytes of a failed list download` 与 `test(gate-hub): show an aborted ticket reply is counted as 200` 暴露了诊断上的缺口。10 月 28 日周三,`fix(gate-hub): count only completed ticket replies` 和 `feat(gated,gate-hub): report each gate's installed list version in its heartbeat` 让交付结果和各闸机安装的版本可见。 + +10 月 29 日周四,`feat(lab): publish the season list as signed text` 提供了演练所用的较大季票单。10 月 30 日周五,`test(gate-hub): show a ticket only in the synced season list is rejected` 与 `fix(gate-hub): decide with and serve the verified season list` 让放行判断和提供的票单一致;`test(lab): show a north gate behind a path-MTU black hole holds the TLS status port`、`test(gate-hub): show one stalled client holds the TLS status port for every gate` 和 `fix(gate-hub): serve the TLS status port from four workers` 处理了共用监听端口受阻的问题。Ingrid、Yuki 和 Ben 接受本决定。 + +## 决定 + +1. 场馆路由器向发送方返回 ICMP“需要分片”(type 3 code 4),仍丢弃其他“目的不可达”消息。网络规划记录每个路由网段的 MTU。 +2. 每台闸机在心跳中报告已安装票单的版本(ETag)以及上次确认该票单的时间。hub 显示并导出每台闸机的 `current`、`stale` 或 `unknown` 状态;未报告版本时记为 `unknown`,不算错误。 +3. `/tickets` 回复全部发送完毕才计为 200,否则计为 `status="incomplete"`。闸机下载失败时记录所处阶段和已收到的字节数。 +4. hub 用同一份已验证季票单进行放行判断并提供下载:SHA-256 必须等于 ETag,整份票单须按启动文件规则成功加载,文件及其目录都须同步到磁盘。拒绝的票单不启用,下一轮再试。hub 仍将票据签名检查交给闸机,这沿用 ADR 0018 和 [ADR 0019](0019-authenticate-devices-with-mutual-tls.zh-CN.md) 的第 6 条限制。 +5. 8444 端口由四个工作线程和容量为 16 的队列服务。队列满时关闭新连接,并计入 `gatepost_status_queue_full_total{listener="status"}`。供员工使用的 8081 端口仍为单线程。期限仍为每一步 2 s、每条连接 10 s。 + +## 考虑过的方案 + +- 在北入口链路上限制 TCP MSS:这会掩盖路径的真实 MTU,还须在每条路径上维护。未采用。 +- 降低 hub 或闸机的 MTU:为修复一条路径而改变所有路径。未采用。 +- 按文件年龄判断闸机票单:收到 304 回复后文件年龄仍会增长,也不能说明票单是不是最新。选择比较版本。 +- 缩短 8444 票单回复的期限,或给闸机的取票周期加抖动:更短的期限会把 hub 绑到闸机的 300 ms 限制;抖动不能缩短单条连接的占用时间。选择增加工作线程;复盘仍将抖动列为待办。 + +## 后果与已知限制 + +1. 较小的回复可能掩盖中断。hub 将回复交给内核;所有写入返回后,就计为完整。在场馆实验室(Linux `7.0.14-linuxkit`,`net.ipv4.tcp_wmem` 为 `4096 16384 4194304`),闸机发出请求后既不接收也不确认,内核在 5 次运行中每次仍接受 30,750 字节:起初一次接受 24,984 字节,第一个 2 s 步骤后又接受 5,766 字节。`ss` 显示 `Send-Q` 为 30,750,发送缓冲为 `tb46080`。这些字节包括 342 字节的响应头、三条各 8214 字节的记录,以及后续 5,766 字节。每条 8214 字节记录承载 8192 字节票单,因此内核接受了约 30 KB 票单,约为 175 至 180 行、每行 170 至 174 个字符。这样小的票单即使闸机已经断开,也可能整体交给内核并计为 200。实验室季票单大得多,约 3.5 MB(3,488,890 字节),因此 `status="incomplete"` 对它有意义。这个界限取决于内核及其设置。 +2. `CONFIG` 不携带 MAC。hub 接受闸机上报的票单版本。持有该闸机证书和私钥的人可以为其虚报票单状态;见 [ADR 0019](0019-authenticate-devices-with-mutual-tls.zh-CN.md) 的第 3、4 条限制。 +3. 闸机仍在扫码循环中同步下载票单,限时 300 ms。要在此期限内接收完整的 3,488,890 字节票单,链路至少需要约 93 Mbit/s(3,488,890 × 8 / 0.3 s);加上 TLS 握手还需要更快。在较慢链路上,闸机只能通过 304 回复维持旧票单。将下载移出扫码循环由 Mateo Rossi 负责,尚未排期。 +4. 卡住的连接仍可占用一个 8444 工作线程最多 10 s;客户端请求后停止读取或断电时,测得占用 4 至 6 s。四条这样的连接会让其他连接等待;持有闸机证书的人也可以故意这样做。8081 仍为单线程。 +5. 闸机按对齐的 20 s 周期取票,没有抖动。 +6. 路由器只放行 type 3 code 4;若其他路径丢弃它,就会再次形成黑洞。闸机票单状态和未完成计数能显示这类路径,但不能修复它。 +7. hub 用已验证季票单作放行判断,但仍不检查票据签名;ADR 0018 和 [ADR 0019](0019-authenticate-devices-with-mutual-tls.zh-CN.md) 第 6 条的限制没有改变。本 ADR 不取代 ADR 0019 的任何部分。 diff --git a/docs/operations/logging.md b/docs/operations/logging.md new file mode 100644 index 0000000..865e2e9 --- /dev/null +++ b/docs/operations/logging.md @@ -0,0 +1,7 @@ +English | [简体中文](logging.zh-CN.md) + +# Logging compatibility at 1.0.0 + +The daemons keep their existing text records in this release. `gated` writes `ACCEPT` and `REJECT` to standard output as the local device decision interface; the venue scripts and hardware adapter depend on those exact lines. The hub's status, sync and alert messages include `key=value` fields, but older diagnostic and capture scripts also parse specific text. Changing every record to a new timestamped format in this release would change those interfaces without a complete migration of the parsers and recorded incidents. + +Run both services under systemd to obtain journal timestamps, service identity and priority. Filter by `_SYSTEMD_UNIT=gated.service` or `_SYSTEMD_UNIT=gate-hub.service`. Do not treat stdout decisions as an audit log: use the gate's durable admission journal and the hub's report store for admission accounting. The ticket-fetch record includes `status`, HTTP code and curl result, and on installation the ETag. A later logging migration must add a timestamp and level to every event, keep stdout device decisions stable, and update all log-parsing tests and lab scripts together. diff --git a/docs/operations/logging.zh-CN.md b/docs/operations/logging.zh-CN.md new file mode 100644 index 0000000..3de7ac5 --- /dev/null +++ b/docs/operations/logging.zh-CN.md @@ -0,0 +1,7 @@ +[English](logging.md) | 简体中文 + +# 1.0.0 的日志兼容性 + +本次发布保留 daemon 现有的文本记录。`gated` 向标准输出写出 `ACCEPT` 和 `REJECT`,作为本地设备决策接口;场馆脚本和硬件适配层依赖这些准确的行。hub 的状态、同步和告警消息包含 `key=value` 字段,但较早的诊断和抓包脚本也解析特定文本。若在此次发布中把所有记录改为带时间戳的新格式,而没有同时迁移解析器和事件记录,就会改变这些接口。 + +通过 systemd 运行两个服务,可由 journal 提供时间戳、服务身份和优先级。按 `_SYSTEMD_UNIT=gated.service` 或 `_SYSTEMD_UNIT=gate-hub.service` 筛选。标准输出的放行决定并非审计日志;入场核算应使用闸机的持久放行日志和 hub 的报告存储。票据获取记录包含 `status`、HTTP 状态和 curl 结果;安装时还包含 ETag。后续日志迁移须为每个事件加入时间戳和级别,保持标准输出设备决定不变,并同时更新所有日志解析测试和实验脚本。 diff --git a/docs/operations/monitoring.md b/docs/operations/monitoring.md index e76af5c..d53f3c7 100644 --- a/docs/operations/monitoring.md +++ b/docs/operations/monitoring.md @@ -22,7 +22,7 @@ The **Venue entrance** dashboard reads the hub's staff-side `/metrics` route. Pr | Row | Panel | On-call reading | | --- | --- | --- | | Traffic | Scans per second by gate and result | Compare accept, used-ticket rejection, unknown-ticket rejection and error rates by gate. | -| Errors | Ticket HTTP errors | `/tickets` replies other than 200, 206 or 304, grouped by status. `incomplete` means the hub could not hand the whole reply to the kernel; a reply the kernel accepted in full counts as 200 or 206 even if the gate never received it. A rising `404` means a gate is fetching from 8081 on a TLS hub. | +| Errors | Ticket HTTP errors | `/tickets` replies other than 200, 206 or 304, grouped by status. `incomplete` means the hub could not hand the whole reply to the kernel; a reply the kernel accepted in full counts as 200 or 206 even if the gate never received it; see [ADR 0020](../adr/0020-keep-path-mtu-feedback-and-check-each-gate-list.md), limit 1. A rising `404` means a gate is fetching from 8081 on a TLS hub. | | Errors | TLS handshake failures | Check the listener and reason to distinguish gate RPC from the status listener. | | Errors | Rejections by result | Compare `reject_used` and `reject_unknown` by gate. | | Errors | Data-centre sync runs | Compare successful and failed synchronization runs in the last minute. | diff --git a/docs/operations/monitoring.zh-CN.md b/docs/operations/monitoring.zh-CN.md index 7948893..f1bfac0 100644 --- a/docs/operations/monitoring.zh-CN.md +++ b/docs/operations/monitoring.zh-CN.md @@ -22,7 +22,7 @@ docker compose -f lab/compose.yaml -f lab/monitoring.yaml rm -sfv prometheus gra | 分组 | 面板 | 值班时怎么读 | | --- | --- | --- | | Traffic | Scans per second by gate and result | 按闸机比较放行、重复票拒绝、未知票拒绝和错误的每秒次数。 | -| Errors | Ticket HTTP errors | 按状态显示 `/tickets` 除 200、206、304 外的响应。`incomplete` 表示 hub 没能把响应全部交给内核;响应一旦全部交给内核,即使闸机最终没有收到,也计为 200 或 206。`404` 持续增长,说明有闸机向启用 TLS 的 hub 的 8081 端口取票。 | +| Errors | Ticket HTTP errors | 按状态显示 `/tickets` 除 200、206、304 外的响应。`incomplete` 表示 hub 没能把响应全部交给内核;响应一旦全部交给内核,即使闸机最终没有收到,也计为 200 或 206,见 [ADR 0020](../adr/0020-keep-path-mtu-feedback-and-check-each-gate-list.zh-CN.md) 的第 1 条限制。`404` 持续增长,说明有闸机向启用 TLS 的 hub 的 8081 端口取票。 | | Errors | TLS handshake failures | 根据监听端口和原因,区分闸机 RPC 与状态服务的握手失败。 | | Errors | Rejections by result | 按闸机比较 `reject_used` 和 `reject_unknown`。 | | Errors | Data-centre sync runs | 比较最近一分钟成功和失败的数据中心同步次数。 | diff --git a/docs/operations/packages.md b/docs/operations/packages.md new file mode 100644 index 0000000..4790726 --- /dev/null +++ b/docs/operations/packages.md @@ -0,0 +1,17 @@ +English | [简体中文](packages.zh-CN.md) + +# Debian packages and device setup + +The release build produces separate `gatepost-gated` and `gatepost-gate-hub` Debian packages for the build architecture. From the repository root: + +```sh +./scripts/dev.sh build-image +./scripts/dev.sh test release +docker run --rm -v "$PWD:/src" -w /src gatepost-build:current sh -c 'cmake --install build/release --prefix /tmp/gatepost-stage && cpack --config build/release/CPackConfig.cmake -G DEB -B build/packages' +``` + +`cmake --install` places the binaries under `usr/bin`, service units under `usr/lib/systemd/system`, launchers under `usr/lib/gatepost`, and example configuration under `etc/gatepost` relative to the chosen prefix. CPack packages those paths as `/usr/bin`, `/usr/lib/...` and `/etc/gatepost/...`. The package scripts create the `gatepost` system user and group, the persistent state directory, and restricted credential directories. The `/etc/gatepost` configuration files are Debian conffiles. Packages do not enable or start a service automatically. + +Install only the package needed on each host. Replace the values in `/etc/gatepost/gated.env` or `gate-hub.env` and the hub configuration. Install trusted CA, chain and private-key files under `/etc/gatepost/credentials/` with root-only access. The hub also loads its SMTP CA and password from this directory. The units use `LoadCredential=` to pass those TLS files into each service's private credential directory. Install per-gate HMAC keys under `/etc/gatepost/mac-keys/gate/GATE_ID.hex` on a gate and `/etc/gatepost/mac-keys/hub/GATE_ID.hex` on the hub; restrict each file to the service group. Install the public ticket-signing keys at the path set by `GATEPOST_PUBLIC_KEYS`, and install signed tickets in `/var/lib/gatepost/tickets.txt`. The key names and gate ID must match the certificate device ID. + +The gate unit uses `/dev/ttyACM0` and `/dev/gpiochip0` by default; adjust the environment file and grant the `gatepost` user the device access needed by the hardware. Validate on the target system with `systemd-analyze verify /usr/lib/systemd/system/gated.service /usr/lib/systemd/system/gate-hub.service`, then enable the applicable service. The units set `NoNewPrivileges`, `ProtectSystem=strict`, `ProtectHome`, `PrivateTmp`, kernel and cgroup protections, and a writable state directory. See [logging compatibility](logging.md) for the journal and durable admission record boundaries. Test keys created by `lab/keys.sh` are for the local lab only. diff --git a/docs/operations/packages.zh-CN.md b/docs/operations/packages.zh-CN.md new file mode 100644 index 0000000..6ef346a --- /dev/null +++ b/docs/operations/packages.zh-CN.md @@ -0,0 +1,17 @@ +[English](packages.md) | 简体中文 + +# Debian 软件包与设备配置 + +发布构建为当前架构生成独立的 `gatepost-gated` 和 `gatepost-gate-hub` Debian 软件包。在仓库根目录执行: + +```sh +./scripts/dev.sh build-image +./scripts/dev.sh test release +docker run --rm -v "$PWD:/src" -w /src gatepost-build:current sh -c 'cmake --install build/release --prefix /tmp/gatepost-stage && cpack --config build/release/CPackConfig.cmake -G DEB -B build/packages' +``` + +`cmake --install` 相对于指定前缀把程序放在 `usr/bin`,服务单元放在 `usr/lib/systemd/system`,启动脚本放在 `usr/lib/gatepost`,示例配置放在 `etc/gatepost`。CPack 将其打包为 `/usr/bin`、`/usr/lib/...` 和 `/etc/gatepost/...`。软件包脚本创建 `gatepost` 系统用户和组、持久状态目录及受限凭据目录。`/etc/gatepost` 下的配置标记为 Debian conffile。安装软件包不会自动启用或启动服务。 + +每台主机只安装所需的软件包。修改 `/etc/gatepost/gated.env` 或 `gate-hub.env` 及 hub 配置。将受信任 CA、证书链和私钥放在 `/etc/gatepost/credentials/`,仅允许 root 访问。hub 还从此目录加载 SMTP CA 和密码。服务单元通过 `LoadCredential=` 将这些 TLS 文件传入各自的私有凭据目录。闸机的 HMAC 密钥放在 `/etc/gatepost/mac-keys/gate/GATE_ID.hex`,hub 对应密钥放在 `/etc/gatepost/mac-keys/hub/GATE_ID.hex`,文件访问限制为服务组。将票据签名公钥放在 `GATEPOST_PUBLIC_KEYS` 指定的路径,将已签名票据放在 `/var/lib/gatepost/tickets.txt`。密钥名称和 gate ID 必须与设备证书中的 ID 一致。 + +闸机单元默认使用 `/dev/ttyACM0` 和 `/dev/gpiochip0`;按硬件修改环境文件,并授予 `gatepost` 用户所需的设备访问权限。在目标系统上运行 `systemd-analyze verify /usr/lib/systemd/system/gated.service /usr/lib/systemd/system/gate-hub.service`,再启用相应服务。服务单元设置 `NoNewPrivileges`、`ProtectSystem=strict`、`ProtectHome`、`PrivateTmp`、内核和 cgroup 保护,以及可写状态目录。journal 和持久入场记录的界限参见[日志兼容性](logging.zh-CN.md)。`lab/keys.sh` 生成的测试密钥只供本地实验使用。 diff --git a/docs/postmortems/2026-10-03-data-centre-link-outage.md b/docs/postmortems/2026-10-03-data-centre-link-outage.md index a6f9116..005e35e 100644 --- a/docs/postmortems/2026-10-03-data-centre-link-outage.md +++ b/docs/postmortems/2026-10-03-data-centre-link-outage.md @@ -38,7 +38,7 @@ Open actions: | Action | Owner | Due | Status | |---|---|---|---| -| Address the lack of an alert when the data centre is unreachable, including when the uplink watcher has exited; notifications must reach people through a path that does not depend solely on the failed link. On 2026-10-26, after the due date passed, Ingrid reassigned this from Yuki Tanaka to Ben Carter; Yuki remains responsible for making the uplink watcher report that it is alive. Link the implementation here when it exists; until then this stays open. | Ben Carter with Noah Williams | 2026-10-29 | Open (overdue since 2026-10-23) | +| Address the lack of an alert when the data centre is unreachable, including when the uplink watcher has exited; notifications must reach people through a path that does not depend solely on the failed link. On 2026-10-26, after the due date passed, Ingrid reassigned this from Yuki Tanaka to Ben Carter; Yuki remains responsible for making the uplink watcher report that it is alive. The mail alerts are implemented in [gate-hub/alert.c](../../gate-hub/alert.c) and described under [Operating it](../../README.md#operating-it); the [drill](../../lab/dc-alert.sh) and [test](../../tests/test_dc_alerts.py) cover them, and the [uplink watcher](../../lab/uplink-watch.sh) supplies the heartbeat. | Ben Carter with Noah Williams | 2026-10-29 | Done (2026-10-29) | | Ask the 4G operator for a path to the data centre without AS 64496, or find another operator; review before the next season's contract renewal. Yuki supplies the looking-glass results; consult Wang because the data centre also connects to 64496. | Grace Kim | 2026-11-30 | Open | | Resolve the gap between ICMP and the hub's `dc_probe`: ICMP can answer while the API is down and nothing switches. | Ben Carter | Not scheduled | Open | diff --git a/docs/postmortems/2026-10-03-data-centre-link-outage.zh-CN.md b/docs/postmortems/2026-10-03-data-centre-link-outage.zh-CN.md index 56f07f2..83411f2 100644 --- a/docs/postmortems/2026-10-03-data-centre-link-outage.zh-CN.md +++ b/docs/postmortems/2026-10-03-data-centre-link-outage.zh-CN.md @@ -38,7 +38,7 @@ | 行动 | 负责人 | 期限 | 状态 | |---|---|---|---| -| 补上数据中心不可达时的告警,也要覆盖上行监视脚本已经退出的情况;通知必须通过不只依赖故障链路的路径送达相关人员。2026-10-26,期限已过,Ingrid 将此项从 Yuki Tanaka 转交给 Ben Carter;Yuki 仍负责让上行监视脚本上报自身存活状态。后续实现后从这里链接过去;在那之前始终保留为未完成项。 | Ben Carter,与 Noah Williams 合作 | 2026-10-29 | 未完成(自 2026-10-23 起逾期) | +| 补上数据中心不可达时的告警,也要覆盖上行监视脚本已经退出的情况;通知必须通过不只依赖故障链路的路径送达相关人员。2026-10-26,期限已过,Ingrid 将此项从 Yuki Tanaka 转交给 Ben Carter;Yuki 仍负责让上行监视脚本上报自身存活状态。邮件告警实现在 [gate-hub/alert.c](../../gate-hub/alert.c),说明见 README 的[运行与排查](../../README.zh-CN.md#运行与排查);[演练](../../lab/dc-alert.sh)和[测试](../../tests/test_dc_alerts.py)覆盖这两类告警,[上行监视脚本](../../lab/uplink-watch.sh)提供心跳。 | Ben Carter,与 Noah Williams 合作 | 2026-10-29 | 已完成(2026-10-29) | | 向 4G 运营商询问不经 AS 64496 到数据中心的路径,或另找运营商;在下一季合同续签前复查。Yuki 提供 looking glass 结果;咨询 Wang,因为数据中心也接在 64496 上。 | Grace Kim | 2026-11-30 | 未完成 | | 解决 ICMP 与 hub 的 `dc_probe` 互不相连的问题:ICMP 能回答、API 已坏时不会切换。 | Ben Carter | 尚未排期 | 未完成 | diff --git a/docs/postmortems/2026-10-24-north-entrance-ticket-list.md b/docs/postmortems/2026-10-24-north-entrance-ticket-list.md new file mode 100644 index 0000000..f37d5df --- /dev/null +++ b/docs/postmortems/2026-10-24-north-entrance-ticket-list.md @@ -0,0 +1,47 @@ +English | [简体中文](2026-10-24-north-entrance-ticket-list.zh-CN.md) + +# 2026-10-24 north entrance ticket list incident: blameless post-mortem + +- Date: 2026-10-30 +- Participants: Ingrid Larsen (technical lead), Yuki Tanaka (network), Aisha Rahman (security), Noah Williams (drills), Mateo Rossi (gates), Ben Carter (hub), Wang Hao (data centre), Grace Kim (event operations), Fatima Zahra (venue) + +## Summary and impact + +Before doors opened on Saturday, October 24, the hub was given that day's ticket list and restarted as usual. The north entrance was an event-specific segment behind a link with MTU 1400. Its firewall dropped ICMP destination-unreachable messages, including “fragmentation needed”. The north gates, north1 and north2, stayed online and scanned, but answered `not_in_list` for tickets sold that day; other entrances admitted those tickets. Fatima directed the affected ticket holders to the east entrance and kept the gate logs. Nobody was alerted. + +The north gates could connect to the hub, but could not receive the new list body across that link. The measurements below come from lab reproductions after the event; they are not measurements of how long ticket holders waited at the venue or how many were affected. + +## Timeline + +- 2026-10-24, Saturday before doors-open: The hub received the day's list and restarted. The north gates, north1 and north2, remained online but rejected newly sold tickets as `not_in_list`. Other entrances admitted them. Fatima sent the affected ticket holders east and retained the gate logs; no alert reached anyone. +- 2026-10-26, Monday: Ingrid moved the overdue data-centre alert action from the October 3 review to Ben Carter with Noah Williams, due October 29. Yuki added the north entrance segment to the lab with the entrance firewall as configured on site. Noah reproduced the failure with `lab/north-entrance.sh`: at MTU 1400, it printed `result: north1 new list FAIL (not installed within 90 s; gate1 installed it)` and `result: north1 new ticket FAIL (GP-900000000003 not_in_list)`. At MTU 1200, the handshake failed too, and the drill also printed `result: north1 hub link FAIL (offline during old-ticket scan)`. +- 2026-10-27, Tuesday: Yuki, reviewed by Aisha, changed `lab/compose.yaml` so the router returned “fragmentation needed” to the hub. The unchanged drill then printed `result: north1 ok` at both MTUs. Mateo made failed gate downloads report their phase and progress in `tests/test_ticket_fetch_progress.py`; behind the lab black hole, north1 logged `event=ticket_fetch state=failed http=200 curl=28 reason=timeout phase=body received=0 expected=17706`. Ben showed with `tests/test_ticket_reply_count.py` that an aborted ticket reply was counted as 200. +- 2026-10-28, Wednesday: The hub began counting only completed ticket replies as 200 and the rest as `status="incomplete"`. Mateo and Ben added each gate's installed list version to its heartbeat and a hub comparison with the current list (`tests/test_gate_list_version.py`). Wang and Yuki added Prometheus and Grafana to the venue lab (`lab/monitoring.yaml`). Ben removed an unidentified “unknown” row from gate list status. +- 2026-10-29, Thursday: Noah's `lab/dc-alert.sh` showed that nobody was told when the data centre was unreachable or the uplink watcher stopped. Ben added mail alerts for both, with Yuki supplying the watcher heartbeat. Wang made the data centre publish the signed season list as text; in the lab it held 20000 tickets and was 3,488,890 bytes. +- 2026-10-30, Friday: Noah's `tests/test_hub_season_reload.py`, `tests/test_hub_served_list.py`, and `tests/test_hub_tickets_send_change.py` exposed four failures in the hub as it had run that week: `result: season-only ticket still rejected 10 s after a successful sync (successes=1)`, `result: /tickets served the changed file while the hub decides with the list it loaded`, `result: grown file: sent 1048576 bytes beyond Content-Length 21473706`, and `result: shrunk file: sent 10736690 of 21473706 body bytes and counted the reply as 200`. Ben made the hub decide with and serve one immutable copy of the verified season list. Noah changed drills to deliver list changes through the data centre. His `lab/status-stall-blackhole.sh` then showed a lost north-gate download holding the hub's TLS status port 8444, which then served one connection at a time; a client that stopped reading held it in the same way on a healthy network. Ben changed 8444 to four workers with a queue of 16. The review met that afternoon. + +## Cause and detection + +Each gate scan and link check opens a TLS connection. The hub's first handshake flight is 1,250 bytes of TLS records (`lab/captures/socket-exchange/tls-connection.txt`) sent as one 1,302-byte IP packet (`lab/captures/socket-exchange/tls-connection.pcap`); its size depends on the certificate chain. That packet fits under MTU 1400, so the gates could appear online and scan. The list body left the hub in 1500-byte packets, which the north link dropped. With “fragmentation needed” filtered by the entrance firewall, the router never told the hub to send smaller packets. The MTU 1200 lab result also lost the handshake, which explains why that reproduction looked like an offline gate rather than a stale list. + +The gate logs were the venue evidence; no alert reported the stale list. Before the hub changes on Friday, `/tickets` served the file as it stood on disk while admission decisions used the list loaded at startup. The fetched list and the hub's decision list could therefore differ. That mismatch was a separate finding, not the cause of the north link's packet loss. The lab's incomplete-reply metric and gate list-version status now make stalled delivery and stale installations visible; the data-centre and watcher mail alerts close the overdue alert action from the earlier review. + +## Recovery measurements and actions + +The router change let the unchanged north entrance drill pass at both MTUs. These are lab results, not a measured venue recovery time. The gate's `phase=body received=0 expected=17706` line distinguished a completed HTTP response header followed by no list body from a failed handshake. Counting aborted replies as `status="incomplete"` and comparing reported installed versions with the current list gave the hub a way to show incomplete delivery and stale gates. The verified season list now supplies both admission decisions and `/tickets` from the same immutable copy, avoiding the separate file-change failures exposed on Friday. + +With the 3,488,890-byte season list and the black hole restored in `lab/status-stall-blackhole.sh`, a north gate's lost download held the hub's TLS status port 8444, which then served one connection at a time, for about 6.1 s once per 20 s fetch cycle (`held_ms` 6126 to 6161). A venue gate's `/status` request waited as long; its list fetch timed out after 300 ms. After a new list, venue gates installed it in 18, 38 or 58 s, or took more than 60 s. The roughly 6 s were three 2 s steps: the hub restarted its send deadline before each write, two writes still sent part of their data, and the third sent nothing. A client that stopped reading could hold the port the same way even on a healthy network. + +With four workers and a queue of 16 on 8444, the same lab drill's longest `/status` wait was 0.05 s. Each north gate still held one worker for about 6.1 s, but both venue gates installed the new list 18 s after the hub. This limits how a stalled transfer affects other gates; it does not make that transfer complete. + +Open actions: + +| Action | Owner | Due | Status | +|---|---|---|---| +| Record in ADR 0020 the gate's synchronous list download inside its scan loop and its 300 ms limit. A 3,488,890-byte body needs at least about 93 Mbit/s to arrive within that limit (3,488,890 × 8 / 0.3 s), more with the TLS handshake; a slower link can only keep the old list through 304 replies. Moving the download out of the scan loop remains unscheduled under Mateo Rossi. | Ingrid Larsen and Yuki Tanaka | 2026-10-30 | Open | +| Review port 8081, which is still served by one thread and is for staff only. | Ben Carter | Not scheduled | Open | +| Add jitter to gates' aligned 20 s fetch cycles so they do not all ask together. | Mateo Rossi | Not scheduled | Open | + +## What we learned + +An online gate and a successful scan connection did not show that a larger ticket list could cross the same path. The firewall's ICMP rule prevented the hub from learning the north link's MTU, while the small handshake concealed the difference. Gate list versions, incomplete-reply accounting and the download-progress log make that gap observable. The later season-list and stalled-client tests also showed that list consistency and a shared status listener matter to admission at other entrances. The lab changes reduce those effects, while the scan-loop download limit, staff port and synchronized fetch cycles remain open. diff --git a/docs/postmortems/2026-10-24-north-entrance-ticket-list.zh-CN.md b/docs/postmortems/2026-10-24-north-entrance-ticket-list.zh-CN.md new file mode 100644 index 0000000..fd32498 --- /dev/null +++ b/docs/postmortems/2026-10-24-north-entrance-ticket-list.zh-CN.md @@ -0,0 +1,47 @@ +[English](2026-10-24-north-entrance-ticket-list.md) | 简体中文 + +# 2026-10-24 北入口票单事件:无责复盘 + +- 日期:2026-10-30 +- 参与:Ingrid Larsen(技术负责人)、Yuki Tanaka(网络)、Aisha Rahman(安全)、Noah Williams(演练)、Mateo Rossi(闸机)、Ben Carter(hub)、Wang Hao(数据中心)、Grace Kim(活动运营)、Fatima Zahra(场馆) + +## 摘要与影响 + +10 月 24 日周六开门前,hub 像往常一样取得当天的票单并重启。北入口是为这场活动设置的独立网段,所经链路的 MTU 为 1400;入口防火墙丢弃 ICMP“目的不可达”消息,其中包括“需要分片”。north1 和 north2 一直在线,也能扫码,却对当天售出的票回答 `not_in_list`;其他入口可以放行这些票。Fatima 引导持票人改走东入口,并保留闸机日志。没有人收到告警。 + +北入口闸机能连上 hub,却收不到穿过这段链路的新票单正文。下文的数字来自事后的实验室复现,不代表持票人在现场等了多久,也不代表受影响人数。 + +## 时间线 + +- 2026-10-24 周六开门前:hub 取得当天票单并重启。north1 和 north2 保持在线,但把新售出的票判为 `not_in_list`;其他入口正常放行。Fatima 让受影响的持票人改走东入口,留下闸机日志;无人收到告警。 +- 2026-10-26 周一:Ingrid 把 10 月 3 日复盘中已经逾期的数据中心告警事项转交 Ben Carter,与 Noah Williams 合作,期限为 10 月 29 日。Yuki 按现场配置把北入口网段和防火墙加入实验室。Noah 用 `lab/north-entrance.sh` 复现:MTU 1400 时输出 `result: north1 new list FAIL (not installed within 90 s; gate1 installed it)` 和 `result: north1 new ticket FAIL (GP-900000000003 not_in_list)`;MTU 1200 时握手也失败,还输出 `result: north1 hub link FAIL (offline during old-ticket scan)`。 +- 2026-10-27 周二:Yuki 修改 `lab/compose.yaml`,让路由器向 hub 返回“需要分片”,Aisha 完成复核。原样重跑演练,两个 MTU 下都输出 `result: north1 ok`。Mateo 在 `tests/test_ticket_fetch_progress.py` 中让下载失败日志说明进度;实验室黑洞后的 north1 记录 `event=ticket_fetch state=failed http=200 curl=28 reason=timeout phase=body received=0 expected=17706`。Ben 用 `tests/test_ticket_reply_count.py` 证明,中途断开的票单回复仍被计为 200。 +- 2026-10-28 周三:hub 改为只把完整回复计为 200,其他计为 `status="incomplete"`。Mateo 和 Ben 让闸机在心跳中报告已安装的票单版本,hub 将其与当前版本比较(`tests/test_gate_list_version.py`)。Wang 和 Yuki 为场馆实验室加入 Prometheus、Grafana(`lab/monitoring.yaml`)。Ben 从闸机票单状态中去掉了未识别连接造成的“unknown”行。 +- 2026-10-29 周四:Noah 的 `lab/dc-alert.sh` 表明,数据中心不可达或上行监视脚本停止时都无人收到通知。Ben 为两种情况加入邮件告警,Yuki 补上监视脚本的心跳。Wang 让数据中心以文本形式发布签名的季票单;实验室票单含 20000 张票,大小为 3,488,890 字节。 +- 2026-10-30 周五:Noah 的 `tests/test_hub_season_reload.py`、`tests/test_hub_served_list.py` 和 `tests/test_hub_tickets_send_change.py` 暴露出 hub 本周运行版本的四个问题:`result: season-only ticket still rejected 10 s after a successful sync (successes=1)`、`result: /tickets served the changed file while the hub decides with the list it loaded`、`result: grown file: sent 1048576 bytes beyond Content-Length 21473706`、`result: shrunk file: sent 10736690 of 21473706 body bytes and counted the reply as 200`。Ben 让 hub 用同一份不可变的、已验证季票单作判断和对外提供票单。Noah 改为通过数据中心更新演练票单。随后,`lab/status-stall-blackhole.sh` 显示,北入口闸机丢失的下载会占住 hub 当时一次只服务一条连接的 TLS 状态端口 8444;即使网络正常,停止读取的客户端也能造成同样情况。Ben 将 8444 改为四个工作线程和容量为 16 的队列。当天下午,团队召开复盘会。 + +## 原因与发现 + +闸机每次扫码和链路检查都会新建 TLS 连接。hub 首轮握手发出 1,250 字节 TLS 记录(`lab/captures/socket-exchange/tls-connection.txt`),组成一个 1,302 字节 IP 包(`lab/captures/socket-exchange/tls-connection.pcap`);大小取决于证书链。它小于 MTU 1400,所以闸机可以保持在线并扫码。票单正文却装在 1500 字节的包里发出,被北入口链路丢弃。入口防火墙过滤了“需要分片”,路由器便无法通知 hub 改发较小的包。实验室把 MTU 降到 1200 后,连握手也过不去,因此那次复现呈现为闸机离线,而不是只缺新票单。 + +现场留下的证据是闸机日志;旧票单没有触发告警。周五修复 hub 之前,`/tickets` 提供的是磁盘上当时的文件,而放行判断仍使用启动时加载的票单。闸机取到的票单可能与 hub 判断用的票单不同。这是另一个发现,并非北入口丢包的原因。实验室现在能通过未完成回复的指标和闸机票单版本状态看见下载中断、安装过期;数据中心与监视脚本的邮件告警也结清了上次复盘的逾期事项。 + +## 恢复测量与行动 + +路由器改动后,北入口原样演练在两种 MTU 下均通过。这些是实验室结果,没有测出现场恢复用了多久。闸机的 `phase=body received=0 expected=17706` 日志说明 HTTP 响应头已经到达,票单正文却一个字节也没收到,可与握手失败区分。hub 现在把中断回复计为 `status="incomplete"`,并比较闸机报告的已安装版本与当前版本,能显示交付未完成或闸机仍在使用旧票单。已验证季票单的同一份不可变副本同时用于放行判断和 `/tickets`,也消除了周五测试暴露的文件变化问题。 + +在 `lab/status-stall-blackhole.sh` 中恢复黑洞,并使用 3,488,890 字节的季票单后,一台北入口闸机丢失的下载每隔 20 s 就占住 hub 当时一次只服务一条连接的 TLS 状态端口 8444 约 6.1 s(`held_ms` 为 6126 至 6161)。场馆闸机的 `/status` 请求要等同样久,票单下载在 300 ms 后超时。hub 换上新票单后,场馆闸机分别用了 18、38、58 s,或超过 60 s 才安装。约 6 s 是三步,每步最多等 2 s:hub 每次写入前都会重新设定发送期限,前两次只写出了一部分,第三次一个字节也没写出去。即使网络健康,客户端停止读取也能这样占住端口。 + +8444 改为四个工作线程、容量为 16 的队列后,同一实验室演练中,`/status` 最长等待 0.05 s。每台北入口闸机仍各占一个工作线程约 6.1 s,但两台场馆闸机都在 hub 更新后 18 s 安装了新票单。这个改动让卡住的下载不再拖累其他闸机,但那次下载本身仍然完不成。 + +未完成事项: + +| 行动 | 负责人 | 期限 | 状态 | +|---|---|---|---| +| 在 ADR 0020 中记录闸机仍在扫码循环里同步下载票单,期限为 300 ms。3,488,890 字节的正文若要在限时内收完,链路至少约需 93 Mbit/s(3,488,890 × 8 / 0.3 s),加上 TLS 握手还需更快;较慢的链路只能靠 304 回复维持旧票单。将下载移出扫码循环由 Mateo Rossi 负责,目前未排期。 | Ingrid Larsen 和 Yuki Tanaka | 2026-10-30 | 未完成 | +| 复查仍由单线程服务的 8081 端口;该端口只供工作人员使用。 | Ben Carter | 尚未排期 | 未完成 | +| 为闸机对齐的 20 s 取票周期加入抖动,避免同时请求。 | Mateo Rossi | 尚未排期 | 未完成 | + +## 学到的事 + +闸机在线、扫码连接成功,不能证明更大的票单也能穿过同一条路径。防火墙的 ICMP 规则让 hub 无从得知北入口链路的 MTU,而较小的握手包掩盖了差异。闸机票单版本、未完成回复计数和下载进度日志让这类问题有了可见证据。随后对季票单和停止读取的客户端的测试还表明,票单一致性和共用状态端口也会影响其他入口的放行。实验室改动降低了这些影响;扫码循环内下载的限时、工作人员端口和同步取票周期仍需处理。 diff --git a/lab/README.md b/lab/README.md index 7bc87d7..ece0487 100644 --- a/lab/README.md +++ b/lab/README.md @@ -39,7 +39,7 @@ With the lab running, `sh lab/device-tls.sh` first checks that the SHA-256 of th With the lab running, `sh lab/tls/record.sh` writes small text records to `lab/captures/device-tls/`: each device chain's verification result, gate1's TLS 1.3 HELLO and CONFIG replies on 7000, its authenticated ticket-list status and byte count on 8444, the hub's 200 and conditional 304 with ETag from the data-centre stub on 8443, and the hub's `dc_sync` and `dc_link` lines without `time=`. The script fails if an expected reply is missing and does not print keys, barcodes or ticket IDs. -Run `sh lab/status-stall.sh` to stall gate2’s ticket download over TLS on port 8444. By default it uses the data centre’s 20000-ticket season list; set `STALL_EXTRA` to sign and publish that many additional tickets before the stall. It prints the served ticket count and byte size, asks `/status` every five seconds on hub port 8081 and gate1 port 8444 with its certificate, and reports the hub send queue and relevant logs. `WATCH` sets the observation time. Cleanup restores the previous data-centre extra file, waits for the hub and checked gates to install the restored list, and removes the network rules. +Run `sh lab/status-stall.sh` to stall gate2’s ticket download over TLS on port 8444. By default it uses the data centre’s 20000-ticket season list; set `STALL_EXTRA` to sign and publish that many additional tickets before the stall. With the default `STALL_EXTRA=0`, the season list alone (about 3.5 MB) already holds the hub’s sender in this lab; raise `STALL_EXTRA` only if a faster machine sends the whole list before the stall appears and the drill no longer reports a hold. It prints the served ticket count and byte size, asks `/status` every five seconds on hub port 8081 and gate1 port 8444 with its certificate, and reports the hub send queue and relevant logs. `WATCH` sets the observation time. Cleanup restores the previous data-centre extra file, waits for the hub and checked gates to install the restored list, and removes the network rules. Run `sh lab/status-stall-blackhole.sh` with all four gates running to remove the router's ICMP fragmentation-needed ACCEPT rule, set the north interface MTU to 1400, and publish three signed tickets through the data centre. For 60 seconds it probes 8444 `/status` from gate1, reports waits over one second, hub and venue-gate logs, whether both venue gates installed the new list, and the hub's 8081 `/status` time. A wait over one second prints the held-listener result and exits 1; otherwise it exits 0, while an environment mismatch or failed cleanup exits 2. Cleanup stops the probe, restores the MTU and exact OUTPUT chain, restores the extra ticket file, restarts the hub to clear learned path MTU, and waits for all four gates to reinstall the original list. On a healthy network, a client that stops reading similarly holds one of the four 8444 workers. diff --git a/lab/README.zh-CN.md b/lab/README.zh-CN.md index 39d5cc4..1b91458 100644 --- a/lab/README.zh-CN.md +++ b/lab/README.zh-CN.md @@ -39,7 +39,7 @@ after connection duration ms: 3.6 实验环境启动后,运行 `sh lab/tls/record.sh`,将简短文本记录写入 `lab/captures/device-tls/`:各设备证书链的验证结果、gate1 在 7000 上通过 TLS 1.3 收到的 HELLO 和 CONFIG 回复、在 8444 上持证获取票单的 HTTP 状态及字节数、hub 在 8443 上从数据中心替身取得的 200 与带 ETag 条件请求的 304,以及去掉 `time=` 的 hub `dc_sync` 和 `dc_link` 日志。缺少预期回复时脚本失败;输出不含密钥、条码或票号。 -运行 `sh lab/status-stall.sh`,让 gate2 在 8444 端口通过 TLS 下载票单时停住。默认使用数据中心原有的 20000 张票;设置 `STALL_EXTRA` 后,脚本会自行签署指定数量的新票,经数据中心发布,再制造停滞。脚本先打印 hub 实际提供的票数和字节数,然后每五秒分别由 hub 查询 8081 的 `/status`、由 gate1 持证书查询 8444 的 `/status`,最后报告 hub 的发送队列及相关日志。`WATCH` 设置观察时长。收尾恢复数据中心额外票文件的原内容,等待 hub 和所检查的闸机装回原票单,并撤销网络规则。 +运行 `sh lab/status-stall.sh`,让 gate2 在 8444 端口通过 TLS 下载票单时停住。默认使用数据中心原有的 20000 张票;设置 `STALL_EXTRA` 后,脚本会自行签署指定数量的新票,经数据中心发布,再制造停滞。默认 `STALL_EXTRA=0` 时,单靠约 3.5 MB 的季票单就足以在本实验中占住 hub 的发送端;只有在更快的机器上整份票单已发完、停滞尚未出现,导致演练不再报告发送端被占住时,才调高 `STALL_EXTRA`。脚本先打印 hub 实际提供的票数和字节数,然后每五秒分别由 hub 查询 8081 的 `/status`、由 gate1 持证书查询 8444 的 `/status`,最后报告 hub 的发送队列及相关日志。`WATCH` 设置观察时长。收尾恢复数据中心额外票文件的原内容,等待 hub 和所检查的闸机装回原票单,并撤销网络规则。 四台闸机都运行时,执行 `sh lab/status-stall-blackhole.sh`。脚本移除路由器允许发送“需要分片”ICMP 的规则,将北侧接口 MTU 设为 1400,再通过数据中心发布三张新签名票;随后由 gate1 连续 60 秒探测 8444 的 `/status`,列出超过一秒的等待、hub 与场馆闸机日志、两台场馆闸机是否装上新票单,以及 hub 的 8081 `/status` 用时。只要有一次等待超过一秒,就报告 8444 被占住并以 1 退出;全部在一秒内应答则以 0 退出,环境不符或收尾失败以 2 退出。收尾停止探测,恢复 MTU 和原样的 OUTPUT 链,还原额外票文件,重启 hub 清除学到的路径 MTU,并等待四台闸机装回原票单。即使网络正常,下载时停止读取的客户端也会占住 8444 的四个工作线程之一。 diff --git a/lab/captures/device-tls/gate-protocol.txt b/lab/captures/device-tls/gate-protocol.txt index fdf24aa..0845005 100644 --- a/lab/captures/device-tls/gate-protocol.txt +++ b/lab/captures/device-tls/gate-protocol.txt @@ -1,3 +1,3 @@ HELLO=OK -scans=0 tickets=100 +scans=0 tickets=20000 HELLO=REFUSED chain=leaf_only reason=unknown_ca diff --git a/lab/captures/device-tls/gate-status.txt b/lab/captures/device-tls/gate-status.txt index 7cb40db..f26a567 100644 --- a/lab/captures/device-tls/gate-status.txt +++ b/lab/captures/device-tls/gate-status.txt @@ -1 +1 @@ -status=200 bytes=17190 +status=200 bytes=3488890 diff --git a/lab/captures/north-entrance/session.txt b/lab/captures/north-entrance/session.txt new file mode 100644 index 0000000..e645e6d --- /dev/null +++ b/lab/captures/north-entrance/session.txt @@ -0,0 +1,49 @@ +fault: router eth3 mtu=1400 +observation: router OUTPUT rules for ICMP +-A OUTPUT -p icmp -m icmp --icmp-type 3/4 -j ACCEPT +-A OUTPUT -p icmp -m icmp --icmp-type 3 -j DROP +precondition: the data centre publishes three new tickets before doors open +observation: /tickets counters after hub install +gatepost_http_requests_total{route="tickets",status="200"} 14 +gatepost_http_requests_total{route="tickets",status="206"} 2 +gatepost_http_requests_total{route="tickets",status="304"} 4 +gatepost_http_requests_total{route="tickets",status="400"} 0 +gatepost_http_requests_total{route="tickets",status="403"} 0 +gatepost_http_requests_total{route="tickets",status="404"} 0 +gatepost_http_requests_total{route="tickets",status="405"} 0 +gatepost_http_requests_total{route="tickets",status="416"} 0 +gatepost_http_requests_total{route="tickets",status="503"} 0 +gatepost_http_requests_total{route="tickets",status="500"} 0 +gatepost_http_requests_total{route="tickets",status="incomplete"} 0 +scan: north1 ticket=GP-900000000001 +scan: north1 ticket=GP-900000000001 result=REJECT reason=not_in_list +observation: at opening north1 scans GP-900000000001: REJECT not_in_list +scan: north1 ticket=GP-000000000000 +scan: north1 ticket=GP-000000000000 result=ACCEPT reason= +north1 hub_link: online +scan: gate1 ticket=GP-900000000002 +scan: gate1 ticket=GP-900000000002 result=ACCEPT reason= +scan: north1 ticket=GP-900000000003 +scan: north1 ticket=GP-900000000003 result=ACCEPT reason= +observation: north1 post-fault ticket_fetch lines (time removed) +observation: /tickets counters at end +gatepost_http_requests_total{route="tickets",status="200"} 18 +gatepost_http_requests_total{route="tickets",status="206"} 2 +gatepost_http_requests_total{route="tickets",status="304"} 4 +gatepost_http_requests_total{route="tickets",status="400"} 0 +gatepost_http_requests_total{route="tickets",status="403"} 0 +gatepost_http_requests_total{route="tickets",status="404"} 0 +gatepost_http_requests_total{route="tickets",status="405"} 0 +gatepost_http_requests_total{route="tickets",status="416"} 0 +gatepost_http_requests_total{route="tickets",status="503"} 0 +gatepost_http_requests_total{route="tickets",status="500"} 0 +gatepost_http_requests_total{route="tickets",status="incomplete"} 0 +result: north1 ok +cleanup: router mtu 1500 ok +cleanup: router firewall unchanged ok +cleanup: data centre extra tickets restored ok +cleanup: gate1 online with original list ok +cleanup: gate2 online with original list ok +cleanup: north1 online with original list ok +cleanup: north2 online with original list ok +cleanup: hub route cache ok diff --git a/lab/captures/offline-reports/session.txt b/lab/captures/offline-reports/session.txt index c783ab6..52a51b7 100644 --- a/lab/captures/offline-reports/session.txt +++ b/lab/captures/offline-reports/session.txt @@ -1,5 +1,6 @@ Linux 6.8.0-151-generic aarch64 ACCEPT ACCEPT +ACCEPT {"status":"ok","legacy_connections":0,"offline_duplicates":1} 2 /var/lib/gatepost/reports.log diff --git a/lab/compose.yaml b/lab/compose.yaml index caaf1f2..b99f558 100644 --- a/lab/compose.yaml +++ b/lab/compose.yaml @@ -285,7 +285,7 @@ services: networks: venue: {ipv4_address: 10.77.20.53} mail: - image: axllent/mailpit:v1.27.7 + image: axllent/mailpit:v1.27.7@sha256:cae83a33cd9b9598e4acb210be673dda7e741d5271ed4045310ab456950a136a environment: MP_SMTP_BIND_ADDR: 0.0.0.0:587 MP_SMTP_TLS_CERT: /tls/test-cert.pem diff --git a/lab/monitoring-check.sh b/lab/monitoring-check.sh index 73e85f2..8d38c89 100644 --- a/lab/monitoring-check.sh +++ b/lab/monitoring-check.sh @@ -46,6 +46,17 @@ running=$(docker compose -f lab/compose.yaml ps --status running --services 2>/d for service in hub gate1 gate2; do printf '%s\n' "$running" | grep -qx "$service" || mismatch "venue $service is not running" done +# Wait for all monitored gates to install their ticket lists. +for attempt in $(seq 1 90); do + ready=1 + for gate in gate1 gate2 north1 north2; do + docker compose -f lab/compose.yaml exec -T "$gate" test -f /var/lib/gatepost/tickets.txt.etag 2>/dev/null || ready=0 + done + [ "$ready" -eq 0 ] || break + sleep 1 +done +[ "$ready" -eq 1 ] || fail 'a monitored gate has not installed its ticket list' + if [ -z "${GATEPOST_GRAFANA_ADMIN_PASSWORD:-}" ]; then GATEPOST_GRAFANA_ADMIN_PASSWORD=$(openssl rand -hex 24) || mismatch 'cannot generate password' printf '%s\n' 'Generated a temporary Grafana administrator password for this check.' diff --git a/lab/two-gate-scan.sh b/lab/two-gate-scan.sh index c0c08d2..27a4310 100755 --- a/lab/two-gate-scan.sh +++ b/lab/two-gate-scan.sh @@ -7,6 +7,7 @@ ticket=$(sed -n '11p' lab/keys/generated/tickets.txt) next_ticket=$(sed -n '12p' lab/keys/generated/tickets.txt) test -n "$ticket" && test -n "$next_ticket" trap '$compose down -v; rm -rf lab/runtime' EXIT +rm -rf lab/runtime $compose up -d --build waited=0 until [ "$($compose exec -T gate1 readlink /proc/1/exe)" = /src/build/debug/gated ] && diff --git a/packaging/gate-control/conffiles b/packaging/gate-control/conffiles new file mode 100644 index 0000000..599925c --- /dev/null +++ b/packaging/gate-control/conffiles @@ -0,0 +1 @@ +/etc/gatepost/gated.env diff --git a/packaging/gate-hub.service b/packaging/gate-hub.service new file mode 100644 index 0000000..05d456f --- /dev/null +++ b/packaging/gate-hub.service @@ -0,0 +1,30 @@ +[Unit] +Description=Gatepost venue hub +After=network-online.target +Wants=network-online.target + +[Service] +Type=simple +User=gatepost +Group=gatepost +EnvironmentFile=/etc/gatepost/gate-hub.env +ExecStart=/usr/lib/gatepost/run-gate-hub +Restart=on-failure +RestartSec=2 +StateDirectory=gatepost +NoNewPrivileges=yes +ProtectSystem=strict +ProtectHome=yes +PrivateTmp=yes +ProtectKernelTunables=yes +ProtectKernelModules=yes +ProtectControlGroups=yes +ReadWritePaths=/var/lib/gatepost +LoadCredential=ca.pem:/etc/gatepost/credentials/ca.pem +LoadCredential=server-chain.crt:/etc/gatepost/credentials/server-chain.crt +LoadCredential=server.key:/etc/gatepost/credentials/server.key +LoadCredential=mail-ca.pem:/etc/gatepost/credentials/mail-ca.pem +LoadCredential=smtp-password:/etc/gatepost/credentials/smtp-password + +[Install] +WantedBy=multi-user.target diff --git a/packaging/gated.service b/packaging/gated.service new file mode 100644 index 0000000..17085ad --- /dev/null +++ b/packaging/gated.service @@ -0,0 +1,31 @@ +[Unit] +Description=Gatepost gate device +After=network-online.target +Wants=network-online.target + +[Service] +Type=notify +User=gatepost +Group=gatepost +EnvironmentFile=/etc/gatepost/gated.env +ExecStart=/usr/lib/gatepost/run-gated +Restart=on-failure +RestartSec=2 +WatchdogSec=10 +StateDirectory=gatepost +AmbientCapabilities=CAP_NET_RAW +CapabilityBoundingSet=CAP_NET_RAW +NoNewPrivileges=yes +ProtectSystem=strict +ProtectHome=yes +PrivateTmp=yes +ProtectKernelTunables=yes +ProtectKernelModules=yes +ProtectControlGroups=yes +ReadWritePaths=/var/lib/gatepost +LoadCredential=ca.pem:/etc/gatepost/credentials/ca.pem +LoadCredential=client-chain.crt:/etc/gatepost/credentials/client-chain.crt +LoadCredential=client.key:/etc/gatepost/credentials/client.key + +[Install] +WantedBy=multi-user.target diff --git a/packaging/hub-control/conffiles b/packaging/hub-control/conffiles new file mode 100644 index 0000000..722fb35 --- /dev/null +++ b/packaging/hub-control/conffiles @@ -0,0 +1,2 @@ +/etc/gatepost/gate-hub.env +/etc/gatepost/hub.conf diff --git a/packaging/postinst b/packaging/postinst new file mode 100755 index 0000000..fc57b40 --- /dev/null +++ b/packaging/postinst @@ -0,0 +1,16 @@ +#!/bin/sh +set -e +if ! getent group gatepost >/dev/null; then + addgroup --system gatepost +fi +install -d -m 0750 /var/lib/gatepost +if ! id gatepost >/dev/null 2>&1; then + adduser --system --ingroup gatepost --home /var/lib/gatepost --no-create-home --shell /usr/sbin/nologin gatepost +fi +install -d -o gatepost -g gatepost -m 0750 /var/lib/gatepost +install -d -o root -g root -m 0700 /etc/gatepost/credentials +install -d -o root -g gatepost -m 0750 /etc/gatepost/mac-keys +if command -v systemctl >/dev/null 2>&1; then + systemctl daemon-reload >/dev/null 2>&1 || : +fi +exit 0 diff --git a/packaging/run-gate-hub.sh b/packaging/run-gate-hub.sh new file mode 100755 index 0000000..8fd9338 --- /dev/null +++ b/packaging/run-gate-hub.sh @@ -0,0 +1,10 @@ +#!/bin/sh +set -eu +: "${CREDENTIALS_DIRECTORY:?systemd credentials are required}" +export GATEPOST_TLS_CA="$CREDENTIALS_DIRECTORY/ca.pem" +export GATEPOST_TLS_CERT="$CREDENTIALS_DIRECTORY/server-chain.crt" +export GATEPOST_TLS_KEY="$CREDENTIALS_DIRECTORY/server.key" +export GATEPOST_MAC_KEY_DIR="/etc/gatepost/mac-keys" +exec /usr/bin/gate-hub \ + "${GATEPOST_TICKETS:-/var/lib/gatepost/tickets.txt}" \ + "${GATEPOST_LISTEN_PORT:-7000}" pool diff --git a/packaging/run-gated.sh b/packaging/run-gated.sh new file mode 100755 index 0000000..c3c5cda --- /dev/null +++ b/packaging/run-gated.sh @@ -0,0 +1,14 @@ +#!/bin/sh +set -eu +: "${CREDENTIALS_DIRECTORY:?systemd credentials are required}" +export GATEPOST_TLS_CA="$CREDENTIALS_DIRECTORY/ca.pem" +export GATEPOST_TLS_CERT="$CREDENTIALS_DIRECTORY/client-chain.crt" +export GATEPOST_TLS_KEY="$CREDENTIALS_DIRECTORY/client.key" +export GATEPOST_MAC_KEY_DIR="/etc/gatepost/mac-keys" +exec /usr/bin/gated \ + --scanner "${GATEPOST_SCANNER:-tty:/dev/ttyACM0}" \ + --outputs "${GATEPOST_OUTPUTS:-gpio:/dev/gpiochip0}" \ + --gate-id "${GATEPOST_GATE_ID:-gate-1}" \ + --arp-interface "${GATEPOST_ARP_INTERFACE:-eth0}" \ + --hub "${GATEPOST_HUB:?hub address is required}" \ + "${GATEPOST_TICKETS:-/var/lib/gatepost/tickets.txt}"