feat: multi-tenancy, login, per-org SSO and i18n (M2) #46

Merged
Sebi merged 22 commits from feat/m2-tenancy into main 2026-11-21 23:44:17 +00:00
Owner

Milestone M2: multi-tenancy, authentication and the cross-cutting pieces that came up along the way.

Tenancy

  • Users, organizations and memberships with exactly one owner per org.
  • Row-level security on every org table. Queries run in tenant.DB.Tx with an org, user, global or system scope; without a scope nothing is visible. The app must connect as a non-superuser role, otherwise RLS is bypassed (a warning is logged at startup).

Authentication

  • Password login (argon2id, rehash on parameter change, constant-time miss path) with optional TOTP, replay-protected codes and single-use recovery codes.
  • Per-organization OpenID Connect SSO: owners manage their own providers; PKCE, nonce and browser-bound state; accounts are linked by issuer subject and never matched by email. Requests to customer IdPs refuse non-public addresses unless UPTIME_SSO_ALLOW_PRIVATE_NETWORKS allows it.
  • Redis-backed sessions with sliding and absolute expiry, CSRF synchronizer tokens plus Origin check, rate limits shared across replicas.
  • Secrets at rest (TOTP seeds, client secrets) sealed with a rotatable keyring (UPTIME_SECRET_KEYS).

Cross-cutting

  • English and German UI and API messages; tests fail on missing or unused catalog keys.
  • Request IDs in response headers, logs and API error bodies.
  • Code follows the Google Go style guide; .golangci.yml added.

New configuration

UPTIME_SECRET_KEYS (required), UPTIME_SIGNUP, UPTIME_SESSION_IDLE, UPTIME_SESSION_ABSOLUTE, UPTIME_PUBLIC_URL, UPTIME_SSO_ALLOW_PRIVATE_NETWORKS. UPTIME_LOG_FORMAT was removed (always JSON).

Testing

UPTIME_TEST_DATABASE_URL and UPTIME_TEST_REDIS_URL (a Redis database reserved for tests; it is flushed) enable the integration tests, including full SSO flows against an in-process IdP.

Follow-ups

#41 enforce the org TOTP requirement, #45 option to require SSO, #43 re-enable staticcheck.

Closes #1, #2, #3, #4, #5, #40, #42, #44

🤖 Generated with Claude Code

https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3

Milestone M2: multi-tenancy, authentication and the cross-cutting pieces that came up along the way. ## Tenancy - Users, organizations and memberships with exactly one owner per org. - Row-level security on every org table. Queries run in `tenant.DB.Tx` with an org, user, global or system scope; without a scope nothing is visible. The app must connect as a non-superuser role, otherwise RLS is bypassed (a warning is logged at startup). ## Authentication - Password login (argon2id, rehash on parameter change, constant-time miss path) with optional TOTP, replay-protected codes and single-use recovery codes. - Per-organization OpenID Connect SSO: owners manage their own providers; PKCE, nonce and browser-bound state; accounts are linked by issuer subject and never matched by email. Requests to customer IdPs refuse non-public addresses unless `UPTIME_SSO_ALLOW_PRIVATE_NETWORKS` allows it. - Redis-backed sessions with sliding and absolute expiry, CSRF synchronizer tokens plus Origin check, rate limits shared across replicas. - Secrets at rest (TOTP seeds, client secrets) sealed with a rotatable keyring (`UPTIME_SECRET_KEYS`). ## Cross-cutting - English and German UI and API messages; tests fail on missing or unused catalog keys. - Request IDs in response headers, logs and API error bodies. - Code follows the Google Go style guide; `.golangci.yml` added. ## New configuration `UPTIME_SECRET_KEYS` (required), `UPTIME_SIGNUP`, `UPTIME_SESSION_IDLE`, `UPTIME_SESSION_ABSOLUTE`, `UPTIME_PUBLIC_URL`, `UPTIME_SSO_ALLOW_PRIVATE_NETWORKS`. `UPTIME_LOG_FORMAT` was removed (always JSON). ## Testing `UPTIME_TEST_DATABASE_URL` and `UPTIME_TEST_REDIS_URL` (a Redis database reserved for tests; it is flushed) enable the integration tests, including full SSO flows against an in-process IdP. ## Follow-ups #41 enforce the org TOTP requirement, #45 option to require SSO, #43 re-enable staticcheck. Closes #1, #2, #3, #4, #5, #40, #42, #44 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Sebi added this to the M2 Tenancy & Login milestone 2026-11-21 23:35:50 +00:00
Sebi added 22 commits 2026-11-21 23:35:51 +00:00
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Refs #1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Every query runs inside a transaction carrying app.org_id, app.user_id
or the explicit system scope. Without a scope no rows are visible.

Closes #2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Tokens are only kept as SHA-256 hashes. A per-user index allows ending
all sessions of an account at once.

Closes #1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Unsafe methods require the session's synchronizer token and a matching
Origin, which also covers login requests that have no session yet.

Refs #5

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
Refs #3

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Orgs are created inside their own tenant scope, so signup needs no
system scope.

Refs #3

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Signup is limited to the first user by default (UPTIME_SIGNUP). TOTP
secrets are sealed with UPTIME_SECRET_KEYS and bound to the user id.

Closes #3
Closes #5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Tests fail on catalogs with diverging keys and on message IDs used in
code or templates that no catalog defines.

Refs #42

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
The language comes from the user setting, then the lang cookie, then
Accept-Language, falling back to English. Errors keep a stable code and
carry a translated message.

Closes #42

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
UPTIME_CHECKER_REGION= passed the required check and started a checker
that no monitor could ever be assigned to.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
staticcheck and unused stay disabled until honnef.co/go/tools supports
the Go 1.27 standard library.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Document every package and exported identifier, return the log level
from NewLogger instead of keeping it in a package variable, and stop
tests from mutating the argon2 parameters.

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
A well-formed X-Request-ID from a proxy is kept, otherwise a UUIDv7 is
generated. The ID is echoed in the response header, added to every log
record written with the request context and returned in API error
bodies.

Closes #44

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Identities are keyed by provider and subject. Both tables are tenant
scoped; org_id_by_slug resolves a slug before sign-in without opening a
broader scope.

Refs #4

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Issuer URLs come from customers, so requests to their IdPs refuse
non-public addresses unless private networks are explicitly allowed.

Refs #4

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Owners manage OIDC providers under /settings/sso. Users start at
/sso/<org>. New users can be provisioned for verified emails in allowed
domains; existing accounts are never matched by email and must link
their SSO sign-in while signed in.

Closes #4

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Codes are stored as SHA-256 hashes and consumed with one conditional
update, so concurrent use of the same code succeeds at most once.

Refs #40

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Enabling TOTP returns ten codes that are shown once. Disabling TOTP and
regenerating codes require the password plus a current code.

Closes #40

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Sebi merged commit df218b7641 into main 2026-11-21 23:44:17 +00:00
Sebi deleted branch feat/m2-tenancy 2026-11-21 23:44:19 +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#46