Docs Version v0.2
Docs menu

Running in production

Running several copies of Signari

Changed 10 min readv0.2

On this page

Introduction

One Signari server is a single point of failure. When it stops, nobody can sign in anywhere. To survive that, you run several copies of Signari behind a load balancer.

Every copy connects to the same PostgreSQL and serves the same issuer, so they are one instance between them. There is no leader election to configure, no cache to invalidate, and no sticky sessions to arrange at the load balancer. This page explains what the copies share, and how each part of Signari stays correct when several copies run at once.

Starting a second copy

Each copy needs the same database, root key and issuer. Start each one like this:

Shell# Copy A and copy B, same DSN, same root key, same issuer.SIGNARI_DSN=… SIGNARI_ROOT_KEY=… SIGNARI_ISSUER=https://id.example.com \  signari serve -addr 0.0.0.0:8080

What the copies share

Signing keys, sessions, authorization codes, refresh families, consent, device codes and audit all live in the database. So two copies agree about them without doing anything. Both copies serve identical kids, and a token minted by one verifies at the other.

Each audit entry is appended under one lock on the whole chain. So two entries written at once, by one copy or by two, never claim the same predecessor, and the chain stays one line. See the audit chain.

The "janitor" is the background job that ends expired sessions and purges spent authorization codes. It coordinates with a transaction-scoped advisory lock. One copy sweeps, and the others record Skipped. A node that dies mid-pass releases the lock by rolling back, rather than leaving the janitor stuck.

A pass is many short transactions rather than one long one. A batch is up to 500 sessions or 1,000 rows of a table. Each batch is committed on its own and takes the lock again, and each kind of row gets a batch before any gets a second.

A sweep that fails stops only itself. At 45 seconds a pass stops starting batches, and logs what it left. The next pass carries on, so a backlog after an outage is worked through and no request waits on it.

Sign-in limits, shared by every copy

The sign-in limits are counters in the database, so every copy reads and charges the same ones. Adding a copy does not raise any limit. The 20 failures an address may have in five minutes are 20 across every copy, not 20 at each.

Each counter is keyed by what it limits. So reaching a limit refuses only that address or that account, and everybody else goes on signing in. Each counts failed sign-ins, not attempts:

keylimitstops
signin:fail:ip:<address>20 failures per 5 minone source grinding through many accounts
signin:fail:user:<identifier>30 failures per 15 minmany sources grinding through one account

The address is the connection's own. Behind a proxy you name in SIGNARI_TRUSTED_PROXIES, it is the address that proxy forwarded, as behind a reverse proxy explains. A forwarding header from anyone else is ignored. Honouring a header set by the caller would let an attacker spend somebody else's budget and keep their own.

The per-account limit

That key is chosen by whoever submits the form. So any per-account limit is a way to degrade one named person's sign-in on purpose. It is bounded two ways:

  • The number is high enough that a real person never reaches it.
  • It is a rate limit that expires by itself, not a lockout needing an administrator.

Fifteen minutes of slower sign-in does less harm than a locked account that an administrator has to unlock.

Both limits answer identically. Saying which one was reached would tell an attacker whether the account exists.

Why a fixed window and not a token bucket

A token bucket needs read-then-write: refill by elapsed time, then decrement. Two concurrent requests can both read the same value, and both write their own result. Then a decrement is lost and both are allowed. This happens under concurrent load, which is when a limiter is needed.

A fixed window increments inside the UPDATE, referencing the stored row. So the row lock handles concurrency, and no read is lost. Tested with 100 concurrent requests against a limit of 20, exactly 20 were allowed.

The cost is the boundary. A caller can spend a full window at the end of one and again at the start of the next. So the worst case is 2× across a moment. That bound is fixed, and it does not grow with the number of copies.

One process-local bucket

A generous in-process guard still runs first on the sign-in path. Its job is protecting the database from a flood, not bounding guesses. The shared limits cost a round trip each, and an unbounded flood of them is its own denial of service.

It is set high enough that a real deployment never sees it, and an attacker reaches the keyed limits instead. The bound is half again what the machine can hash. It is measured when the engine starts, with the cost new hashes are made with, and is never less than 100 a second.

How many hash at once is the hasher's own bound. So sign-ins beyond what the machine can hash wait for a slot.

The same reasoning keeps the JSON Web Key Set (JWKS) on a local bucket. It has high volume, nothing expensive behind it, and no security decision resting on the count.

Failing closed

If the database cannot be reached, a sign-in attempt is refused. Signing in needs the database one query later anyway, so failing closed refuses nothing that would have succeeded. Failing open would allow unlimited guesses while the database is unreachable.

The CAPTCHA counter, shared by every copy

