feat: roles, permissions, invitations, api tokens and org policies (M3) #47

Merged
Sebi merged 6 commits from feat/m3-permissions into main 2026-11-22 00:24:29 +00:00
Owner

Milestone M3: roles, permissions and organization policies. Builds on #46.

Model

  • Permissions such as monitors.write or members.manage; write/manage implies read.
  • Built-in roles Admin, Editor, Viewer (seeded, read-only) plus custom roles per org. The owner holds everything implicitly.
  • Assignments are org-wide or scoped to one monitor group or status page. The scoped resources arrive in M4/M7; the model and checks are in place.
  • Nobody can grant, revoke, remove or invite with more than they hold. Editing a custom role requires holding both its old and new permissions.

Access

  • Every /api/v1/org/* route resolves a principal from the session or a Bearer ust_… token and checks a permission.
  • API tokens are personal, capped by the owner's current rights (shrinking roles shrinks tokens; leaving the org revokes them) and cannot manage credentials, members or roles.
  • Invitations: link-based, 7 days, single use, bound to the invited email. The inviter must still be allowed to grant the role when the invitation is accepted. Invitees can create an account regardless of UPTIME_SIGNUP.
  • SSO auto-provisioning assigns a configurable default role (Viewer if unset).

Organization policies

  • Require TOTP: password sessions need TOTP; SSO sessions rely on the IdP's MFA.
  • Require SSO: members must sign in through the org's IdP; the owner keeps a password fallback.
  • A policy cannot be switched on by someone whose own session would violate it.

UI

Members, Roles, API tokens and Organization settings pages; navigation follows permissions; a banner explains unmet policies.

Testing

internal/api/permissions_test.go covers delegation without escalation, tokens following their owner, policies, invitations and org isolation.

Closes #6, #7, #8, #9, #41, #45

🤖 Generated with Claude Code

https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3

Milestone M3: roles, permissions and organization policies. Builds on #46. ## Model - Permissions such as `monitors.write` or `members.manage`; write/manage implies read. - Built-in roles Admin, Editor, Viewer (seeded, read-only) plus custom roles per org. The owner holds everything implicitly. - Assignments are org-wide or scoped to one monitor group or status page. The scoped resources arrive in M4/M7; the model and checks are in place. - Nobody can grant, revoke, remove or invite with more than they hold. Editing a custom role requires holding both its old and new permissions. ## Access - Every `/api/v1/org/*` route resolves a principal from the session or a `Bearer ust_…` token and checks a permission. - API tokens are personal, capped by the owner's *current* rights (shrinking roles shrinks tokens; leaving the org revokes them) and cannot manage credentials, members or roles. - Invitations: link-based, 7 days, single use, bound to the invited email. The inviter must still be allowed to grant the role when the invitation is accepted. Invitees can create an account regardless of `UPTIME_SIGNUP`. - SSO auto-provisioning assigns a configurable default role (Viewer if unset). ## Organization policies - Require TOTP: password sessions need TOTP; SSO sessions rely on the IdP's MFA. - Require SSO: members must sign in through the org's IdP; the owner keeps a password fallback. - A policy cannot be switched on by someone whose own session would violate it. ## UI Members, Roles, API tokens and Organization settings pages; navigation follows permissions; a banner explains unmet policies. ## Testing `internal/api/permissions_test.go` covers delegation without escalation, tokens following their owner, policies, invitations and org isolation. Closes #6, #7, #8, #9, #41, #45 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Sebi added this to the M3 Permissions milestone 2026-11-21 23:50:19 +00:00
Sebi added 4 commits 2026-11-21 23:50:20 +00:00
Refs #6, #7

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Built-in roles are seeded with fixed ids and are read-only for every org.
Existing non-owner members receive the Viewer role.

Refs #6, #7, #8, #9

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Every org route resolves a principal from the session or a bearer token
and checks a permission. Nobody can grant, revoke or remove more than
they hold. Tokens are capped by their owner's current rights and cannot
manage credentials. Orgs can require TOTP or SSO; the owner keeps a
password fallback for SSO.

Closes #6
Closes #7
Closes #8
Closes #9
Closes #41
Closes #45

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Sebi added 2 commits 2026-11-21 23:55:28 +00:00
The built-in Admin role gains tokens.manage.

Refs #48

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Holders of tokens.manage list every token of the org with owner,
permissions, creation, expiry and last use, and can revoke any of them.
A maximum lifetime rejects tokens that would outlive it and shortens
existing ones when it is set.

Closes #48

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Sebi merged commit cc4da47a2b into main 2026-11-22 00:24:29 +00:00
Sebi deleted branch feat/m3-permissions 2026-11-22 00:24:31 +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#47