feat: audit log #68

Merged
Sebi merged 3 commits from feat/audit-log into main 2026-11-22 09:43:53 +00:00
Owner

Stacked on #64.

  • audit_events with kinds org / user / platform, row-level security per kind, new permission audit.read (added to the built-in admin role).
  • Middleware records every successful state-changing request: action from a route table (test fails for unmapped routes), actor, API token, target id and names from the response (fixed allow-list, no secrets; tested), status, IP, user agent, request id. Failed sign-ins are recorded too: on the account if it exists, otherwise in the platform log. SSO sign-ins are recorded explicitly.
  • Views: Settings → Audit log (/settings/audit, GET /api/v1/org/audit), account activity on the security page (GET /api/v1/me/audit), platform log for admins (/admin/audit, GET /api/v1/admin/audit); paged by time.
  • Retention UPTIME_RETENTION_AUDIT (default 365 days) via housekeeping.
  • UPTIME_TRUSTED_PROXIES: gin trusted any X-Forwarded-For, letting clients spoof the address used for rate limits and the audit log; now no proxy is trusted unless configured.

Closes #65

🤖 Generated with Claude Code

https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3

Stacked on #64. - `audit_events` with kinds org / user / platform, row-level security per kind, new permission `audit.read` (added to the built-in admin role). - Middleware records every successful state-changing request: action from a route table (test fails for unmapped routes), actor, API token, target id and names from the response (fixed allow-list, no secrets; tested), status, IP, user agent, request id. Failed sign-ins are recorded too: on the account if it exists, otherwise in the platform log. SSO sign-ins are recorded explicitly. - Views: Settings → Audit log (`/settings/audit`, `GET /api/v1/org/audit`), account activity on the security page (`GET /api/v1/me/audit`), platform log for admins (`/admin/audit`, `GET /api/v1/admin/audit`); paged by time. - Retention `UPTIME_RETENTION_AUDIT` (default 365 days) via housekeeping. - `UPTIME_TRUSTED_PROXIES`: gin trusted any X-Forwarded-For, letting clients spoof the address used for rate limits and the audit log; now no proxy is trusted unless configured. Closes #65 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Sebi added this to the M6 Admin UI milestone 2026-11-22 09:00:12 +00:00
Sebi changed target branch from feat/data-lifecycle to main 2026-11-22 09:39:35 +00:00
Sebi added 25 commits 2026-11-22 09:39:35 +00:00
Closes #20

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
The dashboard lists monitors with status, latency and 24-hour uptime
bars rendered as SVG on the server; monitor pages add 90-day uptime,
latency and recent checks; an editor shows the settings of the selected
check type.

Closes #17
Closes #19

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Composite foreign keys keep pages from listing monitors of other
organizations, independent of row-level security.

Refs #21

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Pages render without JavaScript, are matched by verified custom domain
or by slug, and stay available from a stale snapshot for ten minutes if
the API is unreachable. Snapshots contain no targets or error details.

Refs #21, #22

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Organizations build pages from their monitors, grouped into sections
with public names, choose an accent color, logo and CSS, verify custom
domains with a TXT record and export a page as one self-contained HTML
file. Assignments scoped to a single status page are honored.

Closes #21
Closes #23
Closes #24

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Reconciliation removed every monitor missing from its database read,
including ones created in the meantime; they stayed unscheduled until
the next run a minute later. Upserts now record when they happened and
reconciliation only prunes entries older than its read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Certificates and ACME keys are stored encrypted in the database,
namespaced per owner so an organization's servers cannot read platform
or other organizations' keys. Locks live in Redis and expire.

Refs #22

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
With UPTIME_STATUSPAGE_TLS the server serves HTTPS with ACME
certificates for its hosts and for verified custom domains of pages it
may serve, shared by all instances through the API. Plain HTTP answers
ACME challenges and health checks and redirects everything else.

Closes #22

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
The previous fix read upsert times once and pruned later, so monitors
created in between were still dropped. A Lua script now checks the
upsert time and removes the entry atomically.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Snapshots are persisted to UPTIME_STATUSPAGE_CACHE_DIR and loaded at
start, so pages survive restarts during an outage. Cached pages are
answered without waiting for the API, refreshed in the background and
served for as long as the API stays unreachable, with a notice once they
are older than five minutes. Only an explicit not found from the API
removes a page. Readiness no longer depends on the API when pages are
cached, the server starts without a reachable API, and certificates are
mirrored locally so HTTPS keeps working after a restart.

Closes #56

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
A trigger rejects cycles and nesting deeper than eight levels; composite
foreign keys keep groups and their monitors in one organization.

Refs #57

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Assignments scoped to a group cover all monitors and subgroups below it,
so people can be given exactly one branch of the tree. Deleting a group
moves its content one level up and drops assignments scoped to it.

Refs #57

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
The dashboard nests groups with an aggregated status, the monitor editor
offers the groups one may write to, a page manages groups, and members
can be assigned roles limited to a group or a status page. Settings move
to their own page to keep the navigation short.

Closes #57

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Refs #59

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Bars use a resolution fitting the range and the latency line is placed
by time. The SLA is the share of time a monitor was not down, counted
from incidents and only since the monitor exists. Monitor pages list the
SLA from one hour to 90 days.

Closes #59

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Refs #61

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Ranges grow to 30d, 90d, 180d and 1y, read from the aggregates, and the
SLA table to 180d and 1y. Ranges and SLA windows less than half covered
by data are shown disabled. Monitor pages chart each region separately
with its share of successful checks. Bars align to TimescaleDB's bucket
origin so multi-day buckets match.

Closes #61

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
The hourly and daily aggregates are compressed after 30 and 180 days and
the daily aggregate is no longer kept forever. TimescaleDB telemetry is
turned off for the database, as self-hosted installations must not
report to third parties.

Refs #63

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Refs #63

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
UPTIME_RETENTION_RAW, _HOURLY and _DAILY set TimescaleDB's retention
policies, applied by "api migrate up" with owner rights and on start;
periods too short for the charts are rejected. An hourly job deletes
delivered notifications, stale invitations and expired API tokens after
UPTIME_RETENTION_HOUSEKEEPING and resolved incidents together with the
daily aggregate. The admin panel shows size, compression, retention and
background job status of each storage level.

Closes #63

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Entries are visible by kind: organization entries to the organization,
account entries to the account, platform entries to admins. The built-in
admin role gains the new audit.read permission.

Refs #65

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
gin trusted every proxy by default, so any client could choose the
address used for rate limits and the audit log.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Every state-changing API route is mapped to an action; a test fails for
unmapped routes. Successful changes are recorded with actor, API token,
target, IP, user agent and request ID; failed sign-ins too. Names are
taken from the response, never secrets. Organizations read their log with
audit.read under Settings, users their account activity on the security
page, admins the platform log. Entries expire after UPTIME_RETENTION_AUDIT.

Closes #65

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Sebi merged commit 0bff5e3f91 into main 2026-11-22 09:43:53 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ZB-Server/uptimesebi#68