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:
1 parent
30409697f7
commit
d7d4821e3e
24 files changed
+4677
-439
No files matched your search
+13
-1
@@ -23,6 +23,9 @@ import (
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/web"
|
||||
)
|
||||
|
||||
// viewerRoleID is the built-in Viewer role seeded by migration 00009.
|
||||
var viewerRoleID = uuid.MustParse("00000000-0000-0000-0000-00000000a003")
|
||||
|
||||
const (
|
||||
ssoCookie = "__Host-sso"
|
||||
ssoFlowTTL = 10 * time.Minute
|
||||
@@ -262,7 +265,9 @@ func (s *Server) ssoCallback(c *gin.Context) {
|
||||
if locale == "" {
|
||||
locale = i18n.Lang(ctx)
|
||||
}
|
||||
sess, err := s.sessions.Create(ctx, userID, row.OrgID, locale)
|
||||
sess, err := s.sessions.Create(ctx, auth.NewSession{
|
||||
UserID: userID, OrgID: row.OrgID, Locale: locale, Method: auth.MethodSSO, SSOOrg: row.OrgID,
|
||||
})
|
||||
if err != nil {
|
||||
internalError(c, err)
|
||||
return
|
||||
@@ -322,6 +327,13 @@ func (s *Server) ssoResolveUser(ctx context.Context, row store.SsoProvider, cl s
|
||||
if err := q.AddMembership(ctx, store.AddMembershipParams{OrgID: row.OrgID, UserID: u.ID}); err != nil {
|
||||
return err
|
||||
}
|
||||
role := viewerRoleID
|
||||
if row.DefaultRoleID != nil {
|
||||
role = *row.DefaultRoleID
|
||||
}
|
||||
if _, err := q.CreateAssignment(ctx, store.CreateAssignmentParams{OrgID: row.OrgID, UserID: u.ID, RoleID: role}); err != nil {
|
||||
return err
|
||||
}
|
||||
userID = u.ID
|
||||
return q.CreateIdentity(ctx, store.CreateIdentityParams{ProviderID: row.ID, Subject: cl.Subject, OrgID: row.OrgID, UserID: u.ID, Email: nonEmpty(email)})
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user