A CAPTCHA is a puzzle that tells a person from a script. Adaptive mode counts failures per address, and shows the puzzle after a threshold.

The counter is kept in the database, like the sign-in limits. So a failure on any copy counts on every copy, however the load balancer spreads the requests. internal/captcha takes the counter as an interface, not a database dependency. It is small and pure, and stays testable without one. The engine supplies an implementation backed by the database.

A test checks two properties:

Textthree failures split across two copies → both copies see threefive reads of the counter                 → still three

The count is read every time the sign-in page is rendered. If reading it added to it, showing the page would raise the count until everyone who opened the page got a challenge.

A database error reads as zero, not as "challenge everybody". The sign-in is about to fail for the same reason, and adding a puzzle would not help.

Policy propagation

Every copy asks the database which access policy is in force on every decision. That is one indexed row: the document's digest, and the document itself only when the digest has changed. So a new rule applies on the next request, on every copy, and no two copies enforce different versions.

A rule can say deny: true, and this engine never serves a security-negative decision from a snapshot. A deny rule written to shut a client out must work on the next request, on whichever copy the attacker's request happens to reach. Parsing is memoised, so the cost is the digest query, not a parse.

Issuer aliases are read per request too, like every other decision about what to accept. So an alias you retire stops being accepted on every copy, with no restart.

Outbox delivery

The "outbox" is the queue of notices Signari delivers to other services, such as sign-out notices and security events. Claiming uses FOR UPDATE SKIP LOCKED, which divides the work, so two copies never deliver the same notice.

Delivery runs in three phases, claim, deliver and record, with no transaction open across the network. So a receiver that does not answer never holds row locks, or a database connection from the pool the rest of the engine shares. Delivery is bounded at 32 concurrent POSTs, so one hanging receiver does not delay every notice queued behind it.

Event deliveries work the same way. Each kind of delivery has a goroutine of its own, so a receiver that is down holds up nothing but its own kind. Each drains until its queue is empty.

Claiming also pushes next_attempt_at forward by a lease, which keeps the copies apart after the locks are released. Without it, committing in order to deliver outside a transaction would hand the same rows straight to the other copy.

attempts is not incremented on claim. A crash between claiming and recording is not the application failing to answer. Counting it as one would move a reachable receiver towards being parked.

Tests check that two copies draining at once deliver each notice exactly once. They also check that a row being delivered is not locked, and that a slow receiver does not delay the others.

One mechanism, a policy for each drain

Each kind of notice has a drain of its own, such as one for sign-out notices and one for security events. Each keeps its own policy: how long to back off, what to log, which receiver to call. So one can be tuned without touching another.

The mechanism, where each transaction begins and ends, lives in one place and every drain shares it. So a correction to it reaches every drain at once. A test checks that the security-event drain, too, holds no transaction while it delivers.

Revoking a RADIUS device while serving

The Remote Authentication Dial-In User Service (RADIUS) listener re-reads its device list while it serves. So revoking an access point takes effect with no restart.

These commands revoke a device and restore it:

Shellsignari radius disable-client -name office-apsignari radius enable-client  -name office-ap

Devices are re-read every minute. Measured on a running listener, an access point authenticating normally was revoked, and refused about 70 seconds later with no restart.

An empty list is honoured and logged at WARN, since it means every device has been revoked. A single SQL query either succeeds or returns an error, so there is no partial read to mistake for emptiness. With no devices, network sign-in is off for everyone, so the warning makes that visible.

Startup refuses an empty list, though. A listener starting with no devices is almost always misconfigured, so Signari says so at once rather than serving a port that answers no one.

A read replica, for the audit trail

SIGNARI_READ_DSN points the Admin API's GET /admin/audit-events at a replica, and signari export audit -dsn takes one too. Reading the trail is the long read an administrator makes, and it is append-only. So a replica that lags is only missing the newest events. If the replica does not answer, the primary does, and the log says so.

The replica is used for nothing else:

  • Nothing that decides anything. A session, a token or a client is read from the primary. A replica that has not yet seen a revocation would accept an authentication that should be refused.
  • No list that carries an ETag. A list answered from behind the primary would carry a version the primary has moved past. If-Match exists so that an apply cannot overwrite a change it never saw.

More copies on one machine

This measures client credentials against one database, with 16 workers shared between one load generator per copy. It is the median of two runs, with everything on one 8-core laptop under other load:

Textcopies      tokens/s    errors1           2,864       02           2,657       04           2,969       0

The numbers are flat, because the machine is what ran out. The engines, PostgreSQL and the load generators were sharing eight cores. So this says that a second and a fourth copy cost nothing in coordination, since they share nothing but the database. It does not say how far they scale, which needs hosts of their own.