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

+37 -8
View File
@@ -10,6 +10,8 @@ import (
"sort"
"strings"
"testing"
"git.zb-server.de/ZB-Server/uptimesebi/internal/authz"
)
func catalogKeys(t *testing.T) map[string]map[string]bool {
@@ -57,13 +59,19 @@ func TestCatalogsHaveSameKeys(t *testing.T) {
var usagePatterns = []struct {
re *regexp.Regexp
prefix string
// dir limits the pattern to files below this directory.
dir string
}{
{regexp.MustCompile(`i18n\.T\(ctx, "([a-z0-9_.]+)"[,)]`), ""},
{regexp.MustCompile(`\bfail\(c, [^,]+, "([a-z_]+)"`), "error."},
{regexp.MustCompile(`\b(?:pageFor\(c|s\.page\()(?:, )?"([a-z0-9_.]+)"`), ""},
{regexp.MustCompile(`[^(]"(sso_[a-z_]+)"`), "error."},
{regexp.MustCompile(`return "(invalid_[a-z_]+)"`), "error."},
{regexp.MustCompile(`NoticeID = "([a-z0-9_.]+)"`), ""},
{re: regexp.MustCompile(`i18n\.T\(ctx, "([a-z0-9_.]+)"[,)]`)},
{re: regexp.MustCompile(`\bfail\(c, [^,]+, "([a-z_]+)"`), prefix: "error."},
{re: regexp.MustCompile(`\b(?:pageFor\(c|s\.page\(|s\.orgPage\()(?:, )?"([a-z0-9_.]+)"`)},
{re: regexp.MustCompile(`[^(]"(sso_[a-z_]+)"`), prefix: "error.", dir: "api"},
{re: regexp.MustCompile(`return "(invalid_[a-z_]+)"`), prefix: "error."},
{re: regexp.MustCompile(`code = "([a-z_]+)"`), prefix: "error."},
{re: regexp.MustCompile(`NoticeID = "([a-z0-9_.]+)"`)},
{re: regexp.MustCompile(`@(?:settingsHeading|sectionHeading)\("([a-z0-9_.]+)"`)},
{re: regexp.MustCompile(`@settingsHeading\("[a-z0-9_.]+", "([a-z0-9_.]+)"`)},
{re: regexp.MustCompile(`@policyBanner\("([a-z0-9_.]+)", "([a-z0-9_.]+)"`)},
}
// TestUsedKeysExist scans the source tree for literal message IDs so a typo
@@ -86,9 +94,14 @@ func TestUsedKeysExist(t *testing.T) {
return err
}
for _, u := range usagePatterns {
if u.dir != "" && !strings.Contains(filepath.ToSlash(p), "/"+u.dir+"/") {
continue
}
for _, m := range u.re.FindAllStringSubmatch(string(src), -1) {
if id := u.prefix + m[1]; !en[id] {
missing = append(missing, p+": "+id)
for _, id := range m[1:] {
if id := u.prefix + id; !en[id] {
missing = append(missing, p+": "+id)
}
}
}
}
@@ -103,6 +116,22 @@ func TestUsedKeysExist(t *testing.T) {
}
}
// Permission and scope labels are looked up as "perm.<name>" and
// "scope.<type>".
func TestEveryPermissionHasALabel(t *testing.T) {
en := catalogKeys(t)["en"]
for _, p := range authz.All {
if !en["perm."+string(p)] {
t.Errorf("en.json is missing %q", "perm."+string(p))
}
}
for _, rt := range []authz.ResourceType{authz.MonitorGroup, authz.StatusPage} {
if !en["scope."+string(rt)] {
t.Errorf("en.json is missing %q", "scope."+string(rt))
}
}
}
// The language switcher builds "lang.<code>" dynamically.
func TestEveryLanguageHasAName(t *testing.T) {
c, err := Load()