Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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
32 changes: 30 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ endif()
find_package(Threads REQUIRED)
set(GATE_HUB_SOURCES gate-hub/main.c gate-hub/admission.c gate-hub/metrics.c
gate-hub/prometheus.c gate-hub/dc_probe.c gate-hub/alert.c gate-hub/sync.c
gate-hub/status.c gate-hub/reports.c gate-hub/tls.c)
gate-hub/status.c gate-hub/reports.c gate-hub/tls.c gate-hub/queue.c)
foreach(target gate-hub gate-hub-test)
add_executable(${target} ${GATE_HUB_SOURCES})
target_link_libraries(${target} PRIVATE gate gate_security gate_ticket_signature Threads::Threads)
Expand Down Expand Up @@ -283,5 +283,33 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
endif()
add_test(NAME status_deadline COMMAND ${Python3_EXECUTABLE}
${CMAKE_SOURCE_DIR}/tests/test_status_deadline.py $<TARGET_FILE:gate-hub-test> $<TARGET_FILE:gate-hub>)
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 sync_metrics hub_season_reload hub_served_list hub_tickets_send_change monitoring_config dc_alerts
add_test(NAME status_tls_workers COMMAND ${Python3_EXECUTABLE}
${CMAKE_SOURCE_DIR}/tests/test_status_tls_workers.py $<TARGET_FILE:gate-hub>)
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 <security@elsworne.example>")
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)
4 changes: 2 additions & 2 deletions Dockerfile.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ 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/20261020T000000Z' \
> /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/20261020T000000Z' \
>> /etc/apt/sources.list && \
apt-get -o Acquire::Check-Valid-Until=false update && apt-get install -y --no-install-recommends \
build-essential \
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,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
Expand Down Expand Up @@ -73,7 +75,7 @@ A gate can load a mapped `.gpb` list only without public keys; signed mode refus

## Operating it

