Run the Gateway

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 nodesThrough the Gateway
ProtocolgRPC on 7780, or HTTP on the data bridge (--http-listen)HTTP and SSE only
ClientsThe Go SDK, the TypeScript SDK's gRPC transport, the nova CLIBrowsers, edge runtimes, the TypeScript SDK's HTTP transport, curl
Reaching the leaderThe client follows redirects, so it must reach every node's advertised addressThe Gateway follows them; the client reaches one address
Token checkOn the nodeAt the Gateway when it has a key source, then again on the node
BrowsersNo CORSNamed origins
Per-token rate limitsNonenova_aux.limits, per Gateway
Old recordsRead through a nodeFetched from object storage, through the object cache if you run one
Admin commandsYesNo: the Gateway serves the data API only
Use whenClients run inside your networkClients 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-1 to nova-3 with --auth jwt, TLS, and fleet listeners on 7790.
  • 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 novagateway binary, 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.jwt

The 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.key
INFO 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/healthz
HTTP/2 200
content-length: 0

A 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.

  1. TLS 1.2 or later with your certificate, when you pass --tls-cert and --tls-key. Without them, the Gateway serves plaintext behind a load balancer that terminates TLS.

  2. GET /healthz answers 200 here, before any other step.

  3. CORS, for browsers. A preflight from an origin in --cors-origin gets 204 with the allowed methods (GET, POST, PATCH, DELETE, OPTIONS) and headers (Authorization, Content-Type, Last-Event-ID). Any other origin's preflight gets 403 origin not allowed. With no --cors-origin, every browser origin is refused.

  4. The token, when a --jwt-* source is set. A missing, expired or badly signed token gets 401, and a token's expiry becomes the request's deadline. Without a source, the Gateway forwards tokens unchecked and only the node checks them.

  5. The token's limits, with --enforce-limits; see Limits per token.

  6. Bucket hosts, with one or more --domain; see Bucket hosts.

  7. 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 403 before 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.

rpsnumber
Requests per second, for every route
connectionsinteger
Subscriptions and producer sessions open at once
read_Bpsinteger
Bytes per second served by reads and subscriptions
write_Bpsinteger
Bytes per second of request bodies, producer sessions included

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"}
 429
INFO 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.

--serve-planDefaulttrue
Serve reads from plans; --serve-plan=false sends every read through a node.
--storage-bucket
The bucket for raw plans, from nodes started with --readplan-vending raw. The Gateway fetches with its own read-only storage identity; --storage-endpoint, --storage-region and --storage-path-style locate the store.
--object-cache-instances
Fetch through the object cache, falling back to storage.
--fetch-inflightDefault64MiB
The bytes all fetches hold at once; when it is full, responses wait.
--footer-cache-bytesDefault32MiB
The decoded object footers the Gateway keeps.

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+06

Relaying 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=30s

Run 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

SymptomLikely causeWhat to do
401 auth: no credentialThe request has no Authorization headerSend Authorization: Bearer <token>; query parameters are not read
401 auth: verify token: token is unverifiable: error while executing keyfunc: auth: missing or unknown kidThe token was signed by a key not in the Gateway's JWKS, such as a key added by a rotationExport 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 actionIssue a token with the right scope
403 origin not allowed on a preflightThe browser's origin is not in --cors-originAdd the exact origin, scheme included
429 request rate over the token's rps ceilingThe token's nova_aux.limits ceiling is reachedRaise the limit at the issuer, or slow the client
The fleet listener refused warningThe fleet credential is missing, expired, or not signed by the nodes' keyMint and replace the credential file
novagateway: limits require JWT verification at start--enforce-limits without a --jwt-* sourceAdd --jwt-public-keys-file, --jwt-jwks-url or --jwt-oidc-issuer

See also

On this page