Audit log
Every management write lands in the audit log with its actor, the state before and after, and the new revision. Membership changes are stored as diffs. The table is partitioned by month and indexed by tenant, time and actor. A default partition catches any row whose month has no partition yet, so an audit write never fails. At start and once a day the server keeps the next two months in place withensure_audit_partitions().
It also gives any other month with rows in the default partition its own,
such as the old months latchkey export copies in, and moves those rows
into their month.
latchkey audit prune removes old entries. On Postgres it drops whole
months with owner credentials. On SQLite it deletes old rows and needs write
access to latchkey.db. See
the CLI. Retention is a Helm
value, 400 days by default.
AuditService.ListAuditEntries reads the log, newest first. The admin UI
and latchkey audit read it this way. A tenant’s Admin
reads that tenant’s entries, checked in the same transaction as the read, so
a revoked Admin reads nothing more. An operator reads the instance’s entries,
the writes to domains and kinds, by naming no tenant. Neither reads the
other’s. Entries can be narrowed to those since a time, by one actor, or for
one entity, the part of an operation before the first dot, such as binding
for binding.create.
Each page also counts every matching entry in the retained log, and the
entity filter is not indexed, so a long retention makes pages slower. A page
holds at most 1000 entries. An entry’s time is when its transaction began on
Postgres, so a write that commits slowly can appear behind entries already
read. Following the log with since, starting each read a little before the
newest entry seen and skipping the ids already read, is best effort: a write
whose transaction ran longer than that overlap can be missed. To collect every
entry, also read the whole retained log again from time to time.
Health probes
The server answers the Kubernetes probes on its API port.
Readiness does not check the database. Replicas answer from their snapshot,
so a database outage would otherwise pull every replica out of service at
once. The revision rule handles an
outage instead.
On
SIGTERM the server fails readiness, keeps serving for 5 seconds while
Kubernetes stops routing to it, then waits up to 10 seconds for requests in
flight. A second signal exits at once.
Metrics and traces
The server records these through the OpenTelemetry API.
No metric has a tenant attribute, so the number of series does not grow
with the number of tenants.
caller is the id of a configured owner or
operator, other for anyone else, or unauthenticated. reason is the
Connect code, or revision_timeout. Errors from one caller point at a
misconfigured product.
snapshot.age is what to alert on. Checks in the stalest tenant answer
UNAVAILABLE once it passes LATCHKEY_MAX_STALENESS.
On Postgres nearly every change should arrive with source notify. A poll
that overlaps a notification can count the same change, so an occasional
poll means nothing. A count of poll that keeps pace with notify, or
grows with no notify at all, is worth a look. Notifications may not be
reaching the replica, as behind a connection pooler in transaction mode.
The server binary exports them over OTLP when
OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_METRICS_ENDPOINT is
set, and reads the other standard OTEL_* variables. See
Configuration. In
embedded mode they go to the global meter provider the product sets.
The SDK exports, through the OpenTelemetry API, check latency
(latchkey.sdk.check.duration), timeouts (latchkey.sdk.check.timeouts),
requests denied because Latchkey could not be asked
(latchkey.sdk.check.unavailable), decision cache lookups by hit
(latchkey.sdk.cache.lookups) and registration failures
(latchkey.sdk.registration.failures). It also emits spans for the
interceptor, the check and the parent resolver. With no provider set they
cost nothing.
Decision log
The SDK logs every deny, and in shadow mode every decision, throughslog
with the mode, the request, the tenant, the subject, each check’s kind,
action and resource id, and the code. A product can bridge slog to
OpenTelemetry logs. These are not Postgres rows, so decision volume never
competes with the policy tables. A configurable sample of allows comes after
V1.
Explaining access
ExplainAccess answers why a subject can or cannot do something. It lists
the bindings that reach the subject and flags a subject id that matched
nothing. latchkey explain is its command line form.