Tickets in this repository are synthetic; generate them with `tools/gen_tickets.py`. On a device, choose the scanner and outputs at startup. Standard output carries decisions and standard error carries device errors and, for each rejected scan, one `event=scan` line with the reason (see [rejection diagnostics](docs/security/ticket-signing.md#rejection-diagnostics)). The hub writes one `event=scan` line to standard error for each scan, with `time` (Unix microseconds), `level`, `gate`, `ticket` (or `length` for malformed input), `result` and `decision_us` (elapsed microseconds). It also logs `event=connection_open` and `event=connection_close` with the peer address; the gate is `unknown` until a `SCAN` identifies it. On ports 7000 and 8444, handshake failures log `event=tls_handshake state=failed reason=<reason> peer=<address>` and `event=status_client state=handshake_failed reason=<reason> peer=<address>`, respectively; a 7000 handshake deadline logs `state=timeout peer=<address>`. The address comes from the accepted connection. The same peer and reason on a listener produce one line until the reason changes or a handshake succeeds. Each listener remembers 64 peers, forgetting the oldest seen when full. A status connection that runs out of time logs `event=status_client state=timeout` with the peer address and `held_ms`. `event=admission_unlock_failed state=after_decision` reports a failed ticket mutex unlock, and `event=operation_failed` reports a failed system operation. `gated` writes one `event=hub_link` line to standard error when its hub link becomes `online` or `offline`, or the offline reason changes; offline reasons are `refused`, `timeout`, `resolver`, or the TLS reasons below. The resolver logs `event=hub_resolver` only when DNS changes between `failed` and `resolved`. All daemon diagnostics use space-separated `key=value` fields, `time` as Unix microseconds, and `level` and `event` fields. It does not repeat the line for scans while both state and reason are unchanged. A local decision still appears on standard output and in the optional scan log. An optional scan log path records `barcode=... result=...` (in signed mode, `<field> result=...` under the rejection-diagnostic rule above) on a buffered, long-lived file descriptor. Use `scripts/scan-syscalls.sh` and `scripts/scan-latency.sh` in the build container to inspect system calls and latency; see the [measurements](docs/perf/scan-syscalls.md).
Tickets in this repository are synthetic; generate them with `tools/gen_tickets.py`. On a device, choose the scanner and outputs at startup. Standard output carries decisions and standard error carries device errors and, for each rejected scan, one `event=scan` line with the reason (see [rejection diagnostics](docs/security/ticket-signing.md#rejection-diagnostics)). The hub writes one `event=scan` line to standard error for each scan, with `time` (Unix microseconds), `level`, `gate`, `ticket` (or `length` for malformed input), `result` and `decision_us` (elapsed microseconds). It also logs `event=connection_open` and `event=connection_close` with the peer address; the gate is `unknown` until a `SCAN` identifies it. On ports 7000 and 8444, handshake failures log `event=tls_handshake state=failed reason=<reason> peer=<address>` and `event=status_client state=handshake_failed reason=<reason> peer=<address>`, respectively; a 7000 handshake deadline logs `state=timeout peer=<address>`. The address comes from the accepted connection. The same peer and reason on a listener produce one line until the reason changes or a handshake succeeds. Each listener remembers 64 peers, forgetting the oldest seen when full. A status connection that runs out of time logs `event=status_client state=timeout` with the peer address and `held_ms`. A full 8444 queue logs `event=status_queue state=full peer=<address>` at most once per second. `event=admission_unlock_failed state=after_decision` reports a failed ticket mutex unlock, and `event=operation_failed` reports a failed system operation. `gated` writes one `event=hub_link` line to standard error when its hub link becomes `online` or `offline`, or the offline reason changes; offline reasons are `refused`, `timeout`, `resolver`, or the TLS reasons below. The resolver logs `event=hub_resolver` only when DNS changes between `failed` and `resolved`. All daemon diagnostics use space-separated `key=value` fields, `time` as Unix microseconds, and `level` and `event` fields. It does not repeat the line for scans while both state and reason are unchanged. A local decision still appears on standard output and in the optional scan log. An optional scan log path records `barcode=... result=...` (in signed mode, `<field> result=...` under the rejection-diagnostic rule above) on a buffered, long-lived file descriptor. Use `scripts/scan-syscalls.sh` and `scripts/scan-latency.sh` in the build container to inspect system calls and latency; see the [measurements](docs/perf/scan-syscalls.md).

TLS failure reasons in the device link logs (see the [device-certificate renewal runbook](docs/runbooks/renew-device-certificate.md)):

Expand All @@ -97,7 +99,7 @@ Ticket work logs `event=ticket_sync` for build start, completion or failure and
The data-centre probe logs `event=dc_dns` when resolution becomes `resolved`, `stale`, `failed`, or `recovered`. A stale address is usable for at most 30 seconds; `reason=stale_expired` means the grace period ended, and `reason=never_resolved` that the name has not resolved since the hub started. `resolved` is the first successful lookup, `recovered` one after a failure. It logs `event=dc_link state=connected` or `state=failed` only when the connection state changes, and `state=connected address=... previous=...` when it stays connected but moves to another address; this TCP probe uses port 8443 with device TLS configured, or 8080 otherwise. `GATEPOST_DC_HOST` sets the host that both the probe and the sync connect to (default `api.elsworne.example`); the sync always checks the certificate as `api.elsworne.example`. A failed probe startup or socket close uses `event=operation_failed`.

Mail alerts also cover two hub faults: `Data centre unreachable` when probe rounds cannot connect, and `Uplink watcher stopped` when the configured heartbeat file stops changing. Each uses `alert_after_seconds`, sends once per incident after that threshold, sends no recovery mail, re-arms on recovery, and keeps the sent state across hub restarts. The watcher writes the file each loop; its modification time is the heartbeat because a shell has no portable monotonic clock and the watcher and hub share a wall clock in the same container. The hub grants a fresh threshold after restart. These alerts log `event=mail_alert alert=data_centre state=failed/sent` or `alert=uplink_watcher state=failed/sent`; gate alerts retain `event=mail_alert gate=... state=failed` once when submission fails and `state=sent` after submission and durable state update. Persistent alert-state file failures and their recovery use `event=mail_state state=failed` and `state=recovered`. Alert initialization failures use `event=operation_failed`.
In the test builds, without device TLS, the hub serves `/tickets`, `/status` and `/metrics` over HTTP on port 8081. When device TLS and `GATEPOST_STATUS` are configured, port 8081 serves `/status` and `/metrics` but answers `GET /tickets` with 404; port 8444 serves the list and the other routes over TLS 1.3 at the same bind address. Port 8444 requires a venue CA-signed gate certificate and accepts only `Host: hub.venue.lan` or `Host: hub.venue.lan:8444`. With device TLS configured, a gate fetches `https://hub.venue.lan:8444/tickets` on startup and periodically, connecting to the `--hub` host while verifying the hub certificate as `hub.venue.lan` and presenting its own certificate. In the test builds, without device TLS, it fetches over 8081: with `--hub 10.77.20.10:7000`, it asks for `http://10.77.20.10:8081/tickets` and sends `Host: 10.77.20.10:8081`. Set `GATEPOST_TICKETS_URL` to override the URL; production builds accept only `https://` and `file://` overrides, while the `http://` override warning appears only in test builds. The hub answers only Host values listed in `GATEPOST_STATUS_HOSTS` (default `hub.venue.lan`, `hub.venue.lan:8081`, `127.0.0.1:8081` and `localhost:8081`) and returns 400 to any other. For plaintext gates reaching the hub by address, add `<address>:8081` to `GATEPOST_STATUS_HOSTS`; the variable replaces the default list, so keep the names you still use. A gate logs `event=ticket_fetch state=failed http=<status> curl=<code> reason=<reason> phase=<phase> received=<bytes> expected=<bytes|unknown>` when fetching starts failing or the reason or phase changes. It suppresses repeats with the same reason and phase even if the byte counts differ, and logs `event=ticket_fetch state=recovered` once when it works again. The gate retains used-ticket state when installing a new list. With device TLS configured, the hub syncs the signed season list from `/season.txt` over port 8443 using its certificate; without device TLS it uses port 8080. Before switching decisions, it checks that SHA-256 matches the ETag, the complete list loads under the start-file rules, and the downloaded file and its directory were synced. `/tickets` and decisions use the same immutable in-memory list. A switch logs `event=season_list state=installed tickets=<n> used=<n> load_ms=<ms>`; a refused list logs `event=season_list state=rejected reason=digest` or `reason=load errno=<n>` once per ETag and reason. The hub keeps its current list after a refusal and tries again on the next round.
In the test builds, without device TLS, the hub serves `/tickets`, `/status` and `/metrics` over HTTP on port 8081. When device TLS and `GATEPOST_STATUS` are configured, port 8081 serves `/status` and `/metrics` but answers `GET /tickets` with 404; port 8444 serves the list and the other routes over TLS 1.3 at the same bind address. Port 8081 uses one thread for staff; port 8444 uses four workers and a queue of 16. The venue has four gates (gate1, gate2, north1, north2), each with at most one 8444 connection open at a time. A stuck gate holds one worker while the others can still be served; if the north link fails, its two gates hold at most two workers, leaving workers for both venue gates. Four stuck clients at once make others wait again. Port 8444 requires a venue CA-signed gate certificate and accepts only `Host: hub.venue.lan` or `Host: hub.venue.lan:8444`. With device TLS configured, a gate fetches `https://hub.venue.lan:8444/tickets` on startup and periodically, connecting to the `--hub` host while verifying the hub certificate as `hub.venue.lan` and presenting its own certificate. In the test builds, without device TLS, it fetches over 8081: with `--hub 10.77.20.10:7000`, it asks for `http://10.77.20.10:8081/tickets` and sends `Host: 10.77.20.10:8081`. Set `GATEPOST_TICKETS_URL` to override the URL; production builds accept only `https://` and `file://` overrides, while the `http://` override warning appears only in test builds. The hub answers only Host values listed in `GATEPOST_STATUS_HOSTS` (default `hub.venue.lan`, `hub.venue.lan:8081`, `127.0.0.1:8081` and `localhost:8081`) and returns 400 to any other. For plaintext gates reaching the hub by address, add `<address>:8081` to `GATEPOST_STATUS_HOSTS`; the variable replaces the default list, so keep the names you still use. A gate logs `event=ticket_fetch state=failed http=<status> curl=<code> reason=<reason> phase=<phase> received=<bytes> expected=<bytes|unknown>` when fetching starts failing or the reason or phase changes. It suppresses repeats with the same reason and phase even if the byte counts differ, and logs `event=ticket_fetch state=recovered` once when it works again. The gate retains used-ticket state when installing a new list. With device TLS configured, the hub syncs the signed season list from `/season.txt` over port 8443 using its certificate; without device TLS it uses port 8080. Before switching decisions, it checks that SHA-256 matches the ETag, the complete list loads under the start-file rules, and the downloaded file and its directory were synced. `/tickets` and decisions use the same immutable in-memory list. A switch logs `event=season_list state=installed tickets=<n> used=<n> load_ms=<ms>`; a refused list logs `event=season_list state=rejected reason=digest` or `reason=load errno=<n>` once per ETag and reason. The hub keeps its current list after a refusal and tries again on the next round.

The hub also serves `/metrics` on its staff-side status listener, separate from the gate RPC port. In the lab it binds `10.77.20.10:8081`, and only staff-subnet or loopback clients may read metrics. See [metric names and labels](docs/operations/metrics.md). The hub sends `X-Content-SHA256` with each ticket list; a gate verifies the bytes and prepares its ETag metadata before replacing the old list.

Expand Down
Loading
Loading