Run the Gateway
Put novagateway in front of your nodes to serve the HTTP API to browsers and the internet.
The Gateway, novagateway, serves Nova's HTTP API and server-sent events to clients outside your network. It finds each stream's leader for them, checks their tokens before forwarding, answers browsers' CORS requests, and can serve old records straight from object storage. It keeps nothing on disk, so you can run as many copies as your traffic needs and replace them freely.
Clients see one address. Every request still carries the caller's own token, which the node checks again. Adding or restarting a Gateway behind a load balancer does not disturb clients. A client connected to the Gateway you stop gets 30 seconds to finish its request.
Gateway or direct node access
| Direct to the nodes | Through the Gateway | |
|---|---|---|
| Protocol | gRPC on 7780, or HTTP on the data bridge (--http-listen) | HTTP and SSE only |
| Clients | The Go SDK, the TypeScript SDK's gRPC transport, the nova CLI | Browsers, edge runtimes, the TypeScript SDK's HTTP transport, curl |
| Reaching the leader | The client follows redirects, so it must reach every node's advertised address | The Gateway follows them; the client reaches one address |
| Token check | On the node | At the Gateway when it has a key source, then again on the node |
| Browsers | No CORS | Named origins |
| Per-token rate limits | None | nova_aux.limits, per Gateway |
| Old records | Read through a node | Fetched from object storage, through the object cache if you run one |
| Admin commands | Yes | No: the Gateway serves the data API only |
| Use when | Clients run inside your network | Clients are browsers, or run outside your network |
Keep the nodes on a private network and connect your own services to them directly. Expose only the Gateway to the internet.
Before you start
- A running cluster; see Run Nova on machines. The examples use nodes
nova-1tonova-3with--auth jwt, TLS, and fleet listeners on7790. - The nodes' public signing keys, so the Gateway can check tokens. See Turn on authentication.
- A certificate for the Gateway's name, or a load balancer that terminates TLS in front of it.
- The
novagatewaybinary, built from a checkout like the others:CGO_ENABLED=0 go build -trimpath -o novagateway ./cmd/novagateway.
Start the Gateway
Export the nodes' public keys
On a node, write the public keys the nodes sign with to a file:
nova auth key export --dir /var/lib/nova > /etc/nova/jwks.json{
"keys": [
{
"kty": "OKP",
"use": "sig",
"alg": "EdDSA",
"kid": "k1",
"crv": "Ed25519",
"x": "Bj26w-rpRAFxVRJ-oUfH1gxCvF8JgWTCWObolr4h2Qg"
}
]
}Mint the Gateway's fleet credential
A Gateway can relay on the nodes' fleet listener instead of competing with clients on 7780. There it must show a token that carries nova:gateway, which grants nothing else. Mint one on a node that holds the signing key:
nova token mint --dir /var/lib/nova --scope nova:gateway --subject gateway --ttl 168h \
> /etc/nova/gateway-fleet.jwtThe Gateway reads the file again within 10 seconds of a change, so renew it by replacing the file before it expires. Its remaining life is the metric nova.gateway.fleet_credential.remaining.
Start novagateway
novagateway --addr nova-1:7780 --addr nova-2:7780 \
--fleet-addr nova-1:7790 --fleet-addr nova-2:7790 \
--fleet-credential-file /etc/nova/gateway-fleet.jwt \
--cluster-tls-ca /etc/nova/tls/ca.pem \
--jwt-public-keys-file /etc/nova/jwks.json \
--cors-origin https://app.example.com \
--tls-cert /etc/nova/tls/server.pem --tls-key /etc/nova/tls/server.keyINFO novagateway serving listen=:8080 fleet="[nova-1:7780 nova-2:7780]" fleet_listeners="[nova-1:7790 nova-2:7790]" fleet_credential=true tls=true domains=[] serve_plan=true raw_vending=false object_cache=false--addr and --fleet-addr are seeds: one is enough, more are fallbacks, and a DNS name that resolves to several nodes works too. The nodes' redirects name their advertised addresses, which the Gateway must be able to resolve and reach.
Check it
/healthz answers without a token and without asking the cluster, so use it for the load balancer's health check:
curl -s -i https://gateway:8080/healthzHTTP/2 200
content-length: 0A request without a token is refused at the Gateway. One with a token is forwarded:
curl -s https://gateway:8080/v1/streams/orders
curl -s https://gateway:8080/v1/streams/orders/eu/records \
-H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
-d '{"records":[{"body":"o3"}]}'{
"error": "auth: no credential"
}{
"start": {
"seq_num": 2,
"timestamp_ms": 1795371869756
},
"end": {
"seq_num": 3,
"timestamp_ms": 1795371869756
},
"tail": {
"seq_num": 3,
"timestamp_ms": 1795371869756
}
}What the Gateway checks
Each request passes these steps in order. The first one that refuses it answers the client.
-
TLS 1.2 or later with your certificate, when you pass
--tls-certand--tls-key. Without them, the Gateway serves plaintext behind a load balancer that terminates TLS. -
GET /healthzanswers200here, before any other step. -
CORS, for browsers. A preflight from an origin in
--cors-origingets204with the allowed methods (GET, POST, PATCH, DELETE, OPTIONS) and headers (Authorization, Content-Type, Last-Event-ID). Any other origin's preflight gets403 origin not allowed. With no--cors-origin, every browser origin is refused. -
The token, when a
--jwt-*source is set. A missing, expired or badly signed token gets401, and a token's expiry becomes the request's deadline. Without a source, the Gateway forwards tokens unchecked and only the node checks them. -
The token's limits, with
--enforce-limits; see Limits per token. -
Bucket hosts, with one or more
--domain; see Bucket hosts. -
The scope. Each route names the action it needs, and the path names the bucket and key. A token whose scope does not cover them gets
403before anything is forwarded:{ "error": "dataplane: no grant covers append on orders/eu" }
The node checks the token and its scope again when the request arrives. The Gateway forwards the caller's token unchanged and holds no credential that could read or write on its own.
Limits per token
With --enforce-limits, the Gateway reads ceilings from the token's nova_aux.limits claim, which your own token issuer sets. A token without the claim is not limited. Enforcing limits needs a --jwt-* source; without one, the Gateway refuses to start.
A request over a ceiling gets 429 and one log line. A subscription or producer session that runs out of byte budget pauses instead. Three quick requests with a token whose claim is "limits": {"rps": 2}:
for i in 1 2 3; do
curl -s -w ' %{http_code}\n' https://gateway:8080/v1/streams/orders/eu/records/tail \
-H "Authorization: Bearer $LIMITED_TOKEN"
done{"bookmark":"3","tail":{"seq_num":3,"timestamp_ms":1795371869756}}
200
{"bookmark":"3","tail":{"seq_num":3,"timestamp_ms":1795371869756}}
200
{"error":"request rate over the token's rps ceiling"}
429INFO gateway: shed path=/v1/streams/orders/eu/records/tail why="request rate over the token's rps ceiling"Each Gateway counts on its own, per token sub, for up to 16,384 subjects at a time. With three Gateways behind a load balancer, a caller can reach about three times its ceiling.
Bucket hosts
With --domain nova.example, a request to {bucket}.b.{location}.nova.example serves that bucket's streams, so the path drops the bucket: orders.b.eu.nova.example/v1/streams/eu/records is /v1/streams/orders/eu/records. Bucket hosts exist only under a location's door, {location}.{domain}: orders.b.nova.example is not one. A bucket host serves only /v1/streams/…; anything else answers 404 with a bucket host serves its streams; administration rides the door. Every other host, the door and the bare domain included, serves the full path-style API. Your certificate must cover *.b.{location}.{domain}.
--domain is repeatable (NOVAGATEWAY_DOMAINS in the environment), and each domain names the same buckets. To move to a new domain, start the Gateways with both, and give the certificate the new domain's names. Move clients to the new NOVA_DOMAIN, then drop the old --domain. On Kubernetes, see Move to a new domain.
Reading history from object storage
For a read that names a limit, the Gateway first asks a node for a read plan: the stored objects that hold the records. It fetches those byte ranges itself, then asks the node for whatever the plan did not cover, and returns one response. Old records then cost the nodes one plan instead of the bytes. A read without limit, or one that starts at a tail offset, goes through a node.
By default, plans carry presigned URLs, which the Gateway fetches with no storage credential of its own.
Compare the metrics nova.gateway.vended.bytes and nova.gateway.proxied.bytes to see how much reading bypasses the nodes. After two reads of 500 records:
nova_gateway_proxied_bytes_total{verb="read"} 1.6764564e+07
nova_gateway_vended_bytes_total{verb="read"} 8.006e+06Relaying on the fleet listener
With --fleet-addr, the Gateway relays on the nodes' fleet listener, where client connection caps do not apply; see the fleet listener. Under --auth jwt it needs the nova:gateway credential from step 2. Under --auth basic, nodes accept only the operator login there, so leave --fleet-addr unset.
When the fleet listener refuses or cannot be reached, the Gateway relays on --addr, counts nova.gateway.fleet.fallbacks, logs a warning, and tries the fleet listener again 30 seconds later:
WARN gateway: the fleet listener refused or could not be reached; relaying on the client listener until it is tried again reason=refused err="rpc error: code = Unauthenticated desc = auth: the fleet listener admits only the constellation's own processes; dial the client listener" fleet=[nova-1:7790] retry_after=30sRun several Gateways
A Gateway holds only caches: the leader of each stream it has seen, and decoded footers. A new one rebuilds them on its first requests. Put several behind a load balancer and size them for network bandwidth: every byte crosses a Gateway's network interface twice, once from the nodes or object storage and once to the client. Keep them off the nodes' machines so the two do not compete for bandwidth.
On SIGTERM or SIGINT, a Gateway stops accepting connections and gives open requests 30 seconds to finish. Metrics are on --metrics-listen (default :9090), at /metrics. Every flag is in the novagateway reference. On Kubernetes, the controller runs Gateways for you; see Gateway and ingress.
If it goes wrong
| Symptom | Likely cause | What to do |
|---|---|---|
401 auth: no credential | The request has no Authorization header | Send Authorization: Bearer <token>; query parameters are not read |
401 auth: verify token: token is unverifiable: error while executing keyfunc: auth: missing or unknown kid | The token was signed by a key not in the Gateway's JWKS, such as a key added by a rotation | Export the keys again after a rotation, and restart the Gateway |
403 dataplane: no grant covers … | The token's scope does not cover the bucket, key or action | Issue a token with the right scope |
403 origin not allowed on a preflight | The browser's origin is not in --cors-origin | Add the exact origin, scheme included |
429 request rate over the token's rps ceiling | The token's nova_aux.limits ceiling is reached | Raise the limit at the issuer, or slow the client |
The fleet listener refused warning | The fleet credential is missing, expired, or not signed by the nodes' key | Mint and replace the credential file |
novagateway: limits require JWT verification at start | --enforce-limits without a --jwt-* source | Add --jwt-public-keys-file, --jwt-jwks-url or --jwt-oidc-issuer |