Run a gateway
The gateway accepts hash submissions, persists jobs in SQLite, collects and verifies witness signatures, and exposes attestations and proofs. It is the public-facing component and should be treated as an untrusted network boundary around the witness services.
Build and start
Build from the workspace root:
cargo build --release -p witness-gateway
The gateway's relevant flags are:
| Flag | Default | Purpose |
|---|---|---|
--config |
network.json |
Network configuration |
--key-history (WITNESS_KEY_HISTORY) |
none | Signed key history file, needed after the first key change |
--log-key (WITNESS_LOG_KEY_FILE) |
none | Private log key file. Required unless batching is disabled |
--external-witnesses (WITNESS_EXTERNAL_WITNESSES) |
none | JSON file listing optional independent C2SP witnesses |
--tsa-url and related flags |
off | Issue long-term evidence records through an RFC 3161 time-stamp authority; see Preserve evidence |
--host |
127.0.0.1 |
Listen interface |
--port |
8080 |
HTTP listen port |
--database |
gateway.db |
SQLite path |
--admin-ui |
disabled | Enable /admin |
--admin-api-key |
environment | Admin credential |
--ws-auth-token |
environment | WebSocket credential |
--metrics-token |
environment | Metrics credential |
--trusted-proxy |
none | Repeatable trusted reverse-proxy CIDR |
--global-rate-limit-per-minute |
600 |
Global attestation admission limit |
--batch-period-secs (WITNESS_BATCH_PERIOD_SECS) |
60 |
Seconds between Merkle batches and signed checkpoints; 0 disables both |
--checkpoint-refresh-secs (WITNESS_CHECKPOINT_REFRESH_SECS) |
600 |
Re-sign the current tree when the latest checkpoint is older than this, even with no new entries, so auditors can tell the log is alive; 0 disables. Checked on each batch tick |
Example with persistent local storage:
WITNESS_JOB_SIGNING_WINDOW_SECS=300 \
target/release/witness-gateway \
--config /etc/witness/network.json \
--log-key /etc/witness/log.key \
--host 127.0.0.1 \
--port 8080 \
--database /var/lib/witness/gateway.db
The signing window is required. It must be greater than the 30-second worker
lease and no greater than time_policy.max_skew_secs. The example uses
300 seconds, which assumes the network allows at least that much skew.
The gateway speaks plain HTTP. For an internet-exposed service, terminate TLS
at a trusted reverse proxy or load balancer, restrict operational routes
there, and set WITNESS_TRUSTED_PROXIES (or repeat --trusted-proxy) only for
the proxy CIDRs that are authoritative for X-Forwarded-For. For a local nginx
upstream, use WITNESS_TRUSTED_PROXIES=127.0.0.1/32.
Network and witness configuration
network.json defines the network ID, key_epoch, signature scheme,
majority threshold, time_policy.max_skew_secs, log origin and key, and signer keys and
endpoints. Every signer entry must have a nonempty auth_token and an HTTP or
HTTPS endpoint without a username, password, query or fragment. If you
configure a key history file, the gateway checks that it ends at the key set
and epoch in network.json.
Treat the file as a secret because the operational form contains bearer
tokens. The public verification configuration is a different, secret-free
artifact; distribute it to clients and auditors through a channel other than
the gateway so they can pass it with --network-config.
The gateway never needs signer private keys. Generate each signer's key on the
signer's own host and copy only its public key and bearer token into
network.json. Do not mount signer key files into the gateway.
Use trusted paths to the signers. Allow the gateway to reach /v1/sign,
and /add-checkpoint; do not expose those routes to untrusted sources.
Receipt signing uses a bearer token. Checkpoint signing checks the log's
signature instead.
The gateway connects only to the endpoints you configure. It does not follow
redirects and ignores HTTP_PROXY, HTTPS_PROXY and ALL_PROXY, so the
gateway must be able to reach each signer directly. Private addresses and
internal hostnames, such as Docker Compose service names, are fine.
Log key and independent witnesses
Choose a stable log.origin such as example.org/witness/my-network. Do not
reuse it for a new, empty log. Use witness-node --generate-key on the gateway
host to generate a separate Ed25519 keypair. Put just the 64 hex characters of
the private seed in the --log-key file and restrict it to the gateway user
(mode 0600). Put the corresponding public key in log.public_key. Give
signers only the origin and public key.
To add an independent witness, give its operator the log verifier key printed
by witness keys vkeys --network-config FILE. Add its name, C2SP Ed25519
cosignature verifier key, and base URL to your --external-witnesses file:
[{"name":"witness.example/w1","vkey":"<witness verifier key>","url":"https://witness.example/submit"}]
The gateway appends /add-checkpoint to the URL. It attaches valid external
signatures it receives, but publication does not require them. A client that
needs those signatures must set its own
witness policy. The latest note is public at /checkpoint.
Public routes and admission
New requests arrive at POST /v1/attestations; clients retrieve jobs and
proofs through the documented /v1/... routes. Job creation is asynchronous,
and a confirmed result has passed the gateway's threshold verification before
being persisted. The gateway has a 30 requests/minute/IP admission limit, but
this is only defense in depth. See abuse and rate limiting.
The gateway assigns the timestamp once, when it creates the job.
Set the required WITNESS_JOB_SIGNING_WINDOW_SECS; when it expires, the stable
terminal result is status: "failed" with
last_error: "signing_deadline_exceeded". Do not expect a new timestamp for
the same hash; submitting it again returns the failed job.
Configure admin, metrics, and WebSocket authentication before exposure. When
WITNESS_WS_AUTH_TOKEN is unset (or empty/whitespace), /ws/events is
disabled: the upgrade is rejected with HTTP 503 and startup logs that the
endpoint is disabled. There is no unauthenticated WebSocket mode. When a token
is set, subscribers must answer the first-message auth_required challenge,
and the stream carries confirmed attestations only. Keep the gateway's
hardened outbound client enabled for signer requests.
Use a persistent local filesystem for SQLite. Do not place the database on a network filesystem or run multiple gateway processes against one database.