feat(api): enforce roles, org sign-in policies, invitations and api tokens

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
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 00:49:35 +01:00
1 parent 30409697f7
commit d7d4821e3e
24 files changed
+4677 -439

No files matched your search

+28 -9
View File
@@ -12,7 +12,11 @@ type Me struct {
TOTP bool
ActiveOrg string
Orgs []Org
TOTPMissing bool
// Can holds the permissions in the active organization.
Can map[string]bool
// Policy is the error code of an unmet sign-in policy of the active
// organization, or empty.
Policy string
// RecoveryCodesLeft counts unused TOTP recovery codes.
RecoveryCodesLeft int
}
@@ -40,7 +44,15 @@ templ consoleShell(p Page, me Me) {
<span class="text-muted">{ me.Orgs[0].Name }</span>
}
<nav class="ml-auto flex items-center gap-5">
if me.IsOwner {
if me.Can["members.read"] {
<a href="/settings/members" class="text-muted hover:text-ink">{ i18n.T(ctx, "console.nav.members") }</a>
<a href="/settings/roles" class="text-muted hover:text-ink">{ i18n.T(ctx, "console.nav.roles") }</a>
}
if len(me.Orgs) > 0 {
<a href="/settings/tokens" class="text-muted hover:text-ink">{ i18n.T(ctx, "console.nav.tokens") }</a>
}
if me.Can["org.manage"] {
<a href="/settings/org" class="text-muted hover:text-ink">{ i18n.T(ctx, "console.nav.org") }</a>
<a href="/settings/sso" class="text-muted hover:text-ink">{ i18n.T(ctx, "console.nav.sso") }</a>
}
<a href="/settings/security" class="text-muted hover:text-ink">{ i18n.T(ctx, "console.nav.security") }</a>
@@ -49,13 +61,11 @@ templ consoleShell(p Page, me Me) {
</nav>
</div>
</header>
if me.TOTPMissing {
<div class="border-b border-degraded/40 bg-degraded/10">
<p class="mx-auto max-w-5xl px-6 py-2 text-sm">
{ i18n.T(ctx, "console.totp_missing") }
<a href="/settings/security" class="underline underline-offset-2">{ i18n.T(ctx, "console.totp_missing_action") }</a>
</p>
</div>
switch me.Policy {
case "totp_required_by_org":
@policyBanner("error.totp_required_by_org", "console.totp_missing_action", "/settings/security")
case "sso_required_by_org":
@policyBanner("error.sso_required_by_org", "console.sso_required_action", "/sso/"+me.ActiveSlug)
}
<main class="mx-auto max-w-5xl px-6 py-10">
@flash(p)
@@ -150,3 +160,12 @@ templ recoveryOutput() {
<a href="/settings/security" class="text-sm underline underline-offset-2">{ i18n.T(ctx, "security.recovery.saved") }</a>
</div>
}
templ policyBanner(msgID, actionID, href string) {
<div class="border-b border-degraded/40 bg-degraded/10">
<p class="mx-auto max-w-5xl px-6 py-2 text-sm">
{ i18n.T(ctx, msgID) }
<a href={ templ.SafeURL(href) } class="underline underline-offset-2">{ i18n.T(ctx, actionID) }</a>
</p>
</div>